-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
42 lines (34 loc) · 1.28 KB
/
main.py
File metadata and controls
42 lines (34 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import threading
import asyncio
from typing import Union, Literal
from dotenv import load_dotenv
load_dotenv()
from core.logs import logging
from core.utils import BANNER
from strategies.sma_crossover import main as extended_main, app as extended_app
from strategies.sma_crossover_hibachi import main as hibachi_main, app as hibachi_app
# Print ASCII art banner
print(BANNER)
def start_bot_background(exchange: Literal["extended", "hibachi"] = "extended"):
"""Start the bot in a background thread"""
def run_bot():
logging.info(f"Starting bot with exchange: {exchange}")
if exchange == "extended":
main = extended_main
app = extended_app
elif exchange == "hibachi":
main = hibachi_main
app = hibachi_app
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(main())
except Exception as e:
print(f"Bot error: {e}")
raise e
bot_thread = threading.Thread(target=run_bot, daemon=True)
bot_thread.start()
# Start bot when module is imported
start_bot_background(exchange=os.getenv("EXCHANGE", "extended"))
application = hibachi_app if os.getenv("EXCHANGE", "extended") == "hibachi" else extended_app