Skip to content

Commit 4570c4e

Browse files
committed
Merge branch 'feat_aggregate_asset' into 'master'
Feat aggregate asset See merge request server/openapi/openapi-python-sdk!234
2 parents e016ee8 + 314fde1 commit 4570c4e

File tree

8 files changed

+148
-5
lines changed

8 files changed

+148
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 3.3.4 (2025-04-09)
2+
### New
3+
- `TradeClient.get_aggregate_assets`
4+
### Mod
5+
- 选股器字段更新
6+
17
## 3.3.3 (2025-03-05)
28
### New
39
- `QuoteClient.get_quote_overnight` 获取夜盘行情

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__ = '3.3.3'
7+
__VERSION__ = '3.3.4'

tigeropen/common/consts/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class SegmentType(Enum):
6666
ALL = 'ALL'
6767
SEC = 'SEC'
6868
FUT = 'FUT'
69+
FUND = 'FUND'
6970

7071

7172
@unique

tigeropen/common/consts/service_types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
PLACE_FOREX_ORDER = "place_forex_order"
3434
ESTIMATE_TRADABLE_QUANTITY = "estimate_tradable_quantity"
3535
TRANSFER_FUND = "transfer_fund"
36+
AGGREGATE_ASSETS = "aggregate_assets"
3637

3738
USER_LICENSE = "user_license"
3839

tigeropen/trade/domain/prime_account.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,56 @@ def from_dict(d):
9999

100100
def __repr__(self):
101101
return MODEL_REPR.format(self.__class__.__name__, self.__dict__)
102+
103+
104+
class AggregateAsset:
105+
"""
106+
"""
107+
def __init__(self):
108+
# 基础币种
109+
self.currency = None
110+
# 现金余额
111+
self.cash_balance = float('inf')
112+
# 现金余额包括在途
113+
self.cash_balance_with_in_transit = float('inf')
114+
# 具有借贷价值资产
115+
self.equity_with_loan = float('inf')
116+
# 净清算价值
117+
self.net_liquidation = float('inf')
118+
# 初始保证金
119+
self.init_margin = float('inf')
120+
# 维持保证金
121+
self.maintain_margin = float('inf')
122+
# 外汇保证金
123+
self.trade_currency_margin = float('inf')
124+
# 日内风险度
125+
self.intraday_risk_ratio = float('inf')
126+
# 总市值
127+
self.gross_position_value = float('inf')
128+
# 股票持仓市值
129+
self.stock_market_value = float('inf')
130+
# 期权市值
131+
self.option_market_value = float('inf')
132+
# 可用剩余资产
133+
self.cash_available_for_trade = float('inf')
134+
# 可用现金值
135+
self.available_cash = float('inf')
136+
# 已锁定的剩余资产
137+
self.locked_funds = float('inf')
138+
# 锁定现金值
139+
self.locked_cash = float('inf')
140+
# 引用额度
141+
self.credit_limit = float('inf')
142+
# ee 剩余资产
143+
self.excess_equity = float('inf')
144+
# el 剩余流动资产
145+
self.excess_liquidity = float('inf')
146+
147+
@staticmethod
148+
def from_dict(d):
149+
aggregate_asset = AggregateAsset()
150+
aggregate_asset.__dict__.update(d)
151+
return aggregate_asset
152+
153+
def __repr__(self):
154+
return MODEL_REPR.format(self.__class__.__name__, self.__dict__)

tigeropen/trade/request/model.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,50 @@ def to_openapi_dict(self):
131131

132132
return params
133133

134+
class AggregateAssetParams(BaseParams):
135+
def __init__(self):
136+
super(AggregateAssetParams, self).__init__()
137+
self._account = None
138+
self._secret_key = None
139+
self._seg_type = False
140+
self._base_currency = None
141+
142+
@property
143+
def account(self):
144+
return self._account
145+
@account.setter
146+
def account(self, value):
147+
self._account = value
148+
@property
149+
def secret_key(self):
150+
return self._secret_key
151+
@secret_key.setter
152+
def secret_key(self, value):
153+
self._secret_key = value
154+
@property
155+
def seg_type(self):
156+
return self._seg_type
157+
@seg_type.setter
158+
def seg_type(self, value):
159+
self._seg_type = value
160+
@property
161+
def base_currency(self):
162+
return self._base_currency
163+
@base_currency.setter
164+
def base_currency(self, value):
165+
self._base_currency = value
166+
167+
def to_openapi_dict(self):
168+
params = super().to_openapi_dict()
169+
if self.account:
170+
params['account'] = self.account
171+
if self.secret_key:
172+
params['secret_key'] = self.secret_key
173+
if self.seg_type:
174+
params['seg_type'] = self.seg_type
175+
if self.base_currency:
176+
params['base_currency'] = self.base_currency
177+
return params
134178

135179
class PositionParams(BaseParams):
136180
def __init__(self):
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from tigeropen.common.response import TigerResponse
2+
from tigeropen.common.util.string_utils import camel_to_underline_obj
3+
from tigeropen.trade.domain.prime_account import AggregateAsset
4+
5+
6+
class AggregateAssetsResponse(TigerResponse):
7+
def __init__(self):
8+
super().__init__()
9+
self.result = None
10+
self._is_success = None
11+
12+
def parse_response_content(self, response_content):
13+
response = super().parse_response_content(response_content)
14+
if 'is_success' in response:
15+
self._is_success = response['is_success']
16+
17+
if self.data:
18+
self.result = AggregateAsset.from_dict(camel_to_underline_obj(self.data))

tigeropen/trade/trade_client.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
"""
77
import logging
88

9-
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, Market, Currency, Language, OPEN_API_SERVICE_VERSION_V3
9+
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, Market, Currency, Language, OPEN_API_SERVICE_VERSION_V3, \
10+
SegmentType
1011
from tigeropen.common.consts.service_types import CONTRACTS, ACCOUNTS, POSITIONS, ASSETS, ORDERS, ORDER_NO, \
1112
CANCEL_ORDER, MODIFY_ORDER, PLACE_ORDER, ACTIVE_ORDERS, INACTIVE_ORDERS, FILLED_ORDERS, CONTRACT, PREVIEW_ORDER, \
12-
PRIME_ASSETS, ORDER_TRANSACTIONS, QUOTE_CONTRACT, ANALYTICS_ASSET, SEGMENT_FUND_AVAILABLE, SEGMENT_FUND_HISTORY, TRANSFER_FUND, \
13-
TRANSFER_SEGMENT_FUND, CANCEL_SEGMENT_FUND, PLACE_FOREX_ORDER, ESTIMATE_TRADABLE_QUANTITY
13+
PRIME_ASSETS, ORDER_TRANSACTIONS, QUOTE_CONTRACT, ANALYTICS_ASSET, SEGMENT_FUND_AVAILABLE, SEGMENT_FUND_HISTORY, \
14+
TRANSFER_FUND, \
15+
TRANSFER_SEGMENT_FUND, CANCEL_SEGMENT_FUND, PLACE_FOREX_ORDER, ESTIMATE_TRADABLE_QUANTITY, AGGREGATE_ASSETS
1416
from tigeropen.common.exceptions import ApiException
1517
from tigeropen.common.util.common_utils import get_enum_value, date_str_to_timestamp
1618
from tigeropen.common.request import OpenApiRequest
@@ -19,8 +21,9 @@
1921
from tigeropen.trade.domain.order import Order
2022
from tigeropen.trade.request.model import ContractParams, AccountsParams, AssetParams, PositionParams, OrdersParams, \
2123
OrderParams, PlaceModifyOrderParams, CancelOrderParams, TransactionsParams, AnalyticsAssetParams, SegmentFundParams, \
22-
ForexTradeOrderParams, EstimateTradableQuantityModel, FundingHistoryParams
24+
ForexTradeOrderParams, EstimateTradableQuantityModel, FundingHistoryParams, AggregateAssetParams
2325
from tigeropen.trade.response.account_profile_response import ProfilesResponse
26+
from tigeropen.trade.response.aggregate_assets_response import AggregateAssetsResponse
2427
from tigeropen.trade.response.analytics_asset_response import AnalyticsAssetResponse
2528
from tigeropen.trade.response.assets_response import AssetsResponse
2629
from tigeropen.trade.response.contracts_response import ContractsResponse
@@ -316,6 +319,23 @@ def get_prime_assets(self, account=None, base_currency=None, consolidated=True):
316319
raise ApiException(response.code, response.message)
317320
return None
318321

322+
def get_aggregate_assets(self, account=None, seg_type=SegmentType.SEC, base_currency=None):
323+
params = AggregateAssetParams()
324+
params.account = account if account else self._account
325+
params.secret_key = self._secret_key
326+
params.lang = get_enum_value(self._lang)
327+
params.base_currency = get_enum_value(base_currency)
328+
params.seg_type = get_enum_value(seg_type)
329+
request = OpenApiRequest(AGGREGATE_ASSETS, biz_model=params)
330+
response_content = self.__fetch_data(request)
331+
if response_content:
332+
response = AggregateAssetsResponse()
333+
response.parse_response_content(response_content)
334+
if response.is_success():
335+
return response.result
336+
else:
337+
raise ApiException(response.code, response.message)
338+
319339
def get_orders(self, account=None, sec_type=None, market=Market.ALL, symbol=None, start_time=None, end_time=None,
320340
limit=100, is_brief=False, states=None, sort_by=None, seg_type=None):
321341
"""

0 commit comments

Comments
 (0)