Skip to content

Commit 886c461

Browse files
authored
Merge pull request #30 from tigerfintech/feature_preview_order
mod: add order preview
2 parents a803466 + f059d85 commit 886c461

18 files changed

+214
-40
lines changed

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
logbook
21
six
32
simplejson
43
delorean
5-
pandas
4+
pandas==0.24.2
65
python-dateutil
76
pytz
87
pyasn1==0.4.2

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
55
@author: gaoan
66
"""
7+
from os import path
78
from setuptools import find_packages, setup
89

9-
install_requires = ['six', 'simplejson', 'delorean', 'pandas', 'python-dateutil', 'pytz', 'pyasn1==0.4.4', 'rsa==4.0', 'stomp.py']
10+
with open(path.join(path.abspath(path.dirname(__file__)), 'requirements.txt'), encoding='utf-8') as f:
11+
install_requires = f.read()
1012

1113
setup(
1214
name='tigeropen',
13-
version='1.1.7',
15+
version='1.1.8',
1416
description='TigerBrokers Open API',
1517
packages=find_packages(exclude=[]),
1618
author='TigerBrokers',

tigeropen/common/consts/quote_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class QuoteChangeKey(Enum):
2121

2222
@unique
2323
class QuoteKeyType(Enum):
24-
ALL = None # 所有行情数据
24+
ALL = 'askPrice,askSize,bidPrice,bidSize,open,high,low,close,preClose,volume,latestPrice,mi' # 所有行情数据
2525
QUOTE = 'askPrice,askSize,bidPrice,bidSize' # 盘口数据
2626
TRADE = 'open,high,low,close,preClose,volume,latestPrice' # 成交数据
2727
TIMELINE = 'mi' # 分时数据

tigeropen/common/util/contract_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def option_contract(identifier, multiplier=100, currency='USD'):
2626
multiplier=multiplier)
2727

2828

29-
def future_contract(symbol, currency, expiry, exchange, multiplier=None, local_symbol=None):
30-
return Contract(symbol, currency, sec_type='FUT', expiry=expiry, exchange=exchange, multiplier=multiplier,
31-
local_symbol=local_symbol)
29+
def future_contract(symbol, currency, expiry=None, exchange=None, contract_month=None, multiplier=None, local_symbol=None):
30+
return Contract(symbol, currency, sec_type='FUT', expiry=expiry, exchange=exchange, contract_month=contract_month,
31+
multiplier=multiplier, local_symbol=local_symbol)
3232

3333

3434
def future_option_contract(symbol, currency, expiry, strike, put_call, multiplier=None, local_symbol=None,

tigeropen/examples/push_client_demo.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def on_query_subscribed_quote(symbols, focus_keys, limit, used):
1818
:param limit: 当前 tigerid 可以订阅的合约数量
1919
:param used: 目前已订阅的合约数量
2020
:return:
21+
返回示例:
22+
symbols: ['00700', 'SPY'],
23+
focus_keys: {'00700': ['ask_size', 'latest_price', 'ask_price', 'prev_close', 'open', 'minute', 'low', 'volume',
24+
'bid_price', 'bid_size', 'high', 'close'], 'SPY': ['ask_size', 'latest_price', 'ask_price', 'prev_close',
25+
'open', 'minute', 'low', 'volume', 'bid_price', 'bid_size', 'high', 'close']},
26+
limit: 100,
27+
used: 2
28+
2129
"""
2230
print(symbols, focus_keys, limit, used)
2331

@@ -29,19 +37,56 @@ def on_quote_changed(symbol, items, hour_trading):
2937
:param items: list,每个元素是一个tuple,对应订阅的字段名称和值
3038
:param hour_trading: 是否为盘前盘后的交易
3139
:return:
40+
items 数据示例
41+
[('latest_price', 339.8), ('ask_size', 42500), ('ask_price', 340.0), ('bid_size', 1400), ('bid_price', 339.8),
42+
('high', 345.0), ('prev_close', 342.4), ('low', 339.2), ('open', 344.0), ('volume', 7361440),
43+
('minute', {'p': 339.8, 'a': 341.084, 't': 1568098440000, 'v': 7000, 'h': 340.0, 'l': 339.8}),
44+
('timestamp', '1568098469463')]
3245
"""
3346
print(symbol, items, hour_trading)
3447

3548

3649
def on_order_changed(account, items):
50+
"""
51+
52+
:param account:
53+
:param items:
54+
:return:
55+
items 数据示例:
56+
[('order_type', 'LMT'), ('symbol', 'ABCD'), ('order_id', 1000101463), ('sec_type', 'STK'), ('filled', 100),
57+
('quantity', 100), ('segment', 'summary'), ('action', 'BUY'), ('currency', 'USD'), ('id', 173612806463631360),
58+
('order_time', 1568095814556), ('time_in_force', 'DAY'), ('identifier', 'ABCD'), ('limit_price', 113.7),
59+
('outside_rth', True), ('avg_fill_price', 113.7), ('trade_time', 1568095815418),
60+
('status', <OrderStatus.FILLED: 'Filled'>)]
61+
"""
3762
print(account, items)
3863

3964

4065
def on_asset_changed(account, items):
66+
"""
67+
68+
:param account:
69+
:param items:
70+
:return:
71+
items 数据示例:
72+
[('equity_with_loan', 721583.83), ('gross_position_value', 1339641.94),
73+
('excess_liquidity', 378624.18), ('available_funds', 320059.1), ('initial_margin_requirement', 497419.25),
74+
('buying_power', 2293551.51), ('cash', 950059.0), ('segment', 'summary'), ('net_liquidation', 817685.72),
75+
('maintenance_margin_requirement', 439061.54)]
76+
"""
4177
print(account, items)
4278

4379

4480
def on_position_changed(account, items):
81+
"""
82+
83+
:param account:
84+
:param items:
85+
:return:
86+
items 数据示例:
87+
[('symbol', 'ABCD'), ('market_price', 3.68525), ('market_value', 0.0), ('sec_type', 'STK'),
88+
('segment', 'summary'), ('currency', 'USD'), ('quantity', 0.0), ('average_cost', 3.884548)]
89+
"""
4590
print(account, items)
4691

4792

tigeropen/examples/trade_client_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def trade_apis():
9292
new_order = openapi_client.get_order(order_id=order_id)
9393
assert new_order.status == OrderStatus.CANCELLED or new_order.status == OrderStatus.PENDING_CANCEL
9494

95+
# 预览订单 (下单前后保证金要求, 佣金等预览)
96+
result = openapi_client.preview_order(order)
97+
print(result)
98+
9599

96100
if __name__ == '__main__':
97101
get_account_info()

tigeropen/push/push_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
'unrealizedPnl': 'unrealized_pnl', 'secType': 'sec_type', 'localSymbol': 'local_symbol',
3737
'originSymbol': 'origin_symbol', 'contractId': 'contract_id', 'symbol': 'symbol',
3838
'currency': 'currency', 'strike': 'strike', 'expiry': 'expiry', 'right': 'right',
39-
'segment': 'segment'}
39+
'segment': 'segment', 'identifier': 'identifier'}
4040

4141
ORDER_KEYS_MAPPINGS = {'parentId': 'parent_id', 'orderId': 'order_id', 'orderType': 'order_type',
4242
'limitPrice': 'limit_price', 'auxPrice': 'aux_price', 'avgFillPrice': 'avg_fill_price',
@@ -47,7 +47,7 @@
4747
'latestTime': 'trade_time', 'contractId': 'contract_id', 'trailStopPrice': 'trail_stop_price',
4848
'trailingPercent': 'trailing_percent', 'percentOffset': 'percent_offset', 'action': 'action',
4949
'status': 'status', 'currency': 'currency', 'remaining': 'remaining', 'id': 'id',
50-
'segment': 'segment'}
50+
'segment': 'segment', 'identifier': 'identifier'}
5151

5252
if sys.platform == 'linux' or sys.platform == 'linux2':
5353
KEEPALIVE = True

tigeropen/quote/quote_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def get_option_chain(self, symbol, expiry):
441441
def get_option_briefs(self, identifiers):
442442
"""
443443
获取期权最新行情
444-
:param identifiers: 期权代码
444+
:param identifiers: 期权代码列表
445445
:return: pandas.DataFrame, 各 column 的含义如下:
446446
identifier: 期权代码
447447
symbol: 期权对应的正股代码
@@ -461,6 +461,8 @@ def get_option_briefs(self, identifiers):
461461
open: 开盘价
462462
high: 最高价
463463
low: 最低价
464+
rates_bonds: 无风险利率
465+
volatility: 历史波动率
464466
"""
465467
params = MultipleContractParams()
466468
contracts = []

tigeropen/quote/response/future_contract_response.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
from tigeropen.common.response import TigerResponse
1212

1313
COLUMNS = ['contract_code', 'symbol', 'type', 'name', 'contract_month', 'multiplier', 'exchange', 'currency',
14-
'first_notice_date', 'last_bidding_close_time', 'last_trading_date', 'trade', 'continuous']
14+
'first_notice_date', 'last_bidding_close_time', 'last_trading_date', 'trade', 'continuous', 'min_tick']
1515
CONTRACT_FIELD_MAPPINGS = {'contractCode': 'contract_code', 'exchangeCode': 'exchange', 'ibCode': 'symbol',
1616
'contractMonth': 'contract_month', 'firstNoticeDate': 'first_notice_date',
17-
'lastBiddingCloseTime': 'last_bidding_close_time', 'lastTradingDate': 'last_trading_date'}
17+
'lastBiddingCloseTime': 'last_bidding_close_time', 'lastTradingDate': 'last_trading_date',
18+
'minTick': 'min_tick'}
1819

1920

2021
class FutureContractResponse(TigerResponse):

tigeropen/quote/response/option_briefs_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
COLUMNS = ['identifier', 'symbol', 'expiry', 'strike', 'put_call', 'multiplier', 'ask_price', 'ask_size', 'bid_price',
1515
'bid_size', 'pre_close', 'latest_price', 'latest_time', 'volume', 'open_interest', 'open', 'high', 'low',
16-
'rates_bonds']
16+
'rates_bonds', 'volatility']
1717
BRIEF_FIELD_MAPPINGS = {'askPrice': 'ask_price', 'askSize': 'ask_size', 'bidPrice': 'bid_price', 'bidSize': 'bid_size',
1818
'latestPrice': 'latest_price', 'openInterest': 'open_interest', 'preClose': 'pre_close',
1919
'right': 'put_call', 'latestTime': 'latest_time', 'openInt': 'open_interest',

0 commit comments

Comments
 (0)