From 5eab77cc9d6b1ae9dfaff4d327069bc035228610 Mon Sep 17 00:00:00 2001 From: nio Date: Tue, 9 Jul 2019 22:00:54 +0800 Subject: [PATCH] =?UTF-8?q?okex=20=E7=8E=B0=E8=B4=A7=E5=92=8C=E5=90=88?= =?UTF-8?q?=E7=BA=A6=E6=B7=B1=E5=BA=A6=E6=95=B0=E6=8D=AE=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit okex 现货和合约深度数据重复修改 --- vnpy/gateway/okex/okex_gateway.py | 35 ++++++++++++++--------------- vnpy/gateway/okexf/okexf_gateway.py | 33 +++++++++++++-------------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/vnpy/gateway/okex/okex_gateway.py b/vnpy/gateway/okex/okex_gateway.py index 5ea47268..9d257e6a 100644 --- a/vnpy/gateway/okex/okex_gateway.py +++ b/vnpy/gateway/okex/okex_gateway.py @@ -644,27 +644,26 @@ class OkexWebsocketApi(WebsocketClient): def on_depth(self, d): """""" - for tick_data in d: - symbol = d["instrument_id"] - tick = self.ticks.get(symbol, None) - if not tick: - return + symbol = d["instrument_id"] + tick = self.ticks.get(symbol, None) + if not tick: + return - bids = d["bids"] - asks = d["asks"] - for n, buf in enumerate(bids): - price, volume, _ = buf - tick.__setattr__("bid_price_%s" % (n + 1), float(price)) - tick.__setattr__("bid_volume_%s" % (n + 1), float(volume)) + bids = d["bids"] + asks = d["asks"] + for n, buf in enumerate(bids): + price, volume, _ = buf + tick.__setattr__("bid_price_%s" % (n + 1), float(price)) + tick.__setattr__("bid_volume_%s" % (n + 1), float(volume)) - for n, buf in enumerate(asks): - price, volume, _ = buf - tick.__setattr__("ask_price_%s" % (n + 1), float(price)) - tick.__setattr__("ask_volume_%s" % (n + 1), float(volume)) + for n, buf in enumerate(asks): + price, volume, _ = buf + tick.__setattr__("ask_price_%s" % (n + 1), float(price)) + tick.__setattr__("ask_volume_%s" % (n + 1), float(volume)) - tick.datetime = datetime.strptime( - d["timestamp"], "%Y-%m-%dT%H:%M:%S.%fZ") - self.gateway.on_tick(copy(tick)) + tick.datetime = datetime.strptime( + d["timestamp"], "%Y-%m-%dT%H:%M:%S.%fZ") + self.gateway.on_tick(copy(tick)) def on_order(self, d): """""" diff --git a/vnpy/gateway/okexf/okexf_gateway.py b/vnpy/gateway/okexf/okexf_gateway.py index b1212682..c42248ea 100644 --- a/vnpy/gateway/okexf/okexf_gateway.py +++ b/vnpy/gateway/okexf/okexf_gateway.py @@ -709,26 +709,25 @@ class OkexfWebsocketApi(WebsocketClient): def on_depth(self, d): """""" - for tick_data in d: - symbol = d["instrument_id"] - tick = self.ticks.get(symbol, None) - if not tick: - return + symbol = d["instrument_id"] + tick = self.ticks.get(symbol, None) + if not tick: + return - bids = d["bids"] - asks = d["asks"] - for n, buf in enumerate(bids): - price, volume, _, __ = buf - tick.__setattr__("bid_price_%s" % (n + 1), price) - tick.__setattr__("bid_volume_%s" % (n + 1), volume) + bids = d["bids"] + asks = d["asks"] + for n, buf in enumerate(bids): + price, volume, _, __ = buf + tick.__setattr__("bid_price_%s" % (n + 1), price) + tick.__setattr__("bid_volume_%s" % (n + 1), volume) - for n, buf in enumerate(asks): - price, volume, _, __ = buf - tick.__setattr__("ask_price_%s" % (n + 1), price) - tick.__setattr__("ask_volume_%s" % (n + 1), volume) + for n, buf in enumerate(asks): + price, volume, _, __ = buf + tick.__setattr__("ask_price_%s" % (n + 1), price) + tick.__setattr__("ask_volume_%s" % (n + 1), volume) - tick.datetime = utc_to_local(d["timestamp"]) - self.gateway.on_tick(copy(tick)) + tick.datetime = utc_to_local(d["timestamp"]) + self.gateway.on_tick(copy(tick)) def on_order(self, d): """"""