diff --git a/vnpy/api/websocket/WebsocketClient.py b/vnpy/api/websocket/WebsocketClient.py index b9d75e84..8583d4f7 100644 --- a/vnpy/api/websocket/WebsocketClient.py +++ b/vnpy/api/websocket/WebsocketClient.py @@ -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] diff --git a/vnpy/trader/gateway/okexfGateway/okexfGateway.py b/vnpy/trader/gateway/okexfGateway/okexfGateway.py index a81ad856..56c1dd7e 100644 --- a/vnpy/trader/gateway/okexfGateway/okexfGateway.py +++ b/vnpy/trader/gateway/okexfGateway/okexfGateway.py @@ -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):