Skip to content

Commit b5316af

Browse files
committed
Merge branch 'contract_util_iopt' into 'dev'
Contract util iopt/war See merge request !47
2 parents c218b48 + 8bf4f2b commit b5316af

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
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/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
# 或者本地构造订单对象

0 commit comments

Comments
 (0)