From c783bd7d7041947782feb63fdb9d3aaf71bbc144 Mon Sep 17 00:00:00 2001 From: kingkaki <30930379+kingkaki@users.noreply.github.com> Date: Fri, 19 Nov 2021 14:50:24 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=E4=BF=AE=E5=A4=8D=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E7=9A=84None=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit row.get的default value仅在字段不存在时生效。 当tushare返回的值中存在oi字段,但值为None时,依旧会取None值,从而导致后续的存入数据库失败 --- vnpy_tushare/tushare_datafeed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vnpy_tushare/tushare_datafeed.py b/vnpy_tushare/tushare_datafeed.py index 21e029c..f429459 100644 --- a/vnpy_tushare/tushare_datafeed.py +++ b/vnpy_tushare/tushare_datafeed.py @@ -246,8 +246,8 @@ def query_bar_history(self, req: HistoryRequest) -> Optional[List[BarData]]: low_price=round_to(row["low"], 0.000001), close_price=round_to(row["close"], 0.000001), volume=row["vol"], - turnover=row.get("amount", 0), - open_interest=row.get("oi", 0), + turnover=row.get("amount", 0) if row.get("amount", 0) else 0, + open_interest=row.get("oi", 0) if row.get("oi", 0) else 0, gateway_name="TS" )