Skip to content

Commit 229e42f

Browse files
committed
Merge branch 'master' into level2
2 parents 2c6400f + 750cc1c commit 229e42f

25 files changed

+838
-57
lines changed

requirements.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
six
2-
simplejson
3-
delorean
4-
pandas==0.24.2
5-
python-dateutil
6-
pytz
1+
six==1.13.0
2+
simplejson==3.17.0
3+
delorean==1.0.0
4+
pandas==0.25.3
5+
python-dateutil==2.8.1
6+
pytz==2019.3
77
pyasn1==0.4.2
88
rsa==4.0
9-
stomp.py
9+
stomp.py==4.1.22
10+
enum34==1.1.6

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
from os import path
88
from setuptools import find_packages, setup
99

10-
with open(path.join(path.abspath(path.dirname(__file__)), 'requirements.txt'), encoding='utf-8') as f:
10+
with open(path.join(path.abspath(path.dirname(__file__)), 'requirements.txt')) as f:
1111
install_requires = f.read()
1212

1313
setup(
1414
name='tigeropen',
15-
version='1.1.9',
15+
version='1.3.3',
1616
description='TigerBrokers Open API',
1717
packages=find_packages(exclude=[]),
1818
author='TigerBrokers',

tigeropen/common/consts/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Market(Enum):
3131
US = 'US' # 美股
3232
HK = 'HK' # 港股
3333
CN = 'CN' # A股
34+
SG = 'SG' # 新加坡
3435

3536

3637
@unique
@@ -62,6 +63,7 @@ class Currency(Enum):
6263
USD = 'USD' # 美元
6364
HKD = 'HKD' # 港币
6465
CNH = 'CNH' # 离岸人民币
66+
SGD = 'SGD' # 新加坡币
6567

6668

6769
@unique
@@ -132,3 +134,15 @@ class CorporateActionType(Enum):
132134
"""
133135
SPLIT = 'split' # 拆合股
134136
DIVIDEND = 'dividend' # 分红
137+
EARNINGS_CALENDAR = 'earning' # 财报日历
138+
139+
140+
@unique
141+
class IndustryLevel(Enum):
142+
"""
143+
行业级别. 级别从1级到4级依次为: GSECTOR, GGROUP, GIND, GSUBIND
144+
"""
145+
GSECTOR = 'GSECTOR'
146+
GGROUP = 'GGROUP'
147+
GIND = 'GIND'
148+
GSUBIND = 'GSUBIND'

tigeropen/common/consts/push_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ class ResponseType(Enum):
6060
GET_SUB_SYMBOLS_END = 111
6161
GET_SUBSCRIBE_END = 112
6262
GET_CANCEL_SUBSCRIBE_END = 113
63+
64+
ERROR_END = 200

tigeropen/common/consts/service_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@
6666
FINANCIAL_DAILY = 'financial_daily'
6767
FINANCIAL_REPORT = 'financial_report'
6868
CORPORATE_ACTION = 'corporate_action'
69+
70+
# 行业数据
71+
INDUSTRY_LIST = 'industry_list'
72+
INDUSTRY_STOCKS = 'industry_stocks'
73+
STOCK_INDUSTRY = 'stock_industry'
74+

tigeropen/common/util/contract_utils.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
@author: gaoan
66
"""
77
import re
8+
9+
from tigeropen.common.consts import SecurityType
810
from tigeropen.trade.domain.contract import Contract
911

1012

@@ -13,7 +15,8 @@ def stock_contract(symbol, currency, local_symbol=None, exchange=None, contract_
1315
contract_id=contract_id)
1416

1517

16-
def option_contract_by_symbol(symbol, expiry, strike, put_call, currency, multiplier=100, local_symbol=None, contract_id=None):
18+
def option_contract_by_symbol(symbol, expiry, strike, put_call, currency, multiplier=100, local_symbol=None,
19+
contract_id=None):
1720
return Contract(symbol, currency, sec_type='OPT', expiry=expiry, strike=strike, put_call=put_call,
1821
multiplier=multiplier, local_symbol=local_symbol, contract_id=contract_id)
1922

@@ -26,7 +29,8 @@ def option_contract(identifier, multiplier=100, currency='USD'):
2629
multiplier=multiplier)
2730

2831

29-
def future_contract(symbol, currency, expiry=None, exchange=None, contract_month=None, multiplier=None, local_symbol=None):
32+
def future_contract(symbol, currency, expiry=None, exchange=None, contract_month=None, multiplier=None,
33+
local_symbol=None):
3034
return Contract(symbol, currency, sec_type='FUT', expiry=expiry, exchange=exchange, contract_month=contract_month,
3135
multiplier=multiplier, local_symbol=local_symbol)
3236

@@ -41,14 +45,28 @@ def cash_contract(symbol, currency, local_symbol=None):
4145
return Contract(symbol, currency, sec_type='CASH', local_symbol=local_symbol)
4246

4347

48+
def war_contract_by_symbol(symbol, expiry, strike, put_call, local_symbol, multiplier=100, currency='HKD',
49+
contract_id=None):
50+
"""港股窝轮"""
51+
return Contract(symbol, currency=currency, sec_type=SecurityType.WAR.value, expiry=expiry, strike=strike,
52+
put_call=put_call, local_symbol=local_symbol, multiplier=multiplier, contract_id=contract_id)
53+
54+
55+
def iopt_contract_by_symbol(symbol, expiry, strike, put_call, local_symbol, multiplier=100, currency='HKD',
56+
contract_id=None):
57+
"""港股牛熊证"""
58+
return Contract(symbol, currency=currency, sec_type=SecurityType.IOPT.value, expiry=expiry, strike=strike,
59+
put_call=put_call, local_symbol=local_symbol, multiplier=multiplier, contract_id=contract_id)
60+
61+
4462
def extract_option_info(identifier):
4563
"""
4664
从期权中提取 symbol, expiry 等信息
4765
:param identifier:
4866
:return:
4967
"""
5068
if identifier:
51-
tokens = re.findall(r'(\w+)\s*(\d{6})(C|P)(\d+)', identifier, re.M)
69+
tokens = re.findall(r'(\w+)\s*(\d{6})([CP])(\d+)', identifier, re.M)
5270
if len(tokens) == 1:
5371
underlying_symbol, expiry, put_call, strike = tokens[0]
5472
expiry = '20' + expiry

tigeropen/common/util/order_utils.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
@author: gaoan
66
"""
7-
from tigeropen.trade.domain.order import Order
7+
from tigeropen.trade.domain.order import Order, OrderLeg, AlgoParams
88
from tigeropen.common.consts import OrderStatus
99

1010

@@ -74,6 +74,63 @@ def trail_order(account, contract, action, quantity, trailing_percent=None, aux_
7474
return Order(account, contract, action, 'TRAIL', quantity, trailing_percent=trailing_percent, aux_price=aux_price)
7575

7676

77+
def order_leg(leg_type, price, time_in_force='DAY', outside_rth=None):
78+
"""
79+
附加订单
80+
:param leg_type: 附加订单类型. PROFIT 止盈单类型, LOSS 止损单类型
81+
:param price: 附加订单价格.
82+
:param time_in_force: 附加订单有效期. 'DAY'(当日有效)和'GTC'(取消前有效 Good-Til-Canceled).
83+
:param outside_rth: 附加订单是否允许盘前盘后交易(美股专属). True 允许, False 不允许.
84+
"""
85+
return OrderLeg(leg_type=leg_type, price=price, time_in_force=time_in_force, outside_rth=outside_rth)
86+
87+
88+
def limit_order_with_legs(account, contract, action, quantity, limit_price, order_legs=None):
89+
"""
90+
限价单 + 附加订单(仅环球账户支持)
91+
:param account:
92+
:param contract:
93+
:param action: BUY/SELL
94+
:param quantity:
95+
:param limit_price: 限价单价格
96+
:param order_legs: 附加订单列表
97+
:return:
98+
"""
99+
if order_legs and len(order_legs) > 2:
100+
raise Exception('2 order legs at most')
101+
return Order(account, contract, action, 'LMT', quantity, limit_price=limit_price, order_legs=order_legs)
102+
103+
104+
def algo_order_params(start_time=None, end_time=None, no_take_liq=None, allow_past_end_time=None, participation_rate=None):
105+
"""
106+
算法订单参数
107+
:param start_time: 生效开始时间(时间戳 TWAP和VWAP专用)
108+
:param end_time: 生效结束时间(时间戳 TWAP和VWAP专用)
109+
:param no_take_liq: 是否尽可能减少交易次数(VWAP订单专用)
110+
:param allow_past_end_time: 是否允许生效时间结束后继续完成成交(TWAP和VWAP专用)
111+
:param participation_rate: 参与率(VWAP专用,0.01-0.5)
112+
:return:
113+
"""
114+
return AlgoParams(start_time=start_time, end_time=end_time, no_take_liq=no_take_liq,
115+
allow_past_end_time=allow_past_end_time, participation_rate=participation_rate)
116+
117+
118+
def algo_order(account, contract, action, quantity, strategy, algo_params=None, limit_price=None):
119+
"""
120+
算法订单
121+
:param account:
122+
:param contract:
123+
:param action:
124+
:param quantity:
125+
:param strategy: 交易量加权平均价格(VWAP)/时间加权平均价格(TWAP)
126+
:param algo_params: tigeropen.trade.domain.order.AlgoParams
127+
:param limit_price:
128+
:return:
129+
"""
130+
return Order(account, contract, action, order_type=strategy, quantity=quantity, algo_params=algo_params,
131+
limit_price=limit_price, outside_rth=False)
132+
133+
77134
def get_order_status(value):
78135
"""
79136
Invalid(-2), Initial(-1), PendingCancel(3), Cancelled(4), Submitted(5), Filled(6), Inactive(7), PendingSubmit(8)

tigeropen/common/util/web_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def do_post(url, query_string=None, headers=None, params=None, timeout=15, chars
6868
response = connection.getresponse()
6969
result = response.read()
7070

71-
if response.status is not 200:
71+
if response.status != 200:
7272
if PYTHON_VERSION_3 and charset:
7373
result = result.decode(charset)
7474
raise ResponseException('[' + THREAD_LOCAL.uuid + ']invalid http status ' + str(response.status) +

tigeropen/examples/client_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ def get_client_config():
1818
client_config = TigerOpenClientConfig(sandbox_debug=is_sandbox)
1919
client_config.private_key = read_private_key('your private key file path')
2020
client_config.tiger_id = 'your tiger id'
21-
client_config.account = 'your account' # 环球账户
21+
client_config.account = 'your account' # 环球账户.
22+
# 只使用一个账户时,不论是环球账户, 标准账户或是模拟账户, 都填在 client_config.account 下, 默认只会使用这里的账户.
23+
# standard_account 属性和 paper_account 属性只是为多账户时取用方便, 一般可忽略
2224
client_config.standard_account = None # 标准账户
2325
client_config.paper_account = None # 模拟账户
2426
client_config.language = Language.en_US

tigeropen/examples/push_client_demo.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,24 @@ def on_position_changed(account, items):
9090
print(account, items)
9191

9292

93+
def subscribe_callback(destination, content):
94+
"""
95+
订阅成功与否的回调
96+
:param destination: 订阅的类型. 有 quote, trade/asset, trade/position, trade/order
97+
:param content: 回调信息. 如成功 {'code': 0, 'message': 'success'}; 若失败则 code 不为0, message 为错误详情
98+
"""
99+
print('subscribe:{}, callback content:{}'.format(destination, content))
100+
101+
102+
def unsubscribe_callback(destination, content):
103+
"""
104+
退订成功与否的回调
105+
:param destination: 取消订阅的类型. 有 quote, trade/asset, trade/position, trade/order
106+
:param content: 回调信息.
107+
"""
108+
print('subscribe:{}, callback content:{}'.format(destination, content))
109+
110+
93111
# def connect_callback():
94112
# """连接建立回调"""
95113
# print('connected')
@@ -126,9 +144,14 @@ def on_position_changed(account, items):
126144
# 持仓变动回调
127145
# push_client.position_changed = on_position_changed
128146

147+
# 订阅成功与否的回调
148+
push_client.subscribe_callback = subscribe_callback
149+
# 退订成功与否的回调
150+
push_client.unsubscribe_callback = unsubscribe_callback
151+
129152
# 建立推送连接
130153
push_client.connect(client_config.tiger_id, client_config.private_key)
131-
# 断线重连
154+
# 断线重连回调
132155
# push_client.disconnect_callback = disconnect_callback
133156

134157
# 订阅行情

0 commit comments

Comments
 (0)