资产与持仓
获取持仓
功能说明
查询持仓。支持按 Symbol / SecType / Currency / Market 等过滤。 方法签名
func (c *TradeClient) Positions(req model.PositionsRequest) ([]model.Position, error)需要配置中可访问的交易账户。机构账户可通过 SecretKey 鉴权。
参数
model.PositionsRequest
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
SecType | string | 否 | 空值省略 | 无;可选值:ALL, STK, OPT, WAR, IOPT, FUT, FOP, CASH, MLEG, FUND |
Currency | string | 否 | 空值省略 | 无;可选值:ALL, USD, HKD, CNH, SGD |
Market | string | 否 | 空值省略 | 无;可选值:ALL, US, HK, CN, SG |
Right | string | 否 | 空值省略 | 无;可选值:PUT, CALL (option side); br, nr when used as quote adjustment |
Lang | string | 否 | 空值省略 | 无;可选值:zh_CN, zh_TW, en_US |
返回
([]model.Position, error)。关键字段来自 model.Position:
| 字段 | 类型 | 说明 |
|---|---|---|
| Account | string | 账户 ID |
| Symbol | string | 股票代码 |
| SecType | string | 证券类型 |
| Market | string | 市场 |
| Currency | string | 币种 |
| Position | int64 | 持仓数量 |
| PositionScale | int | 持仓精度 |
| PositionQty | float64 | 持仓数量(含精度) |
| SalableQty | float64 | 可卖数量 |
| AverageCost | float64 | 持仓均价 |
| AverageCostByAverage | float64 | 按均价法计算的持仓均价 |
| AverageCostOfCarry | float64 | 持仓成本(含利息) |
| MarketValue | float64 | 持仓市值 |
| RealizedPnl | float64 | 已实现盈亏 |
示例
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"
}
]获取环球账户资产
功能说明
查询环球账户资产。综合/模拟账户虽可调用,但多数字段为空,建议使用 PrimeAssets。支持子账户列表、按市场/币种聚合等选项。 方法签名
func (c *TradeClient) Assets(req model.AssetsRequest) ([]model.Asset, error)需要配置中可访问的交易账户。机构账户可通过 SecretKey 鉴权。
参数
model.AssetsRequest
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
Consolidated | *bool | 否 | 空值省略 | 无;Python 用 is not None 判断 |
Lang | string | 否 | 空值省略 | 无;可选值:zh_CN, zh_TW, en_US |
返回
([]model.Asset, error)。关键字段来自 model.Asset:
| 字段 | 类型 | 说明 |
|---|---|---|
| Account | string | 账户 ID |
| Capability | string | 账户类型 |
| Currency | string | 币种 |
| BuyingPower | float64 | 购买力 |
| CashValue | float64 | 现金余额 |
| NetLiquidation | float64 | 总资产(净清算值) |
| RealizedPnL | float64 | 已实现盈亏 |
| UnrealizedPnL | float64 | 未实现盈亏 |
| Segments | []AssetSegment | 分品种资产列表 |
示例
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
}获取综合/模拟账户资产
功能说明
查询综合/模拟账户资产。 客户端会空账户字段由客户端填入默认账户。
方法签名
func (c *TradeClient) PrimeAssets(req model.AssetsRequest) (*model.PrimeAsset, error)需要配置中可访问的交易账户。机构账户可通过 SecretKey 鉴权。
参数
model.AssetsRequest
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
Consolidated | *bool | 否 | 空值省略 | 无;Python 用 is not None 判断 |
Lang | string | 否 | 空值省略 | 无;可选值:zh_CN, zh_TW, en_US |
返回
(*model.PrimeAsset, error)。关键字段来自 model.PrimeAsset:
| 字段 | 类型 | 说明 |
|---|---|---|
| AccountID | string | 账户 ID |
| UpdateTimestamp | int64 | 更新时间戳 |
| Segments | []PrimeAssetSegment | 分品种资产列表 |
示例
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
}获取历史资产分析
功能说明
按日资产分析(P&L / 净值曲线 / 持仓价值)。 方法签名
func (c *TradeClient) AnalyticsAsset(req model.AnalyticsAssetRequest) ([]model.AnalyticsAsset, error)需要配置中可访问的交易账户。机构账户可通过 SecretKey 鉴权。
参数
model.AnalyticsAssetRequest
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
SegType | string | 否 | 空值省略 | 无;可选值:ALL, SEC, FUT, FUND |
Currency | string | 否 | 空值省略 | 无;可选值:ALL, USD, HKD, CNH, SGD |
StartDate | string | 否 | 空值省略 | 无;yyyy-MM-dd |
Lang | string | 否 | 空值省略 | 无;可选值:zh_CN, zh_TW, en_US |
返回
([]model.AnalyticsAsset, error)。关键字段来自 model.AnalyticsAsset:
| 字段 | 类型 | 说明 |
|---|---|---|
| Date | string | 日期 |
| HoldingValue | float64 | 持仓市值 |
| CashBalance | float64 | 现金余额 |
| Pnl | float64 | 盈亏 |
| PnlRate | float64 | 盈亏率 |
| NetValueIndex | float64 | 净值指数 |
| Currency | string | 币种 |
| SegType | string | 品种类型 |
示例
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}
]
}获取聚合资产
功能说明
综合账户 base_currency 维度资产汇总。 客户端会空账户字段由客户端填入默认账户。
方法签名
func (c *TradeClient) AggregateAssets(req model.AggregateAssetsRequest) (*model.AggregateAssets, error)需要配置中可访问的交易账户。机构账户可通过 SecretKey 鉴权。
参数
model.AggregateAssetsRequest
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
SegType | string | 否 | 空值省略 | 无;可选值:ALL, SEC, FUT, FUND |
Lang | string | 否 | 空值省略 | 无;可选值:zh_CN, zh_TW, en_US |
返回
(*model.AggregateAssets, error)。关键字段来自 model.AggregateAssets:
| 字段 | 类型 | 说明 |
|---|---|---|
| AccountID | string | 账户 ID |
| NetLiquidation | float64 | 总资产(净清算值) |
| GrossPositionValue | float64 | 证券总市值 |
| CashBalance | float64 | 现金余额 |
| BaseCurrency | string | 基础币种 |
| CurrencyAssets | []CurrencyAsset | 分币种资产列表 |
示例
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"
}
]Updated 9 days ago
