adshao / go-binance

A Go SDK for Binance API
MIT License
1.48k stars 662 forks source link

How to get x-mbx-used-weight-1m? #556

Closed KDVMan closed 2 months ago

KDVMan commented 2 months ago

Hello, please tell me how to get the limits that were spent during the request, for example NewExchangeInfoService Binance returns rateLimits in the header, so you need to get them somehow.

thank you in advance

brunoksato commented 2 months ago

func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
    resp, err := t.UnderlyingTransport.RoundTrip(req)
    if resp != nil && resp.Header != nil {
        usedWeight, _ = strconv.Atoi(resp.Header.Get("X-Mbx-Used-Weight-1m"))
    }

    return resp, err
}

func NewBinance(apiKey, secretKey string) *Binance {
    futures.WebsocketKeepalive = true
    client := futures.NewClient(apiKey, secretKey)
    c := http.Client{Transport: &transport{UnderlyingTransport: http.DefaultTransport}}
    client.HTTPClient = &c
    client.Debug = os.Getenv("debug") == "true"
    b := Binance{
        Client: client,
    }```
KDVMan commented 2 months ago

Thanks)