-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (53 loc) · 1.64 KB
/
main.py
File metadata and controls
64 lines (53 loc) · 1.64 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import multiprocessing
import asyncio
import sys
from config import BUFFER_SIZE
from Agregator.Server import run_server
from Manager.BotMaster import BotMaster
from Telegram.UtilsTG import run_telegram_bot
def run_bot_master(signal_queue: multiprocessing.Queue):
"""
Starts the BotMaster process which manages the trading logic.
:param signal_queue: Multiprocessing queue to receive signals
"""
try:
bot_master = BotMaster(signal_queue)
asyncio.run(bot_master.start())
except Exception as e:
print(f"[run_bot_master] Error: {e}")
raise
def main():
"""
Main entry point of the application.
Initializes and starts the Server, BotMaster, and Telegram Bot processes.
"""
# Signal queue from FastAPI
signal_queue = multiprocessing.Queue(maxsize=BUFFER_SIZE)
# API Server Process
server_process = multiprocessing.Process(
target=run_server,
args=(signal_queue,),
name="ServerProcess"
)
# Trading Logic Process
bot_master_process = multiprocessing.Process(
target=run_bot_master,
args=(signal_queue,),
name="BotMasterProcess"
)
# Telegram Bot Process (polling)
telegram_process = multiprocessing.Process(
target=run_telegram_bot,
name="TelegramBotProcess"
)
# Start all processes
server_process.start()
bot_master_process.start()
telegram_process.start()
# Wait for completion (usually Ctrl+C)
server_process.join()
bot_master_process.join()
telegram_process.join()
if __name__ == "__main__":
multiprocessing.set_start_method('spawn', force=True)
main()