def setUp(self):
        '''测试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)

        #跟随者登陆---------------------
        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)
Beispiel #2
0
 def setUp(self):
     '''测试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)
    def setUpClass(self):
        '''测试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)
        self.account = '500383690'
        self.brokerID = 106
        self.symbol = 'AUDCAD'
        self.cmd = 1
        self.lots = 0.1
Beispiel #4
0
    def setUp(self):
        '''多个Sam跟随下单'''
        #跟随者登录
        datas = {
            "account": userData['wfollowAccount'],
            "password": userData['wfollowpasswd'],
            "remember": "false"
        }
        loginRes = Auth.signin(
            userData['hostName'] + userDataAuth['signin_url'],
            userData['headers'], datas)
        self.assertEqual(loginRes.status_code, userData['status_code_200'])
        self.token = json.loads(loginRes.text)['data']['token']

        # 交易员登录
        datas = {
            "account": userData['waccount'],
            "password": userData['wpasswd'],
            "remember": "false"
        }
        traderLoginRes = Auth.signin(
            userData['hostName'] + userDataAuth['signin_url'],
            userData['headers'], datas)
        self.assertEqual(traderLoginRes.status_code,
                         userData['status_code_200'])
        self.traderToken = json.loads(traderLoginRes.text)['data']['token']
        self.traderUserId = json.loads(traderLoginRes.text)['data']['id']
        self.traderNickname = json.loads(
            traderLoginRes.text)['data']['nickname']

        # 连接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))
        self.stub = mt4api_pb2_grpc.MT4APISrvStub(channel)
    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)
Beispiel #6
0
                varList.readRes = next(input_stream)

        thread = threading.Thread(target=read_incoming)
        thread.start()
        time.sleep(waitTime)
        try:
            print("<--- 【closePosition response】:", varList.readRes)
            return varList.readRes
        except:
            print("Error.....")


if __name__ == '__main__':
    '''测试Sam经纪商开仓,平仓,历史订单'''
    backTestingChannel = grpc.insecure_channel('10.1.0.8' + ':' + str(36217))
    stub = mt4api_pb2_grpc.MT4APISrvStub(backTestingChannel)
    account = '500383690'
    brokerID = 106
    symbol = 'AUDCAD'
    cmd = 1
    lots = 0.1

    res = TradeSAMStream.OpenPosition(stub=stub,
                                      account=account,
                                      brokerID=brokerID,
                                      symbol=symbol,
                                      cmd=cmd,
                                      lots=lots)
    print(res)

    res1 = TradeSAMStream.subscribeMT4API(stub=stub,