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

Round to tick size function #309

Open
posman opened this issue Feb 16, 2023 · 1 comment
Open

Round to tick size function #309

posman opened this issue Feb 16, 2023 · 1 comment

Comments

@posman
Copy link

posman commented Feb 16, 2023

Don't know if this function already exists but I wasn't able to find it (if it already exists then close the issue)

It'd be very helpful to have a function that can round the price and help pass the Binance Filters
https://binance-docs.github.io/apidocs/futures/en/#filters

One of the filters is the PRICE_FILTER where Binance will return error when price is not aligned to tickSize
-4014 Price not increased by tick size

The information for the tickSize is in the informationr returned by /fapi/v1/exchangeInfo

{
  ...
  "symbols": [
    {
      "symbol": "BTCUSDT",
      ...
      "filters": [
        {
          "filterType": "PRICE_FILTER",
          "maxPrice": "300",
          "minPrice": "0.0001", 
          "tickSize": "0.10"
        },
      ]
    }
  ]
}

For example, placing an order for BTCUSDT with entry price $19500.38 will return an error. The correct price that Binance will accept is $19500.30, based on tickSize

One way I found to round the price is:
Math.round(price / tickSize) * tickSize

This works for every tickSize as long as it uses number "1" (just as I think is the case to all symbols in Binance). But it won't work if the number is different, like happens in Futures (in NASDAQ) where ticks could be "0.0005"

@tiagosiebler
Copy link
Owner

Completely agree, would like to get utility functions like this added to the SDK, including adding unit test coverage to make sure all the different scenarios we see are covered and never accidentally broken. It's one of the painful aspects of trading on binance that could be made easier like this. I'll get to adding it eventually but I don't have bandwidth for this right now, but if anyone wants to contribute, I'd love to see some proposals/pull requests or even just code snippets here.

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

No branches or pull requests

2 participants