-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path__main__.py
More file actions
58 lines (53 loc) · 1.75 KB
/
Copy path__main__.py
File metadata and controls
58 lines (53 loc) · 1.75 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
import asyncio
import logging
import config
import time
from BotApp.Instruments import BinanceFutures
from BotApp.strategy import SampleStrategy
from Server import server
from aiogram import executor
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s',
level=logging.WARNING)
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
# Полуение количества секунд между свечами
async def get_timer():
a = 0
b = 0
for i in config.time_frame:
if i.isdigit():
a += 1
if config.time_frame[-1] == 's':
b = 1
if config.time_frame[-1] == 'm':
b = 60
if config.time_frame[-1] == 'h':
b = 3600
if config.time_frame[-1] == 'd':
b = 86400
timer = int(config.time_frame[0:a]) * b
return timer
async def main():
starttime = time.time()
timer = await get_timer()
SampleStrategy('BTCUSDT', config.time_frame)
SampleStrategy('ETHUSDT', config.time_frame)
while True:
if server.trade_access:
tasks = []
await BinanceFutures.check_balance()
print(BinanceFutures.balance)
for i in BinanceFutures.coins:
task = asyncio.create_task(i.trading())
tasks.append(task)
await asyncio.sleep(0)
await asyncio.gather(*tasks)
await asyncio.sleep(timer - ((time.time() - starttime) % timer))
else:
await asyncio.sleep(0)
if __name__ == "__main__":
try:
loop = asyncio.get_event_loop()
loop.create_task(main())
executor.start_polling(server.dp, skip_updates=True)
except Exception as err:
logging.error(err, exc_info=True)