bittrex

package module
v0.0.0-...-b7ef684 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2019 License: MIT Imports: 15 Imported by: 0

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 (
	API_BASE      = "https://bittrex.com/api/" // Bittrex API endpoint
	API_BASE_3    = "https://api.bittrex.com/" // Bittrex API endpoint
	API_VERSION   = "v1.1"
	API_VERSION_3 = "v3"
	WS_BASE       = "socket.bittrex.com" // Bittrex WS API endpoint
	WS_HUB        = "CoreHub"            // SignalR main hub
)
View Source
const TIME_FORMAT = "2006-01-02T15:04:05"

Variables

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

Functions

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)

NewClient returns a new Bittrex HTTP client with custom timeout

Types

type Address

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

type Balance

type Balance struct {
	Currency      string          `json:"Currency"`
	Balance       decimal.Decimal `json:"Balance"`
	Available     decimal.Decimal `json:"Available"`
	Pending       decimal.Decimal `json:"Pending"`
	CryptoAddress string          `json:"CryptoAddress"`
	Requested     bool            `json:"Requested"`
	Uuid          string          `json:"Uuid"`
}

type BalanceD

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

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) BuyLimit

func (b *Bittrex) BuyLimit(market string, quantity, rate decimal.Decimal) (uuid string, err error)

BuyLimit is used to place a limited buy order in a specific market.

func (*Bittrex) CancelOrder

func (b *Bittrex) CancelOrder(orderID string) (err error)

CancelOrder is used to cancel a buy or sell order.

func (*Bittrex) GetBalance

func (b *Bittrex) GetBalance(currency string) (balance Balance, err error)

Getbalance is used to retrieve the balance from your account for a specific currency. currency: a string literal for the currency (ex: LTC)

func (*Bittrex) GetBalances

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

GetBalances is used to retrieve all balances from your account

func (*Bittrex) GetCurrencies

func (b *Bittrex) GetCurrencies() (currencies []Currency, err error)

GetCurrencies is used to get all supported currencies at Bittrex along with other meta data.

func (*Bittrex) GetDepositAddress

func (b *Bittrex) GetDepositAddress(currency string) (address Address, err error)

GetDepositAddress is sed to generate or retrieve an address for a specific currency. currency a string literal for the currency (ie. BTC)

func (*Bittrex) GetDepositHistory

func (b *Bittrex) GetDepositHistory(currency string) (deposits []Deposit, err error)

GetDepositHistory is used to retrieve your deposit history currency string a string literal for the currency (ie. BTC). If set to "all", will return for all currencies

func (*Bittrex) GetDistribution

func (b *Bittrex) GetDistribution(market string) (distribution Distribution, err error)

GetDistribution is used to get the distribution.

func (*Bittrex) GetLatestTick

func (b *Bittrex) GetLatestTick(market string, interval string) ([]Candle, error)

GetLatestTick returns array with a single element latest candle object

func (*Bittrex) GetMarketHistory

func (b *Bittrex) GetMarketHistory(market string) (trades []Trade, err error)

GetMarketHistory is used to retrieve the latest trades that have occured for a specific market. market a string literal for the market (ex: BTC-LTC)

func (*Bittrex) GetMarketSummaries

func (b *Bittrex) GetMarketSummaries() (marketSummaries []MarketSummary, err error)

GetMarketSummaries is used to get the last 24 hour summary of all active exchanges

func (*Bittrex) GetMarketSummary

func (b *Bittrex) GetMarketSummary(market string) (marketSummary []MarketSummary, err error)

GetMarketSummary is used to get the last 24 hour summary for a given market

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. If market is set to "all", GetOpenOrders return all orders If market is set to a specific order, GetOpenOrders return orders for this market

func (*Bittrex) GetOrder

func (b *Bittrex) GetOrder(order_uuid string) (order Order2, err error)

func (*Bittrex) GetOrderBook

func (b *Bittrex) GetOrderBook(market, cat string) (orderBook OrderBook, err error)

GetOrderBook is used to get retrieve the orderbook for a given market market: a string literal for the market (ex: BTC-LTC) cat: buy, sell or both to identify the type of orderbook to return.

func (*Bittrex) GetOrderBookBuySell

func (b *Bittrex) GetOrderBookBuySell(market, cat string) (orderb []Orderb, err error)

GetOrderBookBuySell is used to get retrieve the buy or sell side of an orderbook for a given market market: a string literal for the market (ex: BTC-LTC) cat: buy or sell to identify the type of orderbook to return.

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) GetTicks

func (b *Bittrex) GetTicks(market string, interval string) ([]Candle, error)

GetTicks is used to get ticks history values for a market. Interval can be -> ["oneMin", "fiveMin", "thirtyMin", "hour", "day"]

func (*Bittrex) GetWithdrawalHistory

func (b *Bittrex) GetWithdrawalHistory(currency string) (withdrawals []Withdrawal, err error)

GetWithdrawalHistory is used to retrieve your withdrawal history currency string a string literal for the currency (ie. BTC). If set to "all", will return for all currencies

func (*Bittrex) OrderV3

func (b *Bittrex) OrderV3(newOrder *NewOrderV3) (response *OrderV3, err error)

func (*Bittrex) SellLimit

func (b *Bittrex) SellLimit(market string, quantity, rate decimal.Decimal) (uuid string, err error)

SellLimit is used to place a limited sell order in a specific market.

func (*Bittrex) SetDebug

func (c *Bittrex) SetDebug(enable bool)

set enable/disable http request/response dump

func (*Bittrex) SubscribeExchangeUpdate

func (b *Bittrex) SubscribeExchangeUpdate(market string, dataCh chan<- ExchangeState, stop <-chan bool) error

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

func (*Bittrex) Withdraw

func (b *Bittrex) Withdraw(address, currency string, quantity decimal.Decimal) (withdrawUuid string, err error)

Withdraw is used to withdraw funds from your account. address string the address where to send the funds. currency string literal for the currency (ie. BTC) quantity decimal.Decimal the quantity of coins to withdraw

type Candle

type Candle struct {
	TimeStamp  CandleTime      `json:"T"`
	Open       decimal.Decimal `json:"O"`
	Close      decimal.Decimal `json:"C"`
	High       decimal.Decimal `json:"H"`
	Low        decimal.Decimal `json:"L"`
	Volume     decimal.Decimal `json:"V"`
	BaseVolume decimal.Decimal `json:"BV"`
}

type CandleTime

type CandleTime struct {
	time.Time
}

func (*CandleTime) UnmarshalJSON

func (t *CandleTime) UnmarshalJSON(b []byte) error

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"`
	IsRestricted    bool            `json:"IsRestricted"`
}

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"`
}

type Distribution

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

type ExchangeState

type ExchangeState struct {
	MarketName string
	Nounce     int
	Buys       []OrderUpdate
	Sells      []OrderUpdate
	Fills      []Fill
	Initial    bool
}

ExchangeState contains fills and order book updates for a market.

type Fill

type Fill struct {
	Orderb
	OrderType string
	Timestamp jTime
}

type Market

type Market struct {
	MarketCurrency     string          `json:"MarketCurrency"`
	BaseCurrency       string          `json:"BaseCurrency"`
	MarketCurrencyLong string          `json:"MarketCurrencyLong"`
	BaseCurrencyLong   string          `json:"BaseCurrencyLong"`
	MinTradeSize       decimal.Decimal `json:"MinTradeSize"`
	MarketName         string          `json:"MarketName"`
	IsActive           bool            `json:"IsActive"`
	IsRestricted       bool            `json:"IsRestricted"`
	Notice             string          `json:"Notice"`
	IsSponsored        bool            `json:"IsSponsored"`
	LogoUrl            string          `json:"LogoUrl"`
	Created            string          `json:"Created"`
}

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"`
}

type NewCandles

type NewCandles struct {
	Ticks []Candle `json:"ticks"`
}

type NewOrderV3

type NewOrderV3 struct {
	MarketSymbol  string          `json:"marketSymbol"`
	Direction     string          `json:"direction"`
	Type          string          `json:"type"` // LIMIT
	Quantity      decimal.Decimal `json:"quantity"`
	Limit         decimal.Decimal `json:"limit"`
	TimeInForce   string          `json:"timeInForce"` // GOOD_TIL_CANCELLED||IMMEDIATE_OR_CANCEL||FILL_OR_KILL||POST_ONLY_GOOD_TIL_CANCELLED||IMMEDIATE_OR_CANCEL||FILL_OR_KILL||POST_ONLY_GOOD_TIL_CANCELLED
	ClientOrderId *string         `json:"clientOrderId"`
}

type Order

type Order struct {
	OrderUuid         string          `json:"OrderUuid"`
	Exchange          string          `json:"Exchange"`
	TimeStamp         jTime           `json:"TimeStamp"`
	OrderType         string          `json:"OrderType"`
	Limit             decimal.Decimal `json:"Limit"`
	Quantity          decimal.Decimal `json:"Quantity"`
	QuantityRemaining decimal.Decimal `json:"QuantityRemaining"`
	Commission        decimal.Decimal `json:"Commission"`
	Price             decimal.Decimal `json:"Price"`
	PricePerUnit      decimal.Decimal `json:"PricePerUnit"`
	Opened            string          `json:"Opened,omitempty"`
}

type Order2

type Order2 struct {
	AccountId                  string
	OrderUuid                  string          `json:"OrderUuid"`
	Exchange                   string          `json:"Exchange"`
	Type                       string          `json:"OrderType"`
	Quantity                   decimal.Decimal `json:"Quantity"`
	QuantityRemaining          decimal.Decimal `json:"QuantityRemaining"`
	Limit                      decimal.Decimal `json:"Limit"`
	Reserved                   decimal.Decimal
	ReserveRemaining           decimal.Decimal
	CommissionReserved         decimal.Decimal
	CommissionReserveRemaining decimal.Decimal
	CommissionPaid             decimal.Decimal
	Price                      decimal.Decimal `json:"Price"`
	PricePerUnit               decimal.Decimal `json:"PricePerUnit"`
	Opened                     string
	Closed                     string
	IsOpen                     bool
	Sentinel                   string
	CancelInitiated            bool
	ImmediateOrCancel          bool
	IsConditional              bool
	Condition                  string
	ConditionTarget            decimal.Decimal
}

For getorder

type OrderBook

type OrderBook struct {
	Buy  []Orderb `json:"buy"`
	Sell []Orderb `json:"sell"`
}

type OrderUpdate

type OrderUpdate struct {
	Orderb
	Type int
}

type OrderV3

type OrderV3 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"`
	ExpiresAt     time.Time       `json:"expiresAt"`
	ClientOrderId string          `json:"clientOrderId"`
	FillQuantity  decimal.Decimal `json:"fillQuantity"`
	Commission    decimal.Decimal `json:"commission"`
	Proceeds      decimal.Decimal `json:"proceeds"`
	Status        string          `json:"status"`
	CreatedAt     time.Time       `json:"createdAt"`
	UpdatedAt     time.Time       `json:"updatedAt"`
	ClosedAt      time.Time       `json:"closedAt"`
	Error         string          `json:"error"`
	Code          string          `json:"code"`
}

type Orderb

type Orderb struct {
	Quantity decimal.Decimal `json:"Quantity"`
	Rate     decimal.Decimal `json:"Rate"`
}

type Ticker

type Ticker struct {
	Bid  decimal.Decimal `json:"Bid"`
	Ask  decimal.Decimal `json:"Ask"`
	Last decimal.Decimal `json:"Last"`
}

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"`
}

Used in getmarkethistory

type Uuid

type Uuid struct {
	Id string `json:"uuid"`
}

type Withdrawal

type Withdrawal struct {
	PaymentUuid    string          `json:"PaymentUuid"`
	Currency       string          `json:"Currency"`
	Amount         decimal.Decimal `json:"Amount"`
	Address        string          `json:"Address"`
	Opened         jTime           `json:"Opened"`
	Authorized     bool            `json:"Authorized"`
	PendingPayment bool            `json:"PendingPayment"`
	TxCost         decimal.Decimal `json:"TxCost"`
	TxId           string          `json:"TxId"`
	Canceled       bool            `json:"Canceled"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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