Documentation
¶
Index ¶
- Constants
- func ParseResponse(resp *reqs.Resp, data interface{}) error
- type AccountBalance
- type AccountConfig
- type AccountPosition
- type BalanceDetail
- type BaseResponse
- type CancelOrderRequest
- type CancelOrderResponse
- type Candle
- type Client
- func (c *Client) CancelOrder(req CancelOrderRequest) (*CancelOrderResponse, error)
- func (c *Client) Get(path string) (*reqs.Resp, error)
- func (c *Client) GetAccountBalance(ccy ...string) ([]AccountBalance, error)
- func (c *Client) GetAccountConfig() (*AccountConfig, error)
- func (c *Client) GetAccountPositions(instType, instId string) ([]AccountPosition, error)
- func (c *Client) GetCandles(instId, bar string, limit int) ([]Candle, error)
- func (c *Client) GetInstruments(instType, instId string) ([]Instrument, error)
- func (c *Client) GetOrder(instId, ordId, clOrdId string) (*Order, error)
- func (c *Client) GetOrderHistory(instType string, limit int) ([]Order, error)
- func (c *Client) GetOrderList(instType, instId string) ([]Order, error)
- func (c *Client) GetOrderbook(instId string, sz int) (*Orderbook, error)
- func (c *Client) GetTicker(instId string) (*Ticker, error)
- func (c *Client) GetTickers(instType string) ([]Ticker, error)
- func (c *Client) PlaceOrder(req OrderRequest) (*OrderResponse, error)
- func (c *Client) Post(path string, body interface{}) (*reqs.Resp, error)
- func (c *Client) Request(method, path string, body interface{}) (*reqs.Resp, error)
- func (c *Client) SetBaseURL(baseURL string) *Client
- func (c *Client) SetLeverage(req SetLeverageRequest) (*SetLeverageResponse, error)
- func (c *Client) SetSimulated(simulated bool) *Client
- type Instrument
- type Order
- type OrderRequest
- type OrderResponse
- type Orderbook
- type SetLeverageRequest
- type SetLeverageResponse
- type Ticker
Constants ¶
const ( // 产品类型 InstTypeSpot = "SPOT" // 币币 InstTypeMargin = "MARGIN" // 币币杠杆 InstTypeSwap = "SWAP" // 永续合约 InstTypeFutures = "FUTURES" // 交割合约 InstTypeOption = "OPTION" // 期权 // 交易模式 TdModeCash = "cash" // 非保证金 TdModeCross = "cross" // 全仓 TdModeIsolated = "isolated" // 逐仓 // 订单方向 SideBuy = "buy" // 买入 SideSell = "sell" // 卖出 // 订单类型 OrdTypeMarket = "market" // 市价单 OrdTypeLimit = "limit" // 限价单 OrdTypePostOnly = "post_only" // 只做maker OrdTypeFok = "fok" // 全部成交或立即取消 OrdTypeIoc = "ioc" // 立即成交并取消剩余 // 持仓方向 PosSideLong = "long" // 多头 PosSideShort = "short" // 空头 PosSideNet = "net" // 单向持仓 )
const ( // BaseURL OKX API 基础 URL BaseURL = "https://www.okx.com" // BaseURLAWS OKX AWS 服务器 URL BaseURLAWS = "https://aws.okx.com" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AccountBalance ¶
type AccountBalance struct {
AdjEq string `json:"adjEq"` // 美元层面有效保证金
Details []BalanceDetail `json:"details"` // 各币种资产详细信息
Imr string `json:"imr"` // 美元层面占用保证金
IsoEq string `json:"isoEq"` // 美元层面逐仓仓位权益
MgnRatio string `json:"mgnRatio"` // 美元层面保证金率
Mmr string `json:"mmr"` // 美元层面维持保证金
NotionalUsd string `json:"notionalUsd"` // 以美元价值为单位的持仓数量
OrdFroz string `json:"ordFroz"` // 美元层面全仓挂单占用保证金
TotalEq string `json:"totalEq"` // 美元层面权益
UTime string `json:"uTime"` // 账户信息的更新时间,Unix时间戳的毫秒数格式
}
AccountBalance 账户余额
type AccountConfig ¶
type AccountConfig struct {
AcctLv string `json:"acctLv"` // 账户层级:1 简单交易模式 2 单币种保证金模式 3 跨币种保证金模式 4 组合保证金模式
AutoLoan bool `json:"autoLoan"` // 是否自动借币:true false
CtIsoMode string `json:"ctIsoMode"` // 合约逐仓保证金模式:automatic 自动转入 autonomy 自主转入
GreeksType string `json:"greeksType"` // 希腊字母展示方式:PA 币本位 BS 美元本位
Level string `json:"level"` // 当前带单合约的倍数
LevelTmp string `json:"levelTmp"` // 临时带单合约的倍数
MgnIsoMode string `json:"mgnIsoMode"` // 现货对冲逐仓保证金模式:automatic 自动转入 autonomy 自主转入
PosMode string `json:"posMode"` // 持仓方式:long_short_mode 双向持仓 net_mode 单向持仓
Uid string `json:"uid"` // 用户标识
Label string `json:"label"` // APIKey的备注名
RoleType string `json:"roleType"` // 当前APIKey的权限:0 普通用户 1 资管户用户 2 资管户子账户
TraderInsts []struct {
InstId string `json:"instId"` // 产品ID
} `json:"traderInsts"` // 当前带单合约
KycLv string `json:"kycLv"` // 身份认证等级
IP string `json:"ip"` // API绑定ip地址
Perm string `json:"perm"` // API权限
MainUid string `json:"mainUid"` // 母账户UID
}
AccountConfig 账户配置
type AccountPosition ¶
type AccountPosition struct {
InstType string `json:"instType"` // 产品类型
MgnMode string `json:"mgnMode"` // 保证金模式:cross 全仓 isolated 逐仓
PosId string `json:"posId"` // 持仓ID
PosSide string `json:"posSide"` // 持仓方向:long short net
Pos string `json:"pos"` // 持仓数量
AvailPos string `json:"availPos"` // 可平仓数量
AvgPx string `json:"avgPx"` // 开仓平均价
Upl string `json:"upl"` // 未实现收益
UplRatio string `json:"uplRatio"` // 未实现收益率
InstId string `json:"instId"` // 产品ID
Lever string `json:"lever"` // 杠杆倍数
LiqPx string `json:"liqPx"` // 预估强平价
MarkPx string `json:"markPx"` // 最新标记价格
Imr string `json:"imr"` // 占用保证金
Margin string `json:"margin"` // 保证金余额
MgnRatio string `json:"mgnRatio"` // 保证金率
Mmr string `json:"mmr"` // 维持保证金
Liab string `json:"liab"` // 负债额
LiabCcy string `json:"liabCcy"` // 负债币种
Interest string `json:"interest"` // 利息
TradeId string `json:"tradeId"` // 最新成交ID
NotionalUsd string `json:"notionalUsd"` // 以美元价值为单位的持仓数量
Adl string `json:"adl"` // 信号区
Ccy string `json:"ccy"` // 占用保证金的币种
Last string `json:"last"` // 最新成交价
UsdPx string `json:"usdPx"` // 美元价格(仅适用于期权)
BePx string `json:"bePx"` // 盈亏平衡价
DeltaBS string `json:"deltaBS"` // 美元本位持仓仓位delta
DeltaPA string `json:"deltaPA"` // 币本位持仓仓位delta
GammaBS string `json:"gammaBS"` // 美元本位持仓仓位gamma
GammaPA string `json:"gammaPA"` // 币本位持仓仓位gamma
ThetaBS string `json:"thetaBS"` // 美元本位持仓仓位theta
ThetaPA string `json:"thetaPA"` // 币本位持仓仓位theta
VegaBS string `json:"vegaBS"` // 美元本位持仓仓位vega
VegaPA string `json:"vegaPA"` // 币本位持仓仓位vega
CTime string `json:"cTime"` // 持仓创建时间
UTime string `json:"uTime"` // 最近一次持仓更新时间
PTime string `json:"pTime"` // 持仓信息更新时间
}
AccountPosition 持仓信息
type BalanceDetail ¶
type BalanceDetail struct {
AvailBal string `json:"availBal"` // 可用余额
AvailEq string `json:"availEq"` // 可用保证金
CashBal string `json:"cashBal"` // 币种余额
Ccy string `json:"ccy"` // 币种
CrossLiab string `json:"crossLiab"` // 币种全仓负债额
DiskEq string `json:"disEq"` // 美元层面币种折算权益
Eq string `json:"eq"` // 币种权益
EqUsd string `json:"eqUsd"` // 币种权益美元价值
FrozenBal string `json:"frozenBal"` // 币种占用金额
Interest string `json:"interest"` // 计息
IsoEq string `json:"isoEq"` // 币种逐仓仓位权益
IsoLiab string `json:"isoLiab"` // 币种逐仓负债额
IsoUpl string `json:"isoUpl"` // 逐仓未实现盈亏
Liab string `json:"liab"` // 币种负债额
MaxLoan string `json:"maxLoan"` // 币种最大可借
MgnRatio string `json:"mgnRatio"` // 保证金率
NotionalLever string `json:"notionalLever"` // 杠杆倍数
OrdFrozen string `json:"ordFrozen"` // 挂单冻结数量
Twap string `json:"twap"` // 当前负债币种触发系统自动换币的风险
UTime string `json:"uTime"` // 更新时间,Unix时间戳的毫秒数格式
Upl string `json:"upl"` // 未实现盈亏
UplLiab string `json:"uplLiab"` // 由于仓位未实现亏损导致的负债
StgyEq string `json:"stgyEq"` // 策略权益
}
BalanceDetail 余额详情
type BaseResponse ¶
type BaseResponse struct {
Code string `json:"code"`
Msg string `json:"msg"`
Data json.RawMessage `json:"data,omitempty"`
}
BaseResponse OKX API 基础响应结构
type CancelOrderRequest ¶
type CancelOrderRequest struct {
InstId string `json:"instId"` // 产品ID
OrdId string `json:"ordId,omitempty"` // 订单ID,ordId和clOrdId必须传一个
ClOrdId string `json:"clOrdId,omitempty"` // 客户自定义订单ID
}
CancelOrderRequest 撤单请求
type CancelOrderResponse ¶
type CancelOrderResponse struct {
ClOrdId string `json:"clOrdId"` // 客户自定义订单ID
OrdId string `json:"ordId"` // 订单ID
SCode string `json:"sCode"` // 事件执行结果的code,0代表成功
SMsg string `json:"sMsg"` // 事件执行失败时的msg
}
CancelOrderResponse 撤单响应
type Candle ¶
type Candle struct {
Ts string `json:"ts"` // 开始时间
O string `json:"o"` // 开盘价格
H string `json:"h"` // 最高价格
L string `json:"l"` // 最低价格
C string `json:"c"` // 收盘价格
Vol string `json:"vol"` // 交易量(张)
VolCcy string `json:"volCcy"` // 交易量(币)
VolCcyQt string `json:"volCcyQt"` // 交易量(计价货币)
Confirm string `json:"confirm"` // K线状态:0 K线未完结,1 K线已完结
}
Candle K线数据
type Client ¶
type Client struct {
APIKey string
SecretKey string
Passphrase string
BaseURL string
Simulated bool // 是否使用模拟交易
}
Client OKX API 客户端
func (*Client) CancelOrder ¶
func (c *Client) CancelOrder(req CancelOrderRequest) (*CancelOrderResponse, error)
CancelOrder 撤单
func (*Client) GetAccountBalance ¶
func (c *Client) GetAccountBalance(ccy ...string) ([]AccountBalance, error)
GetAccountBalance 获取账户余额
func (*Client) GetAccountConfig ¶
func (c *Client) GetAccountConfig() (*AccountConfig, error)
GetAccountConfig 获取账户配置
func (*Client) GetAccountPositions ¶
func (c *Client) GetAccountPositions(instType, instId string) ([]AccountPosition, error)
GetAccountPositions 获取持仓信息
func (*Client) GetCandles ¶
GetCandles 获取K线数据 bar: 时间粒度,默认值1m 如 1m/3m/5m/15m/30m/1H/2H/4H 香港时间开盘价k线:6H/12H/1D/2D/3D/1W/1M/3M UTC时间开盘价k线:[/6Hutc/12Hutc/1Dutc/2Dutc/3Dutc/1Wutc/1Mutc/3Mutc]
func (*Client) GetInstruments ¶
func (c *Client) GetInstruments(instType, instId string) ([]Instrument, error)
GetInstruments 获取交易产品基础信息
func (*Client) GetOrderHistory ¶
GetOrderHistory 获取历史订单记录(近7天)
func (*Client) GetOrderList ¶
GetOrderList 获取未成交订单列表
func (*Client) GetOrderbook ¶
GetOrderbook 获取产品深度
func (*Client) GetTickers ¶
GetTickers 获取所有产品行情信息
func (*Client) PlaceOrder ¶
func (c *Client) PlaceOrder(req OrderRequest) (*OrderResponse, error)
PlaceOrder 下单
func (*Client) SetLeverage ¶
func (c *Client) SetLeverage(req SetLeverageRequest) (*SetLeverageResponse, error)
SetLeverage 设置杠杆倍数
func (*Client) SetSimulated ¶
SetSimulated 设置是否使用模拟交易
type Instrument ¶
type Instrument struct {
InstType string `json:"instType"` // 产品类型
InstId string `json:"instId"` // 产品ID
Uly string `json:"uly"` // 标的指数
Category string `json:"category"` // 手续费类别
BaseCcy string `json:"baseCcy"` // 交易货币币种
QuoteCcy string `json:"quoteCcy"` // 计价货币币种
SettleCcy string `json:"settleCcy"` // 盈亏结算和保证金币种
CtVal string `json:"ctVal"` // 合约面值
CtMult string `json:"ctMult"` // 合约乘数
CtValCcy string `json:"ctValCcy"` // 合约面值币种
OptType string `json:"optType"` // 期权类型:C看涨期权 P看跌期权
Stk string `json:"stk"` // 行权价格
ListTime string `json:"listTime"` // 上线日期
ExpTime string `json:"expTime"` // 产品下线时间
Lever string `json:"lever"` // 该instId交易时可用的最高杠杆倍数
TickSz string `json:"tickSz"` // 下单价格精度
LotSz string `json:"lotSz"` // 下单数量精度
MinSz string `json:"minSz"` // 最小下单数量
CtType string `json:"ctType"` // 合约类型:linear 正向合约 inverse 反向合约
Alias string `json:"alias"` // 合约日期别名
State string `json:"state"` // 产品状态
}
Instrument 产品信息
type Order ¶
type Order struct {
InstType string `json:"instType"` // 产品类型
InstId string `json:"instId"` // 产品ID
TgtCcy string `json:"tgtCcy"` // 委托数量的类型
Ccy string `json:"ccy"` // 保证金币种
OrdId string `json:"ordId"` // 订单ID
ClOrdId string `json:"clOrdId"` // 客户自定义订单ID
Tag string `json:"tag"` // 订单标签
Px string `json:"px"` // 委托价格
Sz string `json:"sz"` // 委托数量
Pnl string `json:"pnl"` // 收益
OrdType string `json:"ordType"` // 订单类型
Side string `json:"side"` // 订单方向
PosSide string `json:"posSide"` // 持仓方向
TdMode string `json:"tdMode"` // 交易模式
AccFillSz string `json:"accFillSz"` // 累计成交数量
FillPx string `json:"fillPx"` // 最新成交价格
TradeId string `json:"tradeId"` // 最新成交ID
FillSz string `json:"fillSz"` // 最新成交数量
FillTime string `json:"fillTime"` // 最新成交时间
AvgPx string `json:"avgPx"` // 成交均价
State string `json:"state"` // 订单状态:canceled 撤单成功 live 等待成交 partially_filled 部分成交 filled 完全成交
Lever string `json:"lever"` // 杠杆倍数
TpTriggerPx string `json:"tpTriggerPx"` // 止盈触发价
TpTriggerPxType string `json:"tpTriggerPxType"` // 止盈触发价类型
TpOrdPx string `json:"tpOrdPx"` // 止盈委托价
SlTriggerPx string `json:"slTriggerPx"` // 止损触发价
SlTriggerPxType string `json:"slTriggerPxType"` // 止损触发价类型
SlOrdPx string `json:"slOrdPx"` // 止损委托价
FeeCcy string `json:"feeCcy"` // 交易手续费币种
Fee string `json:"fee"` // 订单交易手续费
RebateCcy string `json:"rebateCcy"` // 返佣金币种
Rebate string `json:"rebate"` // 返佣金额
Category string `json:"category"` // 订单种类
UTime string `json:"uTime"` // 订单状态更新时间
CTime string `json:"cTime"` // 订单创建时间
}
Order 订单信息
type OrderRequest ¶
type OrderRequest struct {
InstId string `json:"instId"` // 产品ID
TdMode string `json:"tdMode"` // 交易模式:isolated 逐仓 cross 全仓 cash 非保证金
Side string `json:"side"` // 订单方向:buy sell
OrdType string `json:"ordType"` // 订单类型:market 市价单 limit 限价单 post_only 只做maker fok 全部成交或立即取消 ioc 立即成交并取消剩余
Sz string `json:"sz"` // 委托数量
Px string `json:"px,omitempty"` // 委托价格,仅限价单有效
PosSide string `json:"posSide,omitempty"` // 持仓方向:long short net,默认net
Ccy string `json:"ccy,omitempty"` // 保证金币种,仅适用于跨币种保证金模式下的全仓杠杆订单
ClOrdId string `json:"clOrdId,omitempty"` // 客户自定义订单ID
Tag string `json:"tag,omitempty"` // 订单标签
ReduceOnly bool `json:"reduceOnly,omitempty"` // 是否只减仓,true 或 false,默认false
TgtCcy string `json:"tgtCcy,omitempty"` // 委托数量的类型:base_ccy 交易货币 quote_ccy 计价货币,仅适用于币币市价单
}
OrderRequest 下单请求
type OrderResponse ¶
type OrderResponse struct {
ClOrdId string `json:"clOrdId"` // 客户自定义订单ID
OrdId string `json:"ordId"` // 订单ID
Tag string `json:"tag"` // 订单标签
SCode string `json:"sCode"` // 事件执行结果的code,0代表成功
SMsg string `json:"sMsg"` // 事件执行失败时的msg
}
OrderResponse 下单响应
type Orderbook ¶
type Orderbook struct {
Asks [][]string `json:"asks"` // 卖方深度,[价格, 数量, 已废弃, 订单数量]
Bids [][]string `json:"bids"` // 买方深度,[价格, 数量, 已废弃, 订单数量]
Ts string `json:"ts"` // 深度产生的时间
}
Orderbook 深度数据
type SetLeverageRequest ¶
type SetLeverageRequest struct {
InstId string `json:"instId"` // 产品ID
Ccy string `json:"ccy,omitempty"` // 保证金币种,仅适用于跨币种保证金模式下的全仓杠杆
Lever string `json:"lever"` // 杠杆倍数
MgnMode string `json:"mgnMode"` // 保证金模式:isolated 逐仓 cross 全仓
PosSide string `json:"posSide,omitempty"` // 持仓方向:long short,仅适用于逐仓模式
}
SetLeverage 设置杠杆倍数
type SetLeverageResponse ¶
type SetLeverageResponse struct {
InstId string `json:"instId"` // 产品ID
Lever string `json:"lever"` // 杠杆倍数
MgnMode string `json:"mgnMode"` // 保证金模式
PosSide string `json:"posSide"` // 持仓方向
}
SetLeverageResponse 设置杠杆响应
type Ticker ¶
type Ticker struct {
InstType string `json:"instType"` // 产品类型
InstId string `json:"instId"` // 产品ID
Last string `json:"last"` // 最新成交价
LastSz string `json:"lastSz"` // 最新成交的数量
AskPx string `json:"askPx"` // 卖一价
AskSz string `json:"askSz"` // 卖一数量
BidPx string `json:"bidPx"` // 买一价
BidSz string `json:"bidSz"` // 买一数量
Open24h string `json:"open24h"` // 24小时开盘价
High24h string `json:"high24h"` // 24小时最高价
Low24h string `json:"low24h"` // 24小时最低价
VolCcy24h string `json:"volCcy24h"` // 24小时成交量,以币为单位
Vol24h string `json:"vol24h"` // 24小时成交量,以张为单位
SodUtc0 string `json:"sodUtc0"` // UTC 0 时开盘价
SodUtc8 string `json:"sodUtc8"` // UTC+8 时开盘价
Ts string `json:"ts"` // ticker数据产生时间
}
Ticker 行情数据