Skip to content

Huobi api for Golang. 火币交割合约和永续合约接口.

License

Notifications You must be signed in to change notification settings

f0cii/huobi-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

huobi-api

Huobi api for Golang. 火币交割合约和永续合约接口.

An implementation of Huobi-DM API and Huobi-DM-Swap API.

Installation

go get github.com/frankrap/huobi-api

Usage

package main

import (
	"github.com/frankrap/huobi-api/hbdm"
	"log"
)

func main() {
	accessKey := "[Access Key]"
	secretKey := "[Secret Key]"

	baseURL := "https://api.hbdm.com"
	//baseURL := "https://api.btcgateway.pro"
	apiParams := &hbdm.ApiParameter{
		Debug:              true,
		AccessKey:          accessKey,
		SecretKey:          secretKey,
		EnablePrivateSign:  false,
		Url:                baseURL,
		PrivateKeyPrime256: "",
	}
	client := hbdm.NewClient(apiParams)

	client.GetAccountInfo("BTC")
	orderResult, err := client.Order("BTC",
		"this_week",
		"",
		0,
		3000.0,
		1,
		"buy",
		"open",
		10,
		"limit")
	if err != nil {
		log.Fatal(err)
		return
	}
	log.Printf("%#v", orderResult)

	orders, err := client.GetOpenOrders(
		"BTC",
		0,
		0,
	)
	if err != nil {
		log.Fatal(err)
		return
	}
	log.Printf("%#v", orders)
}

Usage WebSocket

package main

import (
	"github.com/frankrap/huobi-api/hbdm"
	"log"
)

func main() {
	wsURL := "wss://api.hbdm.com/ws"
	//wsURL := "wss://api.btcgateway.pro/ws"
	ws := hbdm.NewWS(wsURL, "", "")

	// 设置Ticker回调
	ws.SetTickerCallback(func(ticker *hbdm.WSTicker) {
		log.Printf("ticker: %#v", ticker)
	})
	// 设置Depth回调
	ws.SetDepthCallback(func(depth *hbdm.WSDepth) {
		log.Printf("depth: %#v", depth)
	})
	// 设置Trade回调
	ws.SetTradeCallback(func(trade *hbdm.WSTrade) {
		log.Printf("trade: %#v", trade)
	})

	// 订阅Ticker
	ws.SubscribeTicker("ticker_1", "BTC_CQ")
	// 订阅Depth
	ws.SubscribeDepth("depth_1", "BTC_CQ")
	// 订阅Trade
	ws.SubscribeTrade("trade_1", "BTC_CQ")
	// 启动WS
	ws.Start()

	select {}
}

About

Huobi api for Golang. 火币交割合约和永续合约接口.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages