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
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
RightstringNoOmitted if emptyAllowed values: PUT, CALL (option side); br, nr when used as quote adjustment
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

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

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

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
}

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

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
}

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
SegTypestringNoOmitted if emptyAllowed values: ALL, SEC, FUT, FUND
CurrencystringNoOmitted if emptyAllowed values: ALL, USD, HKD, CNH, SGD
StartDatestringNoOmitted 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
SegTypestringNoOmitted if emptyAllowed values: ALL, SEC, FUT, FUND
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

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


Did this page help you?