10
10
import requests
11
11
from shinny_structlog import ShinnyLoggerAdapter
12
12
13
- import tqsdk
13
+ from tqsdk .constants import FUTURE_EXCHANGES , SPOT_EXCHANGES , KQ_EXCHANGES , KQD_EXCHANGES , STOCK_EXCHANGES
14
+ from tqsdk .__version__ import __version__
14
15
15
16
16
17
class TqAuth (object ):
@@ -49,7 +50,7 @@ def __init__(self, user_name: str = "", password: str = ""):
49
50
@property
50
51
def _base_headers (self ):
51
52
return {
52
- "User-Agent" : "tqsdk-python %s" % tqsdk . __version__ ,
53
+ "User-Agent" : "tqsdk-python %s" % __version__ ,
53
54
"Accept" : "application/json" ,
54
55
"Authorization" : "Bearer %s" % self ._access_token
55
56
}
@@ -148,9 +149,9 @@ def _has_account(self, account):
148
149
def _has_md_grants (self , symbol ):
149
150
symbol_list = symbol if isinstance (symbol , list ) else [symbol ]
150
151
for symbol in symbol_list :
151
- if symbol .split ('.' , 1 )[0 ] in [ "SHFE" , "DCE" , "CZCE" , "INE" , "CFFEX" , "KQ" , "KQD" , "SSWE" , "GFEX" ] and self ._has_feature ("futr" ):
152
+ if symbol .split ('.' , 1 )[0 ] in ( FUTURE_EXCHANGES + SPOT_EXCHANGES + KQ_EXCHANGES + KQD_EXCHANGES ) and self ._has_feature ("futr" ):
152
153
continue
153
- elif symbol .split ('.' , 1 )[0 ] in ["CSI" , "SSE" , "SZSE" ] and self ._has_feature ("sec" ):
154
+ elif symbol .split ('.' , 1 )[0 ] in ( ["CSI" ] + STOCK_EXCHANGES ) and self ._has_feature ("sec" ):
154
155
continue
155
156
elif symbol in ["SSE.000016" , "SSE.000300" , "SSE.000905" , "SSE.000852" ] and self ._has_feature ("lmt_idx" ):
156
157
continue
@@ -160,8 +161,8 @@ def _has_md_grants(self, symbol):
160
161
161
162
def _has_td_grants (self , symbol ):
162
163
# 对于 opt / cmb / adv 权限的检查由 OTG 做
163
- if symbol .split ('.' , 1 )[0 ] in [ "SSE" , "SZSE" ] and self ._has_feature ("sec" ):
164
+ if symbol .split ('.' , 1 )[0 ] in STOCK_EXCHANGES and self ._has_feature ("sec" ):
164
165
return True
165
- if symbol .split ('.' , 1 )[0 ] in [ "SHFE" , "DCE" , "CZCE" , "INE" , "CFFEX" , "KQ" , "GFEX" ] and self ._has_feature ("futr" ):
166
+ if symbol .split ('.' , 1 )[0 ] in ( FUTURE_EXCHANGES + KQ_EXCHANGES ) and self ._has_feature ("futr" ):
166
167
return True
167
168
raise Exception (f"您的账户不支持交易 { symbol } ,需要购买后才能使用。升级网址:https://www.shinnytech.com/tqsdk_professional/" )
0 commit comments