bittrex

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 21 Imported by: 1

README

go-bittrex GoDoc

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

This version implement V1.1 Bittrex API and the new HMAC authentification.

Import

import "github.com/toorop/go-bittrex"

Usage

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

package main

import (
	"fmt"
	"github.com/toorop/go-bittrex"
)

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

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

	// Get markets
	markets, err := bittrex.GetMarkets()
	fmt.Println(err, markets)
}

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

package main

import (
	"fmt"
	"net/http"
	"time"
	"github.com/toorop/go-bittrex"
)

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

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

	// Bittrex client
	bittrex := bittrex.NewWithCustomHttpClient(API_KEY, API_SECRET, httpClient)

	// Get markets
	markets, err := bittrex.GetMarkets()
	fmt.Println(err, markets)
}

See "Examples" folder for more... examples

Documentation

GoDoc

Stay tuned

Follow me on Twitter

Donate

Donation QR

1HgpsmxV52eAjDcoNpVGpYEhGfgN7mM1JB

Documentation

Overview

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

Index

Constants

View Source
const (
	//APIBASE Bittrex API endpoint
	APIBASE = "https://api.bittrex.com/"
	//APIVERSION api version
	APIVERSION = "v3"
	//WSBASE Bittrex WS API endpoint
	WSBASE = "socket-v3.bittrex.com"
	//WSHUB SignalR main hub
	WSHUB = "C3"

	//ORDERBOOK const
	ORDERBOOK = "orderBook"
	//TICKER const
	TICKER = "ticker"
	//ORDER const
	ORDER = "order"
	//TRADE const
	TRADE = "trade"
	//HEARTBEAT const
	HEARTBEAT = "heartbeat"
	//AUTHEXPIRED const
	AUTHEXPIRED = "authenticationExpiring"
)
View Source
const TIMEFORMAT = "2006-01-02T15:04:05.999Z"

TIMEFORMAT const

Variables

View Source
var CANDLEINTERVALS = map[string]bool{
	"oneMin":    true,
	"fiveMin":   true,
	"thirtyMin": true,
	"hour":      true,
	"day":       true,
}

CANDLEINTERVALS variable

Functions

This section is empty.

Types

type Address

type Address struct {
	Currency string `json:"Currency"`
	Address  string `json:"Address"`
}

Address struct

type Balance

type Balance struct {
	CurrencySymbol string          `json:"currencySymbol"`
	Total          decimal.Decimal `json:"total"`
	Available      decimal.Decimal `json:"available"`
	UpdatedAt      *jTime          `json:"updatedAt"`
}

Balance struct

type BalanceD

type BalanceD struct {
	BalanceD decimal.Decimal `json:"Balance"`
}

BalanceD struct

type Bittrex

type Bittrex struct {
	// contains filtered or unexported fields
}

Bittrex represent a Bittrex client

func New

func New(apiKey, apiSecret string) *Bittrex

New returns an instantiated bittrex struct

func NewWithCustomHTTPClient

func NewWithCustomHTTPClient(apiKey, apiSecret string, httpClient *http.Client) *Bittrex

NewWithCustomHTTPClient returns an instantiated bittrex struct with custom http client

func NewWithCustomTimeout

func NewWithCustomTimeout(apiKey, apiSecret string, timeout time.Duration) *Bittrex

NewWithCustomTimeout returns an instantiated bittrex struct with custom timeout

func (*Bittrex) Authentication

func (b *Bittrex) Authentication(c *signalr.Client) error

Authentication func

func (*Bittrex) CancelOrder

func (b *Bittrex) CancelOrder(orderID string) (respone []byte, err error)

CancelOrder is used to cancel a buy or sell order.

func (*Bittrex) GetBalances

func (b *Bittrex) GetBalances() (balances []Balance, err error)

GetBalances is used to retrieve all balances from your account

func (*Bittrex) GetMarkets

func (b *Bittrex) GetMarkets() (markets []Market, err error)

GetMarkets is used to get the open and available trading markets at Bittrex along with other meta data.

func (*Bittrex) GetOpenOrders

func (b *Bittrex) GetOpenOrders(market string) (openOrders []Order, err error)

GetOpenOrders returns orders that you currently have opened.

func (*Bittrex) GetOrder

func (b *Bittrex) GetOrder(orderUUID string) (order Order, err error)

GetOrder func

func (*Bittrex) GetOrderBook

func (b *Bittrex) GetOrderBook(book *OrderBook) (err error)

GetOrderBook is used to get the current orderbook values for a market.

func (*Bittrex) GetOrderHistory

func (b *Bittrex) GetOrderHistory(market string) (orders []Order, err error)

GetOrderHistory used to retrieve your order history. market string literal for the market (ie. BTC-LTC). If set to "all", will return for all market

func (*Bittrex) GetTicker

func (b *Bittrex) GetTicker(market string) (ticker Ticker, err error)

GetTicker is used to get the current ticker values for a market.

func (*Bittrex) NewOrder

func (b *Bittrex) NewOrder(order NewOrder) (response []byte, err error)

NewOrder is used to place a order in a specific market.

func (*Bittrex) SetDebug

func (b *Bittrex) SetDebug(enable bool)

SetDebug set enable/disable http request/response dump

func (*Bittrex) SubscribeOrderUpdates

func (b *Bittrex) SubscribeOrderUpdates(dataCh chan<- OrderUpdate) error

SubscribeOrderUpdates func

func (*Bittrex) SubscribeOrderbookUpdates

func (b *Bittrex) SubscribeOrderbookUpdates(market string, orderbook chan<- OrderBook, stop chan bool) error

SubscribeOrderbookUpdates subscribes for updates of the market. Updates will be sent to dataCh. To stop subscription, send to, or close 'stop'.

func (*Bittrex) SubscribeTickerUpdates

func (b *Bittrex) SubscribeTickerUpdates(market string, quotes chan<- Quote) error

SubscribeTickerUpdates subscribes for updates of the market.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client struct

func NewClient

func NewClient(apiKey, apiSecret string) (c *Client)

NewClient return a new Bittrex HTTP client

func NewClientWithCustomHTTPConfig

func NewClientWithCustomHTTPConfig(apiKey, apiSecret string, httpClient *http.Client) (c *Client)

NewClientWithCustomHTTPConfig returns a new Bittrex HTTP client using the predefined http client

func NewClientWithCustomTimeout

func NewClientWithCustomTimeout(apiKey, apiSecret string, timeout time.Duration) (c *Client)

NewClientWithCustomTimeout returns a new Bittrex HTTP client with custom timeout

type Currency

type Currency struct {
	Currency        string          `json:"Currency"`
	CurrencyLong    string          `json:"CurrencyLong"`
	MinConfirmation int             `json:"MinConfirmation"`
	TxFee           decimal.Decimal `json:"TxFee"`
	IsActive        bool            `json:"IsActive"`
	CoinType        string          `json:"CoinType"`
	BaseAddress     string          `json:"BaseAddress"`
	Notice          string          `json:"Notice"`
}

Currency struct

type Deposit

type Deposit struct {
	ID            int64           `json:"Id"`
	Amount        decimal.Decimal `json:"Amount"`
	Currency      string          `json:"Currency"`
	Confirmations int             `json:"Confirmations"`
	LastUpdated   jTime           `json:"LastUpdated"`
	TxID          string          `json:"TxId"`
	CryptoAddress string          `json:"CryptoAddress"`
}

Deposit struct

type Distribution

type Distribution struct {
	Distribution   []BalanceD      `json:"Distribution"`
	Balances       decimal.Decimal `json:"Balances"`
	AverageBalance decimal.Decimal `json:"AverageBalance"`
}

Distribution struct

type Market

type Market struct {
	Symbol              string          `json:"symbol"`
	BaseCurrencySymbol  string          `json:"baseCurrencySymbol"`
	QuoteCurrencySymbol string          `json:"quoteCurrencySymbol"`
	MinTradeSize        decimal.Decimal `json:"minTradeSize"`
	Precision           int             `json:"precision"`
	Status              string          `json:"status"`
	CreatedAt           jTime           `json:"createdAt"`
	Notice              string          `json:"notice"`
	ProhibitedIn        []string        `json:"prohibitedIn"`
}

Market struct

type MarketSummary

type MarketSummary struct {
	MarketName     string          `json:"MarketName"`
	High           decimal.Decimal `json:"High"`
	Low            decimal.Decimal `json:"Low"`
	Ask            decimal.Decimal `json:"Ask"`
	Bid            decimal.Decimal `json:"Bid"`
	OpenBuyOrders  int             `json:"OpenBuyOrders"`
	OpenSellOrders int             `json:"OpenSellOrders"`
	Volume         decimal.Decimal `json:"Volume"`
	Last           decimal.Decimal `json:"Last"`
	BaseVolume     decimal.Decimal `json:"BaseVolume"`
	PrevDay        decimal.Decimal `json:"PrevDay"`
	TimeStamp      string          `json:"TimeStamp"`
}

MarketSummary struct

type NewOrder

type NewOrder struct {
	MarketSymbol  string `json:"marketSymbol"`
	Direction     string `json:"direction"`
	Type          string `json:"type"`
	Quantity      string `json:"quantity"`
	Ceiling       string `json:"ceiling,omitempty"`
	Limit         string `json:"limit,omitempty"`
	TimeInForce   string `json:"timeInForce"`
	ClientOrderID string `json:"clientOrderId,omitempty"`
	UseAwards     bool   `json:"useAwards"`
}

NewOrder struct

type Order

type Order struct {
	ID            string          `json:"id"`
	MarketSymbol  string          `json:"marketSymbol"`
	Direction     string          `json:"direction"`
	Type          string          `json:"type"`
	Quantity      decimal.Decimal `json:"quantity"`
	Limit         decimal.Decimal `json:"limit"`
	Ceiling       decimal.Decimal `json:"ceiling"`
	TimeInForce   string          `json:"timeInForce"`
	ClientOrderID string          `json:"clientOrderId"`
	FillQuantity  decimal.Decimal `json:"fillQuantity"`
	Commission    decimal.Decimal `json:"commission"`
	Proceeds      decimal.Decimal `json:"proceeds"`
	Status        string          `json:"status"`
	CreatedAt     jTime           `json:"createdAt"`
	UpdatedAt     *jTime          `json:"updatedAt"`
	ClosedAt      *jTime          `json:"closedAt"`
	OrderToCancel struct {
		Type string `json:"type"`
		ID   string `json:"id"`
	} `json:"orderToCancel"`
}

Order struct

type OrderBook

type OrderBook struct {
	MarketSymbol string       `json:"marketSymbol"`
	Depth        int          `json:"depth"`
	Sequence     int          `json:"sequence"`
	BidDeltas    []OrderDelta `json:"bidDeltas"`
	AskDeltas    []OrderDelta `json:"askDeltas"`
}

OrderBook struct

type OrderBook2

type OrderBook2 struct {
	BidDeltas []OrderDelta `json:"bid"`
	AskDeltas []OrderDelta `json:"ask"`
}

OrderBook2 struct

type OrderDelta

type OrderDelta struct {
	Quantity decimal.Decimal `json:"quantity"`
	Rate     decimal.Decimal `json:"rate"`
}

OrderDelta struct

type OrderUpdate

type OrderUpdate struct {
	AccountID string `json:"accountId"`
	Sequence  int    `json:"sequence"`
	Delta     struct {
		ID           string `json:"id"`
		MarketSymbol string `json:"marketSymbol"`
		Direction    string `json:"direction"`
		Type         string `json:"type"`
		Quantity     string `json:"quantity"`
		Limit        string `json:"limit"`
		TimeInForce  string `json:"timeInForce"`
		FillQuantity string `json:"fillQuantity"`
		Commission   string `json:"commission"`
		Proceeds     string `json:"proceeds"`
		Status       string `json:"status"`
		CreatedAt    jTime  `json:"createdAt"`
		UpdatedAt    *jTime `json:"updatedAt"`
		ClosedAt     *jTime `json:"closedAt"`
	} `json:"delta"`
}

OrderUpdate struct

type Quote

type Quote struct {
	Symbol string
	Last   decimal.Decimal
	Bid    decimal.Decimal
	Ask    decimal.Decimal
	Volume decimal.Decimal
}

type Responce

type Responce struct {
	Success   bool        `json:"Success"`
	ErrorCode interface{} `json:"ErrorCode"`
}

Responce struct

type Ticker

type Ticker struct {
	Symbol        string
	LastTradeRate decimal.Decimal `json:"lastTradeRate"`
	BidRate       decimal.Decimal `json:"bidRate"`
	AskRate       decimal.Decimal `json:"askRate"`
}

Ticker struct

type Trade

type Trade struct {
	OrderUUID int64           `json:"Id"`
	Timestamp jTime           `json:"TimeStamp"`
	Quantity  decimal.Decimal `json:"Quantity"`
	Price     decimal.Decimal `json:"Price"`
	Total     decimal.Decimal `json:"Total"`
	FillType  string          `json:"FillType"`
	OrderType string          `json:"OrderType"`
}

Trade Used in getmarkethistory

type TradeUpdate

type TradeUpdate struct {
	Deltas []struct {
		ID         string          `json:"id"`
		ExecutedAt time.Time       `json:"executedAt"`
		Quantity   decimal.Decimal `json:"quantity"`
		Rate       decimal.Decimal `json:"rate"`
		TakerSide  string          `json:"takerSide"`
	} `json:"deltas"`
	Sequence     int    `json:"sequence"`
	MarketSymbol string `json:"marketSymbol"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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