Hi Arcamus,
Thank you for your valuable suggestions. I’ve made several adjustments to the script following your recommendations, and I’d like to share the changes implemented so far for your review. I’m currently testing the latest version of the bot and will update you with results throughout the day.
-
Debugging Enhancements
I’ve added a detailed log that prints all the key parameters of the bot in each iteration. This includes the current price, Bollinger Bands (high, low, and average), balance, position status, calculated notional, and any warnings or errors encountered.
New log generated by the script:
2024-12-25 14:02:08 - Details:
- Current Price: 98429.20
- BB Low: 98121.35, BB High: 98713.68
- BB Average: 98417.51
- USDT Balance: 226.97
- BTC Balance: 0.000000
- Current Position: none
- Position Size: 0.000000
- Timeframe: 15m, Leverage: 5x, Stop-Loss: 15.0%
Additionally, if a warning or error occurs, the log includes the related message. For example:
Warning: Time difference is high (-1398 ms). Please verify your system clock.
Error fetching OHLCV data: binanceusdm {“code”:-1021,“msg”:“Timestamp for this request was 1000ms ahead of the server’s time.”}
-
Time Synchronization
I implemented a function that syncs the local time with Binance’s server at startup and at regular intervals. Since this adjustment, the {“code”:-1021} timestamp error has not reappeared. However, the bot does issue a warning if the time difference exceeds 1000 ms.
Relevant Code: Time Synchronization
def sync_time_with_binance():
server_time = exchange.fetch_time()
local_time = int(time.time() * 1000)
time_difference = local_time - server_time
print(f"Time synchronized with Binance: Difference of {time_difference} ms.“)
if abs(time_difference) > 1000:
print(f"Warning: Time difference is high ({time_difference} ms). Please verify your system clock.”)
return time_difference
-
User-Defined Parameters
At startup, the bot prompts the user to input leverage, timeframe, and Stop-Loss percentage. This allows greater flexibility in tailoring the strategy.
Relevant Code: User Input
def get_user_settings():
lev = int(input("Enter leverage level (e.g., 5): "))
stop_loss_pct = float(input("Enter Stop-Loss percentage (e.g., 0.15 for 15%): "))
timeframe = input("Enter timeframe (e.g., 15m, 5m, 1h): ").lower()
return lev, stop_loss_pct, timeframe
-
Notional Validation
The script now validates the notional before submitting the order and logs a message if it is below the 100 USD threshold.
Relevant Code: Notional Validation
def calculate_order_amount(price):
usdt_balance, _, _, _ = get_balance_and_positions()
usdt_to_use = usdt_balance * 0.75
order_amount = usdt_to_use / price
notional = order_amount * price
print(f"Calculated amount: {order_amount:.6f} BTC (Notional: {notional:.2f} USD).“)
if notional < 100:
print(f"Error: Insufficient notional ({notional:.2f} USD). Minimum required is 100 USD.”)
return order_amount
Current Behavior
The bot now generates a comprehensive and detailed log in each iteration, enabling us to analyze all key parameters.
Time synchronization seems to have resolved the timestamp issue, and there are no recent errors related to notional validation.
I am still testing how the bot performs under various market conditions.
Questions
Do you think the current log is sufficient for thorough analysis, or would you recommend adding more details?
Based on the shared code fragments, do you notice any further adjustments we should make?
Is there anything else we should monitor or validate to ensure the bot functions correctly?
I greatly appreciate any feedback or additional suggestions you can provide. I’ll keep you updated on the test results throughout the day.
Best regards,
Daniel