Skip to content

Commit 73348ab

Browse files
committed
position param; price util
1 parent 3b2e5d3 commit 73348ab

File tree

6 files changed

+66
-4
lines changed

6 files changed

+66
-4
lines changed

tigeropen/common/consts/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,10 @@ class IndustryLevel(Enum):
140140
GGROUP = 'GGROUP'
141141
GIND = 'GIND'
142142
GSUBIND = 'GSUBIND'
143+
144+
145+
@unique
146+
class TickSizeType(Enum):
147+
CLOSED = 'CLOSED'
148+
OPEN_CLOSED = 'OPEN_CLOSED'
149+
OPEN = 'OPEN'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/7/13
4+
# @Author : sukai
5+
6+
class PriceUtil:
7+
8+
@staticmethod
9+
def match_tick_size(price, tick_sizes):
10+
pass

tigeropen/trade/domain/contract.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self, symbol=None, currency=None, contract_id=None, sec_type=None,
1515
long_maintenance_margin=None, contract_month=None, identifier=None, primary_exchange=None,
1616
market=None, min_tick=None, trading_class=None, status=None, continuous=None, trade=None,
1717
marginable=None, close_only=None,
18-
last_trading_date=None, first_notice_date=None, last_bidding_close_time=None):
18+
last_trading_date=None, first_notice_date=None, last_bidding_close_time=None, tick_sizes=None):
1919
self.contract_id = contract_id
2020
self.symbol = symbol
2121
self.currency = get_enum_value(currency)
@@ -54,6 +54,8 @@ def __init__(self, symbol=None, currency=None, contract_id=None, sec_type=None,
5454
self.market = market
5555
# 最小报价单位
5656
self.min_tick = min_tick
57+
# tick size info list
58+
self.tick_sizes = tick_sizes
5759
# 合约的交易级别名称
5860
self.trading_class = trading_class
5961
# 状态

tigeropen/trade/request/model.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ def __init__(self):
117117
self._currency = None
118118
self._market = None
119119
self._sub_accounts = None
120+
self._expiry = None
121+
self._strike = None
122+
self._right = None
120123

121124
@property
122125
def account(self):
@@ -174,6 +177,30 @@ def sub_accounts(self):
174177
def sub_accounts(self, value):
175178
self._sub_accounts = value
176179

180+
@property
181+
def expiry(self):
182+
return self._expiry
183+
184+
@expiry.setter
185+
def expiry(self, value):
186+
self._expiry = value
187+
188+
@property
189+
def strike(self):
190+
return self._strike
191+
192+
@strike.setter
193+
def strike(self, value):
194+
self._strike = value
195+
196+
@property
197+
def right(self):
198+
return self._right
199+
200+
@right.setter
201+
def right(self, value):
202+
self._right = value
203+
177204
def to_openapi_dict(self):
178205
params = dict()
179206
if self.account:
@@ -197,6 +224,15 @@ def to_openapi_dict(self):
197224
if self.sub_accounts:
198225
params['sub_accounts'] = self.sub_accounts
199226

227+
if self.expiry:
228+
params['expiry'] = self.expiry
229+
230+
if self.strike:
231+
params['strike'] = self.strike
232+
233+
if self.right:
234+
params['right'] = self.right
235+
200236
return params
201237

202238

tigeropen/trade/response/contracts_response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import json
88

99
from tigeropen.common.response import TigerResponse
10-
from tigeropen.common.util.string_utils import camel_to_underline
10+
from tigeropen.common.util.string_utils import camel_to_underline, camel_to_underline_obj
1111
from tigeropen.trade.domain.contract import Contract
1212

1313
CONTRACT_FIELD_MAPPINGS = {'conid': 'contract_id', 'right': 'put_call', 'tradeable': 'trade'}
@@ -31,6 +31,8 @@ def parse_response_content(self, response_content):
3131
contract_fields = {}
3232
for key, value in item.items():
3333
tag = CONTRACT_FIELD_MAPPINGS[key] if key in CONTRACT_FIELD_MAPPINGS else camel_to_underline(key)
34+
if isinstance(value, (list, dict)):
35+
value = camel_to_underline_obj(value)
3436
contract_fields[tag] = value
3537
contract = Contract()
3638
for k, v in contract_fields.items():

tigeropen/trade/trade_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def get_derivative_contracts(self, symbol, sec_type, expiry, lang=None):
175175
return None
176176

177177
def get_positions(self, account=None, sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL,
178-
symbol=None, sub_accounts=None):
178+
symbol=None, sub_accounts=None, expiry=None, strike=None, put_call=None):
179179
"""
180180
获取持仓数据
181181
:param account:
@@ -202,7 +202,12 @@ def get_positions(self, account=None, sec_type=SecurityType.STK, currency=Curren
202202
params.currency = get_enum_value(currency)
203203
params.market = get_enum_value(market)
204204
params.symbol = symbol
205-
205+
if expiry:
206+
params.expiry = expiry
207+
if strike:
208+
params.strike = strike
209+
if put_call:
210+
params.right = put_call
206211
request = OpenApiRequest(POSITIONS, biz_model=params)
207212
response_content = self.__fetch_data(request)
208213
if response_content:

0 commit comments

Comments
 (0)