Git Product home page Git Product logo

huobi-api's Introduction

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 {}
}

huobi-api's People

Contributors

f0cii avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.