[Fix] Okex 修正了登录时无持仓时的报错
This commit is contained in:
parent
268f833bdc
commit
fc7eb66226
@ -388,27 +388,28 @@ class OkexfRestApi(RestClient):
|
||||
#----------------------------------------------------------------------
|
||||
def onQueryPosition(self, data, request):
|
||||
""""""
|
||||
for d in data['holding'][0]:
|
||||
longPosition = VtPositionData()
|
||||
longPosition.gatewayName = self.gatewayName
|
||||
longPosition.symbol = d['instrument_id']
|
||||
longPosition.exchange = 'OKEX'
|
||||
longPosition.vtSymbol = '.'.join([longPosition.symbol, longPosition.exchange])
|
||||
longPosition.direction = DIRECTION_LONG
|
||||
longPosition.vtPositionName = '.'.join([longPosition.vtSymbol, longPosition.direction])
|
||||
longPosition.position = int(d['long_qty'])
|
||||
longPosition.frozen = longPosition.position - int(d['long_avail_qty'])
|
||||
longPosition.price = float(d['long_avg_cost'])
|
||||
|
||||
shortPosition = copy(longPosition)
|
||||
shortPosition.direction = DIRECTION_SHORT
|
||||
shortPosition.vtPositionName = '.'.join([shortPosition.vtSymbol, shortPosition.direction])
|
||||
shortPosition.position = int(d['short_qty'])
|
||||
shortPosition.frozen = shortPosition.position - int(d['short_avail_qty'])
|
||||
shortPosition.price = float(d['short_avg_cost'])
|
||||
|
||||
self.gateway.onPosition(longPosition)
|
||||
self.gateway.onPosition(shortPosition)
|
||||
for holding in data['holding']:
|
||||
for d in holding:
|
||||
longPosition = VtPositionData()
|
||||
longPosition.gatewayName = self.gatewayName
|
||||
longPosition.symbol = d['instrument_id']
|
||||
longPosition.exchange = 'OKEX'
|
||||
longPosition.vtSymbol = '.'.join([longPosition.symbol, longPosition.exchange])
|
||||
longPosition.direction = DIRECTION_LONG
|
||||
longPosition.vtPositionName = '.'.join([longPosition.vtSymbol, longPosition.direction])
|
||||
longPosition.position = int(d['long_qty'])
|
||||
longPosition.frozen = longPosition.position - int(d['long_avail_qty'])
|
||||
longPosition.price = float(d['long_avg_cost'])
|
||||
|
||||
shortPosition = copy(longPosition)
|
||||
shortPosition.direction = DIRECTION_SHORT
|
||||
shortPosition.vtPositionName = '.'.join([shortPosition.vtSymbol, shortPosition.direction])
|
||||
shortPosition.position = int(d['short_qty'])
|
||||
shortPosition.frozen = shortPosition.position - int(d['short_avail_qty'])
|
||||
shortPosition.price = float(d['short_avg_cost'])
|
||||
|
||||
self.gateway.onPosition(longPosition)
|
||||
self.gateway.onPosition(shortPosition)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def onQueryOrder(self, data, request):
|
||||
|
Loading…
Reference in New Issue
Block a user