def setUp(self):
        #交易员登陆---------------------
        tradeDatas = {"account":webAPIData['account'], "password":webAPIData['passwd'], "remember":"false"}
        tradeSignin = Auth.signin(webAPIData['hostName'] + authData['signin_url'], webAPIData['headers'], tradeDatas)
        #登录成功,返回200 ok
        self.assertEqual(tradeSignin.status_code, webAPIData['status_code_200'])
        #保存账号的nickName,待获取userID使用
        self.tradeNickName = json.loads(tradeSignin.text)['data']['nickname']
        # #保存登录时的token,待登出使用
        self.tradeUserToken = json.loads(tradeSignin.text)['data']['token']
        #保存userID
        self.tradeUserID = json.loads(tradeSignin.text)['data']['id']
        #规整headers
        self.tradeHeaders = dict(webAPIData['headers'], **{webAPIData['Authorization'] : webAPIData['Bearer'] + self.tradeUserToken})
        #获取指定经纪商的accountIndex。当前为:pcio
        self.tradePicoAccountIndex = Account.getSpecialAccountIndex(headers = self.tradeHeaders, brokerID=riskControlData["testBrokerID"])[0]
        self.switchTradeAccount = Account.switchAccount(webAPIData['hostName'] + accountData['switchAccount'], self.tradeHeaders, index=self.tradePicoAccountIndex)
        #账号切换成功
        self.assertEqual(self.switchTradeAccount.status_code, webAPIData['status_code_200'])
        #获取交易员交易token
        self.tradeToken = Account.getToken(self.tradeHeaders, onlyTokn="true", printLogs=1)
        
        #跟随者登陆---------------------
        followDatas = {"account":webAPIData['followAccount'], "password":webAPIData['followPasswd'], "remember":"false"}
        followSignin = Auth.signin(webAPIData['hostName'] + authData['signin_url'], webAPIData['headers'], followDatas)
        #登录成功,返回200 ok
        self.assertEqual(followSignin.status_code, webAPIData['status_code_200'])
        # #保存登录时的token,待登出使用
        self.followUserToken = json.loads(followSignin.text)['data']['token']
        #规整headers
        self.followHeaders = dict(webAPIData['headers'], **{webAPIData['Authorization'] : webAPIData['Bearer'] + self.followUserToken})
        #获取指定经纪商的accountIndex。当前为:pcio
        self.followPicoAccountIndex = Account.getSpecialAccountIndex(headers = self.followHeaders, brokerID=riskControlData["testBrokerID"])[0]
        self.switchFollowAccount = Account.switchAccount(webAPIData['hostName'] + accountData['switchAccount'], self.followHeaders, index=self.followPicoAccountIndex)
        #账号切换成功
        self.assertEqual(self.switchFollowAccount.status_code, webAPIData['status_code_200'])
        #获取跟随者交易token
        self.followToken = Account.getToken(self.followHeaders, onlyTokn="true", printLogs=1)

        #一倍建立跟随
        self.tradeIndex = str(self.tradeUserID) + '_' + self.tradePicoAccountIndex
        #设置跟随策略
        followDatas = {"accountIndex": self.followPicoAccountIndex, webAPIData['followStrategy']: webAPIData['follow_ratio'], 
        webAPIData['follow_setting']: 1, webAPIData['followDirection']: webAPIData['follow_positive']}
        createFollow = FollowManage.createFollow(webAPIData['hostName'] + followData['createFollow_url'] + self.tradeIndex, headers = self.followHeaders, datas =followDatas, interfaceName="createFollow")
        #断言跟随成功
        self.assertEqual(createFollow.status_code, webAPIData['status_code_200'])

        #设置全局风控参数。关闭风控信号
        globalRiskControlData = {webAPIData['signalSwitch']: webAPIData['signalSwitch_close']}
        setRiskControl = RiskControl.setRiskControl(webAPIData['hostName'] + riskControlData['setRiskControl_url'], accountIndex=self.followPicoAccountIndex, headers = self.followHeaders, datas=globalRiskControlData)
        self.assertEqual(setRiskControl.status_code, webAPIData['status_code_200'])

        #设置针对单个交易员的风控参数。初始为默认值
        specialTradeDatas = { "accountIndex": self.followPicoAccountIndex}
        setRiskControlForTrader = RiskControl.setRiskControlForTrader(webAPIData['hostName'] + riskControlData['setRiskControlForTrader_url'] + self.tradeIndex, headers=self.followHeaders, datas=specialTradeDatas, interfaceName="setRiskControlForTrader")
        self.assertEqual(setRiskControlForTrader.status_code, webAPIData['status_code_200'])
    def tearDown(self):
        #清空测试环境,还原测试数据
        #清除所有测试订单,如果有
        '''获取交易员的所有交易订单,并平掉'''
        tradeOrderParams = {webAPIData['orderStatus']:webAPIData['orderStatus_open']}
        getTradeOrders = Order.getOrders(webAPIData['hostName'] + orderData['getOrders_url'], self.tradeHeaders, params=tradeOrderParams)
        #获取订单成功,返回200 ok
        self.assertEqual(getTradeOrders.status_code, webAPIData['status_code_200'])
        tradeOrdersIDList = Order.getOrdersID(getTradeOrders)
        #平掉当前用户所有订单,如果有
        # #web sockets批量平仓
        closeParam = { tradeOnlineData['orderParam_code']: tradeOnlineData['ws_code_219'], tradeOnlineData['orderParam_tickets']: tradeOrdersIDList }
        closePositionRes = TradeOnline.OnlineTradeEvent.tradeEvent(self, tradeOnlineData['ws_host'], tradeOnlineData['ws_port'], {'token': self.tradeToken}, closeParam)
        #校验code等于0,为及时单平仓成功
        self.assertEqual(closePositionRes["code"], tradeOnlineData['ws_code_0'])

        '''获取跟随者的所有交易订单,并平掉'''
        followOrderParams = {webAPIData['orderStatus']:webAPIData['orderStatus_open']}
        getFollowOrders = Order.getOrders(webAPIData['hostName'] + orderData['getOrders_url'], self.followHeaders, params=followOrderParams)
        #获取订单成功,返回200 ok
        self.assertEqual(getFollowOrders.status_code, webAPIData['status_code_200'])
        followOrdersIDList = Order.getOrdersID(getFollowOrders)
        #平掉当前用户所有订单,如果有
        # #web sockets批量平仓
        closeParam = { tradeOnlineData['orderParam_code']: tradeOnlineData['ws_code_219'], tradeOnlineData['orderParam_tickets']: followOrdersIDList }
        closePositionRes = TradeOnline.OnlineTradeEvent.tradeEvent(self, tradeOnlineData['ws_host'], tradeOnlineData['ws_port'], {'token': self.followToken}, closeParam)
        #校验code等于0,为及时单平仓成功
        self.assertEqual(closePositionRes["code"], tradeOnlineData['ws_code_0'])

        #还原风控参数
        #设置全局风控参数。打开风控信号
        globalRiskControlData = {webAPIData['signalSwitch']: webAPIData['signalSwitch_open']}
        setRiskControl = RiskControl.setRiskControl(webAPIData['hostName'] + riskControlData['setRiskControl_url'], accountIndex=self.followPicoAccountIndex, headers = self.followHeaders, datas=globalRiskControlData)
        self.assertEqual(setRiskControl.status_code, webAPIData['status_code_200'])
        #设置针对单个交易员的风控参数。初始为默认值
        specialTradeDatas = { "accountIndex": self.followPicoAccountIndex}
        setRiskControlForTrader = RiskControl.setRiskControlForTrader(webAPIData['hostName'] + riskControlData['setRiskControlForTrader_url'] + self.tradeIndex, headers=self.followHeaders, datas=specialTradeDatas, interfaceName="setRiskControlForTrader")
        self.assertEqual(setRiskControlForTrader.status_code, webAPIData['status_code_200'])
        #还原针对单个交易员的风控品种参数。
        symbolList = [{webAPIData['Symbol']: tradeOnlineData["fm_EURCAD"], webAPIData['FollowType']: 1, webAPIData['StrategyType']: 2, webAPIData['Direction']: 2, 
        webAPIData['FollowSize']: 1, webAPIData['Locked']: False }]
        specialTradeDatas1 = { "accountIndex": int(self.followPicoAccountIndex), webAPIData['symbolList']: symbolList}
        setRiskControlForTrader1 = RiskControl.setRiskControlForTraderSymbols(webAPIData['hostName'] + riskControlData['setRiskControlForTraderSymbols_url'] + self.tradeIndex, headers=self.followHeaders, datas=specialTradeDatas1, interfaceName="setRiskControlForTraderSymbols")
        self.assertEqual(setRiskControlForTrader1.status_code, webAPIData['status_code_200'])

        # 取消跟随关系
        deleteFollow = FollowManage.deleteFollow(webAPIData['hostName'] + followData['deleteFollow_url'] + self.tradeIndex, headers = self.followHeaders, accountIndex=self.followPicoAccountIndex)
        self.assertEqual(deleteFollow.status_code, webAPIData['status_code_200'])

        #登出followme系统
        tradeSignout = Auth.signout(webAPIData['hostName'] + authData['signout_url'], datas = self.tradeHeaders)
        self.assertEqual(tradeSignout.status_code, webAPIData['status_code_200'])
        followSignout = Auth.signout(webAPIData['hostName'] + authData['signout_url'], datas = self.followHeaders)
        self.assertEqual(followSignout.status_code, webAPIData['status_code_200'])
    def tearDown(self):
        #清空测试环境,还原测试数据
        #清除所有测试订单,如果有
        #还原风控参数
        #设置全局风控参数。关闭风控信号
        globalRiskControlData = {
            webAPIData['signalSwitch']: webAPIData['signalSwitch_open']
        }
        setRiskControl = RiskControl.setRiskControl(
            webAPIData['hostName'] + riskControlData['setRiskControl_url'],
            accountIndex=self.followPicoAccountIndex,
            headers=self.followHeaders,
            datas=globalRiskControlData)
        self.assertEqual(setRiskControl.status_code,
                         webAPIData['status_code_200'])
        #设置针对单个交易员的风控参数。初始为默认值
        specialTradeDatas = {"accountIndex": self.followPicoAccountIndex}
        setRiskControlForTrader = RiskControl.setRiskControlForTrader(
            webAPIData['hostName'] +
            riskControlData['setRiskControlForTrader_url'] + self.tradeIndex,
            headers=self.followHeaders,
            datas=specialTradeDatas,
            interfaceName="setRiskControlForTrader")
        self.assertEqual(setRiskControlForTrader.status_code,
                         webAPIData['status_code_200'])

        # 取消跟随关系
        deleteFollow = FollowManage.deleteFollow(
            webAPIData['hostName'] + followData['deleteFollow_url'] +
            self.tradeIndex,
            headers=self.followHeaders,
            accountIndex=self.followPicoAccountIndex)
        self.assertEqual(deleteFollow.status_code,
                         webAPIData['status_code_200'])

        #登出followme系统
        tradeSignout = Auth.signout(webAPIData['hostName'] +
                                    authData['signout_url'],
                                    datas=self.tradeHeaders)
        self.assertEqual(tradeSignout.status_code,
                         webAPIData['status_code_200'])
        followSignout = Auth.signout(webAPIData['hostName'] +
                                     authData['signout_url'],
                                     datas=self.followHeaders)
        self.assertEqual(followSignout.status_code,
                         webAPIData['status_code_200'])
Exemple #4
0
    def test_disableFollowPeriods_currTime(self):
        '''当前时间点清空时间保护设置,交易员下单。检查跟随者跟单情况(可以跟上)'''
        #设置针对单个交易员的风控参数。当前小时为时间保护,不交易
        currWeek = FMCommon.getCurrWeek()  #获取当前为周几
        currHour = FMCommon.getCurrHour()  #获取当前时间为几点
        specialTradeDatas = {"accountIndex": self.followPicoAccountIndex}
        setRiskControlForTrader = RiskControl.setRiskControlForTrader(
            webAPIData['hostName'] +
            riskControlData['setRiskControlForTrader_url'] + self.tradeIndex,
            headers=self.followHeaders,
            datas=specialTradeDatas,
            interfaceName="setRiskControlForTrader")
        self.assertEqual(setRiskControlForTrader.status_code,
                         webAPIData['status_code_200'])

        #下单时的手数为实际值除以100
        openParam = {
            tradeOnlineData['orderParam_code']: tradeOnlineData['ws_code_210'],
            tradeOnlineData['orderParam_symbol']:
            tradeOnlineData['broker_EURCAD'],
            tradeOnlineData['orderParam_volume']: 300
        }
        openPositionRes = TradeOnline.OnlineTradeEvent.tradeEvent(
            self, tradeOnlineData['ws_host'], tradeOnlineData['ws_port'],
            {'token': self.tradeToken}, openParam)
        #校验code等于0,为及时单开仓成功
        self.assertEqual(openPositionRes["code"], tradeOnlineData['ws_code_0'])
        #校验手数为下单时的手数为实际值除以100(300/100)
        self.assertEqual(openPositionRes["order"]["volume"], 300)
        #保存orderID,待开仓使用
        self.orderID = openPositionRes["order"]["order_id"]

        #获取跟随者订单信息
        followOrderParams = {
            webAPIData['orderStatus']: webAPIData['orderStatus_open']
        }
        getFollowOrder = Order.getOrders(webAPIData['hostName'] +
                                         orderData['getOrders_url'],
                                         headers=self.followHeaders,
                                         params=followOrderParams)
        #断言获取跟随订单成功
        self.assertEqual(getFollowOrder.status_code,
                         webAPIData['status_code_200'])
        #断言跟随者订单跟随的品种为:EURCAD
        self.assertEqual(
            json.loads(getFollowOrder.text)['data']['items'][0]['SYMBOL'],
            tradeOnlineData['broker_EURCAD'])
        #断言跟随者订单跟随的手数为:0.1手
        self.assertEqual(
            float(
                json.loads(getFollowOrder.text)['data']['items'][0]['VOLUME']),
            3)

        #平掉测试订单
        closeParam = {
            tradeOnlineData['orderParam_code']: tradeOnlineData['ws_code_211'],
            tradeOnlineData['orderParam_ticket']: self.orderID,
            tradeOnlineData['orderParam_volume']: 300
        }
        closePositionRes = TradeOnline.OnlineTradeEvent.tradeEvent(
            self, tradeOnlineData['ws_host'], tradeOnlineData['ws_port'],
            {'token': self.tradeToken}, closeParam)
        #校验code等于0,为及时单平仓成功
        self.assertEqual(closePositionRes["code"],
                         tradeOnlineData['ws_code_0'])
        #校验rcmd等于210,为及时单开仓
        self.assertEqual(closePositionRes["rcmd"],
                         tradeOnlineData['ws_code_211'])
        #校验平掉的单号,为本测试及时单开仓的单号
        self.assertEqual(closePositionRes['order']["order_id"], self.orderID)
    def setUp(self):
        #交易员登陆---------------------
        tradeDatas = {
            "account": webAPIData['account'],
            "password": webAPIData['passwd'],
            "remember": "false"
        }
        tradeSignin = Auth.signin(
            webAPIData['hostName'] + authData['signin_url'],
            webAPIData['headers'], tradeDatas)
        #登录成功,返回200 ok
        self.assertEqual(tradeSignin.status_code,
                         webAPIData['status_code_200'])
        #保存账号的nickName,待获取userID使用
        self.tradeNickName = json.loads(tradeSignin.text)['data']['nickname']
        # #保存登录时的token,待登出使用
        self.tradeUserToken = json.loads(tradeSignin.text)['data']['token']
        #保存userID
        self.tradeUserID = json.loads(tradeSignin.text)['data']['id']
        #规整headers
        self.tradeHeaders = dict(
            webAPIData['headers'], **{
                webAPIData['Authorization']:
                webAPIData['Bearer'] + self.tradeUserToken
            })
        #获取指定经纪商的accountIndex。当前为:pcio
        self.tradePicoAccountIndex = Account.getSpecialAccountIndex(
            headers=self.tradeHeaders, accountType=2, brokerID=106)[4]
        self.switchTradeAccount = Account.switchAccount(
            webAPIData['hostName'] + accountData['switchAccount'],
            self.tradeHeaders,
            index=self.tradePicoAccountIndex)
        #账号切换成功
        self.assertEqual(self.switchTradeAccount.status_code,
                         webAPIData['status_code_200'])
        #获取交易员交易token
        self.tradeToken = Account.getToken(self.tradeHeaders,
                                           onlyTokn="true",
                                           printLogs=1)
        tokenRes = Account.getToken(self.tradeHeaders, printLogs=0)
        self.tradeMt4Account = json.loads(
            tokenRes.content)["data"]["MT4Account"]
        self.tradeBrokerID = json.loads(tokenRes.content)["data"]["BrokerId"]

        #跟随者登陆---------------------
        followDatas = {
            "account": webAPIData['followAccount'],
            "password": webAPIData['followPasswd'],
            "remember": "false"
        }
        followSignin = Auth.signin(
            webAPIData['hostName'] + authData['signin_url'],
            webAPIData['headers'], followDatas)
        #登录成功,返回200 ok
        self.assertEqual(followSignin.status_code,
                         webAPIData['status_code_200'])
        #保存账号的nickName
        self.followNickName = json.loads(followSignin.text)['data']['nickname']
        # #保存登录时的token,待登出使用
        self.followUserToken = json.loads(followSignin.text)['data']['token']
        #规整headers
        self.followHeaders = dict(
            webAPIData['headers'], **{
                webAPIData['Authorization']:
                webAPIData['Bearer'] + self.followUserToken
            })
        #获取指定经纪商的accountIndex。当前为:pcio
        self.followPicoAccountIndex = Account.getSpecialAccountIndex(
            headers=self.followHeaders,
            brokerID=riskControlData["testBrokerID"])[0]
        self.switchFollowAccount = Account.switchAccount(
            webAPIData['hostName'] + accountData['switchAccount'],
            self.followHeaders,
            index=self.followPicoAccountIndex)
        #账号切换成功
        self.assertEqual(self.switchFollowAccount.status_code,
                         webAPIData['status_code_200'])
        #获取跟随者交易token
        self.followToken = Account.getToken(self.followHeaders,
                                            onlyTokn="true",
                                            printLogs=1)

        #一倍建立跟随
        self.tradeIndex = str(
            self.tradeUserID) + '_' + self.tradePicoAccountIndex
        #设置跟随策略
        followDatas = {
            "accountIndex": self.followPicoAccountIndex,
            webAPIData['followStrategy']: webAPIData['follow_ratio'],
            webAPIData['follow_setting']: 1,
            webAPIData['followDirection']: webAPIData['follow_positive']
        }
        createFollow = FollowManage.createFollow(
            webAPIData['hostName'] + followData['createFollow_url'] +
            self.tradeIndex,
            headers=self.followHeaders,
            datas=followDatas,
            interfaceName="createFollow")
        #断言跟随成功
        self.assertEqual(createFollow.status_code,
                         webAPIData['status_code_200'])

        #设置全局风控参数。账号最大持仓为:3
        globalRiskControlData = {
            webAPIData['signalSwitch']: webAPIData['signalSwitch_open'],
            webAPIData['maxPositionLots']: 3
        }
        setRiskControl = RiskControl.setRiskControl(
            webAPIData['hostName'] + riskControlData['setRiskControl_url'],
            accountIndex=self.followPicoAccountIndex,
            headers=self.followHeaders,
            datas=globalRiskControlData)
        self.assertEqual(setRiskControl.status_code,
                         webAPIData['status_code_200'])

        #设置针对单个交易员的风控参数。初始为默认值
        specialTradeDatas = {"accountIndex": self.followPicoAccountIndex}
        setRiskControlForTrader = RiskControl.setRiskControlForTrader(
            webAPIData['hostName'] +
            riskControlData['setRiskControlForTrader_url'] + self.tradeIndex,
            headers=self.followHeaders,
            datas=specialTradeDatas,
            interfaceName="setRiskControlForTrader")
        self.assertEqual(setRiskControlForTrader.status_code,
                         webAPIData['status_code_200'])

        #
        '''测试Sam经纪商开仓,平仓,历史订单'''
        host = FMCommon.consul_operater(host=commonConf['consulHost'],
                                        port=commonConf['consulPort'],
                                        server='followme.srv.mt4api.3',
                                        key='ServiceAddress')
        port = FMCommon.consul_operater(host=commonConf['consulHost'],
                                        port=commonConf['consulPort'],
                                        server='followme.srv.mt4api.3',
                                        key='ServicePort')
        channel = grpc.insecure_channel(host + ':' + str(port))
        print(channel, host + ':' + str(port))
        self.stub = mt4api_pb2_grpc.MT4APISrvStub(channel)
Exemple #6
0
        def myThread(account):
            #交易员登陆---------------------
            tradeDatas = {
                "account": account,
                "password": webAPIData['passwd'],
                "remember": "false"
            }
            tradeSignin = Auth.signin(
                webAPIData['hostName'] + authData['signin_url'],
                webAPIData['headers'], tradeDatas)
            #登录成功,返回200 ok
            self.assertEqual(tradeSignin.status_code,
                             webAPIData['status_code_200'])
            #保存账号的nickName,待获取userID使用
            self.tradeNickName = json.loads(
                tradeSignin.text)['data']['nickname']
            # #保存登录时的token,待登出使用
            self.tradeUserToken = json.loads(tradeSignin.text)['data']['token']
            #保存userID
            self.tradeUserID = json.loads(tradeSignin.text)['data']['id']
            #规整headers
            self.tradeHeaders = dict(
                webAPIData['headers'], **{
                    webAPIData['Authorization']:
                    webAPIData['Bearer'] + self.tradeUserToken
                })
            #获取指定经纪商的accountIndex。当前为:pcio
            self.tradePicoAccountIndex = Account.getSpecialAccountIndex(
                headers=self.tradeHeaders, accountType=2, brokerID=106)[0]
            self.switchTradeAccount = Account.switchAccount(
                webAPIData['hostName'] + accountData['switchAccount'],
                self.tradeHeaders,
                index=self.tradePicoAccountIndex)
            #账号切换成功
            self.assertEqual(self.switchTradeAccount.status_code,
                             webAPIData['status_code_200'])
            #获取交易员交易token
            self.tradeToken = Account.getToken(self.tradeHeaders,
                                               onlyTokn="true",
                                               printLogs=1)
            tokenRes = Account.getToken(self.tradeHeaders, printLogs=0)
            self.tradeMt4Account = json.loads(
                tokenRes.content)["data"]["MT4Account"]
            self.tradeBrokerID = json.loads(
                tokenRes.content)["data"]["BrokerId"]

            #一倍建立跟随
            self.tradeIndex = str(
                self.tradeUserID) + '_' + self.tradePicoAccountIndex
            #设置跟随策略
            followDatas = {
                "accountIndex": self.followPicoAccountIndex,
                webAPIData['followStrategy']: webAPIData['follow_ratio'],
                webAPIData['follow_setting']: 1,
                webAPIData['followDirection']: webAPIData['follow_positive']
            }
            createFollow = FollowManage.createFollow(
                webAPIData['hostName'] + followData['createFollow_url'] +
                self.tradeIndex,
                headers=self.followHeaders,
                datas=followDatas,
                interfaceName="createFollow")
            print(createFollow.text)
            #断言跟随成功
            self.assertEqual(createFollow.status_code,
                             webAPIData['status_code_200'])

            #设置全局风控参数。账号最大持仓为:3
            globalRiskControlData = {
                webAPIData['signalSwitch']: webAPIData['signalSwitch_open'],
                webAPIData['maxPositionLots']: 3
            }
            setRiskControl = RiskControl.setRiskControl(
                webAPIData['hostName'] + riskControlData['setRiskControl_url'],
                accountIndex=self.followPicoAccountIndex,
                headers=self.followHeaders,
                datas=globalRiskControlData)
            self.assertEqual(setRiskControl.status_code,
                             webAPIData['status_code_200'])

            #设置针对单个交易员的风控参数。初始为默认值
            specialTradeDatas = {"accountIndex": self.followPicoAccountIndex}
            setRiskControlForTrader = RiskControl.setRiskControlForTrader(
                webAPIData['hostName'] +
                riskControlData['setRiskControlForTrader_url'] +
                self.tradeIndex,
                headers=self.followHeaders,
                datas=specialTradeDatas,
                interfaceName="setRiskControlForTrader")
            self.assertEqual(setRiskControlForTrader.status_code,
                             webAPIData['status_code_200'])

            print(datetime.datetime.now(), i, self.tradeMt4Account,
                  self.tradeBrokerID)

            client = TradeSAM.TradeSAMStream
            print("curr time:", datetime.datetime.now())
            '''sam 开仓'''
            openRes = client.OpenPosition(
                stub=self.stub,
                account=self.tradeMt4Account,
                brokerID=self.tradeBrokerID,
                symbol=tradeOnlineData['broker_EURCAD'],
                cmd=1,
                lots=0.2)
            self.tradeID = openRes.Signal.TradeID
            self.assertEqual(openRes.Signal.Symbol,
                             tradeOnlineData['broker_EURCAD'])
            self.assertEqual(openRes.Signal.Lots, 0.2)
            # 平仓
            closeRes = TradeSAM.TradeSAMStream.ClosePosition(
                stub=self.stub,
                account=self.tradeMt4Account,
                brokerID=self.tradeBrokerID,
                tradeID=self.tradeID,
                lots=0.2)
            self.assertEqual(closeRes.Signal.TradeID, self.tradeID)
            self.assertEqual(closeRes.Signal.Symbol,
                             tradeOnlineData['broker_EURCAD'])