Skip to content

Commit 73ae960

Browse files
committed
Merge branch 'dev' into feature_industry
2 parents 1802742 + e67e7a2 commit 73ae960

File tree

5 files changed

+44
-12
lines changed

5 files changed

+44
-12
lines changed

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/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/trade_client_demo.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
import traceback
99

10+
from tigeropen.common.consts import Currency, SecurityType
1011
from tigeropen.trade.domain.order import OrderStatus
1112
from tigeropen.trade.request.model import AccountsParams
1213
from tigeropen.common.response import TigerResponse
@@ -68,15 +69,22 @@ def trade_apis():
6869
account = client_config.account
6970
openapi_client = TradeClient(client_config, logger=logger)
7071

71-
# stock
72+
# 通过请求获取合约
7273
contract = openapi_client.get_contracts('AAPL')[0]
73-
# 或者本地构造合约对象
74-
# contract = stock_contract(symbol='AAPL', currency='USD')
74+
# contract = openapi_client.get_contract('AAPL', SecurityType.STK, currency=Currency.USD)
7575

76-
# option
76+
# 本地构造合约
77+
# stock 股票
78+
# contract = stock_contract(symbol='AAPL', currency='USD')
79+
# option 期权
7780
# contract = option_contract(identifier='AAPL 190118P00160000')
78-
# future
81+
# contract = option_contract_by_symbol('AAPL', '20200110', strike=280.0, put_call='PUT', currency='USD')
82+
# future 期货
7983
# contract = future_contract('CHF', 'USD', '20190617', multiplier=125000, exchange='GLOBEX')
84+
# war 港股窝轮
85+
# contract = war_contract_by_symbol('02318', '20200326', 107.08, 'CALL', local_symbol='12616', currency='HKD')
86+
# iopt 港股牛熊证
87+
# contract = iopt_contract_by_symbol('02318', '20200420', 87.4, 'CALL', local_symbol='63379', currency='HKD')
8088

8189
order = openapi_client.create_order(account, contract, 'BUY', 'LMT', 100, limit_price=5.0)
8290
# 或者本地构造订单对象

tigeropen/quote/domain/market_status.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88

99
class MarketStatus(object):
10-
def __init__(self, market, status, open_time):
10+
def __init__(self, market, status, open_time, trading_status):
1111
self.market = market
1212
self.status = status
1313
self.open_time = open_time
14+
self.trading_status = trading_status
1415

1516
def __repr__(self):
1617
"""

tigeropen/quote/response/market_status_response.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def parse_response_content(self, response_content):
2626

2727
if self.data and isinstance(self.data, list):
2828
for item in self.data:
29-
market, status, open_time = None, None, None
29+
market, status, open_time, trading_status = None, None, None, None
3030
for key, value in item.items():
3131
if value is None:
3232
continue
@@ -38,12 +38,15 @@ def parse_response_content(self, response_content):
3838
if value.endswith(' EDT') or value.endswith(' EST'):
3939
value = value[0:len(value) - 4]
4040
open_time = dateparser.parse(value)
41+
elif key == 'status':
42+
trading_status = get_string(value)
43+
4144
if open_time and market:
4245
if market == 'US':
4346
open_time = eastern.localize(open_time)
4447
elif market == 'HK':
4548
open_time = hongkong.localize(open_time)
4649
elif market == 'CN':
4750
open_time = china.localize(open_time)
48-
market_status = MarketStatus(market, status, open_time)
51+
market_status = MarketStatus(market, status, open_time, trading_status)
4952
self.markets.append(market_status)

0 commit comments

Comments
 (0)