Get Account Information
get_managed_accounts Get Managed Accounts
TradeClient.get_managed_accounts(account=None)
Description
Fetch a list of managed accounts of the current user, along with account information.
Arguments
Arguments | Type | Description |
---|---|---|
account | str | Account id. Optional,Default value is to return all managed accounts |
Response
list
, each element is a AccountProfile
(tigeropen.trade.domain.profile.AccountProfile)object
Attributes:
Attribute | Type | Description |
---|---|---|
account | str omnibus account:50129912,global account:U5755619,paper account:20191221901212121 | Account |
capability | str | Account Types (CASH: cash account, RegTMargin: Reg T Margin Account, PMGRN: Portfolio Margin) |
status | str | Account Status(New, Funded, Open, Pending, Abandoned, Rejected, Closed, Unknown) |
accountType | str | Account Type, including: GLOBAL,STANDARD,PAPER |
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='path to .pem file which stores the private key', tiger_id='your tiger id', account='your account', secret_key='secret key for authorized trader of institutional user')
trade_client = TradeClient(client_config)
accounts = trade_client.get_managed_accounts()
Response Example
[AccountProfile({'account': 'DU575569', 'capability': None, 'status': 'Funded'})]
get_assets Get Account Summary (Gobal Account)
TradeClient.get_assets(account=None, sub_accounts=None, segment=False, market_value=False)
Description
Get account summary,this method is only recommended for Global Account. You can also get the account summary of your standard, or paper trading account using this method. However, because different account types have different account structures, Please use get_prime_assets to get assets for prime and paper acount.
Arguments
Arguments | Typse | Description |
---|---|---|
account | str | Account id |
sub_accounts | list[str] | A list of sub-accounts, default value is None |
segment | bool | Whether to return data grouped by segments (securities, futures). Default value is False. When set to True, a dict will be returned, where 'C' means futures, 'S' means stocks |
market_value | bool | Whether to return data grouped by currency (USD, HKD, RMB). Default is False |
secret_key | str | Institutional trader key. Only applicable to institutional users. Configured in client_config |
Response
list
Each element of this list is a PortfolioAccount Object。If the user only has one account,there will be only one element in the list returned.
PortfolioAccount(tigeropen.trade.domain.account.PortfolioAccount) has the following structure。
Please refer to Object for data fields in Account、SecuritySegment、CommoditySegment
PortfolioAccount Object
├── account: account id
├── summary: Summary statistics of the current account. The value inside is an Account object
├── segments: account information grouped by segments. A dictionary
│ ├── 'S' stands for securities account, value is SecuritySegment object
│ └── 'C' stands for futures account, value is CommoditySegment object
├── market_value: Account statistics by currency, a dict
│ ├── 'USD' stands for US dollar, value is a MarketValue object
│ ├── 'HKD' stands for Hong Kong dollar, value is a MarketValue object
└─ └── 'CNH' stands for RMB, value is a MarketValue object
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 file path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
portfolio_account = trade_client.get_assets(segment=True, market_value=True)
print(portfolio_account)
# search portfolio object
portfolio1 = portfolio_account[0]
print(portfolio1.account)
print(portfolio1.segments['S'].available_cash)
print(portfolio1.segments['S'].gross_position_value)
print(portfolio1.segments['C'].available_cash)
print(portfolio1.summary.buying_power)
print(portfolio1.summary.cash)
Respond
[PortfolioAccount({'account': 'DU575569',
'summary': Account({'accrued_cash': 0, 'accrued_dividend': 0, 'available_funds': 948.69,
'buying_power': 948.69, 'cash': 948.81, 'currency': 'USD', 'cushion': 0.5944,
'day_trades_remaining': 3, 'equity_with_loan': 1255.69, 'excess_liquidity': 948.81,
'gross_position_value': 647.53, 'initial_margin_requirement': 307,
'maintenance_margin_requirement': 307, 'net_liquidation': 1596.34,
'realized_pnl': 0, 'regt_equity': 1255.81,
'regt_margin': 153.5, 'sma': 3512.56,
'timestamp': 1561529631, 'unrealized_pnl': -885.36}),
'segments': defaultdict(<class 'tigeropen.trade.domain.account.Account'>,
{'C': CommoditySegment({'accrued_cash': 0, 'accrued_dividend': 0,
'available_funds': 0, 'cash': 0, 'equity_with_loan': 0, 'excess_liquidity': 0,
'initial_margin_requirement': 0, 'maintenance_margin_requirement': 0,
'net_liquidation': 0, 'timestamp': 1544393719}),
'S': SecuritySegment({'accrued_cash': 0, 'accrued_dividend': 0,
'available_funds': 120.73, 'cash': 120.73, 'equity_with_loan': 1292.04,
'excess_liquidity': 120.73, 'gross_position_value': 1171.31,
'initial_margin_requirement': 1171.31, 'leverage': 0.91,
'maintenance_margin_requirement': 1171.31, 'net_liquidation': 1292.04,
'regt_equity': 1292.04, 'regt_margin': 585.66, 'sma': 1973.39, 'timestamp': 1545206069})
}),
'market_values': defaultdict(<class 'tigeropen.trade.domain.account.MarketValue'>,
{'CNH': MarketValue({'currency': 'CNH', 'net_liquidation': 0, 'cash_balance': 0,
' stock_market_value': 0, 'option_market_value': 0,
'warrant_value': 0, 'futures_pnl': 0, 'unrealized_pnl': 0,
'realized_pnl': 0, 'exchange_rate': 0.14506,
'net_dividend': 0, 'timestamp': 1544078822}),
'HKD': MarketValue({'currency': 'HKD', 'net_liquidation': 0, 'cash_balance': 0,
'stock_market_value': 0, 'option_market_value': 0,
'warrant_value': 0, 'futures_pnl': 0, 'unrealized_pnl': 0,
'realized_pnl': 0, 'exchange_rate': 0.12743,
'net_dividend': 0, 'timestamp': 1550158606}),
'USD': MarketValue({'currency': 'USD', 'net_liquidation': 1596.34,
'cash_balance': 948.81, 'stock_market_value': 307,
'option_market_value': 340.53, 'warrant_value': 0,
'futures_pnl': 0, 'unrealized_pnl': -885.36,
'realized_pnl': 0, 'exchange_rate': 1,
'net_dividend': 0, 'timestamp': 1561519773})}
)}
)]
get_prime_assets Account Summary for Prime Account
TradeClient.get_prime_assets(account=None)
Description
Get account summary, including asset information and open positions, for your Prime and Paper accounts
Arguments
Argument | Type | Description |
---|---|---|
account | str | account id, if not specified, the request will use default account id configured in client_config |
base_currency | str | Currency, like USD |
consolidated | bool | No |
Example
list
A list where each element is a PortfolioAccount object. If there is only one account, the method will return a one-element list.
The structure of the PortfolioAccount object is as follows.
For a detailed list of data fields contained 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 segments, a dict with the security category as the key, and the value as a Segment object
│ ├── 'S' means securities account, value is Segment object
│ │ ├── currency: currency, such as USD, HKD
│ │ ├── capability: Account Type, Margin: RegTMargin, Cash: Cash
│ │ ├── category: Securities Classification C: (Commodities Futures), S: (Securities Stocks)
│ │ ├── cash_balance: cash that can be traded, plus some cash that has been locked (such as stocks that have been purchased but not yet traded, and some other situations will also have locked cash)
│ │ ├── cash_available_for_trade: The amount of cash and margin that can be traded in the current account
│ │ ├── cash_available_for_withdrawal: The amount of cash that can be withdrawn in the current account
│ │ ├── gross_position_value: total security value: long stock value + short stock value + long option value + short option value. The above items are calculated as absolute values
│ │ ├── equity_with_loan: Equity with loan value (including loan value assets). Securities Segment: Cash value + stock value, Futures Segment: Cash value - maintenance margin
│ │ ├── net_liquidation: net liquidation value
│ │ ├── init_margin: initial margin requirement
│ │ ├── maintain_margin: maintenance margin requirement
│ │ ├── overnight_margin: overnight margin requirement
│ │ ├── unrealized_pl: floating profit and loss
│ │ ├── realized_pl: realized profit and loss
│ │ ├── excess_liquidation': Excess liquidity, used to represent intraday risk value. Calculation method for securities segment: equity_with_loan - maintenance_margin_requirement. Calculation method for futures segment: net_liquidation - maintenance_margin_requirement
│ │ ├── overnight_liquidation: Overnight risk control value, when it is less than 0, account positions will be forced to liquidate, and you need to pay attention to risks
│ │ ├── buying_power: buying power. Estimate how many dollars you can buy in stock assets. The margin account has a maximum of four times the purchasing power of the funds (funds that are not occupited) during the day. Overnight purchasing power Up to two times.
│ │ ├── leverage: The currently leverage, if it is less than 1, it means that the leverage is not used, and if it is greater than 1, it means the leverage multiple used
│ │ ├── uncollected: In transit funds
│ │ ├── locked_funds: Locked funds
│ │ ├── currency_assets: Account asset information differentiated by transaction currency, a dict with currency as key
│ │ │ ├── 'USD' means US dollar, value is CurrencyAsset object
│ │ │ │ ├── currency': current currency, commonly used currencies include: USD-US dollar, HKD-Hong Kong dollar, SGD-Singapore dollar, CNH-RMB
│ │ │ │ ├── cash_balance': cash that can be traded, plus some cash that has been locked (such as stocks that have been purchased but not yet traded, and some other situations will also have locked cash)
│ │ │ │ ├── cash_available_for_trade': The amount of cash that can be traded in the current account
│ │ │ │ ├── gross_position_value': gross value
│ │ │ │ ├── stock_market_value': The market value of the stock, when the category is C (futures type), there will be no stock market value
│ │ │ │ ├── futures_market_value': the market value of futures, when the category is S (stock type), there will be no futures market value
│ │ │ │ ├── option_market_value': the market value of the option
│ │ │ │ ├── unrealized_pl': floating profit and loss within the account
│ │ │ │ ├── realized_pl': realized profit and loss in the account
│ │ │ ├── 'HKD' means Hong Kong dollar, value is CurrencyAsset object
│ │ └─ └── 'CNH' means RMB, value is CurrencyAsset object
│ └── 'C' means futures account, value is Segment object
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 file path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
portfolio_account = trade_client.get_prime_assets(base_currency='USD') # set base currency
print(portfolio_account)
# use example
print(portfolio_account.account)
print(portfolio_account.segments['S'].buying_power)
print(portfolio_account.segments['S'].cash_balance)
print(portfolio_account.segments['S'].unrealized_pl)
print(portfolio_account.segments['S'].currency_assets['USD'].gross_position_value)
print(portfolio_account.segments['S'].currency_assets['HKD'].gross_position_value)
print(portfolio_account.segments['S'].currency_assets['HKD'].cash_balance)
print(portfolio_account.segments['C'].init_margin)
print(portfolio_account.segments['C'].maintain_margin)
print(portfolio_account.segments['C'].currency_assets['USD'].cash_balance)
Respond
>>> 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, 'gross_position_value': 9460.69, 'stock_market_value': 9460.69, 'futures_market_value': inf, 'option_market_value': 0.0, 'unrealized_pl': 4183.4433333, 'realized_pl': -3256.0}),
'HKD': CurrencyAsset({'currency': 'HKD', 'cash_balance': -92554.07, 'cash_available_for_trade': -93664.15, 'gross_position_value': 98691.2, 'stock_market_value': 98691.2, 'futures_market_value': inf, 'option_market_value': 0.0, 'unrealized_pl': -41374.784536, 'realized_pl': 0.0}),
'CNH': CurrencyAsset({'currency': 'CNH', 'cash_balance': 0.0, 'cash_available_for_trade': 0.0, 'gross_position_value': inf, 'stock_market_value': inf, 'futures_market_value': inf, 'option_market_value': inf, 'unrealized_pl': inf, 'realized_pl': inf})}}),
'C': Segment({'currency': 'USD', 'capability': 'RegTMargin', 'category': 'C', 'cash_balance': 3483681.32, 'cash_available_for_trade': 3481701.32, 'cash_available_for_withdrawal': 3481701.32, 'gross_position_value': 1000000.0, 'equity_with_loan': 3481881.32, 'net_liquidation': 3483681.32, 'init_margin': 1980.0, 'maintain_margin': 1800.0, 'overnight_margin': 1800.0, 'unrealized_pl': 932722.41, 'realized_pl': -30.7, 'excess_liquidation': 3481881.32, 'overnight_liquidation': 3481881.32, 'buying_power': 0.0, 'leverage': 0.0,
'currency_assets':
{'USD': CurrencyAsset({'currency': 'USD', 'cash_balance': 3483681.32, 'cash_available_for_trade': 3483681.32, 'gross_position_value': 1000000.0, 'stock_market_value': inf, 'futures_market_value': 1000000.0, 'option_market_value': inf, 'unrealized_pl': 932722.41, 'realized_pl': -30.7}),
'HKD': CurrencyAsset({'currency': 'HKD', 'cash_balance': 0.0, 'cash_available_for_trade': 0.0, 'gross_position_value': inf, 'stock_market_value': inf, 'futures_market_value': inf, 'option_market_value': inf, 'unrealized_pl': inf, 'realized_pl': inf}),
'CNH': CurrencyAsset({'currency': 'CNH', 'cash_balance': 0.0, 'cash_available_for_trade': 0.0, 'gross_position_value': inf, 'stock_market_value': inf, 'futures_market_value': inf, 'option_market_value': inf, 'unrealized_pl': inf, 'realized_pl': inf})}})
}
}
)
get_positions Get Positions
TradeClient.get_positions(account=None, sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL, symbol=None, sub_accounts=None)
Description
Get the position information of the account
Arguments
Argument | Type | Required | Description |
---|---|---|---|
account | str | no | account id, if not specified, default account id configured in client_config will be used |
sec_type | SecurityType | no | SecurityType enumeration, including STK/OPT/FUT, etc., default value is STK. This parameter can be imported from tigeropen.common.consts |
currency | Currency | no | Currency enumeration, including ALL/USD/HKD/CNH, etc., default ALL, can be imported from tigeropen.common.consts |
market | Market | no | Market enumeration, including ALL/US/HK/CN, etc., default ALL, can be imported from tigeropen.common.consts |
symbol | str | no | Ticker symbol |
expiry | str | no | Options expiration date, format: 'yyyyMMdd', example: '220121' |
strike | float | no | Options strike price, example: 100.5 |
put_call | str | no | 'PUT' / 'CALL' for options |
sub_account | list[str] | no | Sub account list |
secret_key | str | no | Institutional trader key. Only applicable to institutional users. It needs to be configured in client_config. Ignore if you are a individual developer |
Response
list
The structure is as follows:
Each element is a Position object. The Position(tigeropen.trade.domain.position.Position) object has the following properties:
Argument | Type | Description |
---|---|---|
account | str | Account id |
contract | Contract | Contract object, tigeropen.trade.domain.contract.Contract |
quantity | int | Position quantity (deprecated) |
position_qty | float | Position quantity |
average_cost | float | Holding cost |
average_cost_by_average | float | Average cost |
market_price | float | Latest price |
market_value | float | Market value |
realized_pnl | float | Realized profit and loss |
unrealized_pnl | float | Unrealized profit and loss |
realized_pnl_by_average | float | Realized profit and loss by average cost |
unrealized_pnl_by_average | float | Unrealized profit and loss by average cost |
unrealized_pnl_percent | float | Unrealized pnl ratio |
unrealized_pnl_percent_by_average | float | Unrealized pnl ratio by average cost |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import SecurityType, Currency, Market
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
positions = trade_client.get_positions(sec_type=SecurityType.STK, currency=Currency.ALL, market=Market.ALL)
# check positions
print(len(positions)) # positions
# check first contract
position1 = positions[0]
print(position1.contract.symbol) # contract, such as AAPL,CL2303
print(position1.contract.sec_type) # contract type, such as STK, FUT
print(position1.contract.multiplier) # contract multiplier
print(position1.average_cost) # position average cost
print(position1.quantity) # position quantity
# check second position
position2 = positions[1]
print(position2.unrealized_pnl) # unrealized gain and lost
print(position2.market_value) # market value of position
Response 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_analytics_asset
TradeClient.get_analytics_asset(account=None, start_date=None, end_date=None, seg_type=None, sub_account=None)
Description
Get historical asset analysis of the account
Arguments
Argument | Type | Required | Description |
---|---|---|---|
account | str | no | Account id,if not specified, use client_config's default account |
start_date | str | no | start date, format yyyy-MM-dd, like '2022-01-01' |
end_date | str | no | end date, format yyyy-MM-dd, like '2022-02-01', if not passed, use current date |
seg_type | SegmentType | no | Account segment. Available: SegmentType.SEC for Securities; SegmentType.FUT for Commodities, can be imported from tigeropen.common.consts.SegmentType |
currency | Currency | no | currency,include ALL/USD/HKD/CNH, can be imported from tigeropen.common.consts.Currency |
sub_account | str | no | Sub-account (for institutional accounts only), if this field is passed, the assets of the sub-account will be returned |
secret_key | str | no | Institutional trader key. Only applicable to institutional users. It needs to be configured in client_config. Ignore if you are a individual developer |
Return
dict
summary: The corresponding value is the asset analysis summary.
Argument | Type | Description |
---|---|---|
pnl | float | Profit and Loss Amount |
pnl_percentage | float | Profit and Loss Amount rate |
annualized_return | float | Annualized rate of return (imputed) |
over_user_percentage | float | Percentage of users exceeded |
history: History assets
Argument | Type | Description |
---|---|---|
date | int | Date timestamp in milliseconds |
pnl | float | Amount of profit or loss compared to the previous day |
pnl_percentage | float | Yield compared to the previous day |
asset | float | Total assets amount |
cash_balance | float | Cash balance |
gross_position_value | float | position market value |
deposit | float | deposit amount |
withdrawal | float | withdrawal amount |
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)
result = trade_client.get_analytics_asset(start_date='2021-12-01', end_date='2021-12-07', seg_type=SegmentType.SEC)
# check summary
print(result['summary']['pnl']) # gain or lost
print(result['summary']['pnl_percentage']) # gain or lost percentage
for data in result['history']: # historical value
print(data['date']) # historiacl date
print(data['pnl']) # gain and lost
Return Example
{'summary': {'pnl': 691.18, 'pnl_percentage': 0.0, 'annualized_return': 0.0, 'over_user_percentage': 0.0},
'history': [{'date': 1638334800000, 'asset': 48827609.65, 'pnl': 0.0, 'pnl_percentage': 0.0, 'cash_balance': 48811698.59, 'gross_position_value': 15911.06, 'deposit': 0.0, 'withdrawal': 0.0, 'dt': '2021-12-01'},
{'date': 1638421200000, 'asset': 48827687.69, 'pnl': 78.04, 'pnl_percentage': 0.0, 'cash_balance': 48811698.59, 'gross_position_value': 15989.1, 'deposit': 0.0, 'withdrawal': 0.0, 'dt': '2021-12-02'},
{'date': 1638507600000, 'asset': 48827583.18, 'pnl': -26.47, 'pnl_percentage': 0.0, 'cash_balance': 48811698.59, 'gross_position_value': 15884.58, 'deposit': 0.0, 'withdrawal': 0.0, 'dt': '2021-12-03'},
{'date': 1638766800000, 'asset': 48827804.28, 'pnl': 194.63, 'pnl_percentage': 0.0, 'cash_balance': 48811698.59, 'gross_position_value': 16105.68, 'deposit': 0.0, 'withdrawal': 0.0, 'dt': '2021-12-06'},
{'date': 1638853200000, 'asset': 48828300.83, 'pnl': 691.18, 'pnl_percentage': 0.0, 'cash_balance': 48811723.0, 'gross_position_value': 16577.82, 'deposit': 0.0, 'withdrawal': 0.0, 'dt': '2021-12-07'}]}
get_segment_fund_available
TradeClient.get_segment_fund_available(from_segment=None, currency=Noone)
Description
get available fund to transfer
Arguments
arg | type | required | desc |
---|---|---|---|
from_segment | str | No | from segment, FUT/SEC |
currency | str | No | currency,USD or HKD |
Return
List[SegmentFundAvailableItem]
, each item is tigeropen.trade.domain.account.SegmentFundAvailableItem
SegmentFundAvailableItem
:
name | type | desc |
---|---|---|
from_segment | string | from segment, FUT SEC |
currency | string | currency,USD/HKD |
amount | float | available fund |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import SecurityType, Currency, Market
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
available = trade_client.get_segment_fund_available(from_segment='SEC', currency='HKD')
print(available)
print(available[0].amount)
Response example
[SegmentFundAvailableItem({'from_segment': 'SEC', 'currency': 'HKD', 'amount': 718859.79})]
transfer_segment_fund
TradeClient.transfer_segment_fund(from_segment, to_segment, amount, currency)
Description
transfer fund within different segment
Arguments
arg | type | required | desc |
---|---|---|---|
from_segment | str | Yes | from segment, FUT/SEC |
to_segment | str | Yes | to segment, FUT/SEC |
currency | str | Yes | currency, USD/HKD |
amount | float | Yes | amount |
Return
tigeropen.trade.domain.account.SegmentFundItem
SegmentFundItem
:
name | type | desc |
---|---|---|
id | int | transfer ID |
from_segment | str | from segment, FUT or SEC |
to_segment | str | to segment, FUT or SEC |
currency | str | transfer currency, USD or HKD |
amount | float | transfer amount |
status | str | status (NEW/PROC/SUCC/FAIL/CANC) |
status_desc | str | status description |
message | str | failed message |
settled_at | int | settled timestamp |
updated_at | int | updated timestamp |
created_at | int | created timestamp |
Request Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import SecurityType, Currency, Market
client_config = get_client_config(private_key_path='', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
res = trade_client.transfer_segment_fund(from_segment='SEC', to_segment='FUT', amount=100, currency='USD')
print(res)
Example
SegmentFundItem({'id': 30322815980011520, 'from_segment': 'SEC', 'to_segment': 'FUT', 'currency': 'USD',
'amount': 100.0, 'status': 'NEW', 'status_desc': '', 'message': None, 'settled_at': None,
'updated_at': 1680243926131, 'created_at': 1680243926131})
cancel_segment_fund
TradeClient.cancel_segment_fund
Desc
cancel a transfer
Argument
arg | type | required | desc |
---|---|---|---|
id | int | Yes | transfer id |
returntigeropen.trade.domain.account.SegmentFundItem
SegmentFundItem
:
name | type | desc |
---|---|---|
id | int | transfer ID |
from_segment | str | from segment, FUT or SEC |
to_segment | str | to segment, FUT or SEC |
currency | str | transfer currency, USD or HKD |
amount | float | transfer amount |
status | str | status (NEW/PROC/SUCC/FAIL/CANC) |
status_desc | str | status description |
message | str | failed message |
settled_at | int | settled timestamp |
updated_at | int | updated timestamp |
created_at | int | created timestamp |
Request example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import SecurityType, Currency, Market
client_config = get_client_config(private_key_path='', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
res = trade_client.cancel_segment_fund(id=<transfer id>)
print(res)
Response example
SegmentFundItem({'id': 30322815980011520, 'from_segment': 'SEC', 'to_segment': 'FUT', 'currency': 'USD',
'amount': 100.0, 'status': 'CANC', 'message': None, 'settled_at': None, 'updated_at': 1680243926131, 'created_at': 1680243926131})
get_segment_fund_history
TradeClient.get_segment_fund_history
Desc
query transfer history
Arguments
arg | type | required | desc |
---|---|---|---|
limit | Integer | No | limit number. 100~500 |
Returntigeropen.trade.domain.account.SegmentFundItem
SegmentFundItem
:
name | type | desc |
---|---|---|
id | int | transfer ID |
from_segment | str | from segment, FUT or SEC |
to_segment | str | to segment, FUT or SEC |
currency | str | transfer currency, USD or HKD |
amount | float | transfer amount |
status | str | status (NEW/PROC/SUCC/FAIL/CANC) |
status_desc | str | status description |
message | str | failed message |
settled_at | int | settled timestamp |
updated_at | int | updated timestamp |
created_at | int | created timestamp |
Request Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import SecurityType, Currency, Market
client_config = get_client_config(private_key_path='', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
history = trade_client.get_segment_fund_history()
print(history)
Response Example
[SegmentFundItem({'id': 16256385456537600, 'from_segment': 'SEC', 'to_segment': 'FUT', 'currency': 'USD',
'amount': 100000.0, 'status': 'SUCC', 'status_desc': '', 'message': None,
'settled_at': 1572925581000, 'updated_at': 1572925578000, 'created_at': 1572925578000}),
SegmentFundItem({'id': 16256377863667712, 'from_segment': 'SEC', 'to_segment': 'FUT', 'currency': 'USD',
'amount': 100000.0, 'status': 'SUCC', 'status_desc': '', 'message': None,
'settled_at': 1572925525000, 'updated_at': 1572925520000, 'created_at': 1572925520000}),
SegmentFundItem({'id': 15554843128627200, 'from_segment': 'SEC', 'to_segment': 'FUT', 'currency': 'USD',
'amount': 100000.0, 'status': 'SUCC', 'status_desc': '', 'message': None, 'settled_at': 1567573240000,
'updated_at': 1567573235000, 'created_at': 1567573235000}),
SegmentFundItem({'id': 14039478715026432, 'from_segment': 'SEC', 'to_segment': 'FUT', 'currency': 'USD', 'amount': 10000.0, 'status': 'SUCC', 'status_desc': '', 'message': None, 'settled_at': 1556011922000, 'updated_at': 1556011922000, 'created_at': 1556011922000})]
Get Estimate Tradable quantity
TradeClient.get_estimate_tradable_quantity()
Desc
Get the maximum quantity that can be bought or sold. Support stocks, options, excluding futures.
Arguments
Order
(tigeropen.trade.domain.order.Order
)
can use tigeropen.common.util.order_utils
, like limit_order(), market_order(), to create Order, see Order
Returntigeropen.trade.domain.position.TradableQuantityItem
name | type | desc |
---|---|---|
tradable_quantity | float | tradable quantity for cash |
financing_quantity | float | tradable quantity for margin |
position_quantity | float | position quantity |
tradable_position_quantity | float | tradable quantity in the position |
Example
from tigeropen.trade.trade_client import TradeClient
from tigeropen.tiger_open_config import get_client_config
from tigeropen.common.consts import SecurityType, Currency, Market
client_config = get_client_config(private_key_path='private key path', tiger_id='your tiger id', account='your account')
trade_client = TradeClient(client_config)
contract = stock_contract(symbol='MSFT', 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)
Response Example
TradableQuantityItem<{'tradable_quantity': 28921.0, 'financing_quantity': 52657.0, 'position_quantity': 0.0, 'tradable_position_quantity': 0}>