mbx

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mbx provides shared rate-limit tracking and error mapping for Binance-family exchanges (Binance, Aster) that use the X-Mbx-* header convention for communicating request weight and order count usage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsRateLimitMessage

func IsRateLimitMessage(message string) bool

IsRateLimitMessage checks if the error message suggests rate limiting.

func MapAPIError

func MapAPIError(exchange string, statusCode int, data []byte, unmarshalErr func([]byte) (int, string, error)) error

MapAPIError parses a Binance-family API error response and wraps rate-limit errors as exchanges.ErrRateLimited. The apiErr parameter should be a pointer to a struct with Code (int) and Message (string) fields populated from the JSON response body. Returns nil if no error mapping was needed — caller should fall through to returning apiErr directly.

func UnmarshalAPIError

func UnmarshalAPIError(data []byte) (code int, message string, err error)

APIErrorFields is a helper that extracts Code and Message from a standard Binance-family JSON error response: {"code": -1003, "msg": "..."}.

Types

type OrderCount

type OrderCount struct {
	Count10s int64
	Count1d  int64
}

OrderCount tracks the order rate as reported by the exchange via X-Mbx-Order-Count-10s and X-Mbx-Order-Count-1d headers.

func (*OrderCount) UpdateByHeader

func (o *OrderCount) UpdateByHeader(header http.Header)

UpdateByHeader reads X-Mbx-Order-Count headers and atomically stores them.

type UsedWeight

type UsedWeight struct {
	Used   int64
	Used1M int64
}

UsedWeight tracks the cumulative request weight as reported by the exchange via X-Mbx-Used-Weight and X-Mbx-Used-Weight-1m headers.

func (*UsedWeight) UpdateByHeader

func (u *UsedWeight) UpdateByHeader(header http.Header)

UpdateByHeader reads X-Mbx-Used-Weight headers and atomically stores them.

Jump to

Keyboard shortcuts

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