Lot size function round off

do u see any flaw in my lot size func. sometimes it just doesnt round off properly sometimes.

def lot_sizing(self, price, amount, btc=False, last=False):
precision_oco = int(markets[self.symbol][‘info’][‘quotePrecision’])
price_str_buy = ‘{:0.0{}f}’.format(price, precision_oco)
btc_per_trade = float(amount)

    filters = markets[self.symbol]['info']['filters']
    step_size = None
    for f in filters:
        if f['filterType'] == 'LOT_SIZE':
            step_size = float(f['stepSize'])
            break

    precision = int(round(-math.log(step_size, 10), 0))

    if btc:
        quantity_buy = (btc_per_trade / price) * 0.999  # calculating the quantity of per coin too buy
    else:
        quantity_buy = float(amount) * 0.999  # calculating the quantity of per coin too buy

    final_quantity_buy = round(quantity_buy, precision)  # rounding of the quantity

    if last:
        final_quantity_buy = final_quantity_buy-step_size  # Total tradeable balance

    return final_quantity_buy

THANKS.

Please find a python forum for dev questions