go-bittrex

module
Version: v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: MIT

README

go-bittrex

Test Lint codecov Go Report Card GoDoc

go-bittrex is a Go client library for accessing the Bittrex API.

Install

go get github.com/alexjorgef/go-bittrex

Quick Start

Check more advanced examples here.

REST API
package main

import (
	"fmt"
	"log"

	"github.com/alexjorgef/go-bittrex/bittrex"
)

func main() {
	client := bittrex.New("", "")
	currency, err := client.GetCurrency("ETH")
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Printf("%+v\n", currency)
}
Websocket
package main

import (
	"fmt"
	"log"
	"time"

	"github.com/alexjorgef/go-bittrex/bittrex"
)

func main() {
	// Bittrex client
	client := bittrex.New("", "")

	// Open channels and start a websocket connection that write to it
	ch := make(chan bittrex.Ticker)
	errCh := make(chan error)
	stopCh := make(chan bool)
	go func() { errCh <- client.SubscribeTickerUpdates("BTC-USD", ch, stopCh) }()
	go func() { errCh <- client.SubscribeTickerUpdates("ETH-USD", ch, stopCh) }()
	go func() { errCh <- client.SubscribeTickerUpdates("ADA-USD", ch, stopCh) }()

	// Read from ticker/error channels only 1 time
	select {
	case ticker := <-ch:
		fmt.Printf("%+v\n", ticker)
	case err := <-errCh:
		fmt.Printf("%+v\n", err)
	}

	// Read from channels and stop after 35 seconds
	for start := time.Now(); time.Since(start) < (35 * time.Second); {
		select {
		case ticker := <-ch:
			fmt.Printf("%+v\n", ticker)
		case err := <-errCh:
			fmt.Printf("%+v\n", err)
		}
	}

	// Read from channels infinitely
	for {
		select {
		case ticker := <-ch:
			fmt.Printf("%+v\n", ticker)
		case err := <-errCh:
			fmt.Printf("%+v\n", err)
		}
	}
}

References

This repository is a cleaned & updated version of toorop/go-bittrex repo (inspired from alexeykaravan/go-bittrex-v3 fork).

Directories

Path Synopsis
Package bittrex is an implementation of the Biitrex API in Golang.
Package bittrex is an implementation of the Biitrex API in Golang.

Jump to

Keyboard shortcuts

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