Merge pull request #1912 from nioss/dev

Dev 修改okex深度数据(ondepth)重复
This commit is contained in:
vn.py 2019-07-12 15:10:36 +08:00 committed by GitHub
commit 33bd9c56c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 35 deletions

View File

@ -644,27 +644,26 @@ class OkexWebsocketApi(WebsocketClient):
def on_depth(self, d): def on_depth(self, d):
"""""" """"""
for tick_data in d: symbol = d["instrument_id"]
symbol = d["instrument_id"] tick = self.ticks.get(symbol, None)
tick = self.ticks.get(symbol, None) if not tick:
if not tick: return
return
bids = d["bids"] bids = d["bids"]
asks = d["asks"] asks = d["asks"]
for n, buf in enumerate(bids): for n, buf in enumerate(bids):
price, volume, _ = buf price, volume, _ = buf
tick.__setattr__("bid_price_%s" % (n + 1), float(price)) tick.__setattr__("bid_price_%s" % (n + 1), float(price))
tick.__setattr__("bid_volume_%s" % (n + 1), float(volume)) tick.__setattr__("bid_volume_%s" % (n + 1), float(volume))
for n, buf in enumerate(asks): for n, buf in enumerate(asks):
price, volume, _ = buf price, volume, _ = buf
tick.__setattr__("ask_price_%s" % (n + 1), float(price)) tick.__setattr__("ask_price_%s" % (n + 1), float(price))
tick.__setattr__("ask_volume_%s" % (n + 1), float(volume)) tick.__setattr__("ask_volume_%s" % (n + 1), float(volume))
tick.datetime = datetime.strptime( tick.datetime = datetime.strptime(
d["timestamp"], "%Y-%m-%dT%H:%M:%S.%fZ") d["timestamp"], "%Y-%m-%dT%H:%M:%S.%fZ")
self.gateway.on_tick(copy(tick)) self.gateway.on_tick(copy(tick))
def on_order(self, d): def on_order(self, d):
"""""" """"""

View File

@ -709,26 +709,25 @@ class OkexfWebsocketApi(WebsocketClient):
def on_depth(self, d): def on_depth(self, d):
"""""" """"""
for tick_data in d: symbol = d["instrument_id"]
symbol = d["instrument_id"] tick = self.ticks.get(symbol, None)
tick = self.ticks.get(symbol, None) if not tick:
if not tick: return
return
bids = d["bids"] bids = d["bids"]
asks = d["asks"] asks = d["asks"]
for n, buf in enumerate(bids): for n, buf in enumerate(bids):
price, volume, _, __ = buf price, volume, _, __ = buf
tick.__setattr__("bid_price_%s" % (n + 1), price) tick.__setattr__("bid_price_%s" % (n + 1), price)
tick.__setattr__("bid_volume_%s" % (n + 1), volume) tick.__setattr__("bid_volume_%s" % (n + 1), volume)
for n, buf in enumerate(asks): for n, buf in enumerate(asks):
price, volume, _, __ = buf price, volume, _, __ = buf
tick.__setattr__("ask_price_%s" % (n + 1), price) tick.__setattr__("ask_price_%s" % (n + 1), price)
tick.__setattr__("ask_volume_%s" % (n + 1), volume) tick.__setattr__("ask_volume_%s" % (n + 1), volume)
tick.datetime = utc_to_local(d["timestamp"]) tick.datetime = utc_to_local(d["timestamp"])
self.gateway.on_tick(copy(tick)) self.gateway.on_tick(copy(tick))
def on_order(self, d): def on_order(self, d):
"""""" """"""