huobiapi

package module
v0.0.0-...-4f13b8d Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 4 Imported by: 0

README

Huobi现货API for Go

官方 API 文档地址:https://huobiapi.github.io/docs/spot/v1/cn/

目录

安装

go get -u https://github.com/feeeei/huobiapi-go

使用

RESTful Client

// 行情 Client
client, err := huobiapi.NewMarketClient()
// OR
// 行情 & 交易 Client
client, err := huobiapi.NewTradeClient("AccessKeyID", "AccessKeySecret")


// 获取 accounts 信息
json, _ := client.Get("/v1/account/accounts")
accounts, _ := json.Get("data").Array()
for _, account := range accounts {
    log.Println(account)
}


// 获取 btcusdt 实时价格
json, _ := client.Get("/market/trade", huobiapi.Params{"symbol": "btcusdt"})
log.Println("Current btcusdt price:", json.Get("data").Get("price").MustFloat64())


// 下单
json, _ := client.Post("/v1/order/orders/place", huobiapi.Params{
	"account-id":      "xxxxxx",
	"amount":          "1.00",
	"price":           "5000.00",
	"source":          "api",
	"symbol":          "btcusdt",
	"type":            "buy-limit",
	"client-order-id": "client-order-id",
})
// dosomething

WebSocket 行情Client

client, _ := huobiapi.NewMarketWSClient()


// 订阅 btcusdt 实时交易明细
err := client.Subscribe("market.btcusdt.trade.detail", func(topic string, json *simplejson.Json) {
    d,_ := json.Encode()
    log.Println(topic, string(d))
})
if err == nil {
    log.Println("Subscribe btcusdt successful")
}


// 取消订阅
client.UnSubscribe("market.btcusdt.trade.detail")

WebSocket 资产&订单Client

client, _ := huobiapi.NewTradeWSClient("AccessKeyID", "AccessKeySecret")


// 请求用户资产数据,阻塞式直接返回结果
json, err := client.Request("accounts.list")
if err == nil {
	d, _ := json.Encode()
	log.Println(string(d))
}


// 订阅账户更新
client.Subscribe("accounts", func(topic string, json *simplejson.Json) {
    d, _ := json.Encode()
	log.Println(string(d))
}, huobiapi.Params{"mode": 0}) // 是否包含已冻结余额


// 订阅btcusdt交易对下订单变更
client.Subscribe("orders.btcusdt.update", func(topic string, json *simplejson.Json) {
    d, _ := json.Encode()
	log.Println(string(d))
})

WebSocket-资产&订单ClientV2

client, _ := huobiapi.NewTradeWSV2Client("AccessKeyID", "AccessKeySecret")

// 订阅btcusdt订阅清算后成交明细
client.Subscribe("trade.clearing#usdthusd", func(topic string, json *simplejson.Json) {
    d, _ := json.Encode()
    log.Println(string(d))
})
// 订阅账户余额变动
client.Subscribe("accounts.update#0", func(topic string, json *simplejson.Json) {
    d, _ := json.Encode()
    log.Println(string(d))
})

其它配置

huobiapi.UseAWSHost()     // 使用aws域名,在aws网络环境下延迟更低
huobiapi.SetAPIHost("xx") // 使用自定义Host,可以使用未被墙Host来在境内使用
huobiapi.DebugMode(true)  // 是否使用Debug模式,打印日志

进度

  • RESTful 行情、账户接口
  • WebSocket 行情、资产&订单 接口
  • 替换 Host 为 aws 域名
  • WebSocket 断线重连
  • WebSocket V2版本客户端

感谢

leizongmin/huobiapi

License

feeeei/huobiapi-go is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugMode

func DebugMode(output bool)

DebugMode 是否使用Debug模式,打印日志

func SetAPIHost

func SetAPIHost(host string)

SetAPIHost 使用自定义Host

func UseAWSHost

func UseAWSHost()

UseAWSHost 使用aws域名,在aws网络下速度时延更低

Types

type MarketClient

type MarketClient = restclient.MarketClient

MarketClient REST格式市场client

func NewMarketClient

func NewMarketClient() (*MarketClient, error)

NewMarketClient 创建REST行情Client

type MarketWSClient

type MarketWSClient = wsclient.MarketWSClient

MarketWSClient WebSocket格式市场client

func NewMarketWSClient

func NewMarketWSClient() (*MarketWSClient, error)

NewMarketWSClient 创建WebSocket行情Client

type Params

type Params = map[string]interface{}

type TradeClient

type TradeClient = restclient.TradeClient

TradeClient REST格式交易client

func NewTradeClient

func NewTradeClient(accessKeyID, accessKeySecret string) (*TradeClient, error)

NewTradeClient 创建REST交易Client

type TradeWSClient

type TradeWSClient = wsclient.TradeWSClient

TradeWSClient WebSocket格式交易client

func NewTradeWSClient

func NewTradeWSClient(accessKeyID, accessKeySecret string) (*TradeWSClient, error)

NewTradeWSClient 创建WebSocket交易Client

type TradeWSV2Client

type TradeWSV2Client = wsclient.TradeWSV2Client

TradeWSV2Client WebSocket格式交易clientV2

func NewTradeWSV2Client

func NewTradeWSV2Client(accessKeyID, accessKeySecret string) (*TradeWSV2Client, error)

NewTradeWSV2Client 创建WebSocket交易Client

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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