A more elegant Client for huobi API with golang

huobi

A more elegant Client for huobi API

example

package main

import (
	"context"
	"log"
	"os"

	"github.com/zhenzou/huobi"
	"github.com/zhenzou/huobi/common"
	"github.com/zhenzou/huobi/config"
	"github.com/zhenzou/huobi/futures"
)

var (
	futureAPi = huobi.NewFutureAPi(config.Config{
		AccessKey: os.Getenv("HUOBI_ACCESS_KEY"),
		SecretKey: os.Getenv("HUOBI_SECRET_KEY"),
		Debug:     true,
	})
	spotAPI = huobi.NewSpotAPI(config.Config{
		Host: "api.huobi.pro",
	})
)

func GetContracts() {
	contracts, err := futureAPi.Market.ListContractInfos(context.Background(), "DOGE-USDT")
	if err != nil {
		panic(err)
	}
	for _, c := range contracts {
		log.Println("contract ", c)
	}
}

func SubscribeFutureTrade(id string) {
	ch, err := futureAPi.Market.SubTradeDetail(context.Background(), "DOGE-USDT")
	if err != nil {
		panic(err)
	}

	for item := range ch {
		log.Println("future ", item)
	}
}

func SubscribeSpotTrade() {
	ch, err := spotAPI.Market.SubTradeDetail(context.Background(), "dogeusdt")
	if err != nil {
		panic(err)
	}
	for resp := range ch {
		log.Println("spot ", resp)
	}
}

func SubscribeKLine() {
	ch, err := futureAPi.Market.SubKLine(context.Background(), "DOGE-USDT", "1min")
	if err != nil {
		panic(err)
	}

	for item := range ch {
		log.Println("kline ", item)
	}
}

func SubscribeBasis() {
	ch, err := futureAPi.Index.SubBasis(context.Background(), "DOGE-USDT", "1min", "")
	if err != nil {
		panic(err)
	}

	for item := range ch {
		log.Println("kline ", item)
	}
}

func RequestTrade() {
	resp, err := futureAPi.Market.ReqTradeDetail(context.Background(), "DOGE-USDT")
	if err != nil {
		panic(err)
	}
	for _, datum := range resp.Data {
		log.Println("trade ", datum)
	}
}

func SubscribeOrder() {
	ch, err := futureAPi.Order.SubOrders(context.Background(), "DOGE-USDT")
	if err != nil {
		panic(err)
	}
	for order := range ch {
		log.Println("order ", order)
	}
}

func ListOpenTriggerOrders() {
	orders, _, err := futureAPi.Order.ListOpenTriggerOrders(context.Background(), futures.ListOrdersRequest{
		ContractCode: "DOGE-USDT",
	})
	if err != nil {
		panic(err)
	}
	for _, order := range orders {
		log.Println("order ", order)
	}
}

func ListOrders() {
	orders, _, err := futureAPi.Order.ListHistoryOrders(context.Background(), futures.ListOrdersRequest{
		ContractCode: "DOGE-USDT",
		Type:         1,
	})
	if err != nil {
		panic(err)
	}
	for _, order := range orders {
		log.Println("order ", order)
	}
}

func CreateOrder(ctx context.Context) string {
	id, err := futureAPi.Order.CreateTriggerOrder(ctx, futures.CreateTriggerOrderRequest{
		ContractCode:   "DOGE-USDT",
		TriggerType:    "ge",
		TriggerPrice:   0.08602,
		Volume:         10,
		Direction:      "buy",
		Offset:         "open",
		LeverRate:      2,
		OrderPriceType: "optimal_5",
	})
	if err != nil {
		panic(err)
	}
	return id
}

func CancelOrder(id string) {
	err := futureAPi.Order.CancelTriggerOrder(context.Background(), "DOGE-USDT", id)
	if err != nil {
		panic(err)
	}
	println("canceled:" + id)
}

func main() {
	//log.SetLevel(log.DebugLevel)

	go SubscribeFutureTrade("1")
	go SubscribeSpotTrade()
	//go SubscribeFutureTrade("2")
	//RequestTrade()
	//SubscribeOrder()
	//SubscribeKLine()
	//SubscribeBasis()
	//ListOpenTriggerOrders()
	//ListOrders()

	//orderID := CreateOrder(context.Background())

	common.WaitStopSignal()
}
Owner
september
A Software Development Engineer
september
Similar Resources

A phoenix Chain client based on the go-ethereum fork,the new PoA consensus engine is based on the VRF algorithm.

Phoenix Official Golang implementation of the Phoenix protocol. !!!The current version is for testing and developing purposes only!!! Building the sou

Apr 28, 2022

A Go client and CLI for Filecoin Storage Auctions.

go-auctions-client A Go library and CLI to interact with Filecoin Storage Auctions. Join us on our public Slack channel for news, discussions, and sta

Nov 24, 2022

Akroma GO client - Akroma is an EVM based application development platform (smart-contracts).

Akroma Akroma is an EVM based application development platform (smart-contracts). Akroma will utilize a Masternode system, and build out an Oracle pla

Dec 11, 2022

Tool for monitoring your Ethereum clients. Client-agnostic as it queries the standardized JSON-RPC APIs

Tool for monitoring your Ethereum clients. Client-agnostic as it queries the standardized JSON-RPC APIs

e7mon Tool for monitoring your Ethereum clients. Client-agnostic as it queries the standardized JSON-RPC APIs. However, the execution client should be

Dec 20, 2022

Yet another filecoin secondary retrieval client

Yet another filecoin secondary retrieval client

fcr Yet another filecoin secondary retrieval client FCR is a filecoin secondary retrieval client featured with the ability to participate in an ipld r

Nov 9, 2022

LEO (Low Ethereum Orbit) is an Ethereum Portal Network client.

LEO LEO (Low Ethereum Orbit) is an Ethereum Portal Network client. What makes LEO different from other Portal Network clients is that it uses libp2p f

Apr 19, 2022

A Commander for Go implementation of official Ethereum Client

Young A Commander for Go implementation of official Ethereum Client by zhong-my. Overview Young Dependencies Young stands on the shoulder of many grea

Oct 14, 2021

Package pinentry provides a client to GnuPG's pinentry.

Package pinentry provides a client to GnuPG's pinentry.

Dec 9, 2022

A Binance Smart Chain client based on the go-ethereum fork

A Binance Smart Chain client based on the go-ethereum fork

Dec 31, 2022
Related tags
Huobi Eco Chain client based on the go-ethereum fork

The Huobi Open Platform is a unified infrastructure platform based on the technical, traffic and ecological resources of the Huobi Group, and will be gradually open to the blockchain industry.

Dec 31, 2022
Accompanying repository for the "Build Ethereum From Scratch - Smart Contracts and More" course by David Katz
Accompanying repository for the

Build Ethereum From Scratch - Smart Contracts and More This repository accompanies the "Build Ethereum From Scratch - Smart Contracts and More" course

Dec 7, 2022
List your dependencies capabilities and monitor if updates require more capabilities.

A take on supply chain security in Go List your dependencies capabilities and monitor if dependency updates require more capabilities. The Problem Rec

Nov 16, 2022
The Fabric Smart Client is a new Fabric Client that lets you focus on the business processes and simplifies the development of Fabric-based distributed application.

Fabric Smart Client The Fabric Smart Client (FSC, for short) is a new Fabric client-side component whose objective is twofold. FSC aims to simplify th

Dec 14, 2022
Go-block-api - Golang implementation of Ethereum Block API

Go Ethereum Block API Golang implementation of Ethereum Block API This API can s

Jan 13, 2022
Terra client in golang with multiple protocol implementation (anchor, astroport, prism, ...)

Terra A terra client with some protocol partial implementations (anchor, prism, terraswap type routers, ...) To be able to compile, you need to add th

Apr 11, 2022
A command line Crypto-currency ticker made using golang and WazirX Api
A command line Crypto-currency ticker made using golang and WazirX Api

░█████╗░██████╗░██╗░░░██╗██████╗░████████╗███████╗██╗░░██╗ ██╔══██╗██╔══██╗╚██╗░██╔╝██╔══██╗╚══██╔══╝██╔════╝╚██╗██╔╝ ██║░░╚═╝██████╔╝░╚████╔╝░██████╔

Feb 6, 2022
Rosetta-ergo provides a reference implementation of the Rosetta API for Ergo in Golang
Rosetta-ergo provides a reference implementation of the Rosetta API for Ergo in Golang

Rosetta Ergo Overview rosetta-ergo provides a reference implementation of the Rosetta API for Ergo in Golang. If you haven't heard of the Rosetta API,

Aug 9, 2022
Concurrent ssh client

go-cs Concurrent ssh client cs is a program for concurrently executing local or remote commands on multiple hosts. It is using OpenSSH for running rem

Feb 21, 2022
Yet another Binance Smart Chain client based on TrustFi Network

TrustFi Smart Chain The goal of TrustFi Smart Chain is to bring programmability and interoperability to Binance Chain. In order to embrace the existin

Mar 27, 2021