交易操作
Go SDK 通过 TradeClient 提供全部交易接口,所有方法都返回强类型结构体(在 model 包中定义)。下单/改单使用请求结构体 model.OrderRequest(字段以 snake_case 对齐服务端);查询类方法自 v0.3.0 起统一接收对应的 Request 结构体(所有字段可选,Account 留空自动填默认账户)。
完整可运行示例:
package main
import (
"fmt"
"log"
"github.com/tigerfintech/openapi-go-sdk/client"
"github.com/tigerfintech/openapi-go-sdk/config"
"github.com/tigerfintech/openapi-go-sdk/model"
"github.com/tigerfintech/openapi-go-sdk/trade"
)
func main() {
cfg, err := config.NewClientConfig()
if err != nil {
log.Fatal(err)
}
tc := trade.NewTradeClient(client.NewHttpClient(cfg), cfg.Account)
// 查询持仓
positions, err := tc.Positions(model.PositionsRequest{})
if err != nil {
log.Fatal(err)
}
for _, p := range positions {
fmt.Printf("%s qty=%.2f avgCost=%.2f marketValue=%.2f\n",
p.Symbol, p.PositionQty, p.AverageCost, p.MarketValue)
}
// 构造限价单并预览
order := model.LimitOrder(cfg.Account, "AAPL", "STK", "BUY", 10, 150.0)
preview, err := tc.PreviewOrder(order)
if err != nil {
log.Fatal(err)
}
fmt.Printf("isPass=%v commission=%.2f initMargin=%.2f\n",
preview.IsPass, preview.Commission, preview.InitMargin)
// 实际下单
placed, err := tc.PlaceOrder(order)
if err != nil {
log.Fatal(err)
}
fmt.Printf("order id=%d orderId=%d\n", placed.ID, placed.OrderID)
}合约查询
Contract 查询单个合约
tc.Contract(symbol, secType string) ([]model.Contract, error)
说明
查询单个合约的详细信息。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| symbol | string | 是 | 合约代码,如 "AAPL"、"00700" |
| secType | string | 是 | STK / OPT / FUT / WAR / IOPT |
返回
[]model.Contract(常见字段见下)
| 字段 | 类型 | 描述 |
|---|---|---|
| ContractId | int64 | 合约 ID |
| Symbol / Identifier / Name | string | 代码 / 标识 / 名称 |
| SecType / Market / Currency | string | 类型 / 市场 / 货币 |
| PrimaryExchange / Exchange | string | 主/交易所 |
| Multiplier / LotSize | float64 | 合约乘数 / 每手数量 |
| Tradeable / Marginable / Shortable | bool | 是否可交易 / 可融资 / 可做空 |
| Expiry / Strike / Right | string | 期权到期日 / 行权价 / Call/Put |
| TickSizes | []TickSize | 最小变动价位区间 |
示例
cs, err := tc.Contract("AAPL", "STK")
if err != nil {
log.Fatal(err)
}
if len(cs) > 0 {
fmt.Printf("%s contractId=%d exchange=%s\n", cs[0].Symbol, cs[0].ContractId, cs[0].PrimaryExchange)
}Contracts 批量查询合约
tc.Contracts(symbols []string, secType string) ([]model.Contract, error)
说明
批量查询多个合约信息。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| symbols | []string | 是 | 代码列表 |
| secType | string | 是 | 合约类型 |
返回
[]model.Contract(同 Contract)
示例
cs, err := tc.Contracts([]string{"AAPL", "TSLA", "MSFT"}, "STK")QuoteContract 查询衍生品合约
tc.QuoteContract(symbol, secType, expiry string) ([]model.Contract, error)
说明
查询衍生品(期权 / 认股 / 牛熊)合约列表。仅支持 OPT / WAR / IOPT。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| symbol | string | 是 | 标的代码(注意是标的如 "AAPL",不是期权 identifier) |
| secType | string | 是 | OPT / WAR / IOPT |
| expiry | string | 是 | 到期日,格式 YYYYMMDD,如 "20260619" |
返回
[]model.Contract
示例
cs, err := tc.QuoteContract("AAPL", "OPT", "20260619")
if err != nil {
log.Fatal(err)
}
fmt.Printf("options=%d\n", len(cs))订单操作
OrderRequest 订单请求结构
model.OrderRequest 是下单/预览/改单所用的请求对象。字段以 snake_case json tag 对齐服务端:
| 字段 | 类型 | 描述 |
|---|---|---|
| Account | string | 账户 ID(Client 会自动填充) |
| Symbol | string | 合约代码 |
| SecType | string | 合约类型:STK / OPT / FUT |
| Action | string | BUY / SELL |
| OrderType | string | MKT / LMT / STP / STP_LMT / TRAIL 等 |
| TotalQuantity | int64 | 委托数量 |
| LimitPrice | float64 | 限价(LMT / STP_LMT 必填) |
| AuxPrice | float64 | 触发价(STP / STP_LMT / TRAIL 必填) |
| TrailingPercent | float64 | 追踪止损百分比 |
| TimeInForce | string | DAY / GTC / GTD |
| OutsideRth | bool | 是否允许盘前盘后 |
| Market / Currency | string | 市场 / 货币 |
| Expiry / Strike / Right | string | 期权到期日 / 行权价 / CALL / PUT |
| OrderLegs | []OrderLegRequest | 附加止盈/止损腿 |
| AlgoParams | *AlgoParamsRequest | 算法参数(TWAP/VWAP 等) |
便捷构造函数
order := model.MarketOrder(account, symbol, secType, action, qty)
order := model.LimitOrder(account, symbol, secType, action, qty, price)
order := model.StopOrder(account, symbol, secType, action, qty, auxPrice)
order := model.StopLimitOrder(account, symbol, secType, action, qty, limit, aux)
order := model.TrailOrder(account, symbol, secType, action, qty, trailPct)PlaceOrder 下单
tc.PlaceOrder(order model.OrderRequest) (*model.PlaceOrderResult, error)
说明
提交订单到交易所。
返回
*model.PlaceOrderResult
| 字段 | 类型 | 描述 |
|---|---|---|
| ID | int64 | 全局订单 ID(后续 ModifyOrder/CancelOrder 使用) |
| OrderID | int64 | 账户级订单号 |
| SubIDs | []int64 | 子订单 ID |
| Orders | []Order | 订单快照列表 |
示例
order := model.LimitOrder(cfg.Account, "AAPL", "STK", "BUY", 10, 150.0)
order.Market = "US"
order.Currency = "USD"
placed, err := tc.PlaceOrder(order)
if err != nil {
log.Fatal(err)
}
fmt.Printf("id=%d orderId=%d\n", placed.ID, placed.OrderID)PreviewOrder 预览订单
tc.PreviewOrder(order model.OrderRequest) (*model.PreviewResult, error)
说明
在实际下单前预估费用与保证金影响,不会真正提交。
返回
*model.PreviewResult
| 字段 | 类型 | 描述 |
|---|---|---|
| IsPass | bool | 是否通过校验 |
| Commission | float64 | 预估佣金 |
| CommissionCurrency | string | 佣金币种 |
| MarginCurrency | string | 保证金币种 |
| InitMargin / InitMarginBefore | float64 | 下单后 / 下单前初始保证金 |
| MaintMargin / MaintMarginBefore | float64 | 下单后 / 下单前维持保证金 |
| EquityWithLoan / EquityWithLoanBefore | float64 | 带贷款净值(下单后 / 下单前) |
| AvailableEE | float64 | 可用 EE |
| ExcessLiquidity | float64 | 超额流动性 |
| OvernightLiquidation | float64 | 隔夜清算 |
| Message | string | 若 IsPass 为 false 时的错误信息 |
示例
preview, err := tc.PreviewOrder(order)
if err != nil {
log.Fatal(err)
}
fmt.Printf("isPass=%v commission=%.2f initMargin=%.2f\n",
preview.IsPass, preview.Commission, preview.InitMargin)ModifyOrder 修改订单
tc.ModifyOrder(id int64, order model.OrderRequest) (*model.OrderIDResult, error)
说明
修改已提交但未完全成交的订单。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| id | int64 | 是 | 全局订单 ID(PlaceOrderResult.ID) |
| order | model.OrderRequest | 是 | 含新参数的订单对象 |
返回
*model.OrderIDResult(含 ID 字段)
示例
modifyReq := order
modifyReq.LimitPrice = 148.0
mod, err := tc.ModifyOrder(placed.ID, modifyReq)
if err != nil {
log.Fatal(err)
}
fmt.Printf("modified id=%d\n", mod.ID)CancelOrder 取消订单
tc.CancelOrder(id int64) (*model.OrderIDResult, error)
说明
撤销指定订单。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| id | int64 | 是 | 全局订单 ID |
返回
*model.OrderIDResult
示例
canc, err := tc.CancelOrder(placed.ID)
if err != nil {
log.Fatal(err)
}
fmt.Printf("cancelled id=%d\n", canc.ID)订单查询
订单状态枚举(v0.3.0 对齐 Java SDK)
model包提供OrderStatus类型及 8 个常量,服务端数字码通过OrderStatus.Code()获取;Order.Status是string类型,反序列化时若服务端返回整数会自动映射为下列字符串。
常量 字符串 数字码 OrderStatusInvalid"Invalid"-2 OrderStatusInitial"Initial"-1 OrderStatusPendingCancel"PendingCancel"3 OrderStatusCancelled"Cancelled"4 OrderStatusSubmitted"Submitted"5 OrderStatusFilled"Filled"6 OrderStatusInactive"Inactive"7 OrderStatusPendingSubmit"PendingSubmit"8
OrdersRequest.States使用上面的字符串值(如[]string{"Filled", "Submitted"})。
OrdersRequest 订单查询请求结构
model.OrdersRequest 是 Orders / ActiveOrders / InactiveOrders / FilledOrders 共用的查询参数,所有字段均可选(Account 留空自动填默认账户)。
| 参数名 | 类型 | 描述 |
|---|---|---|
| account | string | 账户 ID |
| sec_type | string | STK / OPT / FUT / CASH 等 |
| market | string | 市场,如 US / HK |
| symbol | string | 合约代码 |
| start_date | int64 | 开始时间(毫秒时间戳) |
| end_date | int64 | 结束时间(毫秒时间戳) |
| limit | int | 单次返回条数 |
| is_brief | bool | 是否只返回精简字段 |
| states | []string | 订单状态过滤,值参见上方订单状态枚举 |
| sort_by | string | LATEST_CREATED / LATEST_STATUS_UPDATED |
| seg_type | string | 子账户分段(S 证券 / C 期货等) |
| lang | string | 语言 |
| page_token | string | 分页 token |
| parent_id | int64 | 父订单 ID(仅 ActiveOrders 使用) |
Orders 查询全部订单
tc.Orders(req model.OrdersRequest) ([]model.Order, error)
说明
查询当前账户的全部历史订单。v0.3.0 起改为传入 OrdersRequest,可按时间、状态、合约等字段过滤。
参数
见上方 OrdersRequest。
返回
[]model.Order(常用字段见下)
| 字段 | 类型 | 描述 |
|---|---|---|
| ID | int64 | 全局订单 ID |
| OrderId | int64 | 账户级订单号 |
| Symbol / SecType / Market / Currency | string | 合约信息 |
| Action / OrderType / Status | string | 买卖 / 类型 / 状态(见订单状态枚举) |
| TotalQuantity / FilledQuantity | int64 | 总量 / 已成交 |
| LimitPrice / AvgFillPrice | float64 | 限价 / 均成交价 |
| TimeInForce / OutsideRth | string/bool | 有效期 / 盘前盘后 |
| Commission / RealizedPnl | float64 | 佣金 / 已实现盈亏 |
| OpenTime / UpdateTime / LatestTime | int64 | 时间戳(毫秒) |
| CanModify / CanCancel / IsOpen | bool | 可操作状态 |
| AlgoStrategy | string | 算法策略 |
示例
// 最简调用:查询全部订单
orders, err := tc.Orders(model.OrdersRequest{})
if err != nil {
log.Fatal(err)
}
// 带过滤条件:近 100 条已成交的美股订单
orders, err = tc.Orders(model.OrdersRequest{
Market: "US",
SecType: "STK",
States: []string{"Filled"},
Limit: 100,
SortBy: "LATEST_CREATED",
})
for _, o := range orders {
fmt.Printf("%d %s %s %s qty=%d filled=%d status=%s\n",
o.ID, o.Symbol, o.Action, o.OrderType, o.TotalQuantity, o.FilledQuantity, o.Status)
}GetOrder 按 ID 查询单个订单
tc.GetOrder(req model.GetOrderRequest) (*model.Order, error)
说明
根据订单 ID 查询单个订单详情。Id(全局订单 ID)与 OrderId(账户级订单号)至少传一个。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| id | int64 | 二选一 | 全局订单 ID |
| order_id | int64 | 二选一 | 账户级订单号 |
| is_brief | bool | 否 | 是否只返回精简字段 |
| lang | string | 否 | 语言 |
返回
*model.Order(字段同 Orders 返回项)
示例
o, err := tc.GetOrder(model.GetOrderRequest{Id: placed.ID})
if err != nil {
log.Fatal(err)
}
fmt.Printf("%d %s status=%s filled=%d/%d\n",
o.ID, o.Symbol, o.Status, o.FilledQuantity, o.TotalQuantity)ActiveOrders 查询待成交订单
tc.ActiveOrders(req model.OrdersRequest) ([]model.Order, error)
说明
查询当前挂单中(未完全成交)的订单列表。v0.3.0 起支持通过 OrdersRequest 过滤(可用 ParentId 查询某父订单的子订单)。
参数
返回
[]model.Order
示例
// 最简调用
activeOrders, err := tc.ActiveOrders(model.OrdersRequest{})
// 查询某父订单下的子订单
activeOrders, err = tc.ActiveOrders(model.OrdersRequest{ParentId: 12345678})InactiveOrders 查询已撤销订单
tc.InactiveOrders(req model.OrdersRequest) ([]model.Order, error)
说明
查询已撤销或已过期的订单列表。v0.3.0 起支持通过 OrdersRequest 过滤。
参数
返回
[]model.Order
示例
// 最简调用
inactive, err := tc.InactiveOrders(model.OrdersRequest{})
// 仅查询已撤销
inactive, err = tc.InactiveOrders(model.OrdersRequest{
States: []string{"Cancelled"},
Limit: 50,
})FilledOrders 查询已成交订单
tc.FilledOrders(req model.OrdersRequest) ([]model.Order, error)
说明
查询已成交订单。v0.3.0 起由原 (startDateMs, endDateMs int64) 两个位置参数改为接收 OrdersRequest,时间范围通过 StartDate / EndDate 字段传入。
参数
见 OrdersRequest。StartDate / EndDate 均为毫秒时间戳。
返回
[]model.Order
示例
import "time"
// 最简调用:不限时间(由服务端默认时间窗控制)
filled, err := tc.FilledOrders(model.OrdersRequest{})
// 带时间过滤:近 30 天已成交订单
now := time.Now().UnixMilli()
filled, err = tc.FilledOrders(model.OrdersRequest{
StartDate: now - 30*24*3600*1000,
EndDate: now,
Limit: 200,
})OrderTransactions 查询成交明细
tc.OrderTransactions(req model.OrderTransactionsRequest) ([]model.Transaction, error)
说明
查询订单的逐笔成交明细。v0.3.0 起改为接收 OrderTransactionsRequest;既可按 OrderId 查询指定订单的成交,也可按时间窗 / 合约过滤批量查询。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| order_id | int64 | 否 | 订单 ID(查询单订单成交时传) |
| symbol | string | 否 | 合约代码 |
| sec_type | string | 否 | 合约类型 |
| start_date | int64 | 否 | 开始时间(毫秒时间戳) |
| end_date | int64 | 否 | 结束时间(毫秒时间戳) |
| since_date | string | 否 | 开始日期(yyyyMMdd) |
| to_date | string | 否 | 结束日期(yyyyMMdd) |
| limit | int | 否 | 返回条数 |
| expiry / strike / right | string/float64/string | 否 | 期权合约定位 |
| page_token | string | 否 | 分页 token |
| lang | string | 否 | 语言 |
返回
[]model.Transaction
| 字段 | 类型 | 描述 |
|---|---|---|
| ID | int64 | 成交记录 ID |
| OrderID | int64 | 订单 ID |
| AccountId | int64 | 账户 ID |
| Symbol / SecType / Market / Currency | string | 合约信息 |
| Action | string | 买卖方向(BUY/SELL) |
| FilledQuantity | int64 | 成交数量 |
| FilledPrice | float64 | 成交价格 |
| FilledAmount | float64 | 成交金额 |
| Commission | float64 | 佣金 |
| TransactedAt | string | 成交时间字符串,格式 "YYYY-MM-DD HH:MM:SS" |
| TransactionTime | int64 | 成交时间毫秒时间戳 |
示例
// 最简调用:查询指定订单成交明细
txs, err := tc.OrderTransactions(model.OrderTransactionsRequest{
OrderId: placed.ID,
Symbol: "AAPL",
SecType: "STK",
})
// 带过滤:按时间窗查询某合约的全部成交
txs, err = tc.OrderTransactions(model.OrderTransactionsRequest{
Symbol: "AAPL",
SecType: "STK",
StartDate: now - 7*24*3600*1000,
EndDate: now,
Limit: 100,
})
for _, tx := range txs {
fmt.Printf("%s %s filledPrice=%.2f qty=%d\n", tx.TransactedAt, tx.Action, tx.FilledPrice, tx.FilledQuantity)
}持仓与资产
Positions 查询持仓
tc.Positions(req model.PositionsRequest) ([]model.Position, error)
说明
查询当前账户的所有持仓。v0.3.0 起接收 PositionsRequest,支持按 Symbol / SecType / Currency / Market / SubAccounts 等字段过滤。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| symbol | string | 否 | 合约代码 |
| sec_type | string | 否 | STK / OPT / FUT / CASH 等 |
| currency | string | 否 | 币种 |
| market | string | 否 | 市场 |
| sub_accounts | []string | 否 | 子账户列表 |
| expiry / strike / right | string | 否 | 期权合约定位 |
| asset_quote_type | string | 否 | 报价类型 |
| lang | string | 否 | 语言 |
返回
[]model.Position
| 字段 | 类型 | 描述 |
|---|---|---|
| Account / Symbol / SecType / Market / Currency | string | 基础信息 |
| Position | int64 | 持仓数量 |
| PositionQty / SalableQty | float64 | 持仓数量(精确)/ 可卖数量 |
| AverageCost / AverageCostByAverage | float64 | 摊销成本 / 平均成本 |
| MarketValue | float64 | 市值 |
| UnrealizedPnl / UnrealizedPnlPercent | float64 | 未实现盈亏 / 百分比 |
| RealizedPnl | float64 | 已实现盈亏 |
| TodayPnl / TodayPnlPercent | float64 | 当日盈亏 / 百分比 |
| LatestPrice / LastClosePrice | float64 | 最新价 / 昨收 |
| ContractId / Identifier / Name | - | 合约标识 |
示例
// 最简调用:查询全部持仓
ps, err := tc.Positions(model.PositionsRequest{})
// 带过滤:仅查询美股持仓
ps, err = tc.Positions(model.PositionsRequest{
Market: "US",
SecType: "STK",
})
for _, p := range ps {
fmt.Printf("%s qty=%.0f avgCost=%.2f latest=%.2f pnl=%.2f\n",
p.Symbol, p.PositionQty, p.AverageCost, p.LatestPrice, p.UnrealizedPnl)
}Assets 查询资产
tc.Assets(req model.AssetsRequest) ([]model.Asset, error)
说明
查询账户资产概览(含各子账户分段数据)。v0.3.0 起接收 AssetsRequest。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| segment | bool | 否 | 是否返回分段明细 |
| market_value | bool | 否 | 是否返回市值 |
| sub_accounts | []string | 否 | 子账户列表 |
| base_currency | string | 否 | 基础币种 |
| consolidated | *bool | 否 | 是否合并汇总(nil 表示不传) |
| lang | string | 否 | 语言 |
返回
[]model.Asset
每个 Asset 含账户汇总字段(BuyingPower / CashValue / NetLiquidation / RealizedPnL / UnrealizedPnL / Currency / Capability)以及 Segments []AssetSegment。
每个 AssetSegment 含 Category(如 "S" 证券、"C" 期货) / Title / NetLiquidation / CashValue / AvailableFunds / EquityWithLoan / ExcessLiquidity / InitMarginReq / MaintMarginReq / GrossPositionValue / Leverage 等。
示例
// 最简调用
assets, err := tc.Assets(model.AssetsRequest{})
// 带过滤:返回分段明细
assets, err = tc.Assets(model.AssetsRequest{
Segment: true,
MarketValue: true,
})
for _, a := range assets {
fmt.Printf("account=%s buyingPower=%.2f netLiq=%.2f segments=%d\n",
a.Account, a.BuyingPower, a.NetLiquidation, len(a.Segments))
for _, s := range a.Segments {
fmt.Printf(" [%s] %s netLiq=%.2f available=%.2f\n",
s.Category, s.Title, s.NetLiquidation, s.AvailableFunds)
}
}PrimeAssets 查询综合账户资产
tc.PrimeAssets(req model.AssetsRequest) (*model.PrimeAsset, error)
说明
查询综合账户(Prime 账户)的详细资产信息。v0.3.0 起接收 AssetsRequest(与 Assets 共用请求结构)。
参数
见 Assets 的 AssetsRequest。
返回
*model.PrimeAsset
| 字段 | 类型 | 描述 |
|---|---|---|
| AccountID | string | 账户 ID |
| UpdateTimestamp | int64 | 更新时间(毫秒) |
| Segments | []PrimeAssetSegment | 分段资产 |
每个 PrimeAssetSegment 含完整资产字段:Capability / Category / Currency / CashBalance / CashAvailableForTrade / GrossPositionValue / EquityWithLoan / NetLiquidation / InitMargin / MaintainMargin / OvernightMargin / UnrealizedPL / RealizedPL / TotalTodayPL / BuyingPower / LockedFunds / Leverage 等,以及 CurrencyAssets []CurrencyAsset(含 Currency / CashBalance / CashAvailableForTrade / ForexRate)。
示例
// 最简调用
pa, err := tc.PrimeAssets(model.AssetsRequest{})
// 带过滤:指定基础币种
pa, err = tc.PrimeAssets(model.AssetsRequest{BaseCurrency: "USD"})
if err != nil {
log.Fatal(err)
}
fmt.Printf("account=%s segments=%d\n", pa.AccountID, len(pa.Segments))
for _, s := range pa.Segments {
fmt.Printf(" [%s] netLiq=%.2f buyingPower=%.2f\n",
s.Category, s.NetLiquidation, s.BuyingPower)
for _, ca := range s.CurrencyAssets {
fmt.Printf(" %s cash=%.2f fx=%.4f\n", ca.Currency, ca.CashBalance, ca.ForexRate)
}
}账户管理 (v0.3.0 新增)
ManagedAccounts 查询机构子账户列表
tc.ManagedAccounts(req model.ManagedAccountsRequest) ([]model.ManagedAccount, error)
说明
查询当前主账户下可管理的机构子账户列表。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| lang | string | 否 | 语言 |
返回
[]model.ManagedAccount
| 字段 | 类型 | 描述 |
|---|---|---|
| Account | string | 子账户 ID |
| AccountType | string | 账户类型 |
| Capability | string | 账户能力(现金 / 融资等) |
| Status | string | 账户状态 |
示例
subs, err := tc.ManagedAccounts(model.ManagedAccountsRequest{})
if err != nil {
log.Fatal(err)
}
for _, s := range subs {
fmt.Printf("%s type=%s capability=%s status=%s\n",
s.Account, s.AccountType, s.Capability, s.Status)
}DerivativeContracts 查询衍生品合约
tc.DerivativeContracts(req model.DerivativeContractsRequest) ([]model.Contract, error)
说明
按 symbols + 类型批量查询衍生品合约信息(期权 / 认股 / 牛熊)。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| symbols | []string | 是 | 标的代码列表 |
| sec_type | string | 是 | OPT / WAR / IOPT |
| expiry | string | 否 | 到期日,YYYYMMDD |
| lang | string | 否 | 语言 |
返回
[]model.Contract(字段同 Contract)
示例
cs, err := tc.DerivativeContracts(model.DerivativeContractsRequest{
Symbols: []string{"AAPL", "TSLA"},
SecType: "OPT",
Expiry: "20260619",
})
fmt.Printf("contracts=%d\n", len(cs))资产分析 (v0.3.0 新增)
AnalyticsAsset 按日资产分析
tc.AnalyticsAsset(req model.AnalyticsAssetRequest) ([]model.AnalyticsAsset, error)
说明
按日返回账户持仓价值、现金余额、盈亏与净值指数,用于画账户表现曲线。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| sub_account | string | 否 | 子账户 ID |
| seg_type | string | 否 | 子账户分段 |
| currency | string | 否 | 币种 |
| sub_accounts | []string | 否 | 子账户列表 |
| start_date | string | 否 | 起始日期(yyyy-MM-dd) |
| end_date | string | 否 | 结束日期(yyyy-MM-dd) |
| lang | string | 否 | 语言 |
返回
[]model.AnalyticsAsset
| 字段 | 类型 | 描述 |
|---|---|---|
| Date | string | 日期(yyyy-MM-dd) |
| HoldingValue | float64 | 持仓市值 |
| CashBalance | float64 | 现金余额 |
| Pnl / PnlRate | float64 | 当日盈亏 / 收益率 |
| NetValueIndex | float64 | 净值指数 |
| Currency / SegType | string | 币种 / 分段 |
示例
rows, err := tc.AnalyticsAsset(model.AnalyticsAssetRequest{
StartDate: "2025-01-01",
EndDate: "2025-12-31",
Currency: "USD",
})
for _, r := range rows {
fmt.Printf("%s holding=%.2f cash=%.2f pnl=%.2f nav=%.4f\n",
r.Date, r.HoldingValue, r.CashBalance, r.Pnl, r.NetValueIndex)
}AggregateAssets 综合账户资产汇总
tc.AggregateAssets(req model.AggregateAssetsRequest) (*model.AggregateAssets, error)
说明
在指定 base_currency 视角下汇总综合账户资产(含各币种明细)。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| seg_type | string | 否 | 分段(S / C 等) |
| base_currency | string | 否 | 基础币种(汇总视角) |
| lang | string | 否 | 语言 |
返回
*model.AggregateAssets
| 字段 | 类型 | 描述 |
|---|---|---|
| AccountID | string | 账户 ID |
| NetLiquidation | float64 | 总净值 |
| GrossPositionValue | float64 | 总持仓市值 |
| CashBalance | float64 | 现金余额 |
| BaseCurrency | string | 基础币种 |
| CurrencyAssets | []CurrencyAsset | 各币种明细 |
示例
agg, err := tc.AggregateAssets(model.AggregateAssetsRequest{BaseCurrency: "USD"})
if err != nil {
log.Fatal(err)
}
fmt.Printf("netLiq=%.2f gross=%.2f cash=%.2f currencies=%d\n",
agg.NetLiquidation, agg.GrossPositionValue, agg.CashBalance, len(agg.CurrencyAssets))EstimateTradableQuantity 可交易数量估算
tc.EstimateTradableQuantity(req model.EstimateTradableQuantityRequest) (*model.EstimateTradableQuantity, error)
说明
根据账户可用资金、保证金、现价估算可下单数量(含现金买入、融资买入、做空、可卖出等上限)。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| symbol | string | 是 | 合约代码 |
| sec_type | string | 是 | 合约类型 |
| expiry / strike / right | string | 否 | 期权合约定位 |
| seg_type | string | 否 | 子账户分段 |
| action | string | 是 | BUY / SELL |
| order_type | string | 否 | MKT / LMT / STP / STP_LMT |
| limit_price | float64 | 条件 | LMT / STP_LMT 必填 |
| stop_price | float64 | 条件 | STP / STP_LMT 必填 |
| lang | string | 否 | 语言 |
返回
*model.EstimateTradableQuantity
| 字段 | 类型 | 描述 |
|---|---|---|
| TradableQuantity | float64 | 可下单数量 |
| MaxCashBuyQuantity | float64 | 最大现金买入数量 |
| MaxMarginBuyQuantity | float64 | 最大融资买入数量 |
| MaxShortSellQuantity | float64 | 最大做空数量 |
| MaxPositionSellQty | float64 | 最大持仓可卖数量 |
| CashBuyingPower | float64 | 现金购买力 |
| Currency | string | 币种 |
示例
est, err := tc.EstimateTradableQuantity(model.EstimateTradableQuantityRequest{
Symbol: "AAPL",
SecType: "STK",
Action: "BUY",
OrderType: "LMT",
LimitPrice: 150.0,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("tradable=%.2f cashBuy=%.2f marginBuy=%.2f\n",
est.TradableQuantity, est.MaxCashBuyQuantity, est.MaxMarginBuyQuantity)资金明细与调拨 (v0.3.0 新增)
FundDetails 资金流水明细
tc.FundDetails(req model.FundDetailsRequest) ([]model.FundDetails, error)
说明
按时间窗查询账户资金流水(入金 / 出金 / 费用 / 利息 / 分红等)。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| seg_types | []string | 否 | 分段列表 |
| fund_type | string | 否 | 资金类型 |
| currency | string | 否 | 币种 |
| start_date | int64 | 否 | 起始时间(毫秒时间戳) |
| end_date | int64 | 否 | 结束时间(毫秒时间戳) |
| start | int | 否 | 分页起始位 |
| limit | int | 否 | 返回条数 |
| lang | string | 否 | 语言 |
返回
[]model.FundDetails
| 字段 | 类型 | 描述 |
|---|---|---|
| ID | int64 | 流水 ID |
| Account / SegType / FundType / Currency | string | 基础信息 |
| Amount / Balance | float64 | 金额 / 余额 |
| OccurTime | int64 | 发生时间(毫秒) |
| Remark | string | 备注 |
| ExternalID | string | 外部 ID |
示例
now := time.Now().UnixMilli()
rows, err := tc.FundDetails(model.FundDetailsRequest{
StartDate: now - 30*24*3600*1000,
EndDate: now,
Currency: "USD",
Limit: 100,
})
for _, r := range rows {
fmt.Printf("%d %s amount=%.2f balance=%.2f remark=%s\n",
r.OccurTime, r.FundType, r.Amount, r.Balance, r.Remark)
}FundingHistory 资金调拨记录
tc.FundingHistory(req model.FundingHistoryRequest) ([]model.FundingHistoryItem, error)
说明
查询账户入金 / 出金的调拨记录。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| seg_type | string | 否 | 分段 |
| lang | string | 否 | 语言 |
返回
[]model.FundingHistoryItem
| 字段 | 类型 | 描述 |
|---|---|---|
| ID | int64 | 调拨 ID |
| RefID | string | 外部参考 ID |
| Type | int | 调拨类型码 |
| TypeDesc | string | 调拨类型描述(如 Deposit / Withdrawal) |
| Currency | string | 币种 |
| Amount | float64 | 金额 |
| BusinessDate | string | 业务日期(格式 yyyy/MM/dd) |
| Status | string | 状态码 |
| StatusDesc | string | 状态描述 |
| CompletedStatus | bool | 是否已完成 |
| CreatedAt | int64 | 创建时间(毫秒时间戳) |
| UpdatedAt | int64 | 更新时间(毫秒时间戳) |
示例
rows, err := tc.FundingHistory(model.FundingHistoryRequest{})
for _, r := range rows {
fmt.Printf("%d %s amount=%.2f type=%s status=%s\n", r.ID, r.Currency, r.Amount, r.TypeDesc, r.Status)
}PlaceForexOrder 外汇下单
tc.PlaceForexOrder(req model.ForexOrderRequest) (*model.ForexOrderResult, error)
说明
提交外汇兑换订单(货币之间转换)。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| seg_type | string | 否 | 子账户分段 |
| source_currency | string | 是 | 源币种 |
| source_amount | float64 | 是 | 源金额 |
| target_currency | string | 是 | 目标币种 |
| external_id | string | 否 | 客户端外部 ID |
| time_in_force | string | 否 | DAY / GTC 等 |
| lang | string | 否 | 语言 |
返回
*model.ForexOrderResult
| 字段 | 类型 | 描述 |
|---|---|---|
| ID | string | 外汇订单 ID |
| Status | string | 状态 |
| SourceCurrency / TargetCurrency | string | 源 / 目标币种 |
| SourceAmount / TargetAmount | float64 | 源 / 目标金额 |
| Rate | float64 | 汇率 |
| SubmitTime | int64 | 提交时间(毫秒) |
示例
res, err := tc.PlaceForexOrder(model.ForexOrderRequest{
SourceCurrency: "USD",
SourceAmount: 10000,
TargetCurrency: "HKD",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("id=%s rate=%.4f target=%.2f\n", res.ID, res.Rate, res.TargetAmount)SegmentFundAvailable 查询可调拨资金
tc.SegmentFundAvailable(req model.SegmentFundRequest) ([]model.SegmentFund, error)
说明
查询子账户之间可调拨的资金上限。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| from_segment | string | 否 | 源分段 |
| to_segment | string | 否 | 目标分段 |
| currency | string | 否 | 币种 |
| lang | string | 否 | 语言 |
返回
[]model.SegmentFund
| 字段 | 类型 | 描述 |
|---|---|---|
| FromSegment / ToSegment / Currency | string | 源 / 目标 / 币种 |
| AvailableAmt | float64 | 可调拨金额 |
示例
avail, err := tc.SegmentFundAvailable(model.SegmentFundRequest{
FromSegment: "S",
ToSegment: "C",
Currency: "USD",
})
for _, a := range avail {
fmt.Printf("%s->%s %s available=%.2f\n", a.FromSegment, a.ToSegment, a.Currency, a.AvailableAmt)
}SegmentFundHistory 子账户调拨历史
tc.SegmentFundHistory(req model.SegmentFundRequest) ([]model.SegmentFundHistoryItem, error)
说明
查询子账户资金调拨的历史记录。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
同 SegmentFundRequest(常用 Limit 限定返回条数)。
返回
[]model.SegmentFundHistoryItem
| 字段 | 类型 | 描述 |
|---|---|---|
| ID | int64 | 调拨记录 ID |
| FromSegment / ToSegment / Currency | string | 源 / 目标 / 币种 |
| Amount | float64 | 金额 |
| Status | string | 状态 |
| SubmitTime / UpdateTime | int64 | 提交 / 更新时间(毫秒) |
示例
history, err := tc.SegmentFundHistory(model.SegmentFundRequest{Limit: 50})
for _, h := range history {
fmt.Printf("%d %s->%s %s amount=%.2f status=%s\n",
h.ID, h.FromSegment, h.ToSegment, h.Currency, h.Amount, h.Status)
}TransferSegmentFund 子账户资金调拨
tc.TransferSegmentFund(req model.SegmentFundRequest) (*model.SegmentFund, error)
说明
在子账户(分段)之间提交资金调拨申请。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| account | string | 否 | 账户 ID |
| from_segment | string | 是 | 源分段 |
| to_segment | string | 是 | 目标分段 |
| currency | string | 是 | 币种 |
| amount | float64 | 是 | 金额 |
| lang | string | 否 | 语言 |
返回
*model.SegmentFund(含 ID / Status / SubmitTime 等)
示例
res, err := tc.TransferSegmentFund(model.SegmentFundRequest{
FromSegment: "S",
ToSegment: "C",
Currency: "USD",
Amount: 1000,
})
fmt.Printf("transferId=%s status=%s\n", res.ID, res.Status)CancelSegmentFund 撤销调拨申请
tc.CancelSegmentFund(req model.SegmentFundRequest) (*model.SegmentFund, error)
说明
撤销尚未执行的子账户调拨申请。
仅支持综合账户(STANDARD),模拟账户(PAPER)不支持此接口。
参数
| 参数名 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| id | string | 是 | 调拨申请 ID(来自 TransferSegmentFund 返回的 ID) |
| account | string | 否 | 账户 ID |
| lang | string | 否 | 语言 |
返回
*model.SegmentFund
示例
res, err := tc.CancelSegmentFund(model.SegmentFundRequest{ID: "TX123456"})
fmt.Printf("cancelled id=%s status=%s\n", res.ID, res.Status)通用方法
当 SDK 尚未封装某个 API 时,可通过 HttpClient.ExecuteRaw 直接调用底层接口:
package main
import (
"fmt"
"log"
"github.com/tigerfintech/openapi-go-sdk/client"
"github.com/tigerfintech/openapi-go-sdk/config"
)
func main() {
cfg, err := config.NewClientConfig()
if err != nil {
log.Fatal(err)
}
httpClient := client.NewHttpClient(cfg)
// 直接传入 API 方法名和 JSON 参数
resp, err := httpClient.ExecuteRaw("market_state", `{"market":"US"}`)
if err != nil {
log.Fatal(err)
}
fmt.Println("原始响应:", resp)
}Updated 14 days ago
