From 268f833bdc62467698d2df07f38c032721b009de Mon Sep 17 00:00:00 2001 From: nanoric Date: Mon, 26 Nov 2018 04:15:23 -0400 Subject: [PATCH 1/4] =?UTF-8?q?[Add]=20ws:=E5=9C=A8=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E6=8E=A5=E6=94=B6=E5=88=B0=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=97=B6=E5=B0=9D=E8=AF=95=E8=A7=A3=E5=8C=85=EF=BC=8C?= =?UTF-8?q?=E8=8B=A5=E8=A7=A3=E5=8C=85=E5=A4=B1=E8=B4=A5=E5=88=99=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E5=8E=9F=E6=9D=A5=E7=9A=84=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/api/websocket/WebsocketClient.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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] From fc7eb662264194ac5f8606d7edade141ef91f089 Mon Sep 17 00:00:00 2001 From: nanoric Date: Mon, 26 Nov 2018 04:18:21 -0400 Subject: [PATCH 2/4] =?UTF-8?q?[Fix]=20Okex=20=E4=BF=AE=E6=AD=A3=E4=BA=86?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=97=B6=E6=97=A0=E6=8C=81=E4=BB=93=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gateway/okexfGateway/okexfGateway.py | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) 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): From 870723660942e9acf06d284b1da90df83348a36d Mon Sep 17 00:00:00 2001 From: cclauss Date: Fri, 28 Dec 2018 23:47:57 +0100 Subject: [PATCH 3/4] Use print() function in both Python 2 and Python 3 Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3. --- examples/TurtleStrategy/turtleEngine.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/TurtleStrategy/turtleEngine.py b/examples/TurtleStrategy/turtleEngine.py index 5c3b09e9..aa6603f6 100644 --- a/examples/TurtleStrategy/turtleEngine.py +++ b/examples/TurtleStrategy/turtleEngine.py @@ -1,5 +1,7 @@ # encoding: UTF-8 +from __future__ import print_function + from csv import DictReader from datetime import datetime from collections import OrderedDict, defaultdict @@ -306,7 +308,7 @@ class BacktestingEngine(object): #---------------------------------------------------------------------- def output(self, content): """输出信息""" - print content + print(content) #---------------------------------------------------------------------- def getTradeData(self, vtSymbol=''): @@ -432,4 +434,4 @@ class DailyResult(object): def formatNumber(n): """格式化数字到字符串""" rn = round(n, 2) # 保留两位小数 - return format(rn, ',') # 加上千分符 \ No newline at end of file + return format(rn, ',') # 加上千分符 From 24dbe7d014172a06dc874ee38b5a465b137612f8 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Sat, 29 Dec 2018 09:44:25 +0800 Subject: [PATCH 4/4] =?UTF-8?q?[Mod]=E8=B0=83=E6=95=B4WebsocketClient?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E8=AF=9D=E4=BF=A1=E6=81=AF=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/api/websocket/WebsocketClient.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/vnpy/api/websocket/WebsocketClient.py b/vnpy/api/websocket/WebsocketClient.py index 8583d4f7..d395c4fd 100644 --- a/vnpy/api/websocket/WebsocketClient.py +++ b/vnpy/api/websocket/WebsocketClient.py @@ -270,9 +270,4 @@ class WebsocketClient(object): """ 用于Debug: 记录最后一次发送出去的text """ - try: - # 尝试解包,解不了就算 - text = str(self.unpackData(text)) - except: - pass - self._lastReceivedText = text[:1000] + self._lastReceivedText = text[:1000] \ No newline at end of file