Hi people,
has anyone made proper working functions for buying and selling a pair like “DOGEUSDT” or any other pair (margin trading),
I have tried my best but I end up with different errors like  Lot size failure, Insufficient funds, or the most commonly known price filter errors of this API
the functions I came up with are below as follows, can someone tell me what am I missing

This function is to come up with buy/short quantity and it works pretty fairly
def buy_quantity(symbol,asset): a = 0 while a < 3: try: bal = pd.DataFrame(client.get_margin_account()['userAssets']) bal = bal[bal['asset']==asset] bal = float(bal['free']) * 0.90 break except: print("can't extract asset value..retrying") a+=1 price = float(client.get_recent_trades(symbol=symbol)[0]['price']) stepSize = float(client.get_symbol_info(symbol)['filters'][2]['stepSize']) precision = int(round(math.log(stepSize, 10), 0)) quantity = (bal / price)*0.9995 # Trading fee taken in consideration quantity = round(quantity,precision) return quantity

This function is to cover the short, it basically tries to give you the borrowed quantity
def sell_quantity1(asset): a = 0 while a < 3: try: order = pd.DataFrame(client.get_margin_account()['userAssets']) order = order[order['asset']==asset] order = float(order['borrowed']) break except: print("can't extract borrowed order book...retrying") a+=1 order = round(order,5) return order

This function is to sell the long position
def sell_quantity2(asset): a = 0 while a < 3: try: order = pd.DataFrame(client.get_margin_account()['userAssets']) order = order[order['asset']==asset] order = float(order['free']) break except: print("can't extract order book...retrying") a+=1 order = round(order,5) return order
I think the functions 2 & 3 should work properly like the function 1 but they don’t, some or the other error pops out
Lot size failure, Insufficient funds, or something else, what am I missing here can someone please help me I am struggling from a couple of days
Thanks in advance