cnfuyu / python-binance-api

A Python 2/3 client for the Binance REST and WebSocket APIs
https://www.binance.com/restapipub.html
MIT License
34 stars 14 forks source link

Lot size issue #2

Open O4karitO opened 6 years ago

O4karitO commented 6 years ago

From time to time I get Filter failure: LOT_SIZE error. From what I found it is because binance has a different minimum order volume for each coin. And anything smaller returns an error. in other words for a certain coin 512.6 might be fine but 512.63 will return an error. Number of decimal points allowed is different for every coin

cesar128 commented 6 years ago

i found a workaround for this.

  1. get the ticker for X symbol (lets assume it is LTCBTC)
  2. Define a function to remove trailing zeroes on decimals and get the decimals places : def normalize_fraction(d): normalized = d.normalize() sign, digit, exponent = normalized.as_tuple() return normalized if exponent <= 0 else normalized.quantize(1)
  3. convert the amount you want to get decimals = Decimal(normalize_fraction(Decimal(ticker.bid.qty))).as_tuple().exponent this will return -2 as LTC has 2 decimal places over BTC
  4. Now lets assume you would like to buy 1.25684 LTC amount_to_buy = round(1.25684, (decimals*-1))