Documentation ¶
Index ¶
- type AccountInfo
- type AccountInfoResult
- type ApiParameter
- type CancelData
- type CancelError
- type CancelResult
- type Client
- func (c *Client) Cancel(symbol string, orderID int64, clientOrderID int64) (result CancelResult, err error)
- func (c *Client) GetAccountInfo(symbol string) (result AccountInfoResult, err error)
- func (c *Client) GetContractIndex(symbol string) (result ContractIndexResult, err error)
- func (c *Client) GetContractInfo(symbol, contractType, contractCode string) (result ContractInfoResult, err error)
- func (c *Client) GetHisOrders(symbol string, tradeType int, _type int, status int, createDate int, ...) (result HisOrdersResult, err error)
- func (c *Client) GetKLine(symbol string, period string, size int, from int64, to int64) (result KLineResult, err error)
- func (c *Client) GetMarketDepth(symbol string, _type string) (result MarketDepthResult, err error)
- func (c *Client) GetOpenOrders(symbol string, pageIndex int, pageSize int) (result OpenOrdersResult, err error)
- func (c *Client) GetPositionInfo(symbol string) (result PositionInfoResult, err error)
- func (c *Client) Heartbeat() (result HeartbeatResult, err error)
- func (c *Client) LightningClosePosition(symbol string, contractType string, contractCode string, volume int, ...) (result LightningClosePositionResult, err error)
- func (c *Client) Order(symbol string, contractType string, contractCode string, clientOrderID int64, ...) (result OrderResult, err error)
- func (c *Client) OrderDetail(symbol string, orderID int64, createdAt int64, orderType int, pageIndex int, ...) (err error)
- func (c *Client) OrderInfo(symbol string, orderID int64, clientOrderID int64) (result OrderInfoResult, err error)
- type ContractIndex
- type ContractIndexResult
- type ContractInfo
- type ContractInfoResult
- type Heartbeat
- type HeartbeatResult
- type HisOrdersData
- type HisOrdersResult
- type KLine
- type KLineResult
- type LightningClosePositionResult
- type MarketDepthResult
- type NWS
- func (ws *NWS) Login() error
- func (ws *NWS) SetAccountsCallback(callback func(accounts *WSAccounts))
- func (ws *NWS) SetLiquidationOrdersCallback(callback func(liquidationOrders *WSLiquidationOrders))
- func (ws *NWS) SetMatchOrdersCallback(callback func(order *WSMatchOrder))
- func (ws *NWS) SetOrdersCallback(callback func(order *WSOrder))
- func (ws *NWS) SetPositionsCallback(callback func(positions *WSPositions))
- func (ws *NWS) SetProxy(proxyURL string) (err error)
- func (ws *NWS) Start()
- func (ws *NWS) Subscribe(id string, ch map[string]interface{}) error
- func (ws *NWS) SubscribeAccounts(id string, symbol string)
- func (ws *NWS) SubscribeLiquidationOrders(id string, symbol string)
- func (ws *NWS) SubscribeMatchOrders(id string, symbol string)
- func (ws *NWS) SubscribeOrders(id string, symbol string)
- func (ws *NWS) SubscribePositions(id string, symbol string)
- func (ws *NWS) SubscribeTopic(id string, topic string)
- func (ws *NWS) Unsubscribe(id string) error
- type OpenOrdersData
- type OpenOrdersResult
- type Order
- type OrderData
- type OrderInfoResult
- type OrderResult
- type Position
- type PositionInfoResult
- type Tick
- type WS
- func (ws *WS) SetDepthCallback(callback func(depth *WSDepth))
- func (ws *WS) SetDepthHFCallback(callback func(depth *WSDepthHF))
- func (ws *WS) SetProxy(proxyURL string) (err error)
- func (ws *WS) SetTickerCallback(callback func(ticker *WSTicker))
- func (ws *WS) SetTradeCallback(callback func(trade *WSTrade))
- func (ws *WS) Start()
- func (ws *WS) Subscribe(id string, ch map[string]interface{}) error
- func (ws *WS) SubscribeDepth(id string, symbol string)
- func (ws *WS) SubscribeDepthHF(id string, symbol string, size int, dateType string)
- func (ws *WS) SubscribeTicker(id string, symbol string)
- func (ws *WS) SubscribeTrade(id string, symbol string)
- func (ws *WS) Unsubscribe(id string) error
- type WSAccountData
- type WSAccounts
- type WSDepth
- type WSDepthHF
- type WSLiquidationOrders
- type WSMatchOrder
- type WSMyTrade
- type WSOrder
- type WSPositionData
- type WSPositions
- type WSTick
- type WSTickHF
- type WSTicker
- type WSTickerTick
- type WSTrade
- type WSTradeItem
- type WSTradeTick
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountInfo ¶
type AccountInfo struct { Symbol string `json:"symbol"` MarginBalance float64 `json:"margin_balance"` MarginPosition float64 `json:"margin_position"` MarginFrozen float64 `json:"margin_frozen"` MarginAvailable float64 `json:"margin_available"` ProfitReal float64 `json:"profit_real"` ProfitUnreal float64 `json:"profit_unreal"` RiskRate interface{} `json:"risk_rate"` WithdrawAvailable float64 `json:"withdraw_available"` LiquidationPrice interface{} `json:"liquidation_price"` LeverRate float64 `json:"lever_rate"` AdjustFactor float64 `json:"adjust_factor"` MarginStatic float64 `json:"margin_static"` IsDebit int `json:"is_debit"` }
type AccountInfoResult ¶
type AccountInfoResult struct { Status string `json:"status"` ErrCode int `json:"err_code"` ErrMsg string `json:"err_msg"` Data []AccountInfo `json:"data"` Ts int64 `json:"ts"` }
type ApiParameter ¶
type CancelData ¶
type CancelData struct { Errors []CancelError `json:"errors"` Successes string `json:"successes"` }
type CancelError ¶
type CancelResult ¶
type CancelResult struct { Status string `json:"status"` ErrCode int `json:"err_code"` ErrMsg string `json:"err_msg"` Data CancelData `json:"data"` Ts int64 `json:"ts"` }
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(params *ApiParameter) *Client
func (*Client) Cancel ¶
func (c *Client) Cancel(symbol string, orderID int64, clientOrderID int64) (result CancelResult, err error)
* Cancel 撤销订单
func (*Client) GetAccountInfo ¶
func (c *Client) GetAccountInfo(symbol string) (result AccountInfoResult, err error)
GetAccountInfo 获取用户账户信息
func (*Client) GetContractIndex ¶
func (c *Client) GetContractIndex(symbol string) (result ContractIndexResult, err error)
*
func (*Client) GetContractInfo ¶
func (c *Client) GetContractInfo(symbol, contractType, contractCode string) (result ContractInfoResult, err error)
*
- 期货行情 https://huobiapi.github.io/docs/dm/v1/cn/#0737c93bf7 *
- @param symbol
- "BTC","ETH"...
- @param contractType
- 合约类型: this_week:当周 next_week:下周 quarter:季度
- @param contract_code
- 合约code: BTC200320
- @return
func (*Client) GetHisOrders ¶
func (c *Client) GetHisOrders(symbol string, tradeType int, _type int, status int, createDate int, pageIndex int, pageSize int, contractCode string, orderType string) (result HisOrdersResult, err error)
GetHisOrders 获取合约历史委托
func (*Client) GetKLine ¶
func (c *Client) GetKLine(symbol string, period string, size int, from int64, to int64) (result KLineResult, err error)
获取K线数据 https://huobiapi.github.io/docs/dm/v1/cn/#k symbol true string 合约名称 如"BTC_CW"表示BTC当周合约,"BTC_NW"表示BTC次周合约,"BTC_CQ"表示BTC季度合约 period true string K线类型 1min, 5min, 15min, 30min, 60min,4hour,1day, 1mon size false integer 获取数量 150 [1,2000] from false integer 开始时间戳 10位 单位S to false integer 结束时间戳 10位 单位S
func (*Client) GetMarketDepth ¶
func (c *Client) GetMarketDepth(symbol string, _type string) (result MarketDepthResult, err error)
GetMarketDepth 获取行情深度数据 如"BTC_CW"表示BTC当周合约,"BTC_NW"表示BTC次周合约,"BTC_CQ"表示BTC季度合约 获得150档深度数据,使用step0, step1, step2, step3, step4, step5(step1至step5是进行了深度合并后的深度),使用step0时,不合并深度获取150档数据;获得20档深度数据,使用 step6, step7, step8, step9, step10, step11(step7至step11是进行了深度合并后的深度),使用step6时,不合并深度获取20档数据 https://api.hbdm.com/market/depth?symbol=BTC_CQ&type=step5
func (*Client) GetOpenOrders ¶
func (c *Client) GetOpenOrders(symbol string, pageIndex int, pageSize int) (result OpenOrdersResult, err error)
GetOpenOrders 获取合约当前未成交委托单 page_index: 1,2,3...
func (*Client) GetPositionInfo ¶
func (c *Client) GetPositionInfo(symbol string) (result PositionInfoResult, err error)
GetPositionInfo 用户持仓信息
func (*Client) Heartbeat ¶
func (c *Client) Heartbeat() (result HeartbeatResult, err error)
func (*Client) LightningClosePosition ¶
func (c *Client) LightningClosePosition(symbol string, contractType string, contractCode string, volume int, direction string, clientOrderID int64, orderPriceType string) (result LightningClosePositionResult, err error)
LightningClosePosition 闪电平仓下单
func (*Client) Order ¶
func (c *Client) Order(symbol string, contractType string, contractCode string, clientOrderID int64, price float64, volume float64, direction string, offset string, leverRate int, orderPriceType string) (result OrderResult, err error)
Order 合约下单 https://huobiapi.github.io/docs/dm/v1/cn/#9dc85ffb46
symbol string true "BTC","ETH"... contract_type string true 合约类型 ("this_week":当周 "next_week":下周 "quarter":季度) contract_code string true BTC180914 client_order_id long false 客户自己填写和维护,必须为数字 price decimal false 价格 volume long true 委托数量(张) direction string true "buy":买 "sell":卖 offset string true "open":开 "close":平 lever_rate int true 杠杆倍数[“开仓”若有10倍多单,就不能再下20倍多单] order_price_type string true 订单报价类型 "limit":限价 "opponent":对手价 "post_only":只做maker单,post only下单只受用户持仓数量限制,optimal_5:最优5档、optimal_10:最优10档、optimal_20:最优20档,ioc:IOC订单,fok:FOK订单, "opponent_ioc": 对手价-IOC下单,"optimal_5_ioc":最优5档-IOC下单,"optimal_10_ioc":最优10档-IOC下单,"optimal_20_ioc":最优20档-IOC下单,"opponent_fok": 对手价-FOK下单,"optimal_5_fok":最优5档-FOK下单,"optimal_10_fok":最优10档-FOK下单,"optimal_20_fok":最优20档-FOK下单
type ContractIndex ¶
type ContractIndexResult ¶
type ContractIndexResult struct { Status string `json:"status"` ErrCode int `json:"err_code"` ErrMsg string `json:"err_msg"` Data []ContractIndex `json:"data"` Ts int64 `json:"ts"` }
type ContractInfo ¶
type ContractInfo struct { Symbol string `json:"symbol"` ContractCode string `json:"contract_code"` ContractType string `json:"contract_type"` ContractSize float64 `json:"contract_size"` PriceTick float64 `json:"price_tick"` DeliveryDate string `json:"delivery_date"` CreateDate string `json:"create_date"` ContractStatus int `json:"contract_status"` }
type ContractInfoResult ¶
type ContractInfoResult struct { Status string `json:"status"` ErrCode int `json:"err_code"` ErrMsg string `json:"err_msg"` Data []ContractInfo `json:"data"` Ts int64 `json:"ts"` }
type HeartbeatResult ¶
type HisOrdersData ¶
type HisOrdersResult ¶
type HisOrdersResult struct { Status string `json:"status"` ErrCode int `json:"err_code"` ErrMsg string `json:"err_msg"` Data HisOrdersData `json:"data"` Ts int64 `json:"ts"` }
type KLineResult ¶
type MarketDepthResult ¶
type NWS ¶
NWS WebSocket 订单和用户数据接口
func NewNWS ¶
NewNWS 创建 NWS wsURL: 正式地址 wss://api.hbdm.com/notification 开发地址 wss://api.btcgateway.pro/notification
func (*NWS) SetAccountsCallback ¶
func (ws *NWS) SetAccountsCallback(callback func(accounts *WSAccounts))
func (*NWS) SetLiquidationOrdersCallback ¶
func (ws *NWS) SetLiquidationOrdersCallback(callback func(liquidationOrders *WSLiquidationOrders))
func (*NWS) SetMatchOrdersCallback ¶
func (ws *NWS) SetMatchOrdersCallback(callback func(order *WSMatchOrder))
func (*NWS) SetOrdersCallback ¶
func (*NWS) SetPositionsCallback ¶
func (ws *NWS) SetPositionsCallback(callback func(positions *WSPositions))
func (*NWS) SetProxy ¶
SetProxy 设置代理地址 porxyURL: socks5://127.0.0.1:1080 https://127.0.0.1:1080
func (*NWS) SubscribeAccounts ¶
SubscribeAccounts 订阅资产变动数据 symbol: BTC
func (*NWS) SubscribeLiquidationOrders ¶
SubscribeLiquidationOrders 订阅强平订单数据 symbol: BTC
func (*NWS) SubscribeMatchOrders ¶
SubscribeMatchOrders 订阅撮合订单成交数据 symbol: BTC
func (*NWS) SubscribeOrders ¶
SubscribeOrders 订阅订单成交数据 symbol: BTC
func (*NWS) SubscribePositions ¶
SubscribePositions 订阅持仓变动更新数据 symbol: BTC
func (*NWS) SubscribeTopic ¶
SubscribeTopic 订阅
type OpenOrdersData ¶
type OpenOrdersResult ¶
type OpenOrdersResult struct { Status string `json:"status"` ErrCode int `json:"err_code"` ErrMsg string `json:"err_msg"` Data OpenOrdersData `json:"data"` Ts int64 `json:"ts"` }
type Order ¶
type Order struct { Symbol string `json:"symbol"` ContractCode string `json:"contract_code"` ContractType string `json:"contract_type"` Volume float64 `json:"volume"` Price float64 `json:"price"` OrderPriceTypeRaw sjson.RawMessage `json:"order_price_type"` // 1限价单,3对手价,4闪电平仓,5计划委托,6post_only OrderType int `json:"order_type"` Direction string `json:"direction"` Offset string `json:"offset"` LeverRate int `json:"lever_rate"` OrderID int64 `json:"order_id"` ClientOrderID string `json:"client_order_id"` CreatedAt int64 `json:"created_at"` TradeVolume float64 `json:"trade_volume"` TradeTurnover float64 `json:"trade_turnover"` Fee float64 `json:"fee"` TradeAvgPrice float64 `json:"trade_avg_price"` MarginFrozen float64 `json:"margin_frozen"` Profit float64 `json:"profit"` Status int `json:"status"` OrderSource string `json:"order_source"` OrderIDStr string `json:"order_id_str"` FeeAsset string `json:"fee_asset"` LiquidationType string `json:"liquidation_type"` CreateDate int64 `json:"create_date"` }
func (*Order) OrderPriceType ¶
type OrderInfoResult ¶
type OrderResult ¶
type Position ¶
type Position struct { Symbol string `json:"symbol"` ContractCode string `json:"contract_code"` ContractType string `json:"contract_type"` Volume float64 `json:"volume"` Available float64 `json:"available"` Frozen float64 `json:"frozen"` CostOpen float64 `json:"cost_open"` CostHold float64 `json:"cost_hold"` ProfitUnreal float64 `json:"profit_unreal"` ProfitRate float64 `json:"profit_rate"` LeverRate float64 `json:"lever_rate"` PositionMargin float64 `json:"position_margin"` Direction string `json:"direction"` Profit float64 `json:"profit"` LastPrice float64 `json:"last_price"` }
type PositionInfoResult ¶
type WS ¶
WS WebSocket 市场行情接口
func (*WS) SetDepthCallback ¶
func (*WS) SetDepthHFCallback ¶
func (*WS) SetProxy ¶
SetProxy 设置代理地址 porxyURL: socks5://127.0.0.1:1080 https://127.0.0.1:1080
func (*WS) SetTickerCallback ¶
func (*WS) SetTradeCallback ¶
func (*WS) SubscribeDepth ¶
SubscribeDepth 订阅 Market Depth 数据 id: 订阅的编号 symbol: BTC_CQ
func (*WS) SubscribeDepthHF ¶
SubscribeDepthHF 订阅增量深度 size: 20/150 档位数,20:表示20档不合并的深度,150:表示150档不合并的深度 dateType: 数据类型,不填默认为全量数据,"incremental":增量数据,"snapshot":全量数据
func (*WS) SubscribeTicker ¶
SubscribeTicker 订阅 Market Ticker 数据 id: 订阅的编号 symbol: BTC_CQ
func (*WS) SubscribeTrade ¶
SubscribeTrade 订阅 Market Trade 数据 id: 订阅的编号 symbol: BTC_CQ
type WSAccountData ¶
type WSAccountData struct { Symbol string `json:"symbol"` MarginBalance float64 `json:"margin_balance"` MarginStatic float64 `json:"margin_static"` MarginPosition float64 `json:"margin_position"` MarginFrozen float64 `json:"margin_frozen"` MarginAvailable float64 `json:"margin_available"` ProfitReal float64 `json:"profit_real"` ProfitUnreal float64 `json:"profit_unreal"` WithdrawAvailable float64 `json:"withdraw_available"` RiskRate float64 `json:"risk_rate"` LiquidationPrice float64 `json:"liquidation_price"` LeverRate float64 `json:"lever_rate"` AdjustFactor float64 `json:"adjust_factor"` }
type WSAccounts ¶
type WSAccounts struct { Op string `json:"op"` Topic string `json:"topic"` Ts int64 `json:"ts"` Event string `json:"event"` Data []WSAccountData `json:"data"` }
type WSLiquidationOrders ¶
type WSLiquidationOrders struct { Op string `json:"op"` Topic string `json:"topic"` Ts int64 `json:"ts"` Symbol string `json:"symbol"` ContractCode string `json:"contract_code"` Direction string `json:"direction"` Offset string `json:"offset"` Volume float64 `json:"volume"` Price float64 `json:"price"` CreatedAt int64 `json:"created_at"` }
type WSMatchOrder ¶
type WSMatchOrder struct { Op string `json:"op"` Topic string `json:"topic"` Ts int64 `json:"ts"` Symbol string `json:"symbol"` ContractType string `json:"contract_type"` ContractCode string `json:"contract_code"` Status int `json:"status"` OrderID int64 `json:"order_id"` OrderIDStr string `json:"order_id_str"` OrderType int `json:"order_type"` Trade []WSMyTrade `json:"trade"` }
type WSMyTrade ¶
type WSMyTrade struct { ID string `json:"id"` TradeID int64 `json:"trade_id"` TradeVolume float64 `json:"trade_volume"` TradePrice float64 `json:"trade_price"` TradeFee float64 `json:"trade_fee"` TradeTurnover float64 `json:"trade_turnover"` CreatedAt int64 `json:"created_at"` Role string `json:"role"` }
type WSOrder ¶
type WSOrder struct { Op string `json:"op"` Topic string `json:"topic"` Ts int64 `json:"ts"` Symbol string `json:"symbol"` ContractType string `json:"contract_type"` ContractCode string `json:"contract_code"` Volume float64 `json:"volume"` Price float64 `json:"price"` OrderPriceType string `json:"order_price_type"` Direction string `json:"direction"` Offset string `json:"offset"` Status int `json:"status"` LeverRate float64 `json:"lever_rate"` OrderID int64 `json:"order_id"` OrderIDStr string `json:"order_id_str"` ClientOrderID int64 `json:"client_order_id"` OrderSource string `json:"order_source"` OrderType int `json:"order_type"` CreatedAt int64 `json:"created_at"` TradeVolume float64 `json:"trade_volume"` TradeTurnover float64 `json:"trade_turnover"` Fee float64 `json:"fee"` TradeAvgPrice float64 `json:"trade_avg_price"` MarginFrozen float64 `json:"margin_frozen"` Profit float64 `json:"profit"` Trade []WSMyTrade `json:"trade"` LiquidationType string `json:"liquidation_type"` }
type WSPositionData ¶
type WSPositionData struct { Symbol string `json:"symbol"` ContractCode string `json:"contract_code"` ContractType string `json:"contract_type"` Volume float64 `json:"volume"` Available float64 `json:"available"` Frozen float64 `json:"frozen"` CostOpen float64 `json:"cost_open"` CostHold float64 `json:"cost_hold"` ProfitUnreal float64 `json:"profit_unreal"` ProfitRate float64 `json:"profit_rate"` Profit float64 `json:"profit"` PositionMargin float64 `json:"position_margin"` LeverRate float64 `json:"lever_rate"` Direction string `json:"direction"` LastPrice float64 `json:"last_price"` }
type WSPositions ¶
type WSPositions struct { Op string `json:"op"` Topic string `json:"topic"` Ts int64 `json:"ts"` Event string `json:"event"` Data []WSPositionData `json:"data"` }
type WSTicker ¶
type WSTicker struct { Ch string `json:"ch"` Ts int64 `json:"ts"` Tick WSTickerTick `json:"tick"` }
type WSTickerTick ¶
type WSTrade ¶
type WSTrade struct { Ch string `json:"ch"` Ts int64 `json:"ts"` Tick WSTradeTick `json:"tick"` }
type WSTradeItem ¶
type WSTradeTick ¶
type WSTradeTick struct { ID int64 `json:"id"` Ts int64 `json:"ts"` Data []WSTradeItem `json:"data"` }