-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
107 lines (84 loc) · 2.89 KB
/
main.py
File metadata and controls
107 lines (84 loc) · 2.89 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import asyncio
import os
import threading
import telebot
import telegram_bot
from database.database import Database
from dotenv import load_dotenv
import ccxt
from datetime import datetime
from exchange.bybit_exchange import BybitExchange
from monitoring.monitoring import Monitoring
from multiprocessing import Process
from strategy import strategy_manager
from telegram_bot.handlers import TelegramBotHandlers
# import ccxt
# from exchange.binance_exchange import BinanceExchange
# from exchange.hyperliquid_exchange import HyperLiquidExchange
# from analysis.technical_analysis import TechnicalAnalysis
#
# from utils.converter import Converter
# from eth_utils import from_wei, to_hex
# from eth_account.account import Account
from loguru import logger
load_dotenv()
api_key_bybit = os.getenv('BYBIT_API_TESTNET')
api_secret_bybit = os.getenv('BYBIT_API_SECRET_TESTNET')
login_click = os.getenv('CLICKHOUSE_LOGIN')
password_click = os.getenv('CLICKHOUSE_PASSWORD')
database = Database('localhost', 8123, login_click, password_click)
logger.remove()
logger.add("logs/info.log", level="INFO")
orders_columns = {
'orderId': 'String',
'exchange': 'String',
'symbol': 'String',
'price': 'Decimal(38, 20)',
'stopPrice': 'Decimal(38, 20)',
'qty': 'Decimal(38, 20)',
'executedQty': 'Decimal(38, 20)',
'totalCost': 'Decimal(38, 20)',
'side': 'String',
'orderType': 'String',
'orderStatus': 'String',
'createdTime': 'DateTime',
'updatedTime': 'DateTime',
'commission': 'Decimal(38, 20)'
}
database.create_table('orders', orders_columns)
strategies_columns = {
'strategyId': 'String',
'name': 'String',
'type': 'String',
'exchange': 'String',
'symbol': 'String',
'balance': 'Decimal(38, 20)',
'assetsNumber': 'Decimal(38, 20)',
'openPositions': 'Boolean',
'status': 'Boolean',
'createdTime': 'DateTime',
'settings': 'Map(String, Double)'
}
database.create_table('strategies', strategies_columns)
order_strategy_link_columns = {
'orderId': 'String',
'strategyId': 'String'
}
database.create_table('order_strategy_link', order_strategy_link_columns)
if __name__ == '__main__':
monitoring = Monitoring(database)
strategies = monitoring.get_launched_strategies()
for strategy in strategies:
strategy_manager.start_strategy(strategy['strategyId'], first_launch=True)
telegram_bot_token = os.getenv('TELEGRAM_BOT_TOKEN')
bot = TelegramBotHandlers(monitoring, database, telegram_bot_token)
logger.info("Bot created!")
# thread1 = threading.Thread(target=func)
thread_bot = threading.Thread(target=bot.start_bot)
logger.info(f"Starting {thread_bot.name}...")
thread_bot.start()
# Ожидание завершения обоих потоков
logger.info("Waiting for threads to finish...")
# thread1.join()
thread_bot.join()
logger.info("All threads finished executing.")