1313from tigeropen .common .consts import Market , QuoteRight , BarPeriod , OPEN_API_SERVICE_VERSION_V3
1414from tigeropen .common .consts import THREAD_LOCAL , SecurityType , CorporateActionType , IndustryLevel
1515from tigeropen .common .consts .service_types import GRAB_QUOTE_PERMISSION , QUOTE_DELAY , GET_QUOTE_PERMISSION , \
16- HISTORY_TIMELINE , FUTURE_CONTRACT_BY_CONTRACT_CODE , TRADING_CALENDAR
16+ HISTORY_TIMELINE , FUTURE_CONTRACT_BY_CONTRACT_CODE , TRADING_CALENDAR , FUTURE_CONTRACTS
1717from tigeropen .common .consts .service_types import MARKET_STATE , ALL_SYMBOLS , ALL_SYMBOL_NAMES , BRIEF , \
1818 TIMELINE , KLINE , TRADE_TICK , OPTION_EXPIRATION , OPTION_CHAIN , FUTURE_EXCHANGE , OPTION_BRIEF , \
1919 OPTION_KLINE , OPTION_TRADE_TICK , FUTURE_KLINE , FUTURE_TICK , FUTURE_CONTRACT_BY_EXCHANGE_CODE , \
@@ -72,8 +72,8 @@ class QuoteClient(TigerOpenClient):
7272
7373 def __init__ (self , client_config , logger = None , is_grab_permission = True ):
7474 if not logger :
75- logger = logging .getLogger ('tiger_openapi' )
76- super (QuoteClient , self ).__init__ (client_config , logger = logger )
75+ self . logger = logging .getLogger ('tiger_openapi' )
76+ super (QuoteClient , self ).__init__ (client_config , logger = self . logger )
7777 self ._lang = LANGUAGE
7878 self ._timezone = eastern
7979 if client_config :
@@ -83,7 +83,7 @@ def __init__(self, client_config, logger=None, is_grab_permission=True):
8383 self .permissions = None
8484 if is_grab_permission and self .permissions is None :
8585 self .permissions = self .grab_quote_permission ()
86- logger .info ('Grab quote permission. Permissions:' + str (self .permissions ))
86+ self . logger .info ('Grab quote permission. Permissions:' + str (self .permissions ))
8787
8888 def __fetch_data (self , request ):
8989 try :
@@ -890,6 +890,28 @@ def get_current_future_contract(self, future_type, lang=None):
890890 raise ApiException (response .code , response .message )
891891 return None
892892
893+ def get_all_future_contracts (self , future_type , lang = None ):
894+ """
895+ Query all contracts of a given type
896+ :param future_type: like CL, VIX
897+ :param lang: language
898+ :return: same as "get_current_future_contract"
899+ """
900+ params = FutureContractParams ()
901+ params .type = future_type
902+ params .lang = get_enum_value (lang ) if lang else get_enum_value (self ._lang )
903+
904+ request = OpenApiRequest (FUTURE_CONTRACTS , biz_model = params )
905+ response_content = self .__fetch_data (request )
906+ if response_content :
907+ response = FutureContractResponse ()
908+ response .parse_response_content (response_content )
909+ if response .is_success ():
910+ return response .contracts
911+ else :
912+ raise ApiException (response .code , response .message )
913+ return None
914+
893915 def get_future_contract (self , contract_code , lang = None ):
894916 """
895917 get future contract by contract_code
@@ -1014,10 +1036,10 @@ def get_future_bars_by_page(self, identifier, period=BarPeriod.DAY, begin_time=-
10141036 time .sleep (time_interval )
10151037 return pd .concat (result ).sort_values ('time' ).reset_index (drop = True )
10161038
1017- def get_future_trade_ticks (self , identifiers , begin_index = 0 , end_index = 30 , limit = 1000 ):
1039+ def get_future_trade_ticks (self , identifier , begin_index = 0 , end_index = 30 , limit = 1000 ):
10181040 """
10191041 获取期货逐笔成交
1020- :param identifiers: 期货代码列表
1042+ :param identifier: future identifier. Only supports one identifier
10211043 :param begin_index: 开始索引
10221044 :param end_index: 结束索引
10231045 :param limit: 数量限制
@@ -1028,11 +1050,16 @@ def get_future_trade_ticks(self, identifiers, begin_index=0, end_index=30, limit
10281050 volume: 成交量
10291051 """
10301052 params = FutureQuoteParams ()
1031- params .contract_codes = identifiers
1053+ # Compatible with previous version (previous version 'identifiers' argument is a list)
1054+ params .contract_code = identifier
1055+ if isinstance (identifier , list ):
1056+ self .logger .warning ("the 'identifier' argument should be a string" )
1057+ params .contract_code = identifier [0 ]
10321058 params .begin_index = begin_index
10331059 params .end_index = end_index
10341060 params .limit = limit
10351061 params .lang = get_enum_value (self ._lang )
1062+ params .version = OPEN_API_SERVICE_VERSION_V3
10361063 request = OpenApiRequest (FUTURE_TICK , biz_model = params )
10371064 response_content = self .__fetch_data (request )
10381065 if response_content :
0 commit comments