[Mod]修改数字货币接口查询资金的数据使用VtAccountData

This commit is contained in:
vn.py 2018-07-25 16:07:08 +08:00
parent f3dcc0bf20
commit 2b9d165e86
7 changed files with 80 additions and 108 deletions

View File

@ -1,6 +1,6 @@
{
"apiKey": "",
"apiSecret": "",
"apiKey": "dVOUiqMzayJSW8gCGax_zWpy",
"apiSecret": "dTh0NWAvGA3h9YczL90R1MGxGc_BZtG05EJ3MoiMYRvtS5mL",
"sessionCount": 3,
"symbols": ["XBTUSD", "EOSM18", "XRPM18"]
}

View File

@ -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):

View File

@ -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):
""""""

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -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):