bitfinex

package
v0.0.0-...-2b6d021 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APIHost = "https://api.bitfinex.com"
	Version = "v1"

	//
	DefaultRateLimitEnabled = true

	DefaultCacheEnabled = false

	// RateLimit interval
	AllowedInterval = time.Second * 10
)
View Source
const (
	KeyStringBase = "prices/bitfinex/btcusd"

	DefaultCacheTimeout = time.Second * 3
)

Variables

View Source
var (
	// ErrRequestFailed is returned in the instance a
	// http request does not return a 200
	ErrRequestFailed = errors.New("failed request not successful")

	// ErrNotFound is returned in the instance a
	// http request returns a 404
	ErrNotFound = errors.New("resource not found")

	// ErrCacheEntryExpired is returned if
	// the cached entry that is returned has expired.
	// This SHOULD be taken care of by key expiry, but there is a chance
	// a stale result is returned and by the time of presentation
	// has exceeded the expiry timeline, therefore should be discarded
	ErrCacheEntryExpired = errors.New("cache entry expired, please refresh")
)

Functions

This section is empty.

Types

type BitfinexClient

type BitfinexClient struct {
	Host    string
	Version string

	CacheEnabled bool
	RateLimit    bool
	// contains filtered or unexported fields
}

func New

func New() *BitfinexClient

The simpler New returns the NewV1Client

func NewV1Client

func NewV1Client() *BitfinexClient

func (*BitfinexClient) AddCacheConnection

func (b *BitfinexClient) AddCacheConnection(conn *redis.Client)

func (*BitfinexClient) Do

func (b *BitfinexClient) Do(req *http.Request) (*http.Response, error)

Do executes and parses an HTTP request

func (*BitfinexClient) FetchCached

func (b *BitfinexClient) FetchCached() (*TickerData, error)

func (*BitfinexClient) ParseResponseBody

func (b *BitfinexClient) ParseResponseBody(resp *http.Response) ([]byte, error)

ParseResponseBody takes an http response and turns the body to a []byte

func (*BitfinexClient) Request

func (b *BitfinexClient) Request(method string, url string, data io.Reader) (*http.Request, error)

func (*BitfinexClient) Ticker

func (b *BitfinexClient) Ticker(t Ticker) (*TickerData, error)

func (*BitfinexClient) WriteCached

func (b *BitfinexClient) WriteCached(t *TickerData) error

type Error

type Error struct {
	Message string

	Info []string
}

Error is the structure of a API error response

type Ticker

type Ticker int
const (
	BTC_USD Ticker = iota
)

func (Ticker) String

func (t Ticker) String() string

type TickerData

type TickerData struct {
	Mid       string `json:"mid"`
	Bid       string `json:"bid"`
	Ask       string `json:"ask"`
	LastPrice string `json:"last_price"`
	Low       string `json:"low"`
	High      string `json:"high"`
	Volume    string `json:"volume"`
	Timestamp string `json:"timestamp"`
}

func (*TickerData) FormatPrice

func (t *TickerData) FormatPrice(price int) string

func (TickerData) GetHigh

func (t TickerData) GetHigh() (float64, error)

func (*TickerData) GetLastPrice

func (t *TickerData) GetLastPrice() (float64, error)

func (TickerData) GetLow

func (t TickerData) GetLow() (float64, error)

func (TickerData) GetTimestamp

func (t TickerData) GetTimestamp() (*time.Time, error)

func (*TickerData) SatsPerDollar

func (t *TickerData) SatsPerDollar() int64

Jump to

Keyboard shortcuts

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