Skip to content

Commit

Permalink
[Mod] add extra license files for hsoption gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
vnpy committed Apr 13, 2020
1 parent de1ca29 commit b3b50c5
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 44 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1 @@
recursive-include vnpy *.ico *.ini *.dll *.so *.pyd *.h *.hpp *.cpp *.a *.dat
recursive-include vnpy *.ico *.ini *.dll *.so *.pyd *.h *.hpp *.cpp *.a *.dat *.pfx
Binary file not shown.
27 changes: 27 additions & 0 deletions vnpy/gateway/hsoption/citic.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[t2sdk]
license_file=(20130403)ZXZQ-TESTsfjrt-ALL-0001_3rd.dat
;servers=118.192.134.94:29112
;µçÐÅÇëʹÓÃÕâ¸öµØÖ·£º
servers=124.207.9.94:29112
login_name=syn_send
lang=2052
;lang=2052
;send_queue_size=100
license_pwd=999999
init_recv_buf_size=5120
init_send_buf_size=5120
send_queue_size=1000
errormsg=errormsg.ini
writedata=1
[proxy]
proxy_type=
ip=127.0.0.1
port=
user_name=guest
password=888888
[safe]
safe_level=ssl
client_id=
comm_pwd=
cert_file=s2013.pfx
cert_pwd=999999
100 changes: 57 additions & 43 deletions vnpy/gateway/hsoption/hsoption_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
from datetime import datetime
from time import sleep
import traceback

from vnpy.api.t2sdk import py_t2sdk
from vnpy.api.sopt import MdApi
Expand Down Expand Up @@ -268,7 +269,6 @@ def onRtnDepthMarketData(self, data: dict) -> None:
"""
Callback of tick data update.
"""

symbol = data["InstrumentID"]
exchange = symbol_exchange_map.get(symbol, "")

Expand All @@ -281,7 +281,7 @@ def onRtnDepthMarketData(self, data: dict) -> None:
symbol=symbol,
exchange=exchange,
datetime=datetime.strptime(timestamp, "%Y%m%d %H:%M:%S.%f"),
name=symbol_name_map[symbol],
name=symbol_name_map.get(symbol, ""),
volume=data["Volume"],
open_interest=data["OpenInterest"],
last_price=data["LastPrice"],
Expand Down Expand Up @@ -484,6 +484,40 @@ def on_login(self, data: List[Dict[str, str]]) -> None:
self.asset_prop = d["asset_prop"]
self.sysnode_id = d["sysnode_id"]

# Generate ETF contract data
contract_1 = ContractData(
symbol="510050",
exchange=Exchange.SSE,
name="50ETF",
size=1,
pricetick=0.001,
product=Product.ETF,
gateway_name=self.gateway_name
)
self.gateway.on_contract(contract_1)

contract_2 = ContractData(
symbol="510300",
exchange=Exchange.SSE,
name="300ETF",
size=1,
pricetick=0.001,
product=Product.ETF,
gateway_name=self.gateway_name
)
self.gateway.on_contract(contract_2)

contract_3 = ContractData(
symbol="159919",
exchange=Exchange.SZSE,
name="300ETF",
size=1,
pricetick=0.001,
product=Product.ETF,
gateway_name=self.gateway_name
)
self.gateway.on_contract(contract_3)

self.query_contract()

def on_query_position(self, data: List[Dict[str, str]]) -> None:
Expand Down Expand Up @@ -599,40 +633,6 @@ def on_query_contract(self, data: List[Dict[str, str]]) -> None:
self.gateway.write_log("合约信息查询失败")
return

# Generate ETF contract data
contract_1 = ContractData(
symbol="510050",
exchange=Exchange.SSE,
name="50ETF",
size=1,
pricetick=0.001,
product=Product.ETF,
gateway_name=self.gateway_name
)
self.gateway.on_contract(contract_1)

contract_2 = ContractData(
symbol="510300",
exchange=Exchange.SSE,
name="300ETF",
size=1,
pricetick=0.001,
product=Product.ETF,
gateway_name=self.gateway_name
)
self.gateway.on_contract(contract_2)

contract_3 = ContractData(
symbol="159919",
exchange=Exchange.SZSE,
name="300ETF",
size=1,
pricetick=0.001,
product=Product.ETF,
gateway_name=self.gateway_name
)
self.gateway.on_contract(contract_3)

# Process option contract
for d in data:
contract = ContractData(
Expand Down Expand Up @@ -660,8 +660,15 @@ def on_query_contract(self, data: List[Dict[str, str]]) -> None:

self.gateway.on_contract(contract)

self.gateway.write_log("合约信息查询成功")
self.query_order()
symbol_exchange_map[contract.symbol] = contract.exchange
symbol_name_map[contract.symbol] = contract.name

if len(data) == 1000:
position_str = d["position_str"]
self.query_contract(position_str)
else:
self.gateway.write_log("合约信息查询成功")
self.query_order()

def on_send_order(self, data: List[Dict[str, str]]) -> None:
""""""
Expand Down Expand Up @@ -741,8 +748,11 @@ def on_error(self, error: dict) -> None:

def on_callback(self, function: int, data: dict) -> None:
""""""
func = self.callbacks[function]
func(data)
try:
func = self.callbacks[function]
func(data)
except Exception:
traceback.print_exc()

def send_req(self, function: int, req: dict) -> int:
""""""
Expand Down Expand Up @@ -870,12 +880,12 @@ def subcribe_topic(self, biz_name: str, topic_name: str) -> int:
ret, subscriber = self.connection.NewSubscriber(
sub_callback,
biz_name,
300000
5000
)
if ret != 0:
error_msg = str(self.connection.GetMCLastError(), encoding="gbk")
msg = f"订阅推送失败:{error_msg}"
self.td_api.gateway.write_log(msg)
self.gateway.write_log(msg)
return

# Set subscribe parameters
Expand Down Expand Up @@ -951,10 +961,14 @@ def query_order(self) -> int:
req["request_num"] = "10000"
self.send_req(FUNCTION_QUERY_ORDER, req)

def query_contract(self) -> int:
def query_contract(self, position_str: str = None) -> int:
""""""
req = self.generate_req()
req["request_num"] = "10000"

if position_str:
req["position_str"] = position_str

self.send_req(FUNCTION_QUERY_CONTRACT, req)

def subcribe_order(self) -> None:
Expand Down
Binary file added vnpy/gateway/hsoption/s2013.pfx
Binary file not shown.

0 comments on commit b3b50c5

Please sign in to comment.