From da53a5fc0b615fc3e9437ba96b40ecd68bde9cf7 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Thu, 14 Mar 2019 09:22:03 +0800 Subject: [PATCH] [Mod]Add support for spread product class, close #1479 --- tests/trader/run.py | 16 ++++++------ vnpy/gateway/ctp/ctp_gateway.py | 46 ++++++++++++++++----------------- vnpy/trader/constant.py | 1 + 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/tests/trader/run.py b/tests/trader/run.py index 98a4b1e8..b319b213 100644 --- a/tests/trader/run.py +++ b/tests/trader/run.py @@ -4,10 +4,10 @@ from vnpy.event import EventEngine from vnpy.trader.engine import MainEngine from vnpy.trader.ui import MainWindow, create_qapp -#from vnpy.gateway.bitmex import BitmexGateway -#from vnpy.gateway.futu import FutuGateway -#from vnpy.gateway.ib import IbGateway -#from vnpy.gateway.ctp import CtpGateway +from vnpy.gateway.bitmex import BitmexGateway +from vnpy.gateway.futu import FutuGateway +from vnpy.gateway.ib import IbGateway +from vnpy.gateway.ctp import CtpGateway from vnpy.gateway.tiger import TigerGateway from vnpy.app.cta_strategy import CtaStrategyApp @@ -20,10 +20,10 @@ def main(): event_engine = EventEngine() main_engine = MainEngine(event_engine) - #main_engine.add_gateway(CtpGateway) - #main_engine.add_gateway(IbGateway) - #main_engine.add_gateway(FutuGateway) - #main_engine.add_gateway(BitmexGateway) + main_engine.add_gateway(CtpGateway) + main_engine.add_gateway(IbGateway) + main_engine.add_gateway(FutuGateway) + main_engine.add_gateway(BitmexGateway) main_engine.add_gateway(TigerGateway) main_engine.add_app(CtaStrategyApp) diff --git a/vnpy/gateway/ctp/ctp_gateway.py b/vnpy/gateway/ctp/ctp_gateway.py index 38b62650..793e179a 100644 --- a/vnpy/gateway/ctp/ctp_gateway.py +++ b/vnpy/gateway/ctp/ctp_gateway.py @@ -25,6 +25,7 @@ from vnpy.api.ctp import ( THOST_FTDC_OFEN_CloseToday, THOST_FTDC_PC_Futures, THOST_FTDC_PC_Options, + THOST_FTDC_PC_Combination, THOST_FTDC_CP_CallOptions, THOST_FTDC_CP_PutOptions, THOST_FTDC_HF_Speculation, @@ -102,7 +103,8 @@ EXCHANGE_CTP2VT = { PRODUCT_CTP2VT = { THOST_FTDC_PC_Futures: Product.FUTURES, - THOST_FTDC_PC_Options: Product.OPTION + THOST_FTDC_PC_Options: Product.OPTION, + THOST_FTDC_PC_Combination: Product.SPREAD } OPTIONTYPE_CTP2VT = { @@ -533,28 +535,26 @@ class CtpTdApi(TdApi): Callback of instrument query. """ product = PRODUCT_CTP2VT.get(data["ProductClass"], None) - if not product: - return - - contract = ContractData( - symbol=data["InstrumentID"], - exchange=EXCHANGE_CTP2VT[data["ExchangeID"]], - name=data["InstrumentName"], - product=product, - size=data["VolumeMultiple"], - pricetick=data["PriceTick"], - option_underlying=data["UnderlyingInstrID"], - option_type=OPTIONTYPE_CTP2VT.get(data["OptionsType"], None), - option_strike=data["StrikePrice"], - option_expiry=datetime.strptime(data["ExpireDate"], "%Y%m%d"), - gateway_name=self.gateway_name - ) - - self.gateway.on_contract(contract) - - symbol_exchange_map[contract.symbol] = contract.exchange - symbol_name_map[contract.symbol] = contract.name - symbol_size_map[contract.symbol] = contract.size + if product: + contract = ContractData( + symbol=data["InstrumentID"], + exchange=EXCHANGE_CTP2VT[data["ExchangeID"]], + name=data["InstrumentName"], + product=product, + size=data["VolumeMultiple"], + pricetick=data["PriceTick"], + option_underlying=data["UnderlyingInstrID"], + option_type=OPTIONTYPE_CTP2VT.get(data["OptionsType"], None), + option_strike=data["StrikePrice"], + option_expiry=datetime.strptime(data["ExpireDate"], "%Y%m%d"), + gateway_name=self.gateway_name + ) + + self.gateway.on_contract(contract) + + symbol_exchange_map[contract.symbol] = contract.exchange + symbol_name_map[contract.symbol] = contract.name + symbol_size_map[contract.symbol] = contract.size if last: self.gateway.write_log("合约信息查询成功") diff --git a/vnpy/trader/constant.py b/vnpy/trader/constant.py index 289607c2..77d5e4e4 100644 --- a/vnpy/trader/constant.py +++ b/vnpy/trader/constant.py @@ -50,6 +50,7 @@ class Product(Enum): ETF = "ETF" BOND = "债券" WARRANT = "权证" + SPREAD = "价差" class PriceType(Enum):