账户、持仓与资产
示例上下文
import { createClientConfig, TradeClient } from '@tigeropenapi/tigeropen';
const config = createClientConfig();
const tradeClient = TradeClient.fromConfig(config, config.account, config.secretKey);获取持仓
签名
async getPositions(req?: PositionsRequest): Promise<Position[]>用途
查询持仓。
参数、默认值与约束
| 参数 | 类型 | 必填 | SDK 默认值 | 约束 |
|---|---|---|---|---|
req | PositionsRequest | 否 | None | — |
req.account | string | undefined | 否 | TradeClient account when empty (client) | — |
req.secretKey | string | undefined | 否 | 无 | Institution account secret key. Overrides the default set in ClientConfig; omit to use the config default. |
req.secType | string | undefined | 否 | 无 | — |
req.currency | string | undefined | 否 | 无 | — |
req.market | string | undefined | 否 | 无 | — |
req.symbol | string | undefined | 否 | 无 | — |
req.subAccounts | string[] | undefined | 否 | 无 | — |
req.expiry | string | undefined | 否 | 无 | — |
req.strike | string | undefined | 否 | 无 | — |
req.right | string | undefined | 否 | 无 | — |
req.assetQuoteType | string | undefined | 否 | 无 | — |
req.lang | string | undefined | 否 | 无 | — |
返回
Promise<Position[]>
| 字段 | 类型 | 说明 |
|---|---|---|
| account | string | 账户 |
| symbol | string | 股票代码 |
| secType | string | 证券类型 |
| market | string | 市场 |
| currency | string | 币种 |
| position | number | 持仓数量 |
| positionScale | number | 持仓比例 |
| positionQty | number | 持仓股数 |
| salableQty | number | 可卖数量 |
| averageCost | number | 持仓均价 |
| averageCostByAverage | number | 按平均法计算的持仓均价 |
| averageCostOfCarry | number | 按持仓成本法计算的均价 |
| marketValue | number | 市值 |
| realizedPnl | number | 已实现盈亏 |
| realizedPnlByAverage | number | 按平均法计算的已实现盈亏 |
| unrealizedPnl | number | 未实现盈亏 |
| unrealizedPnlByAverage | number | 按平均法计算的未实现盈亏 |
| unrealizedPnlByCostOfCarry | number | 按持仓成本法计算的未实现盈亏 |
| unrealizedPnlPercent | number | 未实现盈亏百分比 |
| unrealizedPnlPercentByAverage | number | 按平均法计算的未实现盈亏百分比 |
| unrealizedPnlPercentByCostOfCarry | number | 按持仓成本法计算的未实现盈亏百分比 |
| contractId | number | 合约 ID |
| identifier | string | 标识符 |
| name | string | 名称 |
| latestPrice | number | 最新价 |
| lastClosePrice | number | 昨收价 |
| multiplier | number | 合约乘数 |
| status | number | 交易状态 |
| updateTimestamp | number | 更新时间戳 |
| mmPercent | number | 维持保证金比例 |
| mmValue | number | 维持保证金金额 |
| todayPnl | number | 当日盈亏 |
| todayPnlPercent | number | 当日盈亏百分比 |
| comboTypes | string[] | 组合类型 |
| categories | string[] | 分类 |
示例
const result = await tradeClient.getPositions({ market: 'US', secType: 'STK' });
console.log(result);返回示例
[
{
"account": "string",
"symbol": "string",
"secType": "string",
"market": "string",
"currency": "string",
"position": 0,
"positionScale": 0,
"positionQty": 0,
"salableQty": 0,
"averageCost": 0,
"averageCostByAverage": 0,
"averageCostOfCarry": 0,
"marketValue": 0,
"realizedPnl": 0,
"realizedPnlByAverage": 0,
"unrealizedPnl": 0,
"unrealizedPnlByAverage": 0,
"unrealizedPnlByCostOfCarry": 0,
"unrealizedPnlPercent": 0,
"unrealizedPnlPercentByAverage": 0,
"unrealizedPnlPercentByCostOfCarry": 0,
"contractId": 0,
"identifier": "string",
"name": "string",
"latestPrice": 0,
"lastClosePrice": 0,
"multiplier": 0,
"status": 0,
"updateTimestamp": 0,
"mmPercent": 0,
"mmValue": 0,
"todayPnl": 0,
"todayPnlPercent": 0,
"comboTypes": [
"string"
],
"categories": [
"string"
]
}
]获取环球账户资产
签名
async getAssets(req?: AssetsRequest): Promise<Asset[]>用途
查询环球账户资产。综合/模拟账户虽可调用,但多数字段为空,建议使用 getPrimeAssets。
参数、默认值与约束
| 参数 | 类型 | 必填 | SDK 默认值 | 约束 |
|---|---|---|---|---|
req | AssetsRequest | 否 | None | — |
req.account | string | undefined | 否 | TradeClient account when empty (client) | — |
req.secretKey | string | undefined | 否 | 无 | Institution account secret key. Overrides the default set in ClientConfig; omit to use the config default. |
req.subAccounts | string[] | undefined | 否 | 无 | — |
req.segment | boolean | undefined | 否 | 无 | — |
req.marketValue | boolean | undefined | 否 | 无 | — |
req.lang | string | undefined | 否 | 无 | — |
返回
Promise<Asset[]>
| 字段 | 类型 | 说明 |
|---|---|---|
| account | string | 账户 |
| capability | string | 账户能力(如 RegTMargin) |
| currency | string | 币种 |
| buyingPower | number | 购买力 |
| cashValue | number | 现金余额 |
| netLiquidation | number | 净清算价值 |
| realizedPnL | number | 已实现盈亏 |
| unrealizedPnL | number | 未实现盈亏 |
| segments | AssetSegment[] | 账户分区 |
示例
const result = await tradeClient.getAssets({ segment: true, marketValue: true });
console.log(result);返回示例
[
{
"account": "string",
"capability": "string",
"currency": "string",
"buyingPower": 0,
"cashValue": 0,
"netLiquidation": 0,
"realizedPnL": 0,
"unrealizedPnL": 0,
"segments": [
"AssetSegment"
]
}
]获取综合/模拟账户资产
签名
async getPrimeAssets(req?: AssetsRequest): Promise<PrimeAsset | undefined>用途
查询综合/模拟账户资产。
参数、默认值与约束
| 参数 | 类型 | 必填 | SDK 默认值 | 约束 |
|---|---|---|---|---|
req | AssetsRequest | 否 | None | — |
req.account | string | undefined | 否 | TradeClient account when empty (client) | — |
req.secretKey | string | undefined | 否 | 无 | Institution account secret key. Overrides the default set in ClientConfig; omit to use the config default. |
req.subAccounts | string[] | undefined | 否 | 无 | — |
req.segment | boolean | undefined | 否 | 无 | — |
req.marketValue | boolean | undefined | 否 | 无 | — |
req.lang | string | undefined | 否 | 无 | — |
返回
Promise<PrimeAsset | undefined>
| 字段 | 类型 | 说明 |
|---|---|---|
| accountId | string | 账户 ID |
| updateTimestamp | number | 更新时间戳 |
| segments | PrimeAssetSegment[] | 账户分区 |
示例
const result = await tradeClient.getPrimeAssets({ segment: true, marketValue: true });
console.log(result);返回示例
{
"accountId": "string",
"updateTimestamp": 0,
"segments": [
{
"capability": "string",
"category": "string",
"currency": "string",
"cashBalance": 0,
"cashAvailableForTrade": 0,
"grossPositionValue": 0,
"equityWithLoan": 0,
"netLiquidation": 0,
"initMargin": 0,
"maintainMargin": 0,
"overnightMargin": 0,
"unrealizedPL": 0,
"unrealizedPLByCostOfCarry": 0,
"realizedPL": 0,
"totalTodayPL": 0,
"excessLiquidation": 0,
"overnightLiquidation": 0,
"buyingPower": 0,
"lockedFunds": 0,
"leverage": 0,
"uncollected": 0,
"currencyAssets": [
"CurrencyAsset"
],
"consolidatedSegTypes": [
"string"
]
}
]
}获取管理的账户
签名
async getManagedAccounts(req?: ManagedAccountsRequest): Promise<ManagedAccount[]>用途
查询管理的账户列表。
参数、默认值与约束
| 参数 | 类型 | 必填 | SDK 默认值 | 约束 |
|---|---|---|---|---|
req | ManagedAccountsRequest | 否 | None | — |
req.account | string | undefined | 否 | TradeClient account when empty (client) | — |
req.secretKey | string | undefined | 否 | 无 | Institution account secret key. Overrides the default set in ClientConfig; omit to use the config default. |
req.lang | string | undefined | 否 | 无 | — |
返回
Promise<ManagedAccount[]>
| 字段 | 类型 | 说明 |
|---|---|---|
| account | string | 账户 |
| accountType | string | 账户类型 |
| capability | string | 账户能力(如 RegTMargin) |
| status | string | 交易状态 |
示例
const result = await tradeClient.getManagedAccounts({ lang: 'en_US' });
console.log(result);返回示例
[
{
"account": "string",
"accountType": "string",
"capability": "string",
"status": "string"
}
]获取历史资产分析
签名
async getAnalyticsAsset(req: AnalyticsAssetRequest): Promise<AnalyticsAsset[]>用途
查询综合/模拟账户的历史资产分析。
参数、默认值与约束
| 参数 | 类型 | 必填 | SDK 默认值 | 约束 |
|---|---|---|---|---|
req | AnalyticsAssetRequest | 是 | None | — |
req.account | string | undefined | 否 | TradeClient account when empty (client) | — |
req.secretKey | string | undefined | 否 | 无 | Institution account secret key. Overrides the default set in ClientConfig; omit to use the config default. |
req.segType | string | undefined | 否 | 无 | — |
req.startDate | string | undefined | 否 | 无 | 格式 "YYYY-MM-DD" |
req.endDate | string | undefined | 否 | 无 | — |
req.lang | string | undefined | 否 | 无 | — |
返回
Promise<AnalyticsAsset[]>
| 字段 | 类型 | 说明 |
|---|---|---|
| date | string | 日期 |
| holdingValue | number | 持仓价值 |
| cashBalance | number | 现金余额 |
| pnl | number | 盈亏 |
| pnlRate | number | 盈亏率 |
| netValueIndex | number | 净值指数 |
| currency | string | 币种 |
| segType | string | 分区类型 |
示例
const result = await tradeClient.getAnalyticsAsset({ segType: 'SEC', startDate: '2026-01-01', endDate: '2026-01-31' });
console.log(result);返回示例
[
{
"date": "string",
"holdingValue": 0,
"cashBalance": 0,
"pnl": 0,
"pnlRate": 0,
"netValueIndex": 0,
"currency": "string",
"segType": "string"
}
]获取聚合资产
签名
async getAggregateAssets(req?: AggregateAssetsRequest): Promise<AggregateAssets | undefined>用途
查询综合账户分币种资产汇总。
参数、默认值与约束
| 参数 | 类型 | 必填 | SDK 默认值 | 约束 |
|---|---|---|---|---|
req | AggregateAssetsRequest | 否 | None | — |
req.account | string | undefined | 否 | TradeClient account when empty (client) | — |
req.secretKey | string | undefined | 否 | 无 | Institution account secret key. Overrides the default set in ClientConfig; omit to use the config default. |
req.baseCurrency | string | undefined | 否 | 无 | — |
req.segType | string | undefined | 否 | 无 | — |
req.lang | string | undefined | 否 | 无 | — |
返回
Promise<AggregateAssets | undefined>
| 字段 | 类型 | 说明 |
|---|---|---|
| accountId | string | 账户 ID |
| netLiquidation | number | 净清算价值 |
| grossPositionValue | number | 总持仓价值 |
| cashBalance | number | 现金余额 |
| baseCurrency | string | 基础币种 |
| currencyAssets | CurrencyAsset[] | 各币种资产 |
示例
const result = await tradeClient.getAggregateAssets({ baseCurrency: 'USD' });
console.log(result);返回示例
{
"accountId": "string",
"netLiquidation": 0,
"grossPositionValue": 0,
"cashBalance": 0,
"baseCurrency": "string",
"currencyAssets": [
{
"currency": "string",
"cashBalance": 0,
"cashAvailableForTrade": 0,
"forexRate": 0
}
]
}预估可交易数量
签名
async getEstimateTradableQuantity(req: EstimateTradableQuantityRequest): Promise<EstimateTradableQuantity | undefined>用途
查询预估可交易数量。
参数、默认值与约束
| 参数 | 类型 | 必填 | SDK 默认值 | 约束 |
|---|---|---|---|---|
req | EstimateTradableQuantityRequest | 是 | None | — |
req.account | string | undefined | 否 | TradeClient account when empty (client) | — |
req.secretKey | string | undefined | 否 | 无 | Institution account secret key. Overrides the default set in ClientConfig; omit to use the config default. |
req.symbol | string | 是 | 无 | — |
req.secType | string | 是 | 无 | — |
req.action | string | 是 | 无 | — |
req.orderType | string | undefined | 否 | 无 | — |
req.limitPrice | number | undefined | 否 | 无 | — |
req.market | string | undefined | 否 | 无 | — |
req.currency | string | undefined | 否 | 无 | — |
req.expiry | string | undefined | 否 | 无 | — |
req.strike | string | undefined | 否 | 无 | — |
req.right | string | undefined | 否 | 无 | — |
req.lang | string | undefined | 否 | 无 | — |
返回
Promise<EstimateTradableQuantity | undefined>
| 字段 | 类型 | 说明 |
|---|---|---|
| tradableQuantity | number | 可交易数量 |
| maxCashBuyQuantity | number | 现金最大可买数量 |
| maxMarginBuyQuantity | number | 融资最大可买数量 |
| maxShortSellQuantity | number | 最大可做空数量 |
| maxPositionSellQuantity | number | 最大可平仓数量 |
| cashBuyingPower | number | 现金购买力 |
| currency | string | 币种 |
示例
const result = await tradeClient.getEstimateTradableQuantity({ symbol: 'AAPL', secType: 'STK', action: 'BUY' });
console.log(result);返回示例
{
"tradableQuantity": 0,
"maxCashBuyQuantity": 0,
"maxMarginBuyQuantity": 0,
"maxShortSellQuantity": 0,
"maxPositionSellQuantity": 0,
"cashBuyingPower": 0,
"currency": "string"
}Updated 9 days ago
Did this page help you?
