new bot 2

This commit is contained in:
Dobromir Popov
2025-03-10 10:29:40 +02:00
parent c8b0f77d32
commit 9b6d3f94ed
8 changed files with 1307 additions and 7 deletions

View File

@ -9,6 +9,10 @@ import ccxt.async_support as ccxt
from dotenv import load_dotenv
import platform
# Set Windows event loop policy at module level
if platform.system() == 'Windows':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
class LiveDataManager:
def __init__(self, symbol, exchange_name='mexc', window_size=120):
load_dotenv() # Load environment variables
@ -45,12 +49,16 @@ class LiveDataManager:
retries = 3
for attempt in range(retries):
try:
candles = await self.exchange.fetch_ohlcv(self.symbol, '1m', since=since, limit=self.window_size)
candles = await self.exchange.fetch_ohlcv(
self.symbol, '1m', since=since, limit=self.window_size
)
for candle in candles:
self.candles.append(self._format_candle(candle))
if candles:
self.last_candle_time = candles[-1][0]
print(f"Fetched {len(candles)} initial candles.")
print(f"""Fetched {len(candles)} initial candles for period {since} to {now}.
Price range: {min(candle[1] for candle in candles)} to {max(candle[2] for candle in candles)}.
Current price: {candles[-1][4]}. Total volume: {sum(candle[5] for candle in candles)}""")
return # Exit the function if successful
except Exception as e:
print(f"Attempt {attempt + 1} failed: {e}")