From 2cca2aab9cdb2d9645944ce8c41bebb73b72fd26 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Fri, 27 Dec 2019 15:25:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E5=BC=BA]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=85=A8=E5=90=88=E7=BA=A6=3D=E3=80=8B=E7=9C=9F=E5=AE=9E?= =?UTF-8?q?=E5=90=88=E7=BA=A6=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/trader/utility.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vnpy/trader/utility.py b/vnpy/trader/utility.py index 94432105..1340238d 100644 --- a/vnpy/trader/utility.py +++ b/vnpy/trader/utility.py @@ -120,6 +120,21 @@ def get_full_symbol(symbol: str): return symbol +def get_real_symbol_by_exchange(full_symbol, vn_exchange): + """根据交易所,返回真实合约""" + if vn_exchange == Exchange.CFFEX: + return full_symbol.upper() + + if vn_exchange in [Exchange.DCE, Exchange.SHFE, Exchange.INE]: + return full_symbol.lower() + + if vn_exchange == Exchange.CZCE: + underlying_symbol = get_underlying_symbol(full_symbol).upper() + yearmonth_len = len(full_symbol) - len(underlying_symbol) - 1 + return underlying_symbol.upper() + full_symbol[-yearmonth_len:] + + return full_symbol + def get_trading_date(dt: datetime = None): """ 根据输入的时间,返回交易日的日期