-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
140 lines (121 loc) · 4.84 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import silence_tensorflow.auto
from binance.client import Client
from binanceAPI.position_utilities import enter_long, enter_short
from data.triple_list import TripleList
from config import api_key, secret_key
from indicators.price import fetch_price
from indicators.rsi import fetch_RSI
from indicators.fetch_all_indicators import fetch_all_indicators
from tensorflow_utilities.tensor_model import TensorModel
from data.io_utilities import print_with_color, calculateWR
from time import sleep
from data.data_functions import save_result, save_position
import copy
# Binance API initialization
client = Client(api_key, secret_key)
# Global Variable Declarations
price = 0
state = 2
on_long = False
on_short = False
tp_price = 0
sl_price = 0
tp_count = 0
sl_count = 0
csv_path_result = "./data/ragebot_result.csv"
csv_path_dataset = "./data/ragebot_dataset.csv"
date = ""
data_position = None
data_check = None
pseudo = None
triple_log = TripleList()
# Global Functions
def close_position(isTP):
global on_long
global on_short
global tp_count
global sl_count
global csv_path_result
global csv_path_dataset
global date
global state
global pseudo
position = ""
if (on_long and isTP) or (on_short and (not isTP)):
position = "LONG"
elif (on_long and (not isTP)) or (on_short and isTP):
position = "SHORT"
save_position(csv_path_dataset, position, data_position)
if on_long and isTP:
state = state + 1 if (state != 3) else 3
elif on_long and (not isTP):
state = state - 1
elif on_short and isTP:
state = state - 1 if (state != 0) else 0
elif on_short and (not isTP):
state = state + 1
on_long = False
on_short = False
if not pseudo:
save_result(csv_path_result, data_position.date, position, "LONG" if on_long else "SHORT")
if isTP:
tp_count = tp_count + 1
print_with_color("green", "Position closed with TP")
print_with_color("yellow", "TP: " + str(tp_count) + " SL: " +
str(sl_count) + " Win-Rate: " + calculateWR(tp_count, sl_count))
else:
sl_count = sl_count + 1
print_with_color("red", "Position closed with SL")
print_with_color("yellow", "TP: " + str(tp_count) + " SL: " +
str(sl_count) + " Win-Rate: " + calculateWR(tp_count, sl_count))
else:
print_with_color("cyan", "dataset is updated")
position_history = triple_log.get_values()
print_with_color("yellow", "STATE = " + str(state) + ", List: " +
("X" if position_history[0] is None else position_history[0]) + ", " +
("X" if position_history[1] is None else position_history[1]) + ", " +
("X" if position_history[2] is None else position_history[2]))
print_with_color("cyan", "RageBot is running...\n")
while True:
try:
sleep(10)
data_check = fetch_all_indicators(client)
if not (on_long or on_short):
data_position = copy.deepcopy(data_check)
_, prediction = accuracy, prediction = TensorModel(csv_path_dataset).process_model(data_position)
triple_log.add(prediction)
pseudo = True
if state == 3:
if triple_log.confirm("LONG"):
pseudo = False
tp_price, sl_price = enter_long(client, pseudo)
on_long = True
if not pseudo:
print()
print_with_color("yellow", "Entered LONG Current: " + str(round(data_check.price, 2)) +
" TP_PRICE: " + str(round(tp_price, 2)) + " SL_PRICE: " + str(round(sl_price, 2)))
elif state == 2:
tp_price, sl_price = enter_long(client, pseudo)
on_long = True
elif state == 1:
tp_price, sl_price = enter_short(client, pseudo)
on_short = True
elif state == 0:
if triple_log.confirm("SHORT"):
pseudo = False
tp_price, sl_price = enter_short(client, pseudo)
on_short = True
if not pseudo:
print()
print_with_color("yellow", "Entered SHORT Current: " + str(round(data_check.price, 2)) +
" TP_PRICE: " + str(round(tp_price, 2)) + " SL_PRICE: " + str(round(sl_price, 2)))
else:
if (on_long and data_check.price > tp_price) or \
(on_short and data_check.price < tp_price):
close_position(True)
elif (on_long and data_check.price < sl_price) or \
(on_short and data_check.price > sl_price):
close_position(False)
except Exception as e:
error_message = str(e)
print_with_color("yellow", error_message)