Skip to content

Commit b8750a4

Browse files
committed
Merge branch 'dev' into 'master'
Dev See merge request server/openapi/openapi-python-sdk!178
2 parents 9b51baa + 565f1d4 commit b8750a4

35 files changed

Lines changed: 386 additions & 194 deletions

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 2.4.0 (2023-06-07)
2+
### New
3+
- 支持期权组合订单
4+
### Fix
5+
- 修复分页获取k线数据为空时pandas字段索引错误
6+
7+
## 2.3.9 (2023-06-01)
8+
### Fix
9+
- 修复protobuf推送tick数据未解压的问题
10+
### Modify
11+
- 修改订单状态推送proto定义,增加 userMark
12+
113
## 2.3.8 (2023-05-09)
214
### New
315
- 合约接口新增字段保证金优惠信息

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.8'
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/push_client_demo.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from tigeropen.push.pb.QuoteBasicData_pb2 import QuoteBasicData
1717
from tigeropen.push.pb.QuoteDepthData_pb2 import QuoteDepthData
1818
from tigeropen.push.pb.TradeTickData_pb2 import TradeTickData
19+
from tigeropen.push.pb.trade_tick import TradeTick
1920
from tigeropen.push.push_client import PushClient
2021
from tigeropen.examples.client_config import get_client_config
2122

@@ -152,24 +153,11 @@ def on_quote_depth_changed(frame: QuoteDepthData):
152153
print(f'quote depth changed: {frame}')
153154

154155

155-
def on_tick_changed(frame: TradeTickData):
156+
def on_tick_changed(frame: TradeTick):
156157
"""逐笔成交回调
157158
example:
158-
symbol: "00700"
159-
type: "-+"
160-
sn: 37998
161-
priceBase: 3636
162-
priceOffset: 1
163-
time: 1677742815311
164-
time: 69
165-
price: 0
166-
price: 2
167-
volume: 500
168-
volume: 100
169-
quoteLevel: "hkStockQuoteLv2"
170-
timestamp: 1677742815776
171-
secType: "STK"
172-
159+
TradeTick<{'symbol': '00700', 'sec_type': 'STK', 'quote_level': 'hkStockQuoteLv2', 'timestamp': 1685602618145, 'ticks': [TradeTickItem<{'tick_type': '+', 'price': 316.6, 'volume': 100, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602617046, 'sn': 42055}>, TradeTickItem<{'tick_type': '-', 'price': 316.4, 'volume': 600, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602617639, 'sn': 42056}>, TradeTickItem<{'tick_type': '-', 'price': 316.4, 'volume': 200, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602617639, 'sn': 42057}>]}>
160+
TradeTick<{'symbol': 'CLmain', 'sec_type': 'FUT', 'quote_level': '', 'timestamp': 1685602618153, 'ticks': [TradeTickItem<{'tick_type': None, 'price': 68.7, 'volume': 1, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602616000, 'sn': 109150}>, TradeTickItem<{'tick_type': None, 'price': 68.7, 'volume': 1, 'part_code': None, 'part_code_name': None, 'cond': None, 'time': 1685602616000, 'sn': 109151}>]}>
173161
"""
174162
print(frame)
175163

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/network/listener.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,6 @@ def __heartbeat_loop(self):
222222
self.transport.set_connected(False)
223223
self.transport.disconnect_socket()
224224
self.transport.stop()
225-
for listener in self.transport.listeners.values():
226-
listener.on_heartbeat_timeout()
227225
self.heartbeat_thread = None
228226
self.heartbeat_terminate_event.clear()
229227
if self.heartbeats != (0, 0):

tigeropen/push/pb/OrderStatusData.proto

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,45 @@ syntax = "proto3";
22

33
package tigeropen.push.pb;
44

5-
65
message OrderStatusData {
76
sint64 id = 1; // unique order id
87
string account = 2; // user account
98
string symbol = 3;
10-
string identifier = 4;
11-
uint32 multiplier = 5; // multiplier for futures, options, warrants and CBBC
12-
string action = 6; // BUY or SELL
13-
string market = 7; // market. US, HK, etc.
14-
string currency = 8; // currency. USD, HKD, etc.
15-
string segType = 9; // Securities Category C: (Commodities Futures), S: (Securities Stocks)
16-
string secType = 10; // STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH FOREX, FUT Futures, FOP Future Options
9+
string expiry = 4; // for options, formate:yyyyMMdd
10+
string strike = 5; // for options
11+
string right = 6; // for options
12+
string identifier = 7;
13+
uint32 multiplier = 8; // multiplier for futures, options, warrants and CBBC
14+
string action = 9; // BUY or SELL
15+
string market = 10; // market. US, HK, etc.
16+
string currency = 11; // currency. USD, HKD, etc.
17+
string segType = 12; // Securities Category C: (Commodities Futures), S: (Securities Stocks)
18+
string secType = 13; // STK Stocks, OPT Options, WAR Warrants, IOPT CBBC, CASH FOREX, FUT Futures, FOP Future Options
1719

18-
string orderType = 11; // order type
19-
bool isLong = 12;
20-
sint64 totalQuantity = 13; // total quantity
21-
sint32 totalQuantityScale = 14; // total quantity scale
22-
sint64 filledQuantity = 15; // filled quantity
23-
sint32 filledQuantityScale = 16; // filled quantity scale
24-
double avgFillPrice = 17; // average price at which the orders got filled
25-
double limitPrice = 18; // limit price(required when orderType is 'LMT')
26-
double realizedPnl = 19; // realized profit and loss
27-
string status = 20; // order status
20+
string orderType = 14; // order type
21+
bool isLong = 15;
22+
sint64 totalQuantity = 16; // total quantity
23+
sint32 totalQuantityScale = 17; // total quantity scale
24+
sint64 filledQuantity = 18; // filled quantity
25+
sint32 filledQuantityScale = 19; // filled quantity scale
26+
double avgFillPrice = 20; // average price at which the orders got filled
27+
double limitPrice = 21; // limit price(required when orderType is 'LMT')
28+
double stopPrice = 22; // stop price(required when orderType is 'STP')
29+
double realizedPnl = 23; // realized profit and loss
30+
string status = 24; // order status
31+
string replaceStatus = 25; // order replace status
32+
string cancelStatus = 26; // order cancel status
2833

29-
bool outsideRth = 21; // if trade outside regular trading hours (only applicable to U.S. market)
30-
bool canModify = 22;
31-
bool canCancel = 23;
32-
string name = 24; // symbol name
33-
string source = 25; // order source(from 'OpenApi', or not)
34-
string errorMsg = 26; // error message
35-
float commissionAndFee = 27; // commission and fee
36-
uint64 openTime = 28; // timestamp when the order is placed
37-
uint64 timestamp = 29;
34+
bool outsideRth = 27; // if trade outside regular trading hours (only applicable to U.S. market)
35+
bool canModify = 28;
36+
bool canCancel = 29;
37+
bool liquidation = 30;
38+
string name = 31; // symbol name
39+
string source = 32; // order source(from 'OpenApi', or not)
40+
string errorMsg = 33; // error message
41+
string attrDesc = 34; // order description
42+
float commissionAndFee = 35; // commission and fee
43+
uint64 openTime = 36; // timestamp when the order is placed
44+
uint64 timestamp = 37;
45+
string userMark = 38;
3846
}

tigeropen/push/pb/OrderStatusData_pb2.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)