Merge pull request #1262 from nanoric/fix_okex

Fix okex
This commit is contained in:
vn.py 2018-11-26 21:32:05 +08:00 committed by GitHub
commit 9c79ab2167
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 23 deletions

View File

@ -263,11 +263,16 @@ class WebsocketClient(object):
"""
用于Debug 记录最后一次发送出去的text
"""
self._lastSentText = text[:500]
self._lastSentText = text[:1000]
#----------------------------------------------------------------------
def _recordLastReceivedText(self, text):
"""
用于Debug 记录最后一次发送出去的text
"""
self._lastReceivedText = text[:500]
try:
# 尝试解包,解不了就算
text = str(self.unpackData(text))
except:
pass
self._lastReceivedText = text[:1000]

View File

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