Skip to content

Commit 30de364

Browse files
bot startup message sync fixes
1 parent 5c3085d commit 30de364

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

Trading-Automation/trading_automation.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,24 @@ def telegram_main():
422422
# Add periodic alarm job (every 5 minutes)
423423
application.job_queue.run_repeating(alarm_job, interval=300, first=10)
424424

425+
# Send startup alert using post_init hook to avoid scheduling issues
426+
async def post_init(application):
427+
try:
428+
fetch_usdc_balance()
429+
total_positions = len([p for p in positions.items() if get_latest_price(p[0]) and p[1]['qty'] * get_latest_price(p[0]) > DUST_LIMIT])
430+
431+
await send_alarm_message(
432+
f"🤖 BOT STARTED\n\n"
433+
f"✅ System initialized successfully\n"
434+
f"💰 USDC Balance: ${balance['usd']:.2f}\n"
435+
f"📊 Active Positions: {total_positions}\n"
436+
f"⏸️ Trading Status: {'PAUSED' if is_paused() else 'ACTIVE'}\n"
437+
f"🕐 Startup Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
438+
)
439+
except Exception as e:
440+
print(f"[ALERT ERROR] Could not send startup alert: {e}")
441+
442+
application.post_init = post_init
425443
application.run_polling()
426444

427445

@@ -1040,7 +1058,6 @@ def dynamic_momentum_set(symbol):
10401058
Produce per-interval dynamic thresholds tuned for micro-scalping.
10411059
We make shorter TFs a bit more sensitive (lower k), longer TFs stricter (higher k).
10421060
"""
1043-
# You can tweak these multipliers & floors per your fills/slippage stats
10441061
thr_1m = dynamic_momentum_threshold(symbol, '1m', lookback=60, k=0.55, floor_=0.0007, cap_=0.015)
10451062
thr_5m = dynamic_momentum_threshold(symbol, '5m', lookback=48, k=0.70, floor_=0.0010, cap_=0.018)
10461063
thr_15m = dynamic_momentum_threshold(symbol, '15m', lookback=48, k=0.85, floor_=0.0015, cap_=0.020)
@@ -1563,29 +1580,6 @@ async def alarm_job(context: CallbackContext):
15631580
reconcile_positions_with_binance(client, positions)
15641581
print(f"[INFO] Bot paused state on startup: {is_paused()}")
15651582

1566-
# Send startup alert
1567-
import asyncio
1568-
try:
1569-
async def send_startup_alert():
1570-
fetch_usdc_balance()
1571-
total_positions = len([p for p in positions.items() if get_latest_price(p[0]) and p[1]['qty'] * get_latest_price(p[0]) > DUST_LIMIT])
1572-
1573-
await send_alarm_message(
1574-
f"🤖 BOT STARTED\n\n"
1575-
f"✅ System initialized successfully\n"
1576-
f"💰 USDC Balance: ${balance['usd']:.2f}\n"
1577-
f"📊 Active Positions: {total_positions}\n"
1578-
f"⏸️ Trading Status: {'PAUSED' if is_paused() else 'ACTIVE'}\n"
1579-
f"🕐 Startup Time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}"
1580-
)
1581-
1582-
loop = asyncio.new_event_loop()
1583-
asyncio.set_event_loop(loop)
1584-
loop.run_until_complete(send_startup_alert())
1585-
loop.close()
1586-
except Exception as e:
1587-
print(f"[ALERT ERROR] Could not send startup alert: {e}")
1588-
15891583
try:
15901584
trading_thread = threading.Thread(target=trading_loop, daemon=True)
15911585
trading_thread.start()

0 commit comments

Comments
 (0)