[Mod] add support for option
This commit is contained in:
parent
fa6c9e9975
commit
e43315f279
@ -33,8 +33,6 @@ from vnpy.trader.object import (
|
||||
CancelRequest,
|
||||
SubscribeRequest,
|
||||
)
|
||||
from vnpy.trader.utility import get_folder_path
|
||||
from vnpy.trader.event import EVENT_TIMER
|
||||
|
||||
|
||||
STATUS_DA2VT = {
|
||||
@ -73,15 +71,7 @@ OFFSET_DA2VT = {v: k for k, v in OFFSET_VT2DA.items()}
|
||||
|
||||
EXCHANGE_DA2VT = {
|
||||
"APEX": Exchange.APEX,
|
||||
# "SGXQ": Exchange.SGX,
|
||||
# "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
|
||||
"CME": Exchange.CME
|
||||
}
|
||||
EXCHANGE_VT2DA = {v: k for k, v in EXCHANGE_DA2VT.items()}
|
||||
|
||||
@ -90,10 +80,10 @@ PRODUCT_DA2VT = {
|
||||
"O": Product.OPTION,
|
||||
}
|
||||
|
||||
# OPTIONTYPE_DA2VT = {
|
||||
# THOST_FTDC_CP_CallOptions: OptionType.CALL,
|
||||
# THOST_FTDC_CP_PutOptions: OptionType.PUT
|
||||
# }
|
||||
OPTIONTYPE_DA2VT = {
|
||||
"R": OptionType.CALL,
|
||||
"F": OptionType.PUT
|
||||
}
|
||||
|
||||
|
||||
symbol_name_map = {}
|
||||
@ -278,8 +268,7 @@ class DaMarketApi(MarketApi):
|
||||
|
||||
# If not connected, then start connection first.
|
||||
if not self.connect_status:
|
||||
# path = get_folder_path(self.gateway_name.lower())
|
||||
self.createMarketApi(True, "market_log.txt")
|
||||
self.createMarketApi(False, "market_log.txt")
|
||||
|
||||
self.registerNameServer(address)
|
||||
self.init()
|
||||
@ -325,7 +314,7 @@ class DaMarketApi(MarketApi):
|
||||
"MarketTrcode": da_code,
|
||||
}
|
||||
self.reqid += 1
|
||||
i = self.reqMarketData(da_req, self.reqid)
|
||||
self.reqMarketData(da_req, self.reqid)
|
||||
|
||||
self.subscribed[req.symbol] = req
|
||||
|
||||
@ -448,6 +437,11 @@ class DaFutureApi(FutureApi):
|
||||
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_currency_map[contract.symbol] = data["CommodityFCurrencyNo"]
|
||||
|
||||
@ -639,8 +633,7 @@ class DaFutureApi(FutureApi):
|
||||
self.auth_code = auth_code
|
||||
|
||||
if not self.connect_status:
|
||||
#path = get_folder_path(self.gateway_name.lower())
|
||||
self.createFutureApi(True, "future_log.txt")
|
||||
self.createFutureApi(False, "future_log.txt")
|
||||
|
||||
self.registerNameServer(address)
|
||||
self.init()
|
||||
@ -831,4 +824,3 @@ def to_float(data: str) -> float:
|
||||
return 0.0
|
||||
else:
|
||||
return float(data)
|
||||
|
Loading…
Reference in New Issue
Block a user