[Mod] add support for option

This commit is contained in:
vn.py 2019-09-02 16:56:48 +08:00
parent fa6c9e9975
commit e43315f279

View File

@ -33,8 +33,6 @@ from vnpy.trader.object import (
CancelRequest, CancelRequest,
SubscribeRequest, SubscribeRequest,
) )
from vnpy.trader.utility import get_folder_path
from vnpy.trader.event import EVENT_TIMER
STATUS_DA2VT = { STATUS_DA2VT = {
@ -73,15 +71,7 @@ OFFSET_DA2VT = {v: k for k, v in OFFSET_VT2DA.items()}
EXCHANGE_DA2VT = { EXCHANGE_DA2VT = {
"APEX": Exchange.APEX, "APEX": Exchange.APEX,
# "SGXQ": Exchange.SGX, "CME": Exchange.CME
# "NYMEX": Exchange.NYMEX,
# "LME": Exchange.LME,
# "CME_CBT": Exchange.CBOT,
# "HKEX": Exchange.HKFE,
"CME": Exchange.CME,
# "TOCOM": Exchange.TOCOM,
# "KRX": Exchange.KRX,
# "ICE": Exchange.ICE
} }
EXCHANGE_VT2DA = {v: k for k, v in EXCHANGE_DA2VT.items()} EXCHANGE_VT2DA = {v: k for k, v in EXCHANGE_DA2VT.items()}
@ -90,10 +80,10 @@ PRODUCT_DA2VT = {
"O": Product.OPTION, "O": Product.OPTION,
} }
# OPTIONTYPE_DA2VT = { OPTIONTYPE_DA2VT = {
# THOST_FTDC_CP_CallOptions: OptionType.CALL, "R": OptionType.CALL,
# THOST_FTDC_CP_PutOptions: OptionType.PUT "F": OptionType.PUT
# } }
symbol_name_map = {} symbol_name_map = {}
@ -278,8 +268,7 @@ class DaMarketApi(MarketApi):
# If not connected, then start connection first. # If not connected, then start connection first.
if not self.connect_status: if not self.connect_status:
# path = get_folder_path(self.gateway_name.lower()) self.createMarketApi(False, "market_log.txt")
self.createMarketApi(True, "market_log.txt")
self.registerNameServer(address) self.registerNameServer(address)
self.init() self.init()
@ -325,7 +314,7 @@ class DaMarketApi(MarketApi):
"MarketTrcode": da_code, "MarketTrcode": da_code,
} }
self.reqid += 1 self.reqid += 1
i = self.reqMarketData(da_req, self.reqid) self.reqMarketData(da_req, self.reqid)
self.subscribed[req.symbol] = req self.subscribed[req.symbol] = req
@ -448,6 +437,11 @@ class DaFutureApi(FutureApi):
gateway_name=self.gateway_name gateway_name=self.gateway_name
) )
if product == Product.OPTION:
contract.option_type = OPTIONTYPE_DA2VT[data["OptionType"]]
contract.option_strike = to_float(data["OptionStrikePrice"])
contract.option_expiry = datetime.strptime(data["LastTradeDay"], "%Y%m%d")
symbol_name_map[contract.vt_symbol] = contract.name symbol_name_map[contract.vt_symbol] = contract.name
symbol_currency_map[contract.symbol] = data["CommodityFCurrencyNo"] symbol_currency_map[contract.symbol] = data["CommodityFCurrencyNo"]
@ -639,8 +633,7 @@ class DaFutureApi(FutureApi):
self.auth_code = auth_code self.auth_code = auth_code
if not self.connect_status: if not self.connect_status:
#path = get_folder_path(self.gateway_name.lower()) self.createFutureApi(False, "future_log.txt")
self.createFutureApi(True, "future_log.txt")
self.registerNameServer(address) self.registerNameServer(address)
self.init() self.init()
@ -831,4 +824,3 @@ def to_float(data: str) -> float:
return 0.0 return 0.0
else: else:
return float(data) return float(data)