Skip to content

Commit 21e88aa

Browse files
committed
params supports version
1 parent 3549899 commit 21e88aa

File tree

7 files changed

+54
-22
lines changed

7 files changed

+54
-22
lines changed

tigeropen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
55
@author: gaoan
66
"""
7-
__VERSION__ = '2.0.2'
7+
__VERSION__ = '2.0.3'

tigeropen/common/consts/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Leverage, Profitability
1212
from .quote_keys import QuoteChangeKey, QuoteKeyType
1313

14-
OPEN_API_SDK_VERSION = "2.0"
14+
OPEN_API_SERVICE_VERSION = "2.0"
1515

1616
THREAD_LOCAL = threading.local()
1717

tigeropen/common/model.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2021/11/12
4+
# @Author : sukai
5+
6+
class BaseParams:
7+
def __init__(self):
8+
self._version = None # api版本
9+
10+
@property
11+
def version(self):
12+
return self._version
13+
14+
@version.setter
15+
def version(self, value):
16+
self._version = value

tigeropen/quote/request/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import json
99
from tigeropen.common.consts.params import *
10-
from tigeropen.common.consts import OPEN_API_SDK_VERSION
10+
from tigeropen.common.consts import OPEN_API_SERVICE_VERSION
1111

1212

1313
class OpenApiRequest:
@@ -26,7 +26,7 @@ def biz_model(self, value):
2626
def get_params(self):
2727
params = dict()
2828
params[P_METHOD] = self._method
29-
params[P_VERSION] = OPEN_API_SDK_VERSION
29+
params[P_VERSION] = getattr(self.biz_model, P_VERSION)
3030

3131
if self.biz_model:
3232
params[P_BIZ_CONTENT] = json.dumps(obj=self.biz_model.to_openapi_dict(), ensure_ascii=False, sort_keys=True,

tigeropen/quote/request/model.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
55
@author: gaoan
66
"""
7+
from tigeropen.common.model import BaseParams
78

89

9-
class MarketParams:
10+
class MarketParams(BaseParams):
1011
def __init__(self):
12+
super(MarketParams, self).__init__()
1113
self._market = None # 市场
1214
self._sec_type = None # 交易品种
1315
self._lang = None # 语言
@@ -346,8 +348,9 @@ def to_openapi_dict(self):
346348
return params
347349

348350

349-
class SingleContractParams:
351+
class SingleContractParams(BaseParams):
350352
def __init__(self):
353+
super(SingleContractParams, self).__init__()
351354
self._symbol = None
352355
self._put_call = None # for option
353356
self._expiry = None # for option and future
@@ -461,7 +464,7 @@ def to_openapi_dict(self):
461464
return params
462465

463466

464-
class MultipleContractParams:
467+
class MultipleContractParams(BaseParams):
465468
def __init__(self):
466469
super(MultipleContractParams, self).__init__()
467470
self._contracts = None # list of SingleQuoteParams
@@ -484,8 +487,9 @@ def to_openapi_dict(self):
484487
return params
485488

486489

487-
class FutureExchangeParams:
490+
class FutureExchangeParams(BaseParams):
488491
def __init__(self):
492+
super(FutureExchangeParams, self).__init__()
489493
self._exchange_code = None # 交易所
490494
self._lang = None # 语言
491495

@@ -516,7 +520,7 @@ def to_openapi_dict(self):
516520
return params
517521

518522

519-
class FutureTypeParams:
523+
class FutureTypeParams(BaseParams):
520524
def __init__(self):
521525
self._type = None # 期货品种
522526
self._lang = None # 语言
@@ -548,8 +552,9 @@ def to_openapi_dict(self):
548552
return params
549553

550554

551-
class FutureTradingTimeParams:
555+
class FutureTradingTimeParams(BaseParams):
552556
def __init__(self):
557+
super(FutureTradingTimeParams, self).__init__()
553558
self._contract_code = None
554559
self._trading_date = None
555560

@@ -674,8 +679,9 @@ def to_openapi_dict(self):
674679
return params
675680

676681

677-
class DepthQuoteParams:
682+
class DepthQuoteParams(BaseParams):
678683
def __init__(self):
684+
super(DepthQuoteParams, self).__init__()
679685
self._symbols = None
680686
self._market = None
681687

tigeropen/tiger_open_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
import json
99
import uuid
1010

11-
from tigeropen.common.consts import OPEN_API_SDK_VERSION, THREAD_LOCAL
11+
from tigeropen import __VERSION__
12+
from tigeropen.common.consts import OPEN_API_SERVICE_VERSION, THREAD_LOCAL
1213
from tigeropen.common.consts.params import P_TIMESTAMP, P_TIGER_ID, P_METHOD, P_CHARSET, P_VERSION, P_SIGN_TYPE, \
1314
P_DEVICE_ID, P_NOTIFY_URL, COMMON_PARAM_KEYS, P_SIGN
1415
from tigeropen.common.exceptions import ResponseException, RequestException
@@ -36,7 +37,7 @@ def __init__(self, client_config, logger=None):
3637
'Content-type': 'application/json;charset=' + self.__config.charset,
3738
"Cache-Control": "no-cache",
3839
"Connection": "Keep-Alive",
39-
"User-Agent": 'openapi-python-sdk-' + OPEN_API_SDK_VERSION
40+
"User-Agent": 'openapi-python-sdk-' + __VERSION__
4041
}
4142
self.__device_id = self.__get_device_id()
4243

@@ -50,7 +51,7 @@ def __get_common_params(self, params):
5051
common_params[P_TIGER_ID] = self.__config.tiger_id
5152
common_params[P_METHOD] = params[P_METHOD]
5253
common_params[P_CHARSET] = self.__config.charset
53-
common_params[P_VERSION] = params[P_VERSION]
54+
common_params[P_VERSION] = params[P_VERSION] if params.get(P_VERSION) is not None else OPEN_API_SERVICE_VERSION
5455
common_params[P_SIGN_TYPE] = self.__config.sign_type
5556
common_params[P_DEVICE_ID] = self.__device_id
5657
if has_value(params, P_NOTIFY_URL):

tigeropen/trade/request/model.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
55
@author: gaoan
66
"""
7+
from tigeropen.common.model import BaseParams
78

89

9-
class AccountsParams:
10+
class AccountsParams(BaseParams):
1011
def __init__(self):
12+
super(AccountsParams, self).__init__()
1113
self._account = None
1214
self._secret_key = None
1315

@@ -36,8 +38,9 @@ def to_openapi_dict(self):
3638
return params
3739

3840

39-
class AssetParams:
41+
class AssetParams(BaseParams):
4042
def __init__(self):
43+
super(AssetParams, self).__init__()
4144
self._account = None
4245
self._secret_key = None
4346
self._segment = False
@@ -104,8 +107,9 @@ def to_openapi_dict(self):
104107
return params
105108

106109

107-
class PositionParams:
110+
class PositionParams(BaseParams):
108111
def __init__(self):
112+
super(PositionParams, self).__init__()
109113
self._account = None
110114
self._secret_key = None
111115
self._symbol = None
@@ -196,8 +200,9 @@ def to_openapi_dict(self):
196200
return params
197201

198202

199-
class ContractParams:
203+
class ContractParams(BaseParams):
200204
def __init__(self):
205+
super(ContractParams, self).__init__()
201206
self._account = None
202207
self._secret_key = None
203208
self._symbol = None
@@ -324,8 +329,9 @@ def to_openapi_dict(self):
324329
return params
325330

326331

327-
class OrderParams:
332+
class OrderParams(BaseParams):
328333
def __init__(self):
334+
super(OrderParams, self).__init__()
329335
self._account = None # 账户
330336
self._secret_key = None
331337
self._id = None # 订单号(全局)
@@ -404,8 +410,9 @@ def to_openapi_dict(self):
404410
return params
405411

406412

407-
class OrdersParams:
413+
class OrdersParams(BaseParams):
408414
def __init__(self):
415+
super(OrdersParams, self).__init__()
409416
self._account = None # 账户
410417
self._secret_key = None
411418
self._market = None # 市场
@@ -556,8 +563,9 @@ def to_openapi_dict(self):
556563
return params
557564

558565

559-
class PlaceModifyOrderParams:
566+
class PlaceModifyOrderParams(BaseParams):
560567
def __init__(self):
568+
super(PlaceModifyOrderParams, self).__init__()
561569
self.account = None
562570
self.secret_key = None
563571
self.id = None
@@ -661,8 +669,9 @@ def to_openapi_dict(self):
661669
return params
662670

663671

664-
class CancelOrderParams:
672+
class CancelOrderParams(BaseParams):
665673
def __init__(self):
674+
super(CancelOrderParams, self).__init__()
666675
self._account = None
667676
self._secret_key = None
668677
self._id = None

0 commit comments

Comments
 (0)