Skip to content

Commit d195e9d

Browse files
committed
Merge branch 'identifier' into 'dev'
Identifier -> dev See merge request !35
2 parents d1d205a + 71f8c92 commit d195e9d

File tree

13 files changed

+128
-32
lines changed

13 files changed

+128
-32
lines changed

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/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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ def get_option_briefs(self, identifiers):
511511
open: 开盘价
512512
high: 最高价
513513
low: 最低价
514+
rates_bonds: 无风险利率
515+
volatility: 历史波动率
514516
"""
515517
params = MultipleContractParams()
516518
contracts = []

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',

tigeropen/trade/domain/contract.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
55
@author: gaoan
66
"""
7+
from tigeropen.common.consts import SecurityType
78

89

910
class Contract(object):
1011
def __init__(self, symbol, currency, contract_id=None, sec_type=None, exchange=None, origin_symbol=None,
1112
local_symbol=None, expiry=None, strike=None, put_call=None, multiplier=None, name=None,
1213
short_margin=None, short_fee_rate=None, shortable=None, long_initial_margin=None,
13-
long_maintenance_margin=None):
14+
long_maintenance_margin=None, contract_month=None, identifier=None):
1415
self.contract_id = contract_id
1516
self.symbol = symbol
1617
self.currency = currency
@@ -19,26 +20,35 @@ def __init__(self, symbol, currency, contract_id=None, sec_type=None, exchange=N
1920
self.origin_symbol = origin_symbol
2021
self.local_symbol = local_symbol
2122
self.expiry = expiry
23+
# 行权价
2224
self.strike = strike
25+
# 看跌/看涨
2326
self.put_call = put_call
27+
# 合约乘数
2428
self.multiplier = multiplier
29+
# 合约名称
2530
self.name = name
31+
# 做空保证金比例
2632
self.short_margin = short_margin
33+
# 做空费率
2734
self.short_fee_rate = short_fee_rate
35+
# 做空池剩余
2836
self.shortable = shortable
37+
# 做多初始保证金
2938
self.long_initial_margin = long_initial_margin
39+
# 做多维持保证金
3040
self.long_maintenance_margin = long_maintenance_margin
41+
# 合约月份
42+
self.contract_month = contract_month
43+
# 合约标识符
44+
self.identifier = identifier
3145

3246
def __repr__(self):
33-
if self.symbol:
34-
if self.origin_symbol is not None:
35-
return self.origin_symbol
36-
elif self.contract_id:
37-
return '%s/%s/%s/%d' % (self.symbol, self.sec_type, self.currency, self.contract_id)
38-
else:
39-
return '%s/%s/%s' % (self.symbol, self.sec_type, self.currency)
47+
identifier = self.identifier if self.identifier else self.symbol
48+
if self.sec_type == SecurityType.FUT.value:
49+
return '%s/%s/%s/%s' % (identifier, self.sec_type, self.currency, self.exchange)
4050
else:
41-
return '%d' % (self.contract_id,)
51+
return '%s/%s/%s' % (identifier, self.sec_type, self.currency)
4252

4353
def is_cn_stock(self):
4454
"""

tigeropen/trade/domain/order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Order(object):
1919
def __init__(self, account, contract, action, order_type, quantity, limit_price=None, aux_price=None,
2020
trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None,
2121
outside_rth=None, filled=0, avg_fill_price=0, commission=None, realized_pnl=None,
22-
id=None, order_id=None, parent_id=None):
22+
id=None, order_id=None, parent_id=None, order_time=None, trade_time=None):
2323
"""
2424
- account: 订单所属的账户
2525
- id: 全局订单 id
@@ -69,8 +69,8 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
6969
self.trail_stop_price = trail_stop_price
7070
self.trailing_percent = trailing_percent
7171
self.percent_offset = percent_offset
72-
self.order_time = None
73-
self.trade_time = None
72+
self.order_time = order_time
73+
self.trade_time = trade_time
7474

7575
def to_dict(self):
7676
dct = {name: getattr(self, name) for name in self.__slots__ if name not in ORDER_FIELDS_TO_IGNORE}

tigeropen/trade/response/__init__.py

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

88
CONTRACT_FIELDS = set(['symbol', 'market', 'multiplier', 'sec_type', 'currency', 'local_symbol', 'origin_symbol',
99
'expiry', 'strike', 'right', 'contract_id', 'exchange', 'name', 'short_margin', 'short_fee_rate',
10-
'shortable', 'long_initial_margin', 'long_maintenance_margin'])
10+
'shortable', 'long_initial_margin', 'long_maintenance_margin', 'contract_month', 'identifier'])
1111

tigeropen/trade/response/contracts_response.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
CONTRACT_FIELD_MAPPINGS = {'secType': 'sec_type', 'localSymbol': 'local_symbol', 'originSymbol': 'origin_symbol',
1515
'conid': 'contract_id', 'contractId': 'contract_id', 'lastTradingDate': 'expiry',
1616
'shortMargin': 'short_margin', 'shortFeeRate': 'short_fee_rate',
17-
'longInitialMargin': 'long_initial_margin',
17+
'longInitialMargin': 'long_initial_margin', 'contractMonth': 'contract_month',
1818
'longMaintenanceMargin': 'long_maintenance_margin'}
1919

2020

@@ -60,11 +60,12 @@ def parse_response_content(self, response_content):
6060
shortable = contract_fields.get('shortable')
6161
long_initial_margin = contract_fields.get('long_initial_margin')
6262
long_maintenance_margin = contract_fields.get('long_maintenance_margin')
63-
63+
contract_month = contract_fields.get('contract_month')
64+
identifier = contract_fields.get('identifier')
6465
contract = Contract(symbol, currency, contract_id=contract_id, sec_type=sec_type, exchange=exchange,
6566
origin_symbol=origin_symbol, local_symbol=local_symbol, expiry=expiry,
6667
strike=strike, put_call=put_call, multiplier=multiplier, name=name,
6768
short_margin=short_margin, short_fee_rate=short_fee_rate, shortable=shortable,
68-
long_initial_margin=long_initial_margin,
69-
long_maintenance_margin=long_maintenance_margin)
69+
long_initial_margin=long_initial_margin, contract_month=contract_month,
70+
long_maintenance_margin=long_maintenance_margin, identifier=identifier)
7071
self.contracts.append(contract)

0 commit comments

Comments
 (0)