-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (44 loc) · 1.65 KB
/
main.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
import json
import yaml
import asyncio
import discord
from logger import log, embed
from binance_script import BinanceTradeBot
data = "data.json"
with open('auth.yml') as yml:
auth = yaml.load(yml, Loader=yaml.FullLoader)
api_key = auth['binance_api']
api_secret = auth['binance_secret']
discord_key = auth['discord_apikey']
class MyClient(discord.Client):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.bg_task = self.loop.create_task(self.binance_script())
async def on_ready(self):
print('Logged in as')
print(self.user.name)
print(self.user.id)
print('------')
async def binance_script(self):
await self.wait_until_ready()
channel = self.get_channel(877341571173986325) # channel ID goes here
while True:
with open(data, 'r') as file:
config = json.load(file)
for crypto, info in config.items():
bot = BinanceTradeBot(api_key, api_secret, crypto, info)
if bot.get_status():
order = bot.create_order()
message = bot.trade(order)
log(message)
await channel.send(embed=embed(message))
info['status'] = bot.status
info['last_buy'] = bot.last_buy
info['last_sell'] = bot.last_sell
with open(data, 'w') as file:
save = json.dumps(config, indent=4)
file.write(save)
await asyncio.sleep(300)
if __name__ == '__main__':
dc = MyClient()
dc.run(discord_key)