huobi-future-go

module
v0.0.0-...-0a3f110 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2019 License: Apache-2.0

README

huobi-future-go

Huobi-Futures-Go

Installation

go get github.com/banbanpeppa/huobi-future-go

Usage

Basic requests
var TICKER_ALL = []string{"BTC", "ETH", "BCH", "EOS", "LTC", "ETC", "BSV", "XRP"}

params := websocket.NewDefaultParameters()
huobiClient := websocket.NewHuobiWSClient(params)

//定义想要订阅的ws请求体
requests := []websocket.Request{}
for _, ticker := range TICKER_ALL {
    req_cw := websocket.Request{Id: "id7", Sub: "market." + ticker + "_CW.trade.detail"}
    req_nw := websocket.Request{Id: "id7", Sub: "market." + ticker + "_NW.trade.detail"}
    req_cq := websocket.Request{Id: "id7", Sub: "market." + ticker + "_CQ.trade.detail"}
    requests = append(requests, req_cw, req_nw, req_cq)
}

huobiClient.Subscribe(requests)
for obj := range huobiClient.Listen() {
    switch obj.(type) {
    case []byte:
        tradeDetail := &websocket.TradeDetail{}
        err := json.Unmarshal(obj.([]byte), &tradeDetail)
        if err == nil {
            if len(tradeDetail.Tick.Data) > 0 {
                price := tradeDetail.Tick.Data[0].Price
                fmt.Println(tradeDetail.Ch+": ", price)
            }
        }
    }
    default:
        fmt.Println("other type of obj")
}
Huobi Websocket API

合约Websocket 文档

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL