Skip to content

Commit 9cfc172

Browse files
committed
Merge branch 'dev' into feature_position_param
2 parents 3c99168 + 89c9934 commit 9cfc172

File tree

9 files changed

+217
-9
lines changed

9 files changed

+217
-9
lines changed

tigeropen/common/consts/__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ class SecurityType(Enum):
4949
CASH = 'CASH' # 外汇
5050

5151

52+
@unique
53+
class SegmentType(Enum):
54+
SEC = 'SEC'
55+
FUT = 'FUT'
56+
57+
5258
@unique
5359
class Currency(Enum):
5460
"""Enum for currency """
@@ -147,3 +153,10 @@ class TickSizeType(Enum):
147153
CLOSED = 'CLOSED'
148154
OPEN_CLOSED = 'OPEN_CLOSED'
149155
OPEN = 'OPEN'
156+
157+
158+
@unique
159+
class OrderSortBy(Enum):
160+
LATEST_CREATED = 'LATEST_CREATED'
161+
LATEST_STATUS_UPDATED = 'LATEST_STATUS_UPDATED'
162+

tigeropen/common/consts/service_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
INACTIVE_ORDERS = "inactive_orders" # 已撤销订单
2424
FILLED_ORDERS = "filled_orders" # 已成交订单
2525
ORDER_TRANSACTIONS = "order_transactions" # 订单成交记录
26+
ANALYTICS_ASSET = "analytics_asset"
2627

2728
"""
2829
合约

tigeropen/examples/trade_client_demo.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ def get_account_apis():
6464
# 综合/模拟账户获取资产
6565
openapi_client.get_prime_assets()
6666

67+
# get asset history
68+
openapi_client.get_analytics_asset(start_date='2021-12-01', end_date='2021-12-07')
69+
6770

6871
def trade_apis():
6972
account = client_config.account

tigeropen/push/push_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@
6363
'latestTime': 'trade_time', 'contractId': 'contract_id', 'trailStopPrice': 'trail_stop_price',
6464
'trailingPercent': 'trailing_percent', 'percentOffset': 'percent_offset', 'action': 'action',
6565
'status': 'status', 'currency': 'currency', 'remaining': 'remaining', 'id': 'id',
66-
'segment': 'segment', 'identifier': 'identifier', 'replaceStatus': 'replace_status'}
66+
'segment': 'segment', 'identifier': 'identifier', 'replaceStatus': 'replace_status',
67+
'updateTime': 'update_time'}
6768

6869
if sys.platform == 'linux' or sys.platform == 'linux2':
6970
KEEPALIVE = True

tigeropen/trade/domain/order.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class Order:
1616
"quantity", "filled", "_remaining", "avg_fill_price", "commission", "realized_pnl", "_status",
1717
"trail_stop_price", "limit_price", "aux_price", "trailing_percent", "percent_offset", "action",
1818
"order_type", "time_in_force", "outside_rth", "order_legs", "algo_params", "algo_strategy",
19-
"secret_key", "liquidation", "discount", "attr_desc", "source", 'adjust_limit', 'sub_ids', "user_mark"]
19+
"secret_key", "liquidation", "discount", "attr_desc", "source", 'adjust_limit', 'sub_ids', "user_mark",
20+
"update_time"]
2021

2122
def __init__(self, account, contract, action, order_type, quantity, limit_price=None, aux_price=None,
2223
trail_stop_price=None, trailing_percent=None, percent_offset=None, time_in_force=None,
@@ -31,6 +32,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
3132
- order_time: 下单时间
3233
- reason: 下单失败时, 会返回失败原因的描述
3334
- trade_time: 最新成交时间
35+
- update_time: order updated time
3436
- action: 交易方向, 'BUY' / 'SELL'
3537
- quantity: 下单数量
3638
- filled: 成交数量
@@ -84,6 +86,7 @@ def __init__(self, account, contract, action, order_type, quantity, limit_price=
8486
self.percent_offset = percent_offset
8587
self.order_time = order_time
8688
self.trade_time = trade_time
89+
self.update_time = kwargs.get('update_time')
8790
self.order_legs = order_legs
8891
self.algo_params = algo_params
8992
self.secret_key = secret_key

tigeropen/trade/request/model.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ def __init__(self):
473473
self._limit = None
474474
self._states = None
475475
self._parent_id = None
476+
self._sort_by = None
476477

477478
@property
478479
def account(self):
@@ -570,6 +571,14 @@ def parent_id(self):
570571
def parent_id(self, value):
571572
self._parent_id = value
572573

574+
@property
575+
def sort_by(self):
576+
return self._sort_by
577+
578+
@sort_by.setter
579+
def sort_by(self, value):
580+
self._sort_by = value
581+
573582
def to_openapi_dict(self):
574583
params = dict()
575584
if self.account:
@@ -608,6 +617,9 @@ def to_openapi_dict(self):
608617
if self.parent_id:
609618
params['parent_id'] = self.parent_id
610619

620+
if self.sort_by:
621+
params['sort_by'] = self.sort_by
622+
611623
return params
612624

613625

@@ -919,3 +931,107 @@ def to_openapi_dict(self):
919931
params['id'] = self.id
920932

921933
return params
934+
935+
936+
class AnalyticsAssetParams(BaseParams):
937+
def __init__(self):
938+
super().__init__()
939+
self._account = None
940+
self._sub_account = None
941+
self._secret_key = None
942+
self._seg_type = None
943+
self._currency = None
944+
self._sub_accounts = None
945+
self._start_date = None
946+
self._end_date = None
947+
948+
@property
949+
def account(self):
950+
return self._account
951+
952+
@account.setter
953+
def account(self, value):
954+
self._account = value
955+
956+
@property
957+
def sub_account(self):
958+
return self._sub_account
959+
960+
@sub_account.setter
961+
def sub_account(self, value):
962+
self._sub_account = value
963+
964+
@property
965+
def secret_key(self):
966+
return self._secret_key
967+
968+
@secret_key.setter
969+
def secret_key(self, value):
970+
self._secret_key = value
971+
972+
@property
973+
def seg_type(self):
974+
return self._seg_type
975+
976+
@seg_type.setter
977+
def seg_type(self, value):
978+
self._seg_type = value
979+
980+
@property
981+
def currency(self):
982+
return self._currency
983+
984+
@currency.setter
985+
def currency(self, value):
986+
self._currency = value
987+
988+
@property
989+
def sub_accounts(self):
990+
return self._sub_accounts
991+
992+
@sub_accounts.setter
993+
def sub_accounts(self, value):
994+
self._sub_accounts = value
995+
996+
@property
997+
def start_date(self):
998+
return self._start_date
999+
1000+
@start_date.setter
1001+
def start_date(self, value):
1002+
self._start_date = value
1003+
1004+
@property
1005+
def end_date(self):
1006+
return self._end_date
1007+
1008+
@end_date.setter
1009+
def end_date(self, value):
1010+
self._end_date = value
1011+
1012+
def to_openapi_dict(self):
1013+
params = dict()
1014+
if self.account:
1015+
params['account'] = self.account
1016+
1017+
if self.sub_account:
1018+
params['sub_account'] = self.sub_account
1019+
1020+
if self.secret_key:
1021+
params['secret_key'] = self.secret_key
1022+
1023+
if self.seg_type:
1024+
params['seg_type'] = self.seg_type
1025+
1026+
if self.currency:
1027+
params['currency'] = self.currency
1028+
1029+
if self.sub_accounts:
1030+
params['sub_accounts'] = self.sub_accounts
1031+
1032+
if self.start_date:
1033+
params['start_date'] = self.start_date
1034+
1035+
if self.end_date:
1036+
params['end_date'] = self.end_date
1037+
return params
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# @Date : 2022/7/8
4+
# @Author : sukai
5+
import json
6+
from datetime import datetime
7+
8+
from tigeropen.common.response import TigerResponse
9+
from tigeropen.common.util.string_utils import camel_to_underline_obj
10+
11+
12+
class AnalyticsAssetResponse(TigerResponse):
13+
def __init__(self):
14+
super().__init__()
15+
self.result = None
16+
self._is_success = None
17+
18+
def parse_response_content(self, response_content):
19+
response = super().parse_response_content(response_content)
20+
if 'is_success' in response:
21+
self._is_success = response['is_success']
22+
23+
if self.data:
24+
result = camel_to_underline_obj(self.data)
25+
history = result.get('history')
26+
if history:
27+
for item in history:
28+
item['dt'] = datetime.fromtimestamp(item['date'] // 1000).strftime('%Y-%m-%d')
29+
result['history'] = history
30+
self.result = result

tigeropen/trade/response/orders_response.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
'contractId': 'contract_id', 'algoStrategy': 'algo_strategy',
2323
'trailStopPrice': 'trail_stop_price', 'trailingPercent': 'trailing_percent',
2424
'percentOffset': 'percent_offset', 'identifier': 'identifier', 'algoParameters': 'algo_params',
25-
'userMark': 'user_mark'
25+
'userMark': 'user_mark', 'updateTime': 'update_time'
2626
}
2727

2828

@@ -115,6 +115,8 @@ def parse_order(item, secret_key=None):
115115
order.order_time = order_fields.get('order_time')
116116
if 'trade_time' in order_fields:
117117
order.trade_time = order_fields.get('trade_time')
118+
if 'update_time' in order_fields:
119+
order.update_time = order_fields.get('update_time')
118120
if 'reason' in order_fields:
119121
order.reason = order_fields.get('reason')
120122
if secret_key is not None:

0 commit comments

Comments
 (0)