after all, the exchange receives a percentage of all transactions, and in your code only a percentage of transactions is taken away, and not the purchase/sale cost
it is logical to assume that the transaction will be profitable if the sell_price / buy_price - 1 > fee_ratio
I don't understand your math. my vision for calculating the balance is this:
maybe this is valid only for BTCUSDT on binance
after all, the exchange receives a percentage of all transactions, and in your code only a percentage of transactions is taken away, and not the purchase/sale cost it is logical to assume that the transaction will be profitable if the sell_price / buy_price - 1 > fee_ratio