Skip to content

Commit 565f1d4

Browse files
committed
Merge branch 'feat_option_strategy_order' into 'dev'
option combo order See merge request server/openapi/openapi-python-sdk!177
2 parents a7aa812 + 74799cf commit 565f1d4

28 files changed

Lines changed: 222 additions & 144 deletions

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.4.0 (2023-06-07)
2+
### New
3+
- 支持期权组合订单
4+
### Fix
5+
- 修复分页获取k线数据为空时pandas字段索引错误
6+
17
## 2.3.9 (2023-06-01)
28
### Fix
39
- 修复protobuf推送tick数据未解压的问题

tigeropen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
55
@author: gaoan
66
"""
7-
__VERSION__ = '2.3.9'
7+
__VERSION__ = '2.4.0'

tigeropen/common/consts/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SecurityType(Enum):
4848
FUT = 'FUT' # 期货
4949
FOP = 'FOP' # 期货期权
5050
CASH = 'CASH' # 外汇
51-
51+
MLEG = 'MLEG'
5252

5353
@unique
5454
class SegmentType(Enum):
@@ -189,7 +189,8 @@ class OrderType(Enum):
189189
TRAIL = 'TRAIL' # 跟踪止损单
190190
AM = 'AM' # Auction Market ,竞价市价单
191191
AL = 'AL' # Auction Limit ,竞价限价单
192-
192+
TWAP = 'TWAP' # 'Time Weighted Average Price' 时间加权平均价格算法
193+
VWAP = 'VWAP' # 'Volume Weighted Average Price' 成交量加权平均价格算法
193194

194195
@unique
195196
class License(Enum):
@@ -203,3 +204,14 @@ class ServiceType(Enum):
203204
TRADE = 'TRADE'
204205
QUOTE = 'QUOTE'
205206

207+
@unique
208+
class ComboType(Enum):
209+
COVERED = 'COVERED'
210+
PROTECTIVE = 'PROTECTIVE'
211+
VERTICAL = 'VERTICAL'
212+
STRADDLE = 'STRADDLE'
213+
STRANGLE = 'STRANGLE'
214+
CALENDAR = 'CALENDAR'
215+
DIAGONAL = 'DIAGONAL'
216+
SYNTHETIC = 'SYNTHETIC'
217+
CUSTOM = 'CUSTOM'

tigeropen/common/response.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
@author: gaoan
66
"""
7+
import json
78

89

910
class TigerResponse:
@@ -22,4 +23,6 @@ def parse_response_content(self, response):
2223
self.message = response['message']
2324
if 'data' in response:
2425
self.data = response['data']
26+
if isinstance(self.data, str):
27+
self.data = json.loads(self.data)
2528
return response

tigeropen/common/util/order_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
55
@author: gaoan
66
"""
7+
from tigeropen.trade.domain.contract import ContractLeg
78
from tigeropen.trade.domain.order import Order, OrderLeg, AlgoParams
8-
from tigeropen.common.consts import OrderStatus
9+
from tigeropen.common.consts import OrderStatus, OrderType
910

1011

1112
def market_order(account, contract, action, quantity):
@@ -164,6 +165,17 @@ def algo_order(account, contract, action, quantity, strategy, algo_params=None,
164165
limit_price=limit_price, outside_rth=False)
165166

166167

168+
def contract_leg(symbol=None, sec_type=None, expiry=None, strike=None, put_call=None, action=None,
169+
ratio=1):
170+
return ContractLeg(symbol=symbol, sec_type=sec_type, expiry=expiry, strike=strike, put_call=put_call,
171+
action=action, ratio=ratio)
172+
173+
174+
def combo_order(account, contract_legs, combo_type, action, quantity, order_type=OrderType.LMT.value, limit_price=None,
175+
aux_price=None, trailing_percent=None):
176+
return Order(account, None, action=action, order_type=order_type, quantity=quantity, limit_price=limit_price,
177+
aux_price=aux_price, trailing_percent=trailing_percent, combo_type=combo_type,
178+
contract_legs=contract_legs)
167179
def get_order_status(value):
168180
"""
169181
Invalid(-2), Initial(-1), PendingCancel(3), Cancelled(4), Submitted(5), Filled(6), Inactive(7), PendingSubmit(8)

tigeropen/examples/trade_client_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def algo_order_demo():
138138
account = client_config.account
139139
openapi_client = TradeClient(client_config, logger=logger)
140140
contract = stock_contract(symbol='AAPL', currency='USD')
141-
params = algo_order_params(start_time='2020-11-19 23:00:00', end_time='2020-11-19 23:50:00', no_take_liq=True,
141+
params = algo_order_params(start_time=1686147201000, end_time=1686150801000, no_take_liq=True,
142142
allow_past_end_time=True, participation_rate=0.1)
143143
order = algo_order(account, contract, 'BUY', 1000, 'VWAP', algo_params=params, limit_price=100.0)
144144
openapi_client.place_order(order)

tigeropen/push/pb/QuoteData.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ message QuoteData {
4848
double a = 2; // average price of the minute bar
4949
uint64 t = 3; // timestamp of the minute bar
5050
sint64 v = 4; // trading volume of the minute bar
51-
double o = 5; // open price of the minute bar (only futures support)
52-
double h = 6; // highest price of the minute bar (only futures support)
53-
double l = 7; // lowest price of the minute bar (only futures support)
51+
double o = 5; // open price of the minute bar
52+
double h = 6; // highest price of the minute bar
53+
double l = 7; // lowest price of the minute bar
5454
}
5555
}

tigeropen/quote/quote_client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,22 @@ def get_bars_by_page(self, symbol, period=BarPeriod.DAY, begin_time=-1, end_time
480480
current = 0
481481
next_page_token = None
482482
result = list()
483+
result_df = None
483484
while current < total:
484485
if current + page_size >= total:
485486
page_size = total - current
486487
current += page_size
487488
bars = self.get_bars(symbols=symbol, period=period, begin_time=begin_time, end_time=end_time, right=right,
488489
limit=page_size, lang=lang, page_token=next_page_token)
490+
if bars.empty:
491+
result_df = bars
492+
break
489493
next_page_token = bars['next_page_token'].iloc[0]
490494
result.append(bars)
491495
if not next_page_token:
492496
break
493497
time.sleep(time_interval)
494-
return pd.concat(result).sort_values('time').reset_index(drop=True)
498+
return pd.concat(result).sort_values('time').reset_index(drop=True) if result else result_df
495499

496500
def get_trade_ticks(self, symbols, trade_session=None, begin_index=None, end_index=None, limit=None, lang=None,
497501
**kwargs):
@@ -1045,18 +1049,22 @@ def get_future_bars_by_page(self, identifier, period=BarPeriod.DAY, begin_time=-
10451049
current = 0
10461050
next_page_token = None
10471051
result = list()
1052+
result_df = None
10481053
while current < total:
10491054
if current + page_size >= total:
10501055
page_size = total - current
10511056
current += page_size
10521057
bars = self.get_future_bars(identifiers=identifier, period=period, begin_time=begin_time, end_time=end_time,
10531058
limit=page_size, page_token=next_page_token)
1059+
if bars.empty:
1060+
result_df = bars
1061+
break
10541062
next_page_token = bars['next_page_token'].iloc[0]
10551063
result.append(bars)
10561064
if not next_page_token:
10571065
break
10581066
time.sleep(time_interval)
1059-
return pd.concat(result).sort_values('time').reset_index(drop=True)
1067+
return pd.concat(result).sort_values('time').reset_index(drop=True) if result else result_df
10601068

10611069
def get_future_trade_ticks(self, identifier, begin_index=0, end_index=30, limit=1000):
10621070
"""

tigeropen/quote/response/future_quote_bar_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class FutureQuoteBarResponse(TigerResponse):
1717
def __init__(self):
1818
super(FutureQuoteBarResponse, self).__init__()
19-
self.bars = []
19+
self.bars = pd.DataFrame(columns=COLUMNS)
2020
self._is_success = None
2121

2222
def parse_response_content(self, response_content):

tigeropen/quote/response/quote_bar_response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
class QuoteBarResponse(TigerResponse):
1616
def __init__(self):
1717
super(QuoteBarResponse, self).__init__()
18-
self.bars = None
18+
self.bars = pd.DataFrame(columns=COLUMNS)
1919
self._is_success = None
2020

2121
def parse_response_content(self, response_content):

0 commit comments

Comments
 (0)