bitstamp

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

Bitstamp Provider

Overview

The Bitstamp provider is used to fetch the spot price for cryptocurrencies from the Bitstamp API. As standard, all clients can make 400 requests per second. There is a default limit threshold of 10,000 requests per 10 minutes in place.

Documentation

Index

Constants

View Source
const (
	// Name is the name of the Bitstamp provider.
	Name = "bitstamp_api"

	// URL is the base URL of the Bitstamp API. The URL returns all prices, some
	// of which are not needed.
	URL = "https://www.bitstamp.net/api/v2/ticker/"
)

Variables

View Source
var DefaultAPIConfig = config.APIConfig{
	Name:             Name,
	Atomic:           true,
	Enabled:          true,
	Timeout:          3000 * time.Millisecond,
	Interval:         3000 * time.Millisecond,
	ReconnectTimeout: 2000 * time.Millisecond,
	MaxQueries:       1,
	Endpoints:        []config.Endpoint{{URL: URL}},
}

DefaultAPIConfig is the default configuration for the Bitstamp API.

Functions

func NewAPIHandler

func NewAPIHandler(
	api config.APIConfig,
) (types.PriceAPIDataHandler, error)

NewAPIHandler returns a new Bitstamp PriceAPIDataHandler.

Types

type APIHandler

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

APIHandler implements the PriceAPIDataHandler interface for Bitstamp. for more information about the Bitstamp API, refer to the following link: https://www.bitstamp.net/api/#section/What-is-API

func (*APIHandler) CreateURL

func (h *APIHandler) CreateURL(
	tickers []types.ProviderTicker,
) (string, error)

CreateURL returns the URL that is used to fetch data from the Bitstamp API for the given tickers.

func (*APIHandler) ParseResponse

func (h *APIHandler) ParseResponse(
	tickers []types.ProviderTicker,
	resp *http.Response,
) types.PriceResponse

ParseResponse parses the response from the Bitstamp API and returns a GetResponse. Each of the tickers supplied will get a response or an error. Note that the bitstamp API returns all prices, some of which are not needed. The response is filtered to only include the prices that are needed (i.e. the pairs that are in the cache).

type MarketTickerData

type MarketTickerData struct {
	Last string `json:"last"`
	Pair string `json:"pair"`
}

MarketTickerData is the data returned by the Bitstamp API.

type MarketTickerResponse

type MarketTickerResponse []MarketTickerData

MarketTickerResponse is the expected response returned by the Bitstamp API.

ex.

[

{
	"ask": "2211.00",
	"bid": "2188.97",
	"high": "2811.00",
	"last": "2211.00",
	"low": "2188.97",
	"open": "2211.00",
	"open_24": "2211.00",
	"pair": "BTC/USD",
	"percent_change_24": "13.57",
	"side": "0",
	"timestamp": "1643640186",
	"volume": "213.26801100",
	"vwap": "2189.80"
}

]

ref: https://www.bitstamp.net/api/v2/ticker/

Jump to

Keyboard shortcuts

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