Skip to content

Commit b5ae252

Browse files
committed
Merge branch 'feat_us' into 'master'
us support;order preview See merge request server/openapi/openapi-python-sdk!241
2 parents 5624810 + 2a71fad commit b5ae252

File tree

8 files changed

+58
-33
lines changed

8 files changed

+58
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.3.8 (2025-05-29)
2+
### New
3+
- 支持 TBUS 牌照配置
4+
- 支持订单预览
5+
16
## 3.3.7 (2025-05-12)
27
### New
38
- 订单回调添加属性 `attrList`

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__ = '3.3.7'
7+
__VERSION__ = '3.3.8'

tigeropen/common/consts/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ class OrderType(Enum):
211211
class License(Enum):
212212
TBNZ = 'TBNZ'
213213
TBSG = 'TBSG'
214+
TBHK = 'TBHK'
215+
TBAU = 'TBAU'
216+
TBUS = 'TBUS'
214217

215218

216219
@unique

tigeropen/examples/quote_client_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
filemode='a', )
2626
logger = logging.getLogger('TigerOpenApi')
2727

28-
client_config = get_client_config()
29-
openapi_client = QuoteClient(client_config, logger=logger)
28+
_demo_config = get_client_config()
29+
openapi_client = QuoteClient(_demo_config, logger=logger)
3030

3131

3232
def get_quote():

tigeropen/examples/trade_client_demo.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
filemode='a', )
2828
logger = logging.getLogger('TigerOpenApi')
2929

30-
client_config = get_client_config(private_key_path='your private key file path',
31-
tiger_id='your tiger id',
32-
account='your account')
30+
_demo_config = get_client_config(private_key_path='your private key file path',
31+
tiger_id='your tiger id',
32+
account='your account')
3333

3434

3535
def get_contract_apis():
36-
openapi_client = TradeClient(client_config, logger=logger)
36+
openapi_client = TradeClient(_demo_config, logger=logger)
3737
contract = openapi_client.get_contracts('AAPL')[0]
3838
print(contract)
3939
contract = openapi_client.get_contract('AAPL', SecurityType.STK, currency=Currency.USD)
@@ -43,7 +43,7 @@ def get_contract_apis():
4343
print(contracts)
4444

4545
def get_account_apis():
46-
openapi_client = TradeClient(client_config, logger=logger)
46+
openapi_client = TradeClient(_demo_config, logger=logger)
4747
openapi_client.get_managed_accounts()
4848
# 获取订单
4949
openapi_client.get_orders()
@@ -73,7 +73,7 @@ def get_account_apis():
7373

7474
def test_get_orders_by_page():
7575
"""分页获取订单"""
76-
trade_client = TradeClient(client_config)
76+
trade_client = TradeClient(_demo_config)
7777
result = list()
7878
# 每次返回数量(需 <= 300)
7979
limit = 300
@@ -96,8 +96,8 @@ def test_get_orders_by_page():
9696

9797

9898
def trade_apis():
99-
account = client_config.account
100-
openapi_client = TradeClient(client_config, logger=logger)
99+
account = _demo_config.account
100+
openapi_client = TradeClient(_demo_config, logger=logger)
101101

102102
# 通过请求获取合约
103103
contract = openapi_client.get_contracts('AAPL')[0]
@@ -159,8 +159,8 @@ def trade_apis():
159159

160160

161161
def algo_order_demo():
162-
account = client_config.account
163-
openapi_client = TradeClient(client_config, logger=logger)
162+
account = _demo_config.account
163+
openapi_client = TradeClient(_demo_config, logger=logger)
164164
contract = stock_contract(symbol='AAPL', currency='USD')
165165
params = algo_order_params(start_time=1686147201000, end_time=1686150801000, no_take_liq=True,
166166
allow_past_end_time=True, participation_rate=0.1)
@@ -175,9 +175,9 @@ def get_account_info():
175175
:return:
176176
"""
177177
from tigeropen.common.consts.service_types import ACCOUNTS
178-
openapi_client = TigerOpenClient(client_config)
178+
openapi_client = TigerOpenClient(_demo_config)
179179
account = AccountsParams()
180-
account.account = client_config.account
180+
account.account = _demo_config.account
181181
request = OpenApiRequest(method=ACCOUNTS, biz_model=account)
182182

183183
response_content = None
@@ -197,7 +197,7 @@ def get_account_info():
197197

198198

199199
class TestTradeClient(unittest.TestCase):
200-
trade_client = TradeClient(client_config)
200+
trade_client = TradeClient(_demo_config)
201201

202202
def test_transfer_segment_fund(self):
203203
"""资金划转"""

tigeropen/tiger_open_config.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,31 @@
1414
from jproperties import Properties
1515
from pytz import timezone
1616
from tigeropen import __VERSION__
17-
from tigeropen.common.consts import Language, ServiceType
17+
from tigeropen.common.consts import Language, ServiceType, License
1818
from tigeropen.common.util.account_util import AccountUtil
1919
from tigeropen.common.util.common_utils import get_enum_value
2020
from tigeropen.common.util.signature_utils import read_private_key
2121
from tigeropen.common.util.web_utils import do_get
2222

2323
DEFAULT_DOMAIN = 'openapi.tigerfintech.com'
24+
DEFAULT_US_DOMAIN = 'openapi.tradeup.com'
2425
DEFAULT_SANDBOX_DOMAIN = 'openapi-sandbox.tigerfintech.com'
25-
DOMAIN_GARDEN_ADDRESS = 'https://cg.play-analytics.com/'
26+
DOMAIN_GARDEN_ADDRESS = 'https://cg.play-analytics.com'
2627

2728
HTTPS_PROTOCAL = 'https://'
2829
SSL_PROTOCAL = 'ssl'
2930
GATEWAY_SUFFIX = '/gateway'
3031
DOMAIN_SEPARATOR = '-'
3132

32-
# 老虎证券开放平台网关地址
33+
# 网关地址
3334
SERVER_URL = HTTPS_PROTOCAL + DEFAULT_DOMAIN + GATEWAY_SUFFIX
34-
# 老虎证券开放平台 socket 连接域名端口
35+
# socket 域名端口
3536
SOCKET_HOST_PORT = (SSL_PROTOCAL, DEFAULT_DOMAIN, 9883)
36-
# 老虎证券开放平台公钥
37+
# US 网关地址
38+
US_SERVER_URL = HTTPS_PROTOCAL + DEFAULT_US_DOMAIN + GATEWAY_SUFFIX
39+
# US socket 域名端口
40+
US_SOCKET_HOST_PORT = (SSL_PROTOCAL, DEFAULT_US_DOMAIN, 9983)
41+
# 开放平台公钥
3742
TIGER_PUBLIC_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNF3G8SoEcCZh2rshUbayDgLLrj6rKgzNMxDL2HS' \
3843
'nKcB0+GPOsndqSv+a4IBu9+I3fyBp5hkyMMG2+AXugd9pMpy6VxJxlNjhX1MYbNTZJUT4nudki4uh+LM' \
3944
'OkIBHOceGNXjgB+cXqmlUnjlqha/HgboeHSnSgpM3dKSJQlIOsDwIDAQAB'
@@ -126,6 +131,11 @@ def __init__(self, sandbox_debug=None, enable_dynamic_domain=True, props_path='.
126131
if self.enable_dynamic_domain:
127132
self.domain_conf = self.query_domains()
128133
self.refresh_server_info()
134+
elif self.is_us():
135+
self.server_url = US_SERVER_URL
136+
self.quote_server_url = US_SERVER_URL
137+
self.socket_host_port = US_SOCKET_HOST_PORT
138+
129139
self.inited = False
130140

131141
@property
@@ -404,7 +414,10 @@ def query_domains(self):
404414
}
405415
"""
406416
try:
407-
result = json.loads(do_get(DOMAIN_GARDEN_ADDRESS, headers=dict(), params=dict(), timeout=1)) \
417+
url = DOMAIN_GARDEN_ADDRESS
418+
if self.is_us():
419+
url += '?appName=tradeup'
420+
result = json.loads(do_get(url, headers=dict(), params=dict(), timeout=1)) \
408421
.get('items')
409422
if result:
410423
for item in result:
@@ -441,6 +454,9 @@ def _get_domain_by_type(self, service_type, license, is_paper=False):
441454
def sdk_version(self):
442455
return __VERSION__
443456

457+
def is_us(self):
458+
return self.license and License.TBUS.value == get_enum_value(self.license)
459+
444460

445461
def get_client_config(private_key_path, tiger_id, account, sandbox_debug=False, sign_type=None, timeout=None,
446462
language=None, charset=None, server_url=None, socket_host_port=None, secret_key=None,
Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
from tigeropen.common.response import TigerResponse
2-
3-
PREVIEW_ORDER_FIELD_MAPPING = {"initMarginBefore": "init_margin_before", "commissionCurrency": "commission_currency",
4-
"maintMargin": "maint_margin", "equityWithLoan": "equity_with_loan",
5-
"minCommission": "min_commission", "maintMarginBefore": "maint_margin_before",
6-
"initMargin": "init_margin", "equityWithLoanBefore": "equity_with_loan_before",
7-
"marginCurrency": "margin_currency", "maxCommission": "max_commission",
8-
"warningText": "warning_text"}
2+
from tigeropen.common.util.string_utils import camel_to_underline_obj
93

104

115
class PreviewOrderResponse(TigerResponse):
@@ -20,7 +14,4 @@ def parse_response_content(self, response_content):
2014
self._is_success = response['is_success']
2115

2216
if self.data:
23-
for key, value in self.data.items():
24-
field = PREVIEW_ORDER_FIELD_MAPPING.get(key, key)
25-
self.preview_order[field] = value
26-
17+
self.preview_order = camel_to_underline_obj(self.data)

tigeropen/trade/trade_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,18 @@ def preview_order(self, order):
578578
params.percent_offset = order.percent_offset
579579
params.time_in_force = order.time_in_force
580580
params.outside_rth = order.outside_rth
581+
params.order_legs = order.order_legs
582+
params.algo_params = order.algo_params
581583
params.secret_key = order.secret_key if order.secret_key else self._secret_key
584+
params.adjust_limit = order.adjust_limit
585+
params.user_mark = order.user_mark
586+
params.expire_time = order.expire_time
582587
params.lang = get_enum_value(self._lang)
588+
params.combo_type = get_enum_value(order.combo_type)
589+
params.contract_legs = order.contract_legs
590+
params.total_cash_amount = order.total_cash_amount
591+
params.trading_session_type = get_enum_value(order.trading_session_type)
592+
583593
request = OpenApiRequest(PREVIEW_ORDER, biz_model=params)
584594
response_content = self.__fetch_data(request)
585595
if response_content:

0 commit comments

Comments
 (0)