Skip to content

Commit 9803ec4

Browse files
committed
order transactions api
1 parent 8a6e283 commit 9803ec4

File tree

12 files changed

+292
-14
lines changed

12 files changed

+292
-14
lines changed

tigeropen/common/consts/service_types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
PLACE_ORDER = "place_order"
1111
CANCEL_ORDER = "cancel_order"
1212
MODIFY_ORDER = "modify_order"
13+
BATCH_PLACE_ORDER = "batch_place_order"
1314

1415
"""
1516
账户/资产
@@ -22,6 +23,7 @@
2223
ACTIVE_ORDERS = "active_orders" # 待成交订单
2324
INACTIVE_ORDERS = "inactive_orders" # 已撤销订单
2425
FILLED_ORDERS = "filled_orders" # 已成交订单
26+
ORDER_TRANSACTIONS = "order_transactions" # 订单成交记录
2527

2628
"""
2729
合约
@@ -46,6 +48,7 @@
4648
QUOTE_STOCK_TRADE = "quote_stock_trade"
4749
QUOTE_DEPTH = "quote_depth" # level2 深度行情
4850
GRAB_QUOTE_PERMISSION = "grab_quote_permission" # 抢占行情
51+
GET_QUOTE_PERMISSION = "get_quote_permission"
4952

5053
# 期权行情
5154
OPTION_EXPIRATION = "option_expiration"

tigeropen/examples/quote_client_demo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ def get_quote():
2727
# 抢占行情权限
2828
quote_permissions = openapi_client.grab_quote_permission()
2929
print(quote_permissions)
30+
# 查询行情权限
31+
perms = openapi_client.get_quote_permission()
32+
print(perms)
3033

3134
market_status_list = openapi_client.get_market_status(Market.US)
3235
print(market_status_list)

tigeropen/examples/trade_client_demo.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from tigeropen.trade.trade_client import TradeClient
1515
from tigeropen.quote.request import OpenApiRequest
1616
from tigeropen.examples.client_config import get_client_config
17-
# from tigeropen.common.consts import Currency, SecurityType
17+
from tigeropen.common.consts import Currency, SecurityType
1818
from tigeropen.common.util.contract_utils import stock_contract, option_contract_by_symbol, future_contract, \
1919
war_contract_by_symbol, iopt_contract_by_symbol
2020
from tigeropen.common.util.order_utils import limit_order, limit_order_with_legs, order_leg, algo_order_params, \
@@ -60,6 +60,15 @@ def get_account_apis():
6060
# openapi_client.get_open_orders()
6161
# 获取已成交订单
6262
# openapi_client.get_filled_orders(start_time='2019-05-01', end_time='2019-05-21')
63+
64+
# 获取订单成交记录, 仅适用于综合账户
65+
transactions = openapi_client.get_transactions(symbol='AAPL', sec_type=SecurityType.STK, start_time=1641398400000,
66+
end_time=1642398400000)
67+
# transactions = openapi_client.get_transactions(symbol='CL2201', sec_type=SecurityType.FUT)
68+
# transactions = openapi_client.get_transactions(order_id=24844739769009152)
69+
# transactions = openapi_client.get_transactions(symbol='BABA', sec_type='OPT', strike=121, expiry='20220121',
70+
# put_call='CALL')
71+
6372
# 获取持仓
6473
openapi_client.get_positions()
6574
# 获取资产

tigeropen/quote/quote_client.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from tigeropen.common.consts import Market, Language, QuoteRight, BarPeriod, OPEN_API_SERVICE_VERSION_V3
1313
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, CorporateActionType, IndustryLevel
14-
from tigeropen.common.consts.service_types import GRAB_QUOTE_PERMISSION, QUOTE_DELAY
14+
from tigeropen.common.consts.service_types import GRAB_QUOTE_PERMISSION, QUOTE_DELAY, GET_QUOTE_PERMISSION
1515
from tigeropen.common.consts.service_types import MARKET_STATE, ALL_SYMBOLS, ALL_SYMBOL_NAMES, BRIEF, \
1616
TIMELINE, KLINE, TRADE_TICK, OPTION_EXPIRATION, OPTION_CHAIN, FUTURE_EXCHANGE, OPTION_BRIEF, \
1717
OPTION_KLINE, OPTION_TRADE_TICK, FUTURE_KLINE, FUTURE_TICK, FUTURE_CONTRACT_BY_EXCHANGE_CODE, \
@@ -1172,11 +1172,11 @@ def get_stock_industry(self, symbol, market=Market.US):
11721172
def grab_quote_permission(self):
11731173
"""
11741174
抢占行情权限
1175-
:return: 权限列表
1176-
示例: [{'name': 'usQuoteBasic', 'expireAt': 1621931026000},
1177-
{'name': 'usStockQuoteLv2Totalview', 'expireAt': 1621931026000},
1178-
{'name': 'usOptionQuote', 'expireAt': 1621931026000},
1179-
{'name': 'hkStockQuoteLv2', 'expireAt': 1621931026000}]
1175+
:return: 权限列表。expire_at 为-1时表示长期有效
1176+
示例: [{'name': 'usQuoteBasic', 'expire_at': 1621931026000},
1177+
{'name': 'usStockQuoteLv2Totalview', 'expire_at': 1621931026000},
1178+
{'name': 'usOptionQuote', 'expire_at': 1621931026000},
1179+
{'name': 'hkStockQuoteLv2', 'expire_at': -1}]
11801180
"""
11811181
request = OpenApiRequest(GRAB_QUOTE_PERMISSION)
11821182
response_content = self.__fetch_data(request)
@@ -1188,3 +1188,23 @@ def grab_quote_permission(self):
11881188
else:
11891189
raise ApiException(response.code, response.message)
11901190
return False
1191+
1192+
def get_quote_permission(self):
1193+
"""
1194+
查询行情权限。query quote permissions
1195+
:return: 权限列表。expire_at 为-1时表示长期有效
1196+
示例: [{'name': 'usQuoteBasic', 'expire_at': 1621931026000},
1197+
{'name': 'usStockQuoteLv2Totalview', 'expire_at': 1621931026000},
1198+
{'name': 'usOptionQuote', 'expire_at': 1621931026000},
1199+
{'name': 'hkStockQuoteLv2', 'expire_at': -1}]
1200+
"""
1201+
request = OpenApiRequest(GET_QUOTE_PERMISSION)
1202+
response_content = self.__fetch_data(request)
1203+
if response_content:
1204+
response = QuoteGrabPermissionResponse()
1205+
response.parse_response_content(response_content)
1206+
if response.is_success():
1207+
return response.permissions
1208+
else:
1209+
raise ApiException(response.code, response.message)
1210+
return False

tigeropen/quote/response/quote_grab_permission_response.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# @Author : sukai
55
import json
66
from tigeropen.common.response import TigerResponse
7+
from tigeropen.common.util import string_utils
78

89

910
class QuoteGrabPermissionResponse(TigerResponse):
@@ -17,4 +18,4 @@ def parse_response_content(self, response_content):
1718
if 'is_success' in response:
1819
self._is_success = response['is_success']
1920

20-
self.permissions = self.data
21+
self.permissions = string_utils.camel_to_underline_obj(self.data)

tigeropen/trade/domain/account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class SecuritySegment:
7979
- cash: 现金
8080
- equity_with_loan: 含借贷值股权(含贷款价值资产)。计算方法: 现金价值 + 股票价值
8181
- excess_liquidity: 剩余流动性。计算方法: equity_with_loan - maintenance_margin_requirement
82-
- gross_position_value: 证券总价值: 做多股票的价值+做空股票价值+做多期权价值+做空期权价值。以上各项取绝对值计算。
82+
- gross_position_value: 证券总价值: 做多股票的价值+做空股票价值+做多期权价值+做空期权价值。
8383
- initial_margin_requirement: 初始保证金
8484
- leverage: gross_position_value / net_liquidation
8585
- maintenance_margin_requirement: 维持保证金

tigeropen/trade/domain/contract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
class Contract:
12-
def __init__(self, symbol, currency, contract_id=None, sec_type=None, exchange=None, origin_symbol=None,
12+
def __init__(self, symbol=None, currency=None, contract_id=None, sec_type=None, exchange=None, origin_symbol=None,
1313
local_symbol=None, expiry=None, strike=None, put_call=None, multiplier=None, name=None,
1414
short_margin=None, short_fee_rate=None, shortable=None, long_initial_margin=None,
1515
long_maintenance_margin=None, contract_month=None, identifier=None, primary_exchange=None,

tigeropen/trade/domain/order.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,24 @@ def from_tags(tag_values):
181181
return None
182182

183183
def __repr__(self):
184-
return "AlgoParams(%s)" % self.to_dict()
184+
return "AlgoParams(%s)" % self.to_dict()
185+
186+
187+
class Transaction:
188+
"""
189+
订单成交记录。Transactions of order.
190+
"""
191+
def __init__(self, account=None, order_id=None, contract=None, id_=None, action=None,
192+
filled_quantity=None, filled_price=None, filled_amount=None, transacted_at=None):
193+
self.account = account
194+
self.order_id = order_id
195+
self.contract = contract
196+
self.id = id_
197+
self.action = action
198+
self.filled_quantity = filled_quantity
199+
self.filled_price = filled_price
200+
self.filled_amount = filled_amount
201+
self.transacted_at = transacted_at
202+
203+
def __repr__(self):
204+
return "Transaction({})".format(self.__dict__)

tigeropen/trade/request/model.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,147 @@ def to_openapi_dict(self):
563563
return params
564564

565565

566+
class TransactionsParams(BaseParams):
567+
def __init__(self):
568+
super(TransactionsParams, self).__init__()
569+
self._account = None
570+
self._secret_key = None
571+
self._order_id = None
572+
self._sec_type = None
573+
self._symbol = None
574+
self._expiry = None
575+
self._strike = None
576+
self._right = None
577+
self._start_date = None
578+
self._end_date = None
579+
self._limit = None
580+
581+
@property
582+
def account(self):
583+
return self._account
584+
585+
@account.setter
586+
def account(self, value):
587+
self._account = value
588+
589+
@property
590+
def secret_key(self):
591+
return self._secret_key
592+
593+
@secret_key.setter
594+
def secret_key(self, value):
595+
self._secret_key = value
596+
597+
@property
598+
def order_id(self):
599+
return self._order_id
600+
601+
@order_id.setter
602+
def order_id(self, value):
603+
self._order_id = value
604+
605+
@property
606+
def sec_type(self):
607+
return self._sec_type
608+
609+
@sec_type.setter
610+
def sec_type(self, value):
611+
self._sec_type = value
612+
613+
@property
614+
def symbol(self):
615+
return self._symbol
616+
617+
@symbol.setter
618+
def symbol(self, value):
619+
self._symbol = value
620+
621+
@property
622+
def start_date(self):
623+
return self._start_date
624+
625+
@start_date.setter
626+
def start_date(self, value):
627+
self._start_date = value
628+
629+
@property
630+
def end_date(self):
631+
return self._end_date
632+
633+
@end_date.setter
634+
def end_date(self, value):
635+
self._end_date = value
636+
637+
@property
638+
def limit(self):
639+
return self._limit
640+
641+
@limit.setter
642+
def limit(self, value):
643+
self._limit = value
644+
645+
@property
646+
def expiry(self):
647+
return self._expiry
648+
649+
@expiry.setter
650+
def expiry(self, value):
651+
self._expiry = value
652+
653+
@property
654+
def strike(self):
655+
return self._strike
656+
657+
@strike.setter
658+
def strike(self, value):
659+
self._strike = value
660+
661+
@property
662+
def right(self):
663+
return self._right
664+
665+
@right.setter
666+
def right(self, value):
667+
self._right = value
668+
669+
def to_openapi_dict(self):
670+
params = dict()
671+
if self.account:
672+
params['account'] = self.account
673+
674+
if self.order_id:
675+
params['order_id'] = self.order_id
676+
677+
if self.secret_key:
678+
params['secret_key'] = self.secret_key
679+
680+
if self.symbol:
681+
params['symbol'] = self.symbol
682+
683+
if self.sec_type:
684+
params['sec_type'] = self.sec_type
685+
686+
if self.start_date:
687+
params['start_date'] = self.start_date
688+
689+
if self.end_date:
690+
params['end_date'] = self.end_date
691+
692+
if self.limit:
693+
params['limit'] = self.limit
694+
695+
if self.expiry:
696+
params['expiry'] = self.expiry
697+
698+
if self.strike:
699+
params['strike'] = self.strike
700+
701+
if self.right:
702+
params['right'] = self.right
703+
704+
return params
705+
706+
566707
class PlaceModifyOrderParams(BaseParams):
567708
def __init__(self):
568709
super(PlaceModifyOrderParams, self).__init__()

tigeropen/trade/response/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
CONTRACT_FIELDS = set(['symbol', 'market', 'multiplier', 'sec_type', 'currency', 'local_symbol', 'origin_symbol',
9-
'expiry', 'strike', 'right', 'contract_id', 'exchange', 'name', 'short_margin', 'short_fee_rate',
9+
'expiry', 'strike', 'right', 'put_call', 'contract_id', 'exchange', 'name', 'short_margin', 'short_fee_rate',
1010
'shortable', 'long_initial_margin', 'long_maintenance_margin', 'contract_month', 'identifier',
1111
'primary_exchange', 'min_tick', 'trading_class', 'continuous', 'trade',
1212
'last_trading_date', 'first_notice_date', 'last_bidding_close_time'])

0 commit comments

Comments
 (0)