This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor_margin.py
63 lines (50 loc) · 1.97 KB
/
monitor_margin.py
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
import config as conf
import functions.margin as marg
import rebalance_margin as rebalance
from datetime import datetime, timedelta
import time
import telebot
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def monitor_margin(hours=8, frequency=15, rebalance_required=False):
# Set up tg bot
bot = telebot.TeleBot(conf.BOT_ID)
start_time = datetime.now()
end_time = start_time + timedelta(hours=hours)
while datetime.now() <= end_time:
message1 = []
print('--------------')
message1.append('--------------')
cur_time = datetime.now()
message1.append(cur_time.strftime("%H:%M:%S"))
print(cur_time.strftime("%H:%M:%S"))
for wallet in conf.WALLETS:
if wallet['wallet_name'] in conf.SKIP_WALLETS:
# Skip
continue
else:
margin, equity = marg.get_account(wallet['wallet_name'],
conf.HOST,
wallet['data'],
conf.PARAMETERS)
message1.append(wallet['wallet_name'] + " - " + str(margin) + " - " + str(equity))
status = bot.send_message(chat_id=conf.INTERNAL_CHATID_DYDX,
text="\n".join(message1),
disable_notification=True)
if rebalance_required:
message2 = []
print('--------------')
message2.append('--------------')
message2 = rebalance.rebalance_margin()
status = bot.send_message(chat_id=conf.INTERNAL_CHATID_DYDX,
text="\n".join(message2),
disable_notification=True)
time.sleep(60 * frequency)