-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_bot.py
More file actions
56 lines (52 loc) · 1.71 KB
/
Copy pathcrypto_bot.py
File metadata and controls
56 lines (52 loc) · 1.71 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
from parameters import *
from initialize import initialize
from Push_notification import push
from add_row import add_row
from balances import balances
from sell_condition import sell_condition
from buy_condition import buy_condition
from binance_order import binance_order
from database import create, add_row_to_db
import traceback
import math
from datetime import datetime
import time
"""
Runs the whole algorithm, to make the documentation comment the sleep functions and uncomment the break
"""
if database():
create()
df=initialize()
MSG = f"Initiating trading {symbol()} 1h using EMA"
push(MSG)
amt1, amt2=balances(df)
total_initial=amt1+amt2
bought_price=0
while True:
#break #uncomment for doc building
if datetime.now().minute!=0:
time.sleep(60)
continue
action='-'
df=add_row(df)
amt1, amt2=balances(df)
if amt2>amt1 and buy_condition(df):
binance_order(symbol(), amt2, "BUY")
push(f"BUY, price: {df['price'][len(df)-1]}, @: {datetime.now()}")
action='BUY'
bought_price=df['price'][len(df)-1]
if amt1>amt2 and sell_condition(df):
binance_order(symbol(), amt1, "SELL")
rtrn=round(df['price'][len(df)-1]/bought_price, 2)
push(f"SELL, price: {df['price'][len(df)-1]}, return: {rtrn}% @:',{datetime.now()}")
action='SELL'
df["amt_BUSD"][len(df)-1] = amt2
df["amt_BNB"][len(df)-1] = amt1
if(database()):
price=df['price'][len(df)-1]
money=(amt2+amt1)*price
try:
add_row_to_db(price=price, long=df['long_avg'][len(df)-1], short=df['short_avg'][len(df)-1], money=money, action=action)
except:
traceback.print_exc()
time.sleep(math.floor(interval_seconds()*0.5))