binance

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseURL      = "https://api.binance.com"
	BaseWsURL    = "wss://stream.binance.com:9443"
	BaseWsAPIURL = "wss://ws-api.binance.com:443/ws-api/v3"

	EndpointDepth       = "/api/v3/depth"
	EndpointKlines      = "/api/v3/klines"
	EndpointCreateOrder = "/api/v3/order"
	EndpointAccount     = "/api/v3/account"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BinanceHTTPClient

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

func NewBinanceHTTPClient

func NewBinanceHTTPClient(catalog *catalog.Catalog, msgBus *msgbus.MsgBus) BinanceHTTPClient

func (*BinanceHTTPClient) ReqCreateOrder

func (c *BinanceHTTPClient) ReqCreateOrder(acctID int, apiKeyName string, symbolId int, orderType common.OrderType, side common.Side, timeInForce common.TimeInForce, quantity float64, price float64) error

func (*BinanceHTTPClient) ReqDepthSnapshot

func (c *BinanceHTTPClient) ReqDepthSnapshot(symbolId int, limit int) error

GetDepth fetches order book depth from Binance API Uses zero-allocation approach: parses JSON directly into arena buffer

func (*BinanceHTTPClient) ReqHistoricalKline

func (c *BinanceHTTPClient) ReqHistoricalKline(symbolID int, interval string, startTimeNs, endTimeNs uint64, limit int) error

ReqHistoricalKline fetches historical klines via GET /api/v3/klines and publishes TopicEventRespHistoricalKline. Times are nanoseconds; 0 omits the bound.

type BinanceSpotDataClient

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

BinanceSpotDataClient handles Binance spot market data via WebSocket and HTTP It provides a unified interface for both real-time streaming data (WebSocket) and on-demand requests (HTTP REST API)

func NewBinanceSpotDataClient

func NewBinanceSpotDataClient(catalog *catalog.Catalog, msgBus *msgbus.MsgBus) *BinanceSpotDataClient

NewBinanceSpotDataClient creates a new Binance spot data client It initializes both the WebSocket client for real-time data and the HTTP client for REST API requests

func (*BinanceSpotDataClient) Connect

func (c *BinanceSpotDataClient) Connect(ctx context.Context) error

Connect establishes the WebSocket connection and starts processing

func (*BinanceSpotDataClient) Disconnect

func (c *BinanceSpotDataClient) Disconnect()

Disconnect closes the WebSocket connection

func (*BinanceSpotDataClient) HasSub

func (c *BinanceSpotDataClient) HasSub() bool

HasSub returns true if there are any subscriptions configured

func (*BinanceSpotDataClient) ReqDepthSnapshot

func (c *BinanceSpotDataClient) ReqDepthSnapshot(symbolID int, limit int) error

ReqDepthSnapshot requests a depth snapshot via HTTP REST API.

func (*BinanceSpotDataClient) ReqHistoricalKline

func (c *BinanceSpotDataClient) ReqHistoricalKline(symbolID int, interval string, startTimeNs, endTimeNs uint64, limit int) error

ReqHistoricalKline requests historical klines via HTTP REST API.

func (*BinanceSpotDataClient) SubscribeAggTrade

func (c *BinanceSpotDataClient) SubscribeAggTrade(symbolID int)

SubscribeAggTrade subscribes to the aggregate trade stream (@aggTrade) for a symbol.

func (*BinanceSpotDataClient) SubscribeDepthUpdate

func (c *BinanceSpotDataClient) SubscribeDepthUpdate(symbolID int, depthLevel int, pushRateMs int)

SubscribeDepthUpdate subscribes to a depth stream for a symbol. depthLevel 5/10/20 selects Binance partial-book streams (@depthN@… → DepthSnapshot); any other value selects diff depth (@depth@… → DepthUpdate). pushRateMs selects the push rate: >=1000 uses 1s, otherwise 100ms.

func (*BinanceSpotDataClient) SubscribeKline

func (c *BinanceSpotDataClient) SubscribeKline(symbolID int, interval string)

SubscribeKline subscribes to a kline stream for a symbol. interval is a Binance-style string (e.g. "1m", "1h", "1d").

func (*BinanceSpotDataClient) SubscribeTrade

func (c *BinanceSpotDataClient) SubscribeTrade(symbolID int)

SubscribeTrade subscribes to the trade tick stream (@trade) for a symbol.

type BinanceSpotExecutionClient

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

BinanceSpotExecutionClient handles Binance spot order execution via WebSocket API It uses Ed25519 API key for signing and supports order submission, cancellation, and receiving order updates/fills via the WebSocket connection.

Subscription Model: Binance only supports subscribing to the entire user data stream at once. When any granular subscription method is called (SubscribeOrderUpdate, SubscribeFill, SubscribeBalance), the client subscribes to the full stream internally but only publishes events for subscribed types. Unsubscribed event types are logged as unhandled.

func NewBinanceSpotExecutionClient

func NewBinanceSpotExecutionClient(catalog *catalog.Catalog, msgBus *msgbus.MsgBus, accountID int, apiKeyName string, walletID int) (*BinanceSpotExecutionClient, error)

NewBinanceSpotExecutionClient creates a new Binance spot execution client

func (*BinanceSpotExecutionClient) CancelAllOrders

func (c *BinanceSpotExecutionClient) CancelAllOrders(symbolID int) error

CancelAllOrders cancels all open orders for a symbol via WebSocket

func (*BinanceSpotExecutionClient) CancelOrder

func (c *BinanceSpotExecutionClient) CancelOrder(symbolID int, orderID int, clientOrderID int) error

CancelOrder cancels an order by orderID via WebSocket

func (*BinanceSpotExecutionClient) Connect

Connect establishes the WebSocket connection for trading

func (*BinanceSpotExecutionClient) Disconnect

func (c *BinanceSpotExecutionClient) Disconnect()

Disconnect closes the WebSocket connection

func (*BinanceSpotExecutionClient) ReqBalanceSnapshot

func (c *BinanceSpotExecutionClient) ReqBalanceSnapshot(walletType common.WalletType) error

ReqBalanceSnapshot requests account balance snapshot via WebSocket. walletType is accepted for interface compatibility; Binance spot always queries the spot account.

func (*BinanceSpotExecutionClient) SubmitOrder

func (c *BinanceSpotExecutionClient) SubmitOrder(clientOrderID int, symbolID int, side common.Side, orderType common.OrderType, timeInForce common.TimeInForce, price float64, quantity float64) error

SubmitOrder submits a new order via WebSocket

func (*BinanceSpotExecutionClient) SubscribeBalance

func (c *BinanceSpotExecutionClient) SubscribeBalance() error

SubscribeBalance subscribes to wallet/balance update events Binance: Subscribes to user data stream if not already subscribed, enables balance filtering

func (*BinanceSpotExecutionClient) SubscribeFill

func (c *BinanceSpotExecutionClient) SubscribeFill() error

SubscribeFill subscribes to execution/fill events Binance: Subscribes to user data stream if not already subscribed, enables fill filtering

func (*BinanceSpotExecutionClient) SubscribeOrderUpdate

func (c *BinanceSpotExecutionClient) SubscribeOrderUpdate() error

SubscribeOrderUpdate subscribes to order status update events Binance: Subscribes to user data stream if not already subscribed, enables order update filtering

type DepthSubscriptionOptions

type DepthSubscriptionOptions struct {
	PushRate PushRate
	Levels   int // 0 = diff (@depth@…), 5|10|20 = partial (@depthN@…)
}

DepthSubscriptionOptions holds options for depth subscription. Levels 0 means diff-depth stream; 5, 10, or 20 means partial-book stream.

func (*DepthSubscriptionOptions) IsPartialBook

func (o *DepthSubscriptionOptions) IsPartialBook() bool

IsPartialBook reports whether this subscription uses a partial-book stream.

type HTTPError

type HTTPError struct {
	StatusCode int
	Body       string
}

HTTPError represents an HTTP error response

func (*HTTPError) Error

func (e *HTTPError) Error() string

type PushRate

type PushRate int
const (
	PushRate100ms PushRate = iota
	PushRate1s
)

func (PushRate) StreamSuffix

func (p PushRate) StreamSuffix(levels int) string

StreamSuffix returns the Binance depth stream suffix for the given push rate and book levels. Diff depth: "depth@100ms". Partial: "depth20@100ms".

Jump to

Keyboard shortcuts

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