bittrex

package module
v0.0.0-...-8b5f0cc Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2018 License: MIT Imports: 20 Imported by: 0

README

GoDoc Build Status Go Report Card Maintainability codecov

Overview

This package provides a Bittrex client. It provides access to both the standard APIs as well as the undocumented websocket connection.

Documentation

Contribute

If anything is unclear or could be improved, please open an issue or submit a pull request. Thanks!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Balance

type Balance struct {
	Currency      string
	Balance       float64
	Available     float64
	Pending       float64
	CryptoAddress string
}

Balance represents an account balance.

type Candle

type Candle struct {
	Market string
	Time   time.Time
	Open   float64
	High   float64
	Low    float64
	Close  float64
	Volume float64
}

Candle contains the open, high, low, close, and volume data for a market.

func (Candle) String

func (candle Candle) String() string

type CandleHandler

type CandleHandler func(c Candle)

CandleHandler processes a candle.

type Client

type Client struct {
	// HTTPClient is optional. It can be used to inject a custom underlying HTTP
	// client to perform HTTP operations.
	HTTPClient *http.Client

	// HTTPTransport is optional. It can be used to inject a custom underlying
	// HTTP transport into the underlying HTTP client.
	HTTPTransport *http.Transport

	// MaxRetries indicates the maximum number of times to attempt an HTTP
	// operation before failing.
	MaxRetries int

	// RetryWaitDuration is used to determine how long to wait between retries
	// of various operations.
	RetryWaitDuration time.Duration

	// A Bittrex-supplied API key and secret.
	APIKey    string
	APISecret string

	// HostAddr address is the address of the Bittrex server providing the service
	// we're using. Using this variable allows us to more simply test
	// functionality in this package.
	HostAddr string
	// contains filtered or unexported fields
}

Client provides an interface by which people can call the Bittrex API endpoints (both the REST and the WebSocket APIs).

func New

func New(apiKey, apiSecret string) *Client

New creates a new Bittrex client.

func (*Client) Balances

func (c *Client) Balances() ([]Balance, error)

Balances gets the balances held for all currencies in the account.

func (*Client) Cancel

func (c *Client) Cancel(orderUUID string) error

Cancel sends a request to cancel an order with the specified UUID.

func (*Client) LimitBuy

func (c *Client) LimitBuy(market string, quantity, rate float64) error

LimitBuy sends a request to create a limit buy order.

func (*Client) LimitSell

func (c *Client) LimitSell(market string, quantity, rate float64) error

LimitSell sends a request to create a limit sell order.

func (*Client) Markets

func (c *Client) Markets() ([]Market, error)

Markets gets the markets that are traded on Bittrex.

func (*Client) OrderHistory

func (c *Client) OrderHistory() ([]Order, error)

OrderHistory gets the latest orders made through Bittrex for the user's account.

func (*Client) ProcessCandles

func (c *Client) ProcessCandles(interval time.Duration, candleHandler CandleHandler)

ProcessCandles monitors the trade data for all subscribed markets and produces candle data for the specified interval.

func (*Client) Register

func (c *Client) Register(h TradeHandler)

Register saves the specified trade handler to a slice of handlers that will be run against each incoming trade.

func (*Client) SetCustomID

func (c *Client) SetCustomID(id string) error

SetCustomID assigns the specified id to the underlying SignalR client.

func (*Client) Subscribe

func (c *Client) Subscribe(market string, errHandler ErrHandler) error

Subscribe sends a request to Bittrex to start sending us the market data for the indicated market.

func (*Client) Ticks

func (c *Client) Ticks(market string) ([]Tick, error)

Ticks gets a little under 10 days of candle data (14365 minutes) at the one minute interval. However, it is usually missing the last few minutes, so a way to monitor trades (such as the Trades() function) is still required to get up-to-the-minute data.

As a general approach when monitoring data for strategic analysis, this function should be called once a minute for a few minutes until the timestamps from the live trade data (Trades() function) overlap with the data returned by this function. You shouldn't have to wait more than about 5-10 minutes for this to occur; at that point you likely only need to use live trade data and perhaps then use this function as the source of truth for validating your data.

Intervals provided by the underlying Bittrex API are: day, hour, thirtyMin, fiveMin, and oneMin.

type ErrHandler

type ErrHandler func(err error)

ErrHandler processes an error.

type Market

type Market struct {
	MarketCurrency     string
	BaseCurrency       string
	MarketCurrencyLong string
	BaseCurrencyLong   string
	MinTradeSize       float64
	Name               string `json:"MarketName"`
	IsActive           bool
	Created            string
	Notice             *string
	IsSponsored        *bool
	LogoURL            string `json:"LogoUrl"`
}

Market represents a market on Bittrex for trading between two currencies: the market currency and the base currency.

func (Market) String

func (m Market) String() string

type Order

type Order struct {
	OrderUUID         string `json:"OrderUuid"`
	Exchange          string
	TimeStamp         string // format: 2014-07-09T02:58:46.27
	OrderType         string
	Limit             float64
	Quantity          float64
	QuantityRemaining float64
	Commission        float64
	Price             float64
	PricePerUnit      float64
	IsConditional     bool
	Condition         string
	ConditionTarget   *json.RawMessage
	ImmediateOrCancel bool
	Closed            string // This is a timestamp.
}

Order represents an order that is placed on Bittrex.

func (*Order) Market

func (o *Order) Market() string

Market returns this order's exchange. It is purely a convenience function.

func (*Order) Rate

func (o *Order) Rate() float64

Rate returns this order's price per unit. It is purely a convenience function.

func (*Order) Time

func (o *Order) Time() (time.Time, error)

Time returns this order's timestamp converted into a time.Time object.

type RequestParamsRecorder

type RequestParamsRecorder struct {
	Params url.Values
}

RequestParamsRecorder provides a way to record request parameters.

func NewMockRestServer

func NewMockRestServer() (*httptest.Server, *RequestParamsRecorder)

NewMockRestServer returns a new httptest server that can be used to record parameters passed in by each request.

func (*RequestParamsRecorder) SaveParams

func (rr *RequestParamsRecorder) SaveParams(r *http.Request)

SaveParams saves the parameters passed in by the specified HTTP request.

type Tick

type Tick struct {
	Open      float64 `json:"O"`
	High      float64 `json:"H"`
	Low       float64 `json:"L"`
	Close     float64 `json:"C"`
	Volume    float64 `json:"V"`
	Timestamp string  `json:"T"`
	BV        float64
}

Tick represents the open, high, low, and close values along with some other bits of data received from Bittrex.

For example, many of these ticks will be returned by navigating to the following website: https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=BTC-WAVES&tickInterval=oneMin

Here is an example of what they should look like:

{
  "O":0.00061830,
  "H":0.00061830,
  "L":0.00061798,
  "C":0.00061798,
  "V":1220.69744635,
  "T":"2017-11-17T16:51:00",
  "BV":0.75448216
}

func (Tick) String

func (t Tick) String() string

func (*Tick) Time

func (t *Tick) Time() (time.Time, error)

Time returns a time object that is converted from the timestamp value.

type Trade

type Trade struct {
	BaseCurrency   string
	MarketCurrency string

	Type     TradeType
	Price    float64
	Quantity float64
	Time     time.Time
}

Trade represents a trade that is planned or that already happened using the Bittrex API.

func (*Trade) Market

func (t *Trade) Market() string

Market returns the market.

func (Trade) String

func (t Trade) String() string

type TradeHandler

type TradeHandler func(t Trade)

TradeHandler processes a trade.

type TradeType

type TradeType int

TradeType represents a type of trade: either buy or sell.

const (
	// InvalidTradeType is used as the default for the Type type to indicate a
	// variable has not been explicitly set to one of the valid values.
	InvalidTradeType TradeType = iota

	// BuyType represents buy trades.
	BuyType

	// SellType represents sell trades.
	SellType
)

func (TradeType) String

func (t TradeType) String() string

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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