Query Account Information
get_prime_assets Get Prime/Paper Trading Account Asset Information
TradeClient.get_prime_assets(account=None, base_currency=None, consolidated=True)
Description
Get asset information, applicable to prime/paper trading accounts
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | str | No | Account ID, if not specified, uses the default account in client_config |
| base_currency | str | No | Currency |
| consolidated | bool | No | Whether to display aggregated Segment asset metrics, only SEC assets will be aggregated. Default is true |
Returns
list
Each element in the list is a PortfolioAccount object. If there is only one account, the list contains only one element. The structure of the PortfolioAccount object is as follows.
For detailed explanations of fields in PortfolioAccount and Segment, please refer to Object Information
PortfolioAccount Object
├── account: Account ID
├── update_timestamp: Update time, timestamp in milliseconds
├── segments: Account information by product category, a dict with security category as key, value is Segment object
│ ├── 'S' represents Securities account, value is Segment object
│ │ ├── currency: Currency, such as USD
│ │ ├── capability: Account type, margin account: RegTMargin, cash account: Cash.
│ │ ├── category: Trading product category S: (Securities stocks)
│ │ ├── cash_balance: Cash amount.
│ │ ├── cash_available_for_trade: Available funds, including cash and financing limit, used as reference for maximum trading purchasing power.
│ │ ├── cash_available_for_withdrawal: Cash amount currently available for withdrawal from the account
│ │ ├── gross_position_value: Total securities value
│ │ ├── equity_with_loan: Total equity with loan value
│ │ ├── net_liquidation: Total assets; net liquidation value
│ │ ├── init_margin: Initial margin
│ │ ├── maintain_margin: Maintenance margin
│ │ ├── overnight_margin: Overnight margin
│ │ ├── unrealized_pl: Unrealized P&L
│ │ ├── realized_pl: Realized P&L
│ │ ├── excess_liquidation: Current excess liquidity
│ │ ├── overnight_liquidation: Overnight excess liquidity
│ │ ├── buying_power: Buying power
│ │ ├── leverage: Current leverage ratio used
│ │ ├── locked_funds: Locked funds
│ │ ├── uncollected: Funds in transit
│ │ ├── currency_assets: Account asset information by trading currency, a dict with currency as key
│ │ │ ├── 'USD' represents US Dollar, value is CurrencyAsset object
│ │ │ │ ├── currency: Current currency, common currencies include: USD-US Dollar
│ │ │ │ ├── cash_balance: Cash available for trading, plus locked cash portion (such as stocks purchased but not yet settled, and other situations that may have locked cash)
│ │ │ │ ├── cash_available_for_trade: Cash amount currently available for trading in the account
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
client_config = get_client_config(private_key_path='private_key_path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
portfolio_account = trade_client.get_prime_assets(base_currency='USD') # Can set base currency
print(portfolio_account)
# Example of viewing account attributes
print(portfolio_account.account) # Account ID
print(portfolio_account.segments['S'].buying_power) # Securities account buying power
print(portfolio_account.segments['S'].cash_balance) # Securities account cash value
print(portfolio_account.segments['S'].unrealized_pl) # Unrealized P&L
print(portfolio_account.segments['S'].currency_assets['USD'].gross_position_value) # Total securities value in USD
Return Example
PortfolioAccount(
{
'account': '1234567',
'update_timestamp': 1638949616442,
'segments': {
'S': Segment({
'currency': 'USD',
'capability': 'RegTMargin',
'category': 'S',
'cash_balance': 111978.7160247,
'cash_available_for_trade': 123905.775195,
'cash_available_for_withdrawal': 123905.775195,
'gross_position_value': 22113.5652986,
'equity_with_loan': 134092.2813233,
'net_liquidation': 135457.2802984,
'init_margin': 9992.3764097,
'maintain_margin': 8832.4423281,
'overnight_margin': 11607.5876493,
'unrealized_pl': -1121.0821891,
'realized_pl': -3256.0,
'excess_liquidation': 125259.8389952,
'overnight_liquidation': 122484.693674,
'buying_power': 495623.1007801,
'leverage': 0.164693,
'currency_assets': {
'USD': CurrencyAsset({
'currency': 'USD',
'cash_balance': 123844.77,
'cash_available_for_trade': 123792.77
})
}
})
})
get_positions Get Position Data
TradeClient.get_positions(account=None, sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL, symbol=None, sub_accounts=None, expiry=None, strike=None, put_call=None)
Description
Get account position information
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | str | No | Account ID, if not specified, use the default account from client_config |
| sec_type | SecurityType | No | Security type, including STK/OPT, default STK, can be imported from tigeropen.common.consts.SecurityType |
| currency | Currency | No | Currency, including ALL/USD., default ALL, can be imported from tigeropen.common.consts.Currency |
| market | Market | No | Market, including ALL/US etc., default ALL, can be imported from tigeropen.common.consts.Market |
| symbol | str | No | Security symbol |
| sub_accounts | list[str] | No | Sub-account list |
| expiry | str | No | Expiry date (for options). Format 'yyyyMMdd', e.g., '220121' |
| strike | float | No | Strike price (for options). e.g., 100.5 |
| put_call | str | No | Put or call (for options). 'PUT' or 'CALL' |
Returns
List of position objects, type: list
Structure as follows:
Each element is a Position object. Position(tigeropen.trade.domain.position.Position) object has the following attributes:
| Parameter | Type | Description |
|---|---|---|
| account | str | Account |
| contract | Contract | Contract object, tigeropen.trade.domain.contract.Contract |
| quantity | int | Position quantity |
| average_cost | float | Position cost |
| average_cost_by_average | float | Average price cost |
| average_cost_of_carry | float | Average position cost calculated in A-share style (object) |
| market_price | float | Latest price (during trading hours, market price. For US stocks during non-trading hours, prime account shows after-hours closing price) |
| market_value | float | Market value |
| realized_pnl | float | Realized P&L |
| realized_pnl_by_average | float | Realized P&L by average cost |
| unrealized_pnl | float | Unrealized P&L |
| unrealized_pnl_by_average | float | Unrealized P&L by average cost |
| unrealized_pnl_percent | float | Unrealized P&L percentage |
| unrealized_pnl_percent_by_average | float | Unrealized P&L percentage by average cost |
| salable_qty | float | Salable quantity |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.consts import SecurityType, Currency, Market
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
positions = trade_client.get_positions(sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL)
# View position attributes
print(len(positions)) # Number of position securities
# First position contract
position1 = positions[0]
print(position1.contract.symbol) # Contract symbol
print(position1.contract.sec_type) # Contract type, e.g., STK, OPT
print(position1.contract.multiplier) # Contract multiplier
print(position1.average_cost) # Position cost
print(position1.quantity) # Position quantity
# Second position security
position2 = positions[1]
print(position2.unrealized_pnl) # Unrealized P&L
print(position2.market_value) # Position market value
Return Example
[contract: BABA/STK/USD, quantity: 1, average_cost: 178.99, market_price: 176.77,
contract: BIDU/STK/USD, quantity: 3, average_cost: 265.4633, market_price: 153.45,
contract: SPY/STK/USD, quantity: 7, average_cost: 284.9243, market_price: 284.97]get_segment_fund_available Get Available Transfer Funds
TradeClient.get_segment_fund_available(from_segment=None, currency=None)
Description
Get available transfer funds under the corresponding Segment of the account (applicable to prime or paper trading accounts)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| from_segment | str | Yes | Transfer from segment, SEC |
| currency | str | No | Transfer currency, USD |
Returns
List[SegmentFundAvailableItem] List of available transfer fund amounts for each Segment. Each item is tigeropen.trade.domain.account.SegmentFundAvailableItem
SegmentFundAvailableItem Description:
| Name | Type | Description |
|---|---|---|
| from_segment | string | Transfer from segment, SEC |
| currency | string | Transfer currency, USD |
| amount | float | Available funds, unit: corresponding currency |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.consts import SecurityType, Currency, Market
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
available = trade_client.get_segment_fund_available(from_segment='SEC', currency='USD')
print(available)
# Get amount
print(available[0].amount)Return Example
[SegmentFundAvailableItem({'from_segment': 'SEC', 'currency': 'USD', 'amount': 718859.79})]
get_positions Get Position Data
TradeClient.get_positions(account=None, sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL, symbol=None, sub_accounts=None, expiry=None, strike=None, put_call=None)
Description
Get position information for the account
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| account | str | No | Account ID, if not specified, uses the default account in client_config |
| sec_type | SecurityType | No | Security type, including STK/OPT, default STK, can be imported from tigeropen.common.consts.SecurityType |
| currency | Currency | No | Currency, including ALL/USD, default ALL, can be imported from tigeropen.common.consts.Currency |
| market | Market | No | Market, including ALL/US, default ALL, can be imported from tigeropen.common.consts.Market |
| symbol | str | No | Security symbol |
| sub_accounts | list[str] | No | Sub-account list |
| expiry | str | No | Expiration date (for options). Format 'yyyyMMdd', e.g., '220121' |
| strike | float | No | Strike price (for options). e.g., 100.5 |
| put_call | str | No | Put or Call (for options). 'PUT' or 'CALL' |
Returns
List of position objects, type: list
Structure as follows:
Each element is a Position object. Position(tigeropen.trade.domain.position.Position) object has the following attributes:
| Parameter | Type | Description |
|---|---|---|
| account | str | Account |
| contract | Contract | Contract object, tigeropen.trade.domain.contract.Contract |
| quantity | int | Position quantity |
| average_cost | float | Position cost |
| average_cost_by_average | float | Average cost |
| average_cost_of_carry | float | A-share method calculated average position cost (object) |
| market_price | float | Latest price (during trading hours, market price. For US stocks during non-trading hours, prime account shows after-hours closing price) |
| market_value | float | Market value |
| realized_pnl | float | Realized P&L |
| realized_pnl_by_average | float | Average cost realized P&L |
| unrealized_pnl | float | Unrealized P&L |
| unrealized_pnl_by_average | float | Average cost unrealized P&L |
| unrealized_pnl_percent | float | Unrealized P&L percentage |
| unrealized_pnl_percent_by_average | float | Average cost unrealized P&L percentage |
| salable_qty | float | Sellable quantity |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.consts import SecurityType, Currency, Market
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
positions = trade_client.get_positions(sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL)
# View position attributes
print(len(positions)) # Number of position instruments
# First position contract
position1 = positions[0]
print(position1.contract.symbol) # Contract symbol
print(position1.contract.sec_type) # Contract type, e.g., STK, OPT
print(position1.contract.multiplier) # Contract multiplier
print(position1.average_cost) # Position cost
print(position1.quantity) # Position quantity
# Second position instrument
position2 = positions[1]
print(position2.unrealized_pnl) # Unrealized P&L
print(position2.market_value) # Position market value
Return Example
[contract: BABA/STK/USD, quantity: 1, average_cost: 178.99, market_price: 176.77,
contract: BIDU/STK/USD, quantity: 3, average_cost: 265.4633, market_price: 153.45,
contract: SPY/STK/USD, quantity: 7, average_cost: 284.9243, market_price: 284.97]get_segment_fund_available Get Transferable Funds
TradeClient.get_segment_fund_available(from_segment=None, currency=None)
Description
Get transferable funds under the corresponding Segment of the account (applicable to prime or paper trading accounts)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| from_segment | str | Yes | Transfer from segment, SEC |
| currency | str | No | Transfer currency, USD |
Returns
List[SegmentFundAvailableItem] List of transferable fund amounts for each Segment. Each item is tigeropen.trade.domain.account.SegmentFundAvailableItem
SegmentFundAvailableItem Description:
| Name | Type | Description |
|---|---|---|
| from_segment | string | Transfer from segment, SEC |
| currency | string | Transfer currency, USD |
| amount | float | Transferable funds, unit: corresponding currency |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.consts import SecurityType, Currency, Market
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
available = trade_client.get_segment_fund_available(from_segment='SEC', currency='USD')
print(available)
# Get amount
print(available[0].amount)Return Example
[SegmentFundAvailableItem({'from_segment': 'SEC', 'currency': 'USD', 'amount': 718859.79})]
get_estimate_tradable_quantity Get Maximum Tradable Quantity
TradeClient.get_estimate_tradable_quantity(order, seg_type=None)
Description
Query the maximum buyable/sellable quantity for a specific instrument in the account. Supports stocks and options.
Parameters
Order object (tigeropen.trade.domain.order.Order)
You can use utility functions from tigeropen.common.util.order_utils, such as limit_order(), market_order(), to generate order objects locally based on your specific order type and parameters. For creation methods, see Order Object - Construction Methods section
Only supports limit orders or stop orders
Returns
tigeropen.trade.domain.position.TradableQuantityItem object with the following attributes:
| Field | Type | Description |
|---|---|---|
| tradable_quantity | float | Cash buyable/sellable quantity (if action is buy, returns buyable quantity, otherwise sellable quantity) |
| financing_quantity | float | Margin buyable/sellable quantity (not applicable to cash accounts) |
| position_quantity | float | Position quantity |
| tradable_position_quantity | float | Tradable position quantity |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.consts import SecurityType, Currency, Market
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
contract = stock_contract(symbol='XYZX', currency='USD')
order = limit_order(account=client_config.account, contract=contract, action='BUY', limit_price=50, quantity=1)
res = trade_client.get_estimate_tradable_quantity(order)
print(res)Return Example
TradableQuantityItem<{'tradable_quantity': 28921.0, 'financing_quantity': 52657.0, 'position_quantity': 0.0, 'tradable_position_quantity': 0}>
get_funding_history Get Funding History
TradeClient.get_funding_history(seg_type=None)
Description
Query the account's funding history.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| seg_type | SegmentType | No | Segment type |
Returns pandas.DataFrame with the following fields:
| Field | Type | Description |
|---|---|---|
| id | long | ID |
| refId | string | Related business ID |
| type | int | Fund type (1: Deposit; 3: Withdrawal; 20: Withdrawal fee; 21: Withdrawal refund; 22: Withdrawal failure-refund; 23: Withdrawal fee-refund) |
| type_desc | string | Fund type description |
| currency | string | Currency |
| amount | double | Amount |
| business_date | string | Business date |
| completed_status | bool | Whether completed |
| created_at | long | Creation timestamp |
| updated_at | long | Update timestamp |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.consts import SecurityType, Currency, Market
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
res = trade_client.get_funding_history()
print(res)Return Example
id ref_id type type_desc currency amount business_date completed_status updated_at created_at
0 3000000 26 1 Deposit USD 484.88 2017/08/24 True 1503574430000 1503574430000
1 3000001 123 1 Deposit USD 2000.00 2017/12/15 True 1513308908000 1513308908000get_fund_details Get Fund Details
TradeClient.get_fund_details(self, seg_types, account=None, fund_type=None, currency=None, start=0, limit=None, start_date=None, end_date=None, secret_key=None, lang=None):
Description
Get fund details
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| seg_types | list[str] | Yes | Account segment types, options: SegmentType.SEC for securities; can be imported from tigeropen.common.consts.SegmentType. Available values: 'SEC' |
| account | str | No | Account ID, if not provided, uses default account. Only supports prime accounts |
| fund_type | int | No | Fund type, including: ALL (all), DEPOSIT_WITHDRAW (deposits/withdrawals), TRADE (trading), FEE (fees), FUNDS_TRANSFER (fund transfers), CORPORATE_ACTION (corporate actions), ACTIVITY_AWARD (activities), OTHER (others). Default ALL |
| currency | Currency | No | Currency, including USD, can be imported from tigeropen.common.consts.Currency |
| start | int | No | Starting sequence number, starts from 0. For example, if each page has limit 50, and the first two pages returned 100 records, then for the 3rd page, start should be 100, continuing from the 101st record |
| limit | int | No | Maximum number of records to return, default 50, maximum 100 |
| start_date | str | No | Start date, format 'yyyy-MM-dd' |
| end_date | str | No | End date, format 'yyyy-MM-dd' |
| secret_key | str | No | Institutional secret key (individual developers don't need to fill this) |
| lang | Language | No | Supported language, can use enumeration constants provided in tigeropen.common.consts.Language, such as Language.zh_CN, default is Language.en_US, see enumeration parameter section |
Returns pandas.DataFrame with the following fields:
| Field | Type | Description |
|---|---|---|
| id | int | Record ID |
| desc | str | Description |
| currency | str | Currency |
| seg_type | str | SegmentType |
| type | str | Fund type |
| amount | float | Amount |
| business_date | str | Tiger-defined business date, all fund changes for the same trading day across all markets will be recorded under the same business date |
| updated_at | int | Transaction update timestamp |
| page | int | Current page number |
| limit | int | Records per page |
| item_count | int | Total record count |
| page_count | int | Total page count |
| timestamp | int | Timestamp |
| contract_name | str | Contract name |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.common.consts import SecurityType, Currency, Market
from tigeropen.tiger_open_config import TigerOpenClientConfig
client_config = TigerOpenClientConfig(props_path='/path/to/your/properties/file/')
trade_client = TradeClient(client_config)
result = trade_client.get_fund_details(
seg_types=[SegmentType.SEC],
start= 0,
limit = 50,
start_date='2025-03-28',
end_date='2025-04-04',
fund_type='ALL',
# currency = Currency.USD,
# lang = Language.en_US,
)
print(result)
# Paginated retrieval of all data
start = 0
limit = 50
final_result = pd.DataFrame()
while True:
res = trade_client.get_fund_details(seg_types=[SegmentType.SEC], start=start, limit=limit,start_date='2025-01-01', end_date='2025-05-01')
if res.empty:
break
start += limit
final_result = pd.concat([final_result, res], ignore_index=True)
print(final_result)
Return Example
id currency type desc contract_name seg_type amount business_date updated_at page limit item_count page_count timestamp
0 24924145889681231 USD Corporate Action Fee VFS-DIVIDEND SEC -0.10 2025-04-04 1743762173000 1 50 8 1 1745581047814
1 24924145889681229 USD Dividend VFS-DIVIDEND SEC 0.10 2025-04-04 1743762173000 1 50 8 1 1745581047814
2 24924145889681217 USD Corporate Action Fee VFS-DIVIDEND SEC 0.09 2025-04-04 1743762171000 1 50 8 1 1745581047814
3 24924145889681215 USD Dividend Tax VFS-DIVIDEND SEC 0.01 2025-04-04 1743762171000 1 50 8 1 1745581047814
4 24924145889681213 USD Dividend VFS-DIVIDEND SEC -0.10 2025-04-04 1743762171000 1 50 8 1 1745581047814
5 24924145889678880 USD Corporate Action Fee VFS-DIVIDEND SEC -0.09 2025-03-28 1743392460000 1 50 8 1 1745581047814
6 24924145889678878 USD Dividend Tax VFS-DIVIDEND SEC -0.01 2025-03-28 1743392460000 1 50 8 1 1745581047814
7 24924145889678876 USD Dividend VFS-DIVIDEND SEC 0.10 2025-03-28 1743392460000 1 50 8 1 1745581047814Updated 7 days ago