Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to learn or calculate weight of an api request #866

Open
cuneytkilic opened this issue Dec 11, 2022 · 1 comment
Open

How to learn or calculate weight of an api request #866

cuneytkilic opened this issue Dec 11, 2022 · 1 comment

Comments

@cuneytkilic
Copy link

cuneytkilic commented Dec 11, 2022

I am trying to coding a buy/sell strategy but i struggle with "max 2400 request" error.
Basically, my program buys a coin and create limit order and then checks that order is new, filled, cancelled or expired. Program working fine about 8-12 hours. After that gives a max request error. I dont know, how to control, calculate or learn weight of a request.

Also i wonder that the following 2 request code example has the same weight of request or not ?

1-)

await binance.futuresOrderStatus( coin_name, {orderId: coin_orderId} )
.then(json => { console.log(new Date().toLocaleTimeString() + " - order status:  " + json.status) })
.catch(err => console.log( new Date().toLocaleTimeString() + " -53err- " +  err));

2-)

await binance.futuresOrderStatus( coin_name, {orderId: coin_orderId} )
.then(json => {

for(let i=0; i<9999; i++){
    console.log(i + " - " + json.status)
}

console.log(new Date().toLocaleTimeString() + " - futuresOrderStatus() " + coin_name + " - coin_orderId: " + coin_orderId + " - STATUS: " + json.status)

  if(json.status=='FILLED'){
      console.log(new Date().toLocaleTimeString() + " - " + coin_name + " - order successfull.")
      limitten_alindi = true;
  }else if(json.status == 'CANCELED'){
      console.log(new Date().toLocaleTimeString() + " - " + coin_name + " - order cancelled.")
      iptal_edildi = true;
  }
}).catch(err => console.log( new Date().toLocaleTimeString() + " -53err- " +  err));
@cuneytkilic cuneytkilic changed the title How to learn or calculate weight of api request How to learn or calculate weight of an api request Dec 11, 2022
@GTedZ
Copy link

GTedZ commented Jul 1, 2023

In the response headers, there is a parameter X-MBX-USED-WEIGHT-(intervalNum)(intervalLetter) which contains how much weight you used.
Now for spot it's usually 1200, for Futures its 2400, so you can easily calculate how much weight you have left by doing 2400 - X-MBX-USED-WEIGHT-...-... from the headers

and then you can add a timer that resets the usedWeight to 0 or reset your "speedLimiter" every beginning of the minute.

But what is best for you is to instead learn how to use userData streams, listen to the ORDER_TRADE_UPDATE event which sends you the status of the orders in your account

If you want easier documentation, I suggest using my library binance-lib once v3.0.0 comes out with the new IntelliSense documentation (its coming out in a couple of days)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants