Coder Social home page Coder Social logo

go-hitbtc's Introduction

go-hitbtc

go-hitbtc is an implementation of the HitBTC API (public and private) in Golang.

This version implement V2 HitBTC API.

Import

import "github.com/bitbandi/go-hitbtc"

Usage

In order to use the client with go's default http client settings you can do:

package main

import (
	"fmt"
	"github.com/bitbandi/go-hitbtc"
)

const (
	API_KEY    = "YOUR_API_KEY"
	API_SECRET = "YOUR_API_SECRET"
)

func main() {
	// hitbtc client
	hitbtc := hitbtc.New(API_KEY, API_SECRET)

	// Get balances
	balances, err := hitbtc.GetBalances()
	fmt.Println(err, balances)
}

In order to use custom settings for the http client do:

package main

import (
	"fmt"
	"net/http"
	"time"
	"github.com/bitbandi/go-hitbtc"
)

const (
	API_KEY    = "YOUR_API_KEY"
	API_SECRET = "YOUR_API_SECRET"
)

func main() {
	httpClient := &http.Client{
		Timeout: time.Second * 10,
	}

	// hitbtc client
	bc := hitbtc.NewWithCustomHttpClient(conf.hitbtc.ApiKey, conf.hitbtc.ApiSecret, httpClient)

	// Get balances
	balances, err := hitbtc.GetBalances()
	fmt.Println(err, balances)

	// Initialize websocket connection
	client, err := hitbtc.NewWSClient()
	if err != nil {
		handleError(err) // do something
	}
	defer client.Close()

	// Subscribe and handle
	tickerFeed, err := client.SubscribeTicker("ETHBTC")
	for {
		ticker := <-tickerFeed
		fmt.Println(ticker)
	}


}

See "Examples" folder for more... examples

Projects using this library

go-hitbtc's People

Contributors

bitbandi avatar dionbosschieter avatar herenow avatar saniales avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

go-hitbtc's Issues

trouble with order creation

Hi @bitbandi. Thank you for this wrapper. Unfortunately, while I am able to use most functions, I am not able to get PlaceOrder to work.

We are calling the function like so:

var am float64 = 0.082
var qt float64 = 0.02
create_hitbtc_ask(*hitbtc_client, am, qt)

//creates an ask offer on hitbtc
func create_hitbtc_ask(hitbtc_client hitbtc.HitBtc, price, amount float64) {
	payload := hitbtc.Order{}

	payload.Symbol = "ETHBTC"
	payload.Side = "sell"
	payload.Type = "limit"
	payload.TimeInForce = "GTC"
	payload.Quantity = amount
	payload.Price = price

	resp, err := hitbtc_client.PlaceOrder(payload)
	if err != nil {
		fmt.Println("error below")
		fmt.Println(err)
	}
	fmt.Println("resp below")
	fmt.Println(resp)

}

The return is: 404 Not Found

Could you provide an example of how to correctly place an order using your wrapper?

PlacerOrder Symbol not found

Hi @bitbandi

I had been using the this library to check balances and tickers, but at the moment of creating a new order, it is returning

{"error":{"code":2001,"message":"Symbol not found"}}

I checked the symbol using the function GetSymbols and checking the api endpoint from hitbtc but not luck. Also I enabled the debug mode to check the HTTP request/response and copied the payload an executed with curl and with curl it is working properly.

here is the code am using

package main

import (
	"fmt"
	"github.com/saniales/go-hitbtc"
	"log"
	//"net/http"
	//"strconv"
	//	"time"
)

const (
	API_KEY    = "XXXXXXXXXXXXXXXXXXXXXXX"
	API_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)

func main() {
	HClient := hitbtc.New(API_KEY, API_SECRET)

	HClient.SetDebug(true)

	sellOrder := hitbtc.Order{
		Symbol:      "BTCUSD",
		Side:        "sell",
		Price:       4,
		Quantity:    1,
		Type:        "limit",
		TimeInForce: "IOC",
	}
	orderNumber, err := HClient.PlaceOrder(sellOrder)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(orderNumber.ClientOrderId)
}

here is the output of the debug

2020/08/17 16:24:19 dumpReq ok:POST /api/2/order HTTP/1.1
Host: api.hitbtc.com
Accept: application/json
Authorization: Basic XXXXXXXXXXX

price=4.00000000&quantity=1.00000000&side=sell&symbol=BTCUSD&timeInForce=IOC&type=limit
2020/08/17 16:24:19 dumpResponse ok:HTTP/1.1 400 Bad Request
Content-Length: 52
Connection: keep-alive
Content-Type: application/json; charset=UTF-8
Date: Mon, 17 Aug 2020 14:24:19 GMT
Server: nginx

{"error":{"code":2001,"message":"Symbol not found"}}
2020/08/17 16:24:19 400 Bad Request
exit status 1

this is my go version, just in case

❯ go version
go version go1.14.6 linux/amd64

Thanks in advance

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.