@@ -265,7 +265,7 @@ def __init__(self, account: Union[TqMultiAccount, TqAccount, TqSim, None] = None
265
265
self ._pending_diffs = [] # 从网络上收到的待处理的 diffs, 只在 wait_update 函数执行过程中才可能为非空
266
266
self ._pending_peek = False # 是否有发出的 peek_message 还没收到数据回复
267
267
self ._prototype = self ._gen_prototype () # 各业务数据的原型, 用于决定默认值及将收到的数据转为特定的类型
268
- self ._security_prototype = self ._gen_security_prototype () # 股票业务数据原型
268
+ self ._security_prototype = self ._gen_security_prototype () # 股票业务数据原型
269
269
self ._dividend_cache = {} # 缓存合约对应的复权系数矩阵,每个合约只计算一次
270
270
self ._send_chan , self ._recv_chan = TqChan (self ), TqChan (self ) # 消息收发队列
271
271
self ._ws_md_recv_chan = None # 记录 ws_md_recv_chan 引用
@@ -1858,7 +1858,7 @@ def wait_update(self, deadline: Optional[float] = None, _task: Union[asyncio.Tas
1858
1858
self ._process_serial_extra_array (serial )
1859
1859
self ._run_until_idle (async_run = False ) # 这里 self._run_until_idle() 主要为了把上一步计算出得需要绘制的数据发送到 TqWebHelper
1860
1860
if _task is not None :
1861
- # 如果 _task 已经 done,则提前返回 True, False 代表超时会抛错
1861
+ # 如果 _task 已经 done,则提前返回 True, False 代表超时会抛错
1862
1862
_tasks = _task if isinstance (_task , list ) else [_task ]
1863
1863
if all ([t .done () for t in _tasks ]):
1864
1864
return True
@@ -2377,7 +2377,8 @@ def query_quotes(self, ins_class: str = None, exchange_id: str = None, product_i
2377
2377
if isinstance (self ._backtest , TqBacktest ):
2378
2378
variables ["timestamp" ] = int (self ._get_current_datetime ().timestamp () * 1e9 )
2379
2379
args_definitions , args = _get_query_args (variables )
2380
- query = f"query({ args_definitions } ){{multi_symbol_info({ args } ){{ ... on basic {{instrument_id }} }}}}"
2380
+ query = f"query{ f'({ args_definitions } )' if args_definitions else '' } {{multi_symbol_info{ f'({ args } )' if args else '' } {{ ... on basic {{instrument_id }} }}}}"
2381
+
2381
2382
def filter (query_result ):
2382
2383
result = []
2383
2384
for quote in query_result .get ("result" , {}).get ("multi_symbol_info" , []):
@@ -2387,6 +2388,7 @@ def filter(query_result):
2387
2388
else :
2388
2389
result .append (quote ["instrument_id" ])
2389
2390
return result
2391
+
2390
2392
return self ._get_symbol_list (query = query , variables = variables , filter = filter )
2391
2393
2392
2394
def _get_symbol_list (self , query : str , variables : dict , filter : Callable [[dict ], list ]):
@@ -2465,6 +2467,7 @@ def query_cont_quotes(self, exchange_id: str = None, product_id: str = None, has
2465
2467
query = f"query( { args_definitions } ){{multi_symbol_info( { args } ){{...basic ...cont}}}}"
2466
2468
fragments = "fragment basic on basic {instrument_id}" \
2467
2469
"fragment cont on derivative{underlying{edges{node{...on basic{instrument_id exchange_id}...on future {product_id}}}}}"
2470
+
2468
2471
def filter (query_result ):
2469
2472
result = []
2470
2473
for quote in query_result .get ("result" , {}).get ("multi_symbol_info" , []):
@@ -2476,8 +2479,8 @@ def filter(query_result):
2476
2479
continue
2477
2480
result .append (underlying_quote ["instrument_id" ])
2478
2481
return result
2479
- return self ._get_symbol_list (query = query + fragments , variables = variables , filter = filter )
2480
2482
2483
+ return self ._get_symbol_list (query = query + fragments , variables = variables , filter = filter )
2481
2484
2482
2485
def query_options (self , underlying_symbol : str , option_class : str = None , exercise_year : int = None ,
2483
2486
exercise_month : int = None , strike_price : float = None , expired : bool = None , has_A : bool = None ,
@@ -2534,6 +2537,7 @@ def query_options(self, underlying_symbol: str, option_class: str = None, exerci
2534
2537
if self ._stock is False :
2535
2538
raise Exception ("期货行情系统(_stock = False)不支持当前接口调用" )
2536
2539
query , variables = self ._query_options_by_underlying (underlying_symbol )
2540
+
2537
2541
def filter (query_result ):
2538
2542
options = []
2539
2543
exe_year = exercise_year if exercise_year else kwargs .get ("delivery_year" )
@@ -2554,6 +2558,7 @@ def filter(query_result):
2554
2558
continue
2555
2559
options .append (option ["instrument_id" ])
2556
2560
return options
2561
+
2557
2562
return self ._get_symbol_list (query = query , variables = variables , filter = filter )
2558
2563
2559
2564
def query_atm_options (self , underlying_symbol , underlying_price , price_level , option_class , exercise_year : int = None ,
@@ -2644,6 +2649,7 @@ def query_atm_options(self, underlying_symbol, underlying_price, price_level, op
2644
2649
if exercise_year and exercise_month and not (isinstance (exercise_year , int ) and isinstance (exercise_month , int )):
2645
2650
raise Exception ("exercise_year / exercise_month 类型错误" )
2646
2651
query , variables = self ._query_options_by_underlying (underlying_symbol )
2652
+
2647
2653
def filter (query_result ):
2648
2654
options = self ._convert_query_result_to_list (query_result )
2649
2655
if options :
@@ -2659,6 +2665,7 @@ def filter(query_result):
2659
2665
return rst_options
2660
2666
else :
2661
2667
return []
2668
+
2662
2669
return self ._get_symbol_list (query = query , variables = variables , filter = filter )
2663
2670
2664
2671
def query_symbol_info (self , symbol : Union [str , List [str ]]):
@@ -2699,12 +2706,19 @@ def query_symbol_info(self, symbol: Union[str, List[str]]):
2699
2706
* exercise_year: 期权最后行权日年份,只对期权品种有效。
2700
2707
* exercise_month: 期权最后行权日月份,只对期权品种有效。
2701
2708
* option_class: 期权方向
2709
+ * upper_limit: 涨停价
2710
+ * lower_limit: 跌停价
2702
2711
* pre_settlement: 昨结算
2703
2712
* pre_open_interest: 昨持仓
2704
2713
* pre_close: 昨收盘
2705
2714
* trading_time_day: 白盘交易时间段,list 类型
2706
2715
* trading_time_night: 夜盘交易时间段,list 类型
2707
2716
2717
+ 注意:
2718
+
2719
+ 1. 回测时,以下字段值为 nan: "upper_limit", "lower_limit", "pre_settlement", "pre_open_interest", "pre_close"
2720
+ 2. 中金所合约未提供涨停价、跌停价
2721
+
2708
2722
Example1::
2709
2723
2710
2724
from tqsdk import TqApi, TqAuth
@@ -2800,6 +2814,7 @@ def query_all_level_options(self, underlying_symbol, underlying_price, option_cl
2800
2814
if exercise_year and exercise_month and not (isinstance (exercise_year , int ) and isinstance (exercise_month , int )):
2801
2815
raise Exception ("exercise_year / exercise_month 类型错误" )
2802
2816
query , variables = self ._query_options_by_underlying (underlying_symbol )
2817
+
2803
2818
def filter (query_result ):
2804
2819
options = self ._convert_query_result_to_list (query_result )
2805
2820
if options :
@@ -2814,6 +2829,7 @@ def filter(query_result):
2814
2829
return in_money_options , at_money_options , out_of_money_options
2815
2830
else :
2816
2831
return [], [], []
2832
+
2817
2833
return self ._get_symbol_level_list (query = query , variables = variables , filter = filter )
2818
2834
2819
2835
def _get_symbol_level_list (self , query : str , variables : dict , filter : Callable [[dict ], Tuple [list , list , list ]]):
@@ -2907,6 +2923,7 @@ def query_all_level_finance_options(self, underlying_symbol, underlying_price, o
2907
2923
if any ([i not in [0 , 1 , 2 , 3 ] for i in nearbys ]):
2908
2924
raise Exception (f"ETF 期权标的为:{ underlying_symbol } ,exercise_date 参数应该是在 [0, 1, 2, 3] 之间。" )
2909
2925
query , variables = self ._query_options_by_underlying (underlying_symbol )
2926
+
2910
2927
def filter (query_result ):
2911
2928
options = self ._convert_query_result_to_list (query_result )
2912
2929
if options :
@@ -2918,6 +2935,7 @@ def filter(query_result):
2918
2935
return in_money_options , at_money_options , out_of_money_options
2919
2936
else :
2920
2937
return [], [], []
2938
+
2921
2939
return self ._get_symbol_level_list (query = query , variables = variables , filter = filter )
2922
2940
2923
2941
def _query_options_by_underlying (self , underlying_symbol ):
0 commit comments