I used this code : depthdata = client.depth(symbol=symbol) biddepth = depthdata['bids']…
- User
I used this code : depth_data = client.depth(symbol=symbol) bid_depth = depth_data['bids'] ask_depth = depth_data['asks'] buy_price = float(bid_depth[0][0]) if bid_depth else 0.0 sell_price = float(ask_depth[0][0]) if ask_depth else 0.0 buy_qty = float(bid_depth[0][1]) if bid_depth else 0.0 sell_qty = float(ask_depth[0][1]) if ask_depth else 0.0 executed_orders_qty = 0.0 order_price = buy_price executed_orders = order_price == mark_price
for buy_price, buy_qty in bid_depth: if buy_price == mark_price: order = buy_qty executed_orders_qty = order
Subtract executed order quantity from buy_qty
buy_qty = float(bid_depth[0][1]) if bid_depth else 0.0 result = buy_qty - executed_orders_qty buy_price = float(bid_depth[0][0]) if bid_depth else 0.0 sell_price = float(ask_depth[0][0]) if ask_depth else 0.0
print(f"{result} |{buy_qty}")
But I getting ERROR: Traceback (most recent call last): File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 187, in signals = signal_generator(df) ^^^^^^^^^^^^^^^^^^^^ File "c:\Users\Alan.vscode\jew_bot\jew_bot\jew_bot.py", line 115, in signal_generator
buy_result = buy_qty - executed_orders_buy ^^^^^^^ UnboundLocalError: cannot access local variable 'executed_orders_buy' where it is not associated with a value - Assistant
The error you are encountering is because you are trying to access a local variable 'executed_orders_buy' that has not been defined before you use it in the line
buy_result = buy_qty - executed_orders_buy.To fix this issue, you need to define the 'executed_orders_buy' variable before using it. You can initialize it to 0 before the for loop, and then update it within the loop based on your conditions. Here's the updated code:
pythonexecuted_orders_buy = 0.0 for buy_price, buy_qty in bid_depth: if buy_price == mark_price: order = buy_qty executed_orders_buy = order # Subtract executed order quantity from buy_qty buy_qty = float(bid_depth[0][1]) if bid_depth else 0.0 result = buy_qty - executed_orders_buy buy_price = float(bid_depth[0][0]) if bid_depth else 0.0 sell_price = float(ask_depth[0][0]) if ask_depth else 0.0 print(f"{result} |{buy_qty}")Make sure to replace 'executed_orders_buy' with the correct variable name in your code, as it might be different from what I assumed based on the provided code snippet.
- User
- Assistant
The error you're encountering is because you're trying to compare a float value
buy_resultwith a string valuesell_qtyin the lineelif (buy_result > (1 + threshold) > sell_qty) and (buy_price > mark_price + price_threshold):To fix this, you need to convert the
sell_qtyvariable to a float before comparing it withbuy_result. You can update the code as follows:pythonelif (buy_result > (1 + threshold) > float(sell_qty)) and (buy_price > mark_price + price_threshold):By using
float(sell_qty), you will convert thesell_qtyvalue to a float before performing the comparison.Make sure to apply the necessary conversions for comparison wherever you have float and string values being compared.
- User
- Assistant
The error you're encountering is due to subtracting a float value (
executed_orders_buy) from a string value (buy_qty) in the linebuy_result = buy_qty - executed_orders_buy.To resolve this issue, you need to ensure that the variable
buy_qtyandexecuted_orders_buyare both of the same type (float or string) before performing the subtraction operation. You can use thefloat()function to convert the string value to a float before subtracting them.Here's the updated code:
pythonbuy_qty = float(bid_depth[0][1]) if bid_depth else 0.0 executed_orders_buy = float(executed_orders_buy) if executed_orders_buy else 0.0 buy_result = buy_qty - executed_orders_buyBy using
float(executed_orders_buy), you will convert theexecuted_orders_buyvalue to a float before subtracting it frombuy_qty.Make sure to apply the necessary conversions for variables wherever you have mismatched types in your code.