Skip to content

Commit 91cadec

Browse files
committed
aggregate asset
1 parent e016ee8 commit 91cadec

File tree

7 files changed

+143
-4
lines changed

7 files changed

+143
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.3.4
2+
### `TradeClient.get_aggregate_assets`
3+
4+
15
## 3.3.3 (2025-03-05)
26
### New
37
- `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/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.option_market_value = float('inf')
130+
# 期货市值
131+
self.futures_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: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from tigeropen.common.consts import THREAD_LOCAL, SecurityType, Market, Currency, Language, OPEN_API_SERVICE_VERSION_V3
1010
from tigeropen.common.consts.service_types import CONTRACTS, ACCOUNTS, POSITIONS, ASSETS, ORDERS, ORDER_NO, \
1111
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
12+
PRIME_ASSETS, ORDER_TRANSACTIONS, QUOTE_CONTRACT, ANALYTICS_ASSET, SEGMENT_FUND_AVAILABLE, SEGMENT_FUND_HISTORY, \
13+
TRANSFER_FUND, \
14+
TRANSFER_SEGMENT_FUND, CANCEL_SEGMENT_FUND, PLACE_FOREX_ORDER, ESTIMATE_TRADABLE_QUANTITY, AGGREGATE_ASSETS
1415
from tigeropen.common.exceptions import ApiException
1516
from tigeropen.common.util.common_utils import get_enum_value, date_str_to_timestamp
1617
from tigeropen.common.request import OpenApiRequest
@@ -19,8 +20,9 @@
1920
from tigeropen.trade.domain.order import Order
2021
from tigeropen.trade.request.model import ContractParams, AccountsParams, AssetParams, PositionParams, OrdersParams, \
2122
OrderParams, PlaceModifyOrderParams, CancelOrderParams, TransactionsParams, AnalyticsAssetParams, SegmentFundParams, \
22-
ForexTradeOrderParams, EstimateTradableQuantityModel, FundingHistoryParams
23+
ForexTradeOrderParams, EstimateTradableQuantityModel, FundingHistoryParams, AggregateAssetParams
2324
from tigeropen.trade.response.account_profile_response import ProfilesResponse
25+
from tigeropen.trade.response.aggregate_assets_response import AggregateAssetsResponse
2426
from tigeropen.trade.response.analytics_asset_response import AnalyticsAssetResponse
2527
from tigeropen.trade.response.assets_response import AssetsResponse
2628
from tigeropen.trade.response.contracts_response import ContractsResponse
@@ -316,6 +318,23 @@ def get_prime_assets(self, account=None, base_currency=None, consolidated=True):
316318
raise ApiException(response.code, response.message)
317319
return None
318320

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

0 commit comments

Comments
 (0)