Skip to content

Commit b3b50c5

Browse files
committed
[Mod] add extra license files for hsoption gateway
1 parent de1ca29 commit b3b50c5

File tree

5 files changed

+85
-44
lines changed

5 files changed

+85
-44
lines changed

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
recursive-include vnpy *.ico *.ini *.dll *.so *.pyd *.h *.hpp *.cpp *.a *.dat
1+
recursive-include vnpy *.ico *.ini *.dll *.so *.pyd *.h *.hpp *.cpp *.a *.dat *.pfx
Binary file not shown.

vnpy/gateway/hsoption/citic.ini

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[t2sdk]
2+
license_file=(20130403)ZXZQ-TESTsfjrt-ALL-0001_3rd.dat
3+
;servers=118.192.134.94:29112
4+
;µçÐÅÇëʹÓÃÕâ¸öµØÖ·£º
5+
servers=124.207.9.94:29112
6+
login_name=syn_send
7+
lang=2052
8+
;lang=2052
9+
;send_queue_size=100
10+
license_pwd=999999
11+
init_recv_buf_size=5120
12+
init_send_buf_size=5120
13+
send_queue_size=1000
14+
errormsg=errormsg.ini
15+
writedata=1
16+
[proxy]
17+
proxy_type=
18+
ip=127.0.0.1
19+
port=
20+
user_name=guest
21+
password=888888
22+
[safe]
23+
safe_level=ssl
24+
client_id=
25+
comm_pwd=
26+
cert_file=s2013.pfx
27+
cert_pwd=999999

vnpy/gateway/hsoption/hsoption_gateway.py

+57-43
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import requests
55
from datetime import datetime
66
from time import sleep
7+
import traceback
78

89
from vnpy.api.t2sdk import py_t2sdk
910
from vnpy.api.sopt import MdApi
@@ -268,7 +269,6 @@ def onRtnDepthMarketData(self, data: dict) -> None:
268269
"""
269270
Callback of tick data update.
270271
"""
271-
272272
symbol = data["InstrumentID"]
273273
exchange = symbol_exchange_map.get(symbol, "")
274274

@@ -281,7 +281,7 @@ def onRtnDepthMarketData(self, data: dict) -> None:
281281
symbol=symbol,
282282
exchange=exchange,
283283
datetime=datetime.strptime(timestamp, "%Y%m%d %H:%M:%S.%f"),
284-
name=symbol_name_map[symbol],
284+
name=symbol_name_map.get(symbol, ""),
285285
volume=data["Volume"],
286286
open_interest=data["OpenInterest"],
287287
last_price=data["LastPrice"],
@@ -484,6 +484,40 @@ def on_login(self, data: List[Dict[str, str]]) -> None:
484484
self.asset_prop = d["asset_prop"]
485485
self.sysnode_id = d["sysnode_id"]
486486

487+
# Generate ETF contract data
488+
contract_1 = ContractData(
489+
symbol="510050",
490+
exchange=Exchange.SSE,
491+
name="50ETF",
492+
size=1,
493+
pricetick=0.001,
494+
product=Product.ETF,
495+
gateway_name=self.gateway_name
496+
)
497+
self.gateway.on_contract(contract_1)
498+
499+
contract_2 = ContractData(
500+
symbol="510300",
501+
exchange=Exchange.SSE,
502+
name="300ETF",
503+
size=1,
504+
pricetick=0.001,
505+
product=Product.ETF,
506+
gateway_name=self.gateway_name
507+
)
508+
self.gateway.on_contract(contract_2)
509+
510+
contract_3 = ContractData(
511+
symbol="159919",
512+
exchange=Exchange.SZSE,
513+
name="300ETF",
514+
size=1,
515+
pricetick=0.001,
516+
product=Product.ETF,
517+
gateway_name=self.gateway_name
518+
)
519+
self.gateway.on_contract(contract_3)
520+
487521
self.query_contract()
488522

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

602-
# Generate ETF contract data
603-
contract_1 = ContractData(
604-
symbol="510050",
605-
exchange=Exchange.SSE,
606-
name="50ETF",
607-
size=1,
608-
pricetick=0.001,
609-
product=Product.ETF,
610-
gateway_name=self.gateway_name
611-
)
612-
self.gateway.on_contract(contract_1)
613-
614-
contract_2 = ContractData(
615-
symbol="510300",
616-
exchange=Exchange.SSE,
617-
name="300ETF",
618-
size=1,
619-
pricetick=0.001,
620-
product=Product.ETF,
621-
gateway_name=self.gateway_name
622-
)
623-
self.gateway.on_contract(contract_2)
624-
625-
contract_3 = ContractData(
626-
symbol="159919",
627-
exchange=Exchange.SZSE,
628-
name="300ETF",
629-
size=1,
630-
pricetick=0.001,
631-
product=Product.ETF,
632-
gateway_name=self.gateway_name
633-
)
634-
self.gateway.on_contract(contract_3)
635-
636636
# Process option contract
637637
for d in data:
638638
contract = ContractData(
@@ -660,8 +660,15 @@ def on_query_contract(self, data: List[Dict[str, str]]) -> None:
660660

661661
self.gateway.on_contract(contract)
662662

663-
self.gateway.write_log("合约信息查询成功")
664-
self.query_order()
663+
symbol_exchange_map[contract.symbol] = contract.exchange
664+
symbol_name_map[contract.symbol] = contract.name
665+
666+
if len(data) == 1000:
667+
position_str = d["position_str"]
668+
self.query_contract(position_str)
669+
else:
670+
self.gateway.write_log("合约信息查询成功")
671+
self.query_order()
665672

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

742749
def on_callback(self, function: int, data: dict) -> None:
743750
""""""
744-
func = self.callbacks[function]
745-
func(data)
751+
try:
752+
func = self.callbacks[function]
753+
func(data)
754+
except Exception:
755+
traceback.print_exc()
746756

747757
def send_req(self, function: int, req: dict) -> int:
748758
""""""
@@ -870,12 +880,12 @@ def subcribe_topic(self, biz_name: str, topic_name: str) -> int:
870880
ret, subscriber = self.connection.NewSubscriber(
871881
sub_callback,
872882
biz_name,
873-
300000
883+
5000
874884
)
875885
if ret != 0:
876886
error_msg = str(self.connection.GetMCLastError(), encoding="gbk")
877887
msg = f"订阅推送失败:{error_msg}"
878-
self.td_api.gateway.write_log(msg)
888+
self.gateway.write_log(msg)
879889
return
880890

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

954-
def query_contract(self) -> int:
964+
def query_contract(self, position_str: str = None) -> int:
955965
""""""
956966
req = self.generate_req()
957967
req["request_num"] = "10000"
968+
969+
if position_str:
970+
req["position_str"] = position_str
971+
958972
self.send_req(FUNCTION_QUERY_CONTRACT, req)
959973

960974
def subcribe_order(self) -> None:

vnpy/gateway/hsoption/s2013.pfx

3.01 KB
Binary file not shown.

0 commit comments

Comments
 (0)