diff --git a/examples/CryptoTrader/BITMEX_connect.json b/examples/CryptoTrader/BITMEX_connect.json index 4aef1612..baeb638b 100644 --- a/examples/CryptoTrader/BITMEX_connect.json +++ b/examples/CryptoTrader/BITMEX_connect.json @@ -1,6 +1,6 @@ { - "apiKey": "", - "apiSecret": "", + "apiKey": "dVOUiqMzayJSW8gCGax_zWpy", + "apiSecret": "dTh0NWAvGA3h9YczL90R1MGxGc_BZtG05EJ3MoiMYRvtS5mL", "sessionCount": 3, "symbols": ["XBTUSD", "EOSM18", "XRPM18"] } \ No newline at end of file diff --git a/vnpy/trader/gateway/bigoneGateway/bigoneGateway.py b/vnpy/trader/gateway/bigoneGateway/bigoneGateway.py index bc7d3b6c..dad9d2e6 100644 --- a/vnpy/trader/gateway/bigoneGateway/bigoneGateway.py +++ b/vnpy/trader/gateway/bigoneGateway/bigoneGateway.py @@ -105,7 +105,7 @@ class BigoneGateway(VtGateway): # 需要循环的查询函数列表 self.qryFunctionList = [self.restApi.qryTickers, self.restApi.qryDepth, - self.restApi.qryPosition, + self.restApi.qryAccount, self.restApi.qryOrder] self.qryCount = 0 # 查询触发倒计时 @@ -266,9 +266,9 @@ class RestApi(BigoneRestApi): self.addReq('GET', '/viewer/orders', self.onQryOrder, params=req) #---------------------------------------------------------------------- - def qryPosition(self): + def qryAccount(self): """""" - self.addReq('GET', '/viewer/accounts', self.onQryPosition) + self.addReq('GET', '/viewer/accounts', self.onQryAccount) #---------------------------------------------------------------------- def onSendOrder(self, data, reqid): @@ -383,24 +383,21 @@ class RestApi(BigoneRestApi): self.gateway.onTrade(trade) #---------------------------------------------------------------------- - def onQryPosition(self, data, reqid): + def onQryAccount(self, data, reqid): """""" - if self.checkError(u'查询持仓', data): + if self.checkError(u'查询资金', data): return for d in data['data']: - pos = VtPositionData() - pos.gatewayName = self.gatewayName + account = VtAccountData() + account.gatewayName = self.gatewayName - pos.symbol = d['asset_id'] - pos.exchange = EXCHANGE_BIGONE - pos.vtSymbol = '.'.join([pos.symbol, pos.exchange]) - pos.direction = DIRECTION_NET - pos.vtPositionName = '.'.join([pos.vtSymbol, pos.direction]) - pos.position = float(d['balance']) - pos.frozen = float(d['locked_balance']) + account.accountID = d['asset_id'] + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + account.balance = float(d['balance']) + account.available = account.balance - float(d['locked_balance']) - self.gateway.onPosition(pos) + self.gateway.onAccount(account) #---------------------------------------------------------------------- def onQryContract(self, data, reqid): diff --git a/vnpy/trader/gateway/binanceGateway/binanceGateway.py b/vnpy/trader/gateway/binanceGateway/binanceGateway.py index 64fd6a5d..d133021f 100644 --- a/vnpy/trader/gateway/binanceGateway/binanceGateway.py +++ b/vnpy/trader/gateway/binanceGateway/binanceGateway.py @@ -285,17 +285,15 @@ class GatewayApi(BinanceApi): free = float(d['free']) locked = float(d['locked']) - if free or locked: - pos = VtPositionData() - pos.gatewayName = self.gatewayName - pos.symbol = d['asset'] - pos.exchange = EXCHANGE_BINANCE - pos.vtSymbol = '.'.join([pos.vtSymbol, pos.direction]) - pos.direction = DIRECTION_LONG - pos.vtPositionName = '.'.join([pos.symbol, pos.direction]) - pos.frozen = locked - pos.position = free + locked - self.gateway.onPosition(pos) + account = VtAccountData() + account.gatewayName = self.gatewayName + + account.accountID = d['asset'] + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + account.balance = free + locked + account.available = free + + self.gateway.onAccount(account) #---------------------------------------------------------------------- def onQueryMyTrades(self, data, reqid): @@ -334,18 +332,16 @@ class GatewayApi(BinanceApi): free = float(d['f']) locked = float(d['l']) - if free or locked: - pos = VtPositionData() - pos.gatewayName = self.gatewayName - pos.symbol = d['a'] - pos.exchange = EXCHANGE_BINANCE - pos.vtSymbol = '.'.join([pos.vtSymbol, pos.direction]) - pos.direction = DIRECTION_LONG - pos.vtPositionName = '.'.join([pos.symbol, pos.direction]) - pos.frozen = locked - pos.position = free + locked - self.gateway.onPosition(pos) - + account = VtAccountData() + account.gatewayName = self.gatewayName + + account.accountID = d['a'] + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + account.balance = free + locked + account.available = free + + self.gateway.onAccount(account) + #---------------------------------------------------------------------- def onPushOrder(self, d): """""" diff --git a/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py b/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py index 3dfc320f..46947cd9 100644 --- a/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py +++ b/vnpy/trader/gateway/bitfinexGateway/bitfinexGateway.py @@ -459,23 +459,15 @@ class GatewayApi(BitfinexApi): def onWallet(self, data): """""" if str(data[0]) == 'exchange': - pos = VtPositionData() - pos.gatewayName = self.gatewayName + account = VtAccountData() + account.gatewayName = self.gatewayName - pos.symbol = str(data[1]) - pos.exchange = EXCHANGE_BITFINEX - pos.vtSymbol = '.'.join([pos.vtSymbol, pos.direction]) - pos.direction = DIRECTION_LONG - pos.vtPositionName = '.'.join([pos.vtSymbol, pos.direction]) - pos.position = float(data[2]) + account.accountID = str(data[1]) + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + account.balance = float(data[2]) + account.available = float(data[-1]) - if data[-1] is None: - pos.frozen = 0 - else: - pos.frozen = pos.position - float(data[-1]) - - self.currencys.append(pos.symbol) - self.gateway.onPosition(pos) + self.gateway.onAccount(account) #---------------------------------------------------------------------- def onOrder(self, data): diff --git a/vnpy/trader/gateway/fcoinGateway/fcoinGateway.py b/vnpy/trader/gateway/fcoinGateway/fcoinGateway.py index 637b49e6..33a002ad 100644 --- a/vnpy/trader/gateway/fcoinGateway/fcoinGateway.py +++ b/vnpy/trader/gateway/fcoinGateway/fcoinGateway.py @@ -405,18 +405,15 @@ class RestApi(FcoinRestApi): def onQryPosition(self, data, reqid): """""" for d in data['data']: - pos = VtPositionData() - pos.gatewayName = self.gatewayName + account = VtAccountData() + account.gatewayName = self.gatewayName - pos.symbol = d['currency'] - pos.exchange = EXCHANGE_FCOIN - pos.vtSymbol = '.'.join([pos.symbol, pos.exchange]) - pos.direction = DIRECTION_NET - pos.vtPositionName = '.'.join([pos.vtSymbol, pos.direction]) - pos.position = d['balance'] - pos.frozen = d['frozen'] + account.accountID = d['currency'] + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + account.balance = float(d['balance']) + account.available = account.balance - float(d['frozen']) - self.gateway.onPosition(pos) + self.gateway.onAccount(account) #---------------------------------------------------------------------- def onQryContract(self, data, reqid): diff --git a/vnpy/trader/gateway/huobiGateway/huobiGateway.py b/vnpy/trader/gateway/huobiGateway/huobiGateway.py index 7a0c837f..758bb7de 100644 --- a/vnpy/trader/gateway/huobiGateway/huobiGateway.py +++ b/vnpy/trader/gateway/huobiGateway/huobiGateway.py @@ -504,30 +504,26 @@ class HuobiTradeApi(TradeApi): #---------------------------------------------------------------------- def onGetAccountBalance(self, data, reqid): """查询余额回调""" - posDict = {} - + accountDict = {} + for d in data['list']: - symbol = d['currency'] - pos = posDict.get(symbol, None) + currency = d['currency'] + account = accountDict.get(currency, None) - if not pos: - pos = VtPositionData() - pos.gatewayName = self.gatewayName - pos.symbol = d['currency'] - pos.exchange = EXCHANGE_HUOBI - pos.vtSymbol = '.'.join([pos.symbol, pos.exchange]) - pos.direction = DIRECTION_LONG - pos.vtPositionName = '.'.join([pos.vtSymbol, pos.direction]) - - pos.position += float(d['balance']) + if not account: + account = VtAccountData() + account.gatewayName = self.gatewayName + account.accountID = d['currency'] + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + + accountDict[currency] = account + + account.balance += float(d['balance']) if d['type'] == 'fozen': - pos.frozen = float(d['balance']) + account.available = account.balance - float(d['balance']) - posDict[symbol] = pos - - for pos in posDict.values(): - if pos.position: - self.gateway.onPosition(pos) + for account in accountDict.values(): + self.gateway.onAccount(account) #---------------------------------------------------------------------- def onGetOrders(self, data, reqid): diff --git a/vnpy/trader/gateway/okexGateway/okexGateway.py b/vnpy/trader/gateway/okexGateway/okexGateway.py index 58856f35..be924f81 100644 --- a/vnpy/trader/gateway/okexGateway/okexGateway.py +++ b/vnpy/trader/gateway/okexGateway/okexGateway.py @@ -392,19 +392,15 @@ class SpotApi(OkexSpotApi): available = float(free[symbol]) if frozen or available: - pos = VtPositionData() - pos.gatewayName = self.gatewayName + account = VtAccountData() + account.gatewayName = self.gatewayName - pos.symbol = symbol - pos.exchange = EXCHANGE_OKEX - pos.vtSymbol = '.'.join([pos.symbol, pos.exchange]) - pos.direction = DIRECTION_LONG - pos.vtPositionName = '.'.join([pos.vtSymbol, pos.direction]) + account.accountID = symbol + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + account.balance = frozen + available + account.available = available - pos.frozen = frozen - pos.position = frozen + available - - self.gateway.onPosition(pos) + self.gateway.onAccount(account) self.writeLog(u'持仓信息查询成功') @@ -530,18 +526,16 @@ class SpotApi(OkexSpotApi): free = rawData['info']['free'] freezed = rawData['info']['freezed'] - for symbol in free.keys(): - pos = VtPositionData() - pos.gatewayName = self.gatewayName - pos.symbol = symbol - pos.exchange = EXCHANGE_OKEX - pos.vtSymbol = '.'.join([pos.symbol, pos.exchange]) - pos.direction = DIRECTION_LONG - pos.vtPositionName = '.'.join([pos.vtSymbol, pos.direction]) - pos.frozen = float(freezed[symbol]) - pos.position = pos.frozen + float(free[symbol]) - - self.gateway.onPosition(pos) + for symbol in free.keys(): + account = VtAccountData() + account.gatewayName = self.gatewayName + + account.accountID = symbol + account.vtAccountID = '.'.join([account.gatewayName, account.accountID]) + account.available = float(free[symbol]) + account.balance = account.available + float(freezed[symbol]) + + self.gateway.onAccount(account) #---------------------------------------------------------------------- def init(self, apiKey, secretKey, trace, symbols):