Assets and Positions

Positions

Purpose

Lists account positions with instrument, market, currency, and sub-account filters. The client unwraps the server items envelope, and fills an empty account field from the client default.

Signature

func (c *TradeClient) Positions(req model.PositionsRequest) ([]model.Position, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.PositionsRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
AccountstringNoUses the client default when emptyTrading account ID
SecretKeystringNoOmitted if emptyInstitutional-account authentication key
SymbolstringNoOmitted if emptyInstrument symbol
SecTypestringNoOmitted if emptyAllowed values: ALL, STK, OPT, WAR, IOPT, FUT, FOP, CASH, MLEG, FUND
CurrencystringNoOmitted if emptyAllowed values: ALL, USD, HKD, CNH, SGD
MarketstringNoOmitted if emptyAllowed values: ALL, US, HK, CN, SG
SubAccounts[]stringNoOmitted if emptySub-account list
ExpirystringNoOmitted if emptyExpiry date
StrikestringNoOmitted if emptyStrike price
RightstringNoOmitted if emptyAllowed values: PUT, CALL (option side); br, nr when used as quote adjustment
AssetQuoteTypestringNoOmitted if emptyAsset quote type
LangstringNoOmitted if emptyAllowed values: zh_CN, zh_TW, en_US

Returns

([]model.Position, error). Key fields from model.Position:

FieldTypeDescription
AccountstringAccount ID
SymbolstringSymbol code
SecTypestringSecurity type
MarketstringMarket
CurrencystringCurrency
Positionint64Position quantity
PositionScaleintPosition scale
PositionQtyfloat64Position quantity (with scale)
SalableQtyfloat64Salable quantity
AverageCostfloat64Average cost
AverageCostByAveragefloat64Average cost (average method)
AverageCostOfCarryfloat64Cost of carry
MarketValuefloat64Market value
RealizedPnlfloat64Realized P&L
RealizedPnlByAveragefloat64Realized P&L by average cost
UnrealizedPnlfloat64Unrealized P&L
UnrealizedPnlByAveragefloat64Unrealized P&L by average cost
UnrealizedPnlByCostOfCarryfloat64Unrealized P&L by cost of carry
UnrealizedPnlPercentfloat64Unrealized P&L percentage
UnrealizedPnlPercentByAveragefloat64Unrealized P&L percentage by average cost
UnrealizedPnlPercentByCostOfCarryfloat64Unrealized P&L percentage by cost of carry
ContractIdint64Contract ID
IdentifierstringContract identifier
NamestringContract name
LatestPricefloat64Latest price
LastClosePricefloat64Previous close
Multiplierfloat64Contract multiplier
StatusintStatus
UpdateTimestampint64Update time in milliseconds
MmPercentfloat64Maintenance-margin percentage
MmValuefloat64Maintenance-margin value
TodayPnlfloat64Today's P&L
TodayPnlPercentfloat64Today's P&L percentage
ComboTypes[]stringCombo types
Categories[]stringCategories

Invocation example

result, err := tc.Positions(model.PositionsRequest{
	Account: "U123456",
	Symbol: "AAPL",
	SecType: "STK",
	Currency: "USD",
	Market: "US",
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
[
  {
    "symbol": "AAPL",
    "secType": "STK",
    "market": "US",
    "currency": "USD",
    "position": 100,
    "averageCost": 150.25,
    "latestPrice": 308.91,
    "marketValue": 30891.00,
    "unrealizedPnl": 15866.00,
    "realizedPnl": 0.0,
    "account": "12345678"
  },
  {
    "symbol": "MSFT",
    "secType": "STK",
    "market": "US",
    "currency": "USD",
    "position": 50,
    "averageCost": 380.50,
    "latestPrice": 425.30,
    "marketValue": 21265.00,
    "unrealizedPnl": 2240.00,
    "realizedPnl": 0.0,
    "account": "12345678"
  }
]

Rate limit

The base rate limit is 60 requests/min.


Assets

Purpose

Returns account assets with optional segment and market-value details. The client unwraps the server items envelope, and fills an empty account field from the client default.

Signature

func (c *TradeClient) Assets(req model.AssetsRequest) ([]model.Asset, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.AssetsRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
AccountstringNoUses the client default when emptyTrading account ID
SecretKeystringNoOmitted if emptyInstitutional-account authentication key
SegmentboolNoOmitted when falseWhether to return segmented assets
MarketValueboolNoOmitted when falseWhether to return market values
SubAccounts[]stringNoOmitted if emptySub-account list
BaseCurrencystringNoOmitted if emptyBase currency
Consolidated*boolNoOmitted when nilWhether to consolidate assets; a pointer distinguishes explicit false from omission
LangstringNoOmitted if emptyAllowed values: zh_CN, zh_TW, en_US

Returns

([]model.Asset, error). Key fields from model.Asset:

FieldTypeDescription
AccountstringAccount ID
CapabilitystringAccount type
CurrencystringCurrency
BuyingPowerfloat64Buying power
CashValuefloat64Cash balance
NetLiquidationfloat64Net liquidation value
RealizedPnLfloat64Realized P&L
UnrealizedPnLfloat64Unrealized P&L
Segments[]AssetSegmentSegment asset list
AssetSegment fieldTypeDescription
AccountstringAccount ID
CategorystringSegment category
TitlestringSegment title
NetLiquidationfloat64Net liquidation value
CashValuefloat64Cash balance
AvailableFundsfloat64Available funds
EquityWithLoanfloat64Equity with loan
ExcessLiquidityfloat64Excess liquidity
AccruedCashfloat64Accrued cash
AccruedDividendfloat64Accrued dividend
InitMarginReqfloat64Initial margin requirement
MaintMarginReqfloat64Maintenance margin requirement
GrossPositionValuefloat64Gross position value
Leveragefloat64Leverage

Invocation example

result, err := tc.Assets(model.AssetsRequest{
	Account: "U123456",
	Lang: "en_US",
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "account": "12345678",
  "netLiquidation": 125000.00,
  "equityWithLoan": 125000.00,
  "initMarginReq": 35000.00,
  "maintMarginReq": 28000.00,
  "availableFunds": 90000.00,
  "excessLiquidity": 97000.00,
  "buyingPower": 270000.00,
  "cashValue": 50000.00,
  "grossPositionValue": 75000.00,
  "unrealizedPnl": 18106.00,
  "realizedPnl": 3250.00
}

Rate limit

The base rate limit is 60 requests/min.


PrimeAssets

Purpose

Returns the detailed segmented asset model for a prime account. The client fills an empty account field from the client default.

Signature

func (c *TradeClient) PrimeAssets(req model.AssetsRequest) (*model.PrimeAsset, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.AssetsRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
AccountstringNoUses the client default when emptyTrading account ID
SecretKeystringNoUses the client configuration when emptyInstitutional-account authentication key
SegmentboolNoOmitted when falseAssetsRequest compatibility field; PrimeAssets is already segmented, so this is normally unnecessary
MarketValueboolNoOmitted when falseAssetsRequest compatibility field; whether the prime-assets API applies it depends on the API response
SubAccounts[]stringNoOmitted if emptySub-account list; applicable to institutional-account queries
BaseCurrencystringNoOmitted if emptyBase currency; whether the prime-assets API applies it depends on the API response
Consolidated*boolNoOmitted when nilWhether to consolidate assets; a pointer distinguishes explicit false from omission and applies to prime accounts
LangstringNoOmitted if emptyAllowed values: zh_CN, zh_TW, en_US

Returns

(*model.PrimeAsset, error). Key fields from model.PrimeAsset:

FieldTypeDescription
AccountIDstringAccount ID
UpdateTimestampint64Update timestamp
Segments[]PrimeAssetSegmentSegment asset list
PrimeAssetSegment fieldTypeDescription
CapabilitystringAccount capability
CategorystringSegment category
CurrencystringCurrency
CashBalancefloat64Cash balance
CashAvailableForTradefloat64Cash available for trading
GrossPositionValuefloat64Gross position value
EquityWithLoanfloat64Equity with loan
NetLiquidationfloat64Net liquidation value
InitMarginfloat64Initial margin
MaintainMarginfloat64Maintenance margin
OvernightMarginfloat64Overnight margin
UnrealizedPLfloat64Unrealized P&L
UnrealizedPLByCostOfCarryfloat64Unrealized P&L by cost of carry
RealizedPLfloat64Realized P&L
TotalTodayPLfloat64Total P&L today
ExcessLiquidationfloat64Excess liquidity
OvernightLiquidationfloat64Overnight liquidity
BuyingPowerfloat64Buying power
LockedFundsfloat64Locked funds
Leveragefloat64Leverage
Uncollectedfloat64Uncollected funds
CurrencyAssets[]CurrencyAssetPer-currency assets
ConsolidatedSegTypes[]stringConsolidated segment types
CurrencyAsset fieldTypeDescription
CurrencystringCurrency
CashBalancefloat64Cash balance
CashAvailableForTradefloat64Cash available for trading
ForexRatefloat64Exchange rate

Invocation example

result, err := tc.PrimeAssets(model.AssetsRequest{
	Account: "U123456",
	Lang: "en_US",
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "account": "12345678",
  "totalAssets": 125000.00,
  "netLiquidation": 125000.00,
  "totalCashValue": 50000.00,
  "stockMarketValue": 75000.00,
  "optionMarketValue": 0.0,
  "futureMarketValue": 0.0,
  "unrealizedPnl": 18106.00,
  "realizedPnl": 3250.00
}

Rate limit

The base rate limit is 60 requests/min.


AnalyticsAsset

Purpose

Returns daily holding value, cash, P&L, and net-value analytics. The client unwraps the server items envelope, and fills an empty account field from the client default.

Signature

func (c *TradeClient) AnalyticsAsset(req model.AnalyticsAssetRequest) ([]model.AnalyticsAsset, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.AnalyticsAssetRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
AccountstringNoUses the client default when emptyTrading account ID
SubAccountstringNoOmitted if emptyOne sub-account
SecretKeystringNoOmitted if emptyInstitutional-account authentication key
SegTypestringNoOmitted if emptyAllowed values: ALL, SEC, FUT, FUND
CurrencystringNoOmitted if emptyAllowed values: ALL, USD, HKD, CNH, SGD
SubAccounts[]stringNoOmitted if emptySub-account list
StartDatestringNoOmitted if emptyNone; yyyy-MM-dd
EndDatestringNoOmitted if emptyNone; yyyy-MM-dd
LangstringNoOmitted if emptyAllowed values: zh_CN, zh_TW, en_US

Returns

([]model.AnalyticsAsset, error). Key fields from model.AnalyticsAsset:

FieldTypeDescription
DatestringDate
HoldingValuefloat64Holding value
CashBalancefloat64Cash balance
Pnlfloat64P&L
PnlRatefloat64P&L rate
NetValueIndexfloat64Net value index
CurrencystringCurrency
SegTypestringSegment type

Invocation example

result, err := tc.AnalyticsAsset(model.AnalyticsAssetRequest{
	Account: "U123456",
	Currency: "USD",
	StartDate: "2025-01-01",
	EndDate: "2025-01-31",
	Lang: "en_US",
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
{
  "account": "12345678",
  "summary": {
    "netLiquidation": 125000.00,
    "totalCashValue": 50000.00,
    "grossPositionValue": 75000.00,
    "unrealizedPnl": 18106.00,
    "realizedPnl": 3250.00
  },
  "segments": [
    {"secType": "STK", "marketValue": 75000.00, "unrealizedPnl": 18106.00}
  ]
}

AggregateAssets

Purpose

Aggregates account assets in a requested base currency. The client fills an empty account field from the client default.

Signature

func (c *TradeClient) AggregateAssets(req model.AggregateAssetsRequest) (*model.AggregateAssets, error)

Requires a trading account accessible through the configuration. Institutional accounts can authenticate with SecretKey.

Parameters

model.AggregateAssetsRequest

SDK fieldTypeRequiredSerializationSDK default and constraints
AccountstringNoUses the client default when emptyTrading account ID
SecretKeystringNoOmitted if emptyInstitutional-account authentication key
SegTypestringNoOmitted if emptyAllowed values: ALL, SEC, FUT, FUND
BaseCurrencystringNoOmitted if emptyBase currency
LangstringNoOmitted if emptyAllowed values: zh_CN, zh_TW, en_US

Returns

(*model.AggregateAssets, error). Key fields from model.AggregateAssets:

FieldTypeDescription
AccountIDstringAccount ID
NetLiquidationfloat64Net liquidation value
GrossPositionValuefloat64Gross position value
CashBalancefloat64Cash balance
BaseCurrencystringBase currency
CurrencyAssets[]CurrencyAssetPer-currency asset list

CurrencyAsset fields:

FieldTypeDescription
CurrencystringCurrency
CashBalancefloat64Cash balance
CashAvailableForTradefloat64Cash available for trading
ForexRatefloat64Exchange rate

Invocation example

result, err := tc.AggregateAssets(model.AggregateAssetsRequest{
	Account: "U123456",
	Lang: "en_US",
})
if err != nil {
	log.Fatal(err)
}
fmt.Printf("%#v\n", result)
[
  {
    "account": "12345678",
    "accountType": "STANDARD",
    "netLiquidation": 125000.00,
    "totalCashValue": 50000.00,
    "currency": "USD"
  }
]

Rate limit

The base rate limit is 60 requests/min.



Did this page help you?