tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
734 stars 265 forks source link

The last four digits of the excessively long orderId were incorrectly rounded. #360

Closed 0xfuckcode closed 11 months ago

0xfuckcode commented 11 months ago
const { USDMClient, DefaultLogger} = require('binance');
const param = {
  symbol:'ETHUSDT',
  side:'SELL,
  quantity:1,
  type:'LIMIT',
  price:1850,
  timeInForce:'GTC'
}
const order = await client.submitNewOrder(param);
console.log(order);

The returned orderId should be a number like 8389765612825190229, but the current returned orderId has its last three digits rounded, resulting in 8389765612825190000. The orderId for some trading pairs may exceed the maximum integer value that JavaScript's built-in Number type can accurately represent. It is necessary to use the string type or BigInt instead of the Number type.

https://github.com/tiagosiebler/binance/blob/6476fcf365f9c00325d2c070e71efe8a14703241/src/types/futures.ts#L407C19-L407C19

tiagosiebler commented 11 months ago

Totally agree this should be a string type. Unfortunately the JSON returned by binance's API is using a number type for this property.

There's no simple fix for the order ID value without pre-processing the JSON response before attempting to parse it into an object: https://binance-docs.github.io/apidocs/futures/en/#new-order-trade

The suggested workaround commonly used by others, is to instead use a custom order ID before sending the order, and using that for tracking instead - take a look at this thread: https://github.com/tiagosiebler/binance/issues/208#issuecomment-1128681717

0xfuckcode commented 11 months ago

Using custom order ID can be a compromise solution. Thank you very much.