[Mod] add filter for wrong data format in on_depth

This commit is contained in:
vn.py 2019-06-28 16:11:38 +08:00
parent 07ed1c44ac
commit fcaec7d838

View File

@ -1021,14 +1021,19 @@ class HbdmDataWebsocketApi(HbdmWebsocketApiBase):
ws_symbol = data["ch"].split(".")[1] ws_symbol = data["ch"].split(".")[1]
tick = self.ticks[ws_symbol] tick = self.ticks[ws_symbol]
tick.datetime = datetime.fromtimestamp(data["ts"] / 1000) tick.datetime = datetime.fromtimestamp(data["ts"] / 1000)
tick_data = data["tick"]
if "bids" not in tick_data or "asks" not in tick_data:
print(data)
return
bids = data["tick"]["bids"] bids = tick_data["bids"]
for n in range(5): for n in range(5):
price, volume = bids[n] price, volume = bids[n]
tick.__setattr__("bid_price_" + str(n + 1), float(price)) tick.__setattr__("bid_price_" + str(n + 1), float(price))
tick.__setattr__("bid_volume_" + str(n + 1), float(volume)) tick.__setattr__("bid_volume_" + str(n + 1), float(volume))
asks = data["tick"]["asks"] asks = tick_data["asks"]
for n in range(5): for n in range(5):
price, volume = asks[n] price, volume = asks[n]
tick.__setattr__("ask_price_" + str(n + 1), float(price)) tick.__setattr__("ask_price_" + str(n + 1), float(price))