From 7ca9eec4261140f4f593f880ff4d488eb0f57ce7 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Mon, 1 Apr 2019 15:41:50 +0800 Subject: [PATCH] [Fix]close #1460 --- vnpy/app/cta_strategy/engine.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/vnpy/app/cta_strategy/engine.py b/vnpy/app/cta_strategy/engine.py index 311981f1..cb29a652 100644 --- a/vnpy/app/cta_strategy/engine.py +++ b/vnpy/app/cta_strategy/engine.py @@ -151,13 +151,14 @@ class CtaEngine(BaseEngine): Query bar data from RQData. """ symbol, exchange_str = vt_symbol.split(".") - if symbol.upper() not in self.rq_symbols: + rq_symbol = to_rq_symbol(vt_symbol) + if rq_symbol not in self.rq_symbols: return None end += timedelta(1) # For querying night trading period data df = self.rq_client.get_price( - symbol.upper(), + rq_symbol, frequency=interval.value, fields=["open", "high", "low", "close", "volume"], start_date=start, @@ -910,3 +911,29 @@ class CtaEngine(BaseEngine): subject = "CTA策略引擎" self.main_engine.send_email(subject, msg) + + +def to_rq_symbol(vt_symbol: str): + """ + CZCE product of RQData has symbol like "TA1905" while + vt symbol is "TA905.CZCE" so need to add "1" in symbol. + """ + symbol, exchange_str = vt_symbol.split(".") + if exchange_str != "CZCE": + return symbol.upper() + + for count, word in enumerate(symbol): + if word.isdigit(): + break + + product = symbol[:count] + year = symbol[count] + month = symbol[count + 1:] + + if year == "9": + year = "1" + year + else: + year = "2" + year + + rq_symbol = f"{product}{year}{month}".upper() + return rq_symbol