From 5753b87c31786160f14f1cd9a8a0901f7812c695 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Mon, 11 Nov 2019 13:58:31 +0800 Subject: [PATCH 1/2] [Add] general request header for BybitGateway --- vnpy/gateway/bybit/bybit_gateway.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vnpy/gateway/bybit/bybit_gateway.py b/vnpy/gateway/bybit/bybit_gateway.py index 78461aee..5ffae272 100644 --- a/vnpy/gateway/bybit/bybit_gateway.py +++ b/vnpy/gateway/bybit/bybit_gateway.py @@ -187,6 +187,8 @@ class BybitRestApi(RestClient): """ Generate ByBit signature. """ + request.headers = {"Referer": "vn.py"} + if request.method == "GET": api_params = request.params if api_params is None: From 3cd0a2385446327c693444e6bc4492e765ba1d22 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Tue, 12 Nov 2019 14:17:32 +0800 Subject: [PATCH 2/2] [Mod] add error handle when querying history data from BybitGateway --- vnpy/gateway/bybit/bybit_gateway.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vnpy/gateway/bybit/bybit_gateway.py b/vnpy/gateway/bybit/bybit_gateway.py index 5ffae272..b123bedc 100644 --- a/vnpy/gateway/bybit/bybit_gateway.py +++ b/vnpy/gateway/bybit/bybit_gateway.py @@ -531,8 +531,16 @@ class BybitRestApi(RestClient): break else: data = resp.json() - if not data: + + ret_msg = data["ret_msg"] + if ret_msg != "ok": + msg = f"获取历史数据出错,错误信息:{ret_msg}" + self.gateway.write_log(msg) + break + + if not data["result"]: msg = f"获取历史数据为空,开始时间:{start_time},数量:{count}" + self.gateway.write_log(msg) break buf = []