binance

package
v1.2.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: 9 Imported by: 0

README

Binance Provider

Overview

The Binance provider is used to fetch the spot price for cryptocurrencies from the Binance API.

Supported Pairs

To determine the pairs (in the form BASEQUOTE) currencies that the Binance provider supports, you can run the following command:

$ curl -X GET https://api.binance.vision/api/v3/ticker/price         

Documentation

Index

Constants

View Source
const (
	// Name is the name of the Binance provider.
	Name = "binance_api"

	// URL is the base URL of the Binance API. This includes the base and quote
	// currency pairs that need to be inserted into the URL. This URL should be utilized
	// by Non-US users.
	URL = "https://api.binance.com/api/v3/ticker/price?symbols=%s%s%s"

	Quotation    = "%22"
	Separator    = ","
	LeftBracket  = "%5B"
	RightBracket = "%5D"
)

Variables

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

DefaultNonUSAPIConfig is the default configuration for the Binance API.

Functions

func NewAPIHandler

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

NewAPIHandler returns a new Binance PriceAPIDataHandler.

Types

type APIHandler

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

APIHandler implements the PriceAPIDataHandler interface for Binance. for more information about the Binance API, refer to the following link: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#public-api-endpoints

func (*APIHandler) CreateURL

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

CreateURL returns the URL that is used to fetch data from the Binance 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 Binance API and returns a GetResponse. Each of the tickers supplied will get a response or an error.

type Data

type Data struct {
	Symbol string `json:"symbol"`
	Price  string `json:"price"`
}

Data BinanceData is the data returned by the Binance API.

type Response

type Response []Data

Response is the expected response returned by the Binance API. The response is json formatted. Response format:

	[
 {
   "symbol": "LTCBTC",
   "price": "4.00000200"
 },
 {
   "symbol": "ETHBTC",
   "price": "0.07946600"
 }

].

func Decode

func Decode(resp *http.Response) (Response, error)

Decode decodes the given http response into a BinanceResponse.

Jump to

Keyboard shortcuts

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