binance

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package binance defines the connectivity with Binance.

Index

Constants

View Source
const (
	WebSocketURL               = "wss://data-stream.binance.vision/ws/ticker"
	WebSocketRequestsPerSecond = 5
)

Connection parameters for Binance. These are only provided for convenience in testing - operational values should be in the environment.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

Connection wraps a Binance websocket connection.

func Factory

func Factory(
	url string,
	symbol string,
	onQuote func(*mkt.Quote),
	onTrade func(*mkt.Trade),
	onError func(error),
	limiter *utl.RateLimiter,
	lifetime time.Duration,
) *Connection

Factory is the [dma.ConnectionFactory] for a Connection.

func (*Connection) Close

func (x *Connection) Close()

Close the connection.

func (*Connection) Open

func (x *Connection) Open()

Open the connection.

type Request

type Request struct {
	Method string   `json:"method"` // "SUBSCRIBE" or "UNSUBSCRIBE".
	Params []string `json:"params"` // Example "btcusdt@ticker" - the symbol must be lower case.
	ID     int64    `json:"id"`     // Unique per request.
}

Request is a stream request.

type Response

type Response struct {
	Result *string `json:"result,omitempty"` // nil means success.
	ID     int64   `json:"id"`               //
}

Response to a non-query request.

type Ticker

type Ticker struct {
	Symbol  string `json:"s"`
	BidPx   string `json:"b"`
	BidSize string `json:"B"`
	AskPx   string `json:"a"`
	AskSize string `json:"A"`
	LastQty string `json:"Q"`
	LastPx  string `json:"c"`
	TradeID int64  `json:"L"`
}

Ticker is the message for an individual symbol ticker stream. However json.Unmarshal fails with real data (claiming field "L" is a string), but unmarshaling into a basic map does work - albeit with "L" being parsed to a float64. The struct is kept for reference only.

Jump to

Keyboard shortcuts

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