账户、持仓与资产

示例上下文

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 默认值约束
reqPositionsRequestNone
req.accountstring | undefinedTradeClient account when empty (client)
req.secretKeystring | undefinedInstitution account secret key. Overrides the default set in ClientConfig; omit to use the config default.
req.secTypestring | undefined
req.currencystring | undefined
req.marketstring | undefined
req.symbolstring | undefined
req.subAccountsstring[] | undefined
req.expirystring | undefined
req.strikestring | undefined
req.rightstring | undefined
req.assetQuoteTypestring | undefined
req.langstring | undefined

返回

Promise<Position[]>

字段类型说明
accountstring账户
symbolstring股票代码
secTypestring证券类型
marketstring市场
currencystring币种
positionnumber持仓数量
positionScalenumber持仓比例
positionQtynumber持仓股数
salableQtynumber可卖数量
averageCostnumber持仓均价
averageCostByAveragenumber按平均法计算的持仓均价
averageCostOfCarrynumber按持仓成本法计算的均价
marketValuenumber市值
realizedPnlnumber已实现盈亏
realizedPnlByAveragenumber按平均法计算的已实现盈亏
unrealizedPnlnumber未实现盈亏
unrealizedPnlByAveragenumber按平均法计算的未实现盈亏
unrealizedPnlByCostOfCarrynumber按持仓成本法计算的未实现盈亏
unrealizedPnlPercentnumber未实现盈亏百分比
unrealizedPnlPercentByAveragenumber按平均法计算的未实现盈亏百分比
unrealizedPnlPercentByCostOfCarrynumber按持仓成本法计算的未实现盈亏百分比
contractIdnumber合约 ID
identifierstring标识符
namestring名称
latestPricenumber最新价
lastClosePricenumber昨收价
multipliernumber合约乘数
statusnumber交易状态
updateTimestampnumber更新时间戳
mmPercentnumber维持保证金比例
mmValuenumber维持保证金金额
todayPnlnumber当日盈亏
todayPnlPercentnumber当日盈亏百分比
comboTypesstring[]组合类型
categoriesstring[]分类

示例

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 默认值约束
reqAssetsRequestNone
req.accountstring | undefinedTradeClient account when empty (client)
req.secretKeystring | undefinedInstitution account secret key. Overrides the default set in ClientConfig; omit to use the config default.
req.subAccountsstring[] | undefined
req.segmentboolean | undefined
req.marketValueboolean | undefined
req.langstring | undefined

返回

Promise<Asset[]>

字段类型说明
accountstring账户
capabilitystring账户能力(如 RegTMargin)
currencystring币种
buyingPowernumber购买力
cashValuenumber现金余额
netLiquidationnumber净清算价值
realizedPnLnumber已实现盈亏
unrealizedPnLnumber未实现盈亏
segmentsAssetSegment[]账户分区

示例

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 默认值约束
reqAssetsRequestNone
req.accountstring | undefinedTradeClient account when empty (client)
req.secretKeystring | undefinedInstitution account secret key. Overrides the default set in ClientConfig; omit to use the config default.
req.subAccountsstring[] | undefined
req.segmentboolean | undefined
req.marketValueboolean | undefined
req.langstring | undefined

返回

Promise<PrimeAsset | undefined>

字段类型说明
accountIdstring账户 ID
updateTimestampnumber更新时间戳
segmentsPrimeAssetSegment[]账户分区

示例

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 默认值约束
reqManagedAccountsRequestNone
req.accountstring | undefinedTradeClient account when empty (client)
req.secretKeystring | undefinedInstitution account secret key. Overrides the default set in ClientConfig; omit to use the config default.
req.langstring | undefined

返回

Promise<ManagedAccount[]>

字段类型说明
accountstring账户
accountTypestring账户类型
capabilitystring账户能力(如 RegTMargin)
statusstring交易状态

示例

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 默认值约束
reqAnalyticsAssetRequestNone
req.accountstring | undefinedTradeClient account when empty (client)
req.secretKeystring | undefinedInstitution account secret key. Overrides the default set in ClientConfig; omit to use the config default.
req.segTypestring | undefined
req.startDatestring | undefined格式 "YYYY-MM-DD"
req.endDatestring | undefined
req.langstring | undefined

返回

Promise<AnalyticsAsset[]>

字段类型说明
datestring日期
holdingValuenumber持仓价值
cashBalancenumber现金余额
pnlnumber盈亏
pnlRatenumber盈亏率
netValueIndexnumber净值指数
currencystring币种
segTypestring分区类型

示例

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 默认值约束
reqAggregateAssetsRequestNone
req.accountstring | undefinedTradeClient account when empty (client)
req.secretKeystring | undefinedInstitution account secret key. Overrides the default set in ClientConfig; omit to use the config default.
req.baseCurrencystring | undefined
req.segTypestring | undefined
req.langstring | undefined

返回

Promise<AggregateAssets | undefined>

字段类型说明
accountIdstring账户 ID
netLiquidationnumber净清算价值
grossPositionValuenumber总持仓价值
cashBalancenumber现金余额
baseCurrencystring基础币种
currencyAssetsCurrencyAsset[]各币种资产

示例

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 默认值约束
reqEstimateTradableQuantityRequestNone
req.accountstring | undefinedTradeClient account when empty (client)
req.secretKeystring | undefinedInstitution account secret key. Overrides the default set in ClientConfig; omit to use the config default.
req.symbolstring
req.secTypestring
req.actionstring
req.orderTypestring | undefined
req.limitPricenumber | undefined
req.marketstring | undefined
req.currencystring | undefined
req.expirystring | undefined
req.strikestring | undefined
req.rightstring | undefined
req.langstring | undefined

返回

Promise<EstimateTradableQuantity | undefined>

字段类型说明
tradableQuantitynumber可交易数量
maxCashBuyQuantitynumber现金最大可买数量
maxMarginBuyQuantitynumber融资最大可买数量
maxShortSellQuantitynumber最大可做空数量
maxPositionSellQuantitynumber最大可平仓数量
cashBuyingPowernumber现金购买力
currencystring币种

示例

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"
}

Did this page help you?