Skip to content

Commit

Permalink
[Mod] use utc time for ByBit gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
vnpy committed Nov 7, 2019
1 parent 2e01bef commit 65fc733
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions vnpy/gateway/bybit/bybit_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hmac
import time
import sys
import pytz
from datetime import datetime, timedelta
from typing import Any, Dict, List, Callable
from threading import Lock
Expand Down Expand Up @@ -81,6 +82,9 @@
TESTNET_REST_HOST = "https://api-testnet.bybit.com"
TESTNET_WEBSOCKET_HOST = "wss://stream-testnet.bybit.com/realtime"

CHINA_TZ = pytz.timezone("Asia/Shanghai")
UTC_TZ = pytz.utc


class BybitGateway(BaseGateway):
"""
Expand Down Expand Up @@ -711,7 +715,8 @@ def on_tick(self, packet: dict):
if "volume_24h" in update:
tick.volume = update["volume_24h"]

tick.datetime = datetime.fromtimestamp(timestamp / 1_000_000)
local_dt = datetime.fromtimestamp(timestamp / 1_000_000)
tick.datetime = local_dt.astimezone(UTC_TZ)
self.gateway.on_tick(copy(tick))

def on_depth(self, packet: dict):
Expand Down Expand Up @@ -770,7 +775,8 @@ def on_depth(self, packet: dict):
setattr(tick, f"ask_price_{n}", ask_price)
setattr(tick, f"ask_volume_{n}", ask_data["size"])

tick.datetime = datetime.fromtimestamp(timestamp / 1_000_000)
local_dt = datetime.fromtimestamp(timestamp / 1_000_000)
tick.datetime = local_dt.astimezone(UTC_TZ)
self.gateway.on_tick(copy(tick))

def on_trade(self, packet: dict):
Expand Down Expand Up @@ -803,6 +809,7 @@ def on_order(self, packet: dict):
if order:
order.traded = d["cum_exec_qty"]
order.status = STATUS_BYBIT2VT[d["order_status"]]
order.time = d["timestamp"]
else:
# Use sys_orderid as local_orderid when
# order placed from other source
Expand Down

0 comments on commit 65fc733

Please sign in to comment.