how to I get the minimum trade price (i.e. the minimum decimal at which the buy/sell price can be incremented)?
e.g. 0.001 for ETH/BTC or 0.01 for LTC/BTC
I got a list here --> https://support.binance.com/hc/en-us/articles/115000594711-Trading-Rule
(_edit: this list is actually updated, so I scraped it as csv, but it would be nice to have this info from somewhere in the tickers_)
without this information there's no way I can compute the right price to specify in the order, or am I getting something wrong here?
(btw thanks so much for this amazing app, if'm ever gonna make some money I'll send you a donation ;) )
This is how I do it:
def get_binance_eth_symbols():
coins_list = []
precisions_list = []
symbols = client.get_exchange_info()["symbols"]
time.sleep(0.1)
for item in symbols:
if item["quoteAsset"] == "ETH":
# Append coin
coins_list.append(item["baseAsset"])
# Get coin precision
for filter in item["filters"]:
if filter["filterType"] == "PRICE_FILTER":
precisions_list.append(filter["tickSize"])
#pprint(return_list)
return [coins_list, precisions_list]
Create pairs
for i in range(0, len(result[0])):
binance_eth_currencies[str(result[0][i])] = 0
binance_eth_currencies_digits[str(result[0][i])] = float(str(result[1][i]))
order_price = int(order_price/binance_eth_currencies_digits[symbol])*binance_eth_currencies_digits[symbol]
I hope this can help you.
import math
from binance.client import Client
def floatPrecision(amount, precision):
return "{:0.0{}f}".format(float(amount), int(precision))
def getSymbolPrecision(symbol):
symbol_info = client.get_symbol_info(symbol.upper())
symbol_precision = abs(int(math.log10(float(symbol_info['filters'][next((i for (i, f) in enumerate(symbol_info['filters']) if f["filterType"] == "LOT_SIZE"), None)]['minQty']))))
return symbol_precision
ethbtc_precision = getSymbolPrecision('ethbtc')
my_btc_balance = float(client.get_asset_balance(asset='BTC')['free'])
ethbtc_price = float(filter(lambda x: x['symbol'] == 'ETHBTC', client.get_all_tickers())[0]['price'])
ethbtc_order_amount = floatPrecision( my_btc_balance / ethbtc_price, ethbtc_precision )
thanks to everyone who answered.
I haven't quite understood how the precision thing works, but I found the minimum trade amount in
client.get_exchange_info()["symbols"]
and then it is always in the second element of the list included in ['filters']
actually when I tried it first the client.get_asset_balance(asset='BTC') command wasn't working, but I guess this is because I haven't updated the module since last December! :)
Anyways, thanks again, I will implement a simple rounding function given the minimum trade quantity, and if it doesn't work I'll use the "precision algorithm" above.
Most helpful comment
This is how I do it:
Create pairs
order_price = int(order_price/binance_eth_currencies_digits[symbol])*binance_eth_currencies_digits[symbol]