Compare commits
2 Commits
8d28a7e2fc
...
e67077c093
| Author | SHA1 | Date |
|---|---|---|
|
|
e67077c093 | |
|
|
b8606906fb |
Binary file not shown.
|
|
@ -899,6 +899,50 @@ class MLTradingBot:
|
|||
"""Main bot loop"""
|
||||
logger.info('🤖 BOT STARTED (V5 - SUSTAINABLE)')
|
||||
|
||||
# Auto-recover open positions from Binance on restart
|
||||
logger.info('📥 Recovering trades from Binance...')
|
||||
try:
|
||||
for pair in ['BTCUSDT', 'ETHUSDT', 'SOLUSDT', 'BNBUSDT', 'XRPUSDT']:
|
||||
orders = self.binance._client.get_open_orders(symbol=pair)
|
||||
if orders:
|
||||
o = orders[0]
|
||||
self.current_trades[pair] = {
|
||||
'qty': float(o['origQty']),
|
||||
'buy_price': float(o['price']),
|
||||
'buy_time': ''.join([str(i) for i in range(10)]),
|
||||
'order_id': o['orderId'],
|
||||
'peak_profit': 0.0
|
||||
}
|
||||
logger.info(f' ✅ Recovered {pair}: {o[origQty]} @ {o[price]}')
|
||||
except Exception as e:
|
||||
logger.debug(f'Recovery scan: {e}')
|
||||
|
||||
logger.info(f'✅ Recovered {len(self.current_trades)} trades from Binance')
|
||||
|
||||
# STARTUP: Load open orders from Binance so Bot knows its positions
|
||||
logger.info('📥 Loading open positions from Binance...')
|
||||
try:
|
||||
account = await self.binance.get_balance()
|
||||
for pair in ['BTCUSDT', 'ETHUSDT', 'SOLUSDT', 'BNBUSDT', 'XRPUSDT']:
|
||||
try:
|
||||
orders = await self.binance.get_open_orders(pair)
|
||||
if orders:
|
||||
order = orders[0]
|
||||
self.current_trades[pair] = {
|
||||
'qty': float(order['origQty']),
|
||||
'buy_price': float(order['price']),
|
||||
'buy_time': datetime.fromtimestamp(order['time']/1000).isoformat(),
|
||||
'order_id': order['orderId'],
|
||||
'peak_profit': 0.0
|
||||
}
|
||||
logger.info(f' ✅ Loaded {pair}: {order[origQty]} @ ')
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.warning(f'Could not load Binance positions: {e}')
|
||||
|
||||
logger.info(f'✅ Startup complete: {len(self.current_trades)} positions loaded from Binance')
|
||||
|
||||
# Create trigger file location
|
||||
trigger_file = '/tmp/bot_liquidate_trigger'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue