-
Notifications
You must be signed in to change notification settings - Fork 5
/
3c_bot_stats.py
323 lines (281 loc) · 18.1 KB
/
3c_bot_stats.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#################################################################
#
# 3commas bot stats
# giving a better overview of your deals in 3commas
#
# https://github.com/gunleik/3commas-tools
#
# @gunleik
#
#################################################################
import time
import sys
import os
from py3cw.request import Py3CW
from datetime import date
#from pprint import pprint
arguments = len(sys.argv) - 1
if arguments > 0:
me_want = sys.argv[1]
else:
me_want = "today"
if arguments > 1:
argument2 = sys.argv[2]
else:
argument2 = "na"
if me_want == "today" or me_want == "active":
my_limit = 250
else:
my_limit = 1000
if me_want == "--help":
print()
print("Usage: ./3c_bot_stats.sh [today|active|all|datefilter] [totals]")
print()
print("optional arguments:")
print(" today, (default) show deals started, ended today or currently running")
print(" today totals, todays deals, but don't show individual deals")
print(" active, show deals currently running")
print(" all, show all deals (limit on 1000 per account)")
print(" datefilter, e.g. 2021-05-31 to show deals from specific date")
print()
sys.exit()
# initiate API with key/secret from os env
p3cw = Py3CW(
key=os.environ.get('threecommas_key').rstrip(),
secret=os.environ.get('threecommas_secret').rstrip(),
request_options={
'request_timeout': 10,
'nr_of_retries': 1,
'retry_status_codes': [502]
}
)
# change to paper account requires api with account write access
# real or paper account is set on global account settings, so manually changing
# this in the 3c web console makes the setting for this script also
#error, mode = p3cw.request(
# entity='users',
# action='change_mode',
# payload={
# "mode": 'paper'
# }
#)
# info about accounts
error, accounts = p3cw.request(
entity='accounts',
action=''
)
grandtotal_bot_sum = 0
grandtotal_bot_closed_sum = 0
grandtotal_bot_reserved_sum = 0
for account in accounts:
print()
print('##########################################################################################')
print()
print("AccountID: " + str(account['id']) + " # Account Name: " + str(account['name']) + " # Account USD amount: " + str(format(float(account['usd_amount']), '.2f')))
# fetch deals
error, deals = p3cw.request(
entity='deals',
action='',
payload={
"account_id": str(account['id']),
"limit": my_limit
}
)
deals_sorted = sorted(deals, key=lambda botname: botname['bot_name'])
prev_botname = ""
this_bot_sum = 0
this_bot_closed_sum = 0
this_bot_reserved_sum = 0
this_bot_opendeals = 0
this_bot_closeddeals = 0
show_openclosed = False
for deal in deals_sorted:
if deal['finished?'] == True:
this_profitpst = str(deal['final_profit_percentage'])
this_profitusd = str(format(float(deal['usd_final_profit']), '.2f'))
elif deal['finished?'] == False:
this_profitpst = str(deal['actual_profit_percentage'])
this_profitusd = str(format(float(deal['actual_usd_profit']), '.2f'))
else:
this_profit = "err"
if me_want == "today":
show_openclosed = True
if str(date.today()) in str(deal['created_at']) or str(date.today()) in str(deal['closed_at']) or str(deal['closed_at']) == "None":
if deal['bot_name'] != prev_botname:
if this_bot_sum != 0:
print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')), end = '')
print(" # Reserved: " + str(format(this_bot_reserved_sum, '.2f')), end = '')
print(" # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')), end = '')
print(" # OpenDeals: " + str(this_bot_opendeals), end = '')
print(" # ClosedDeals: " + str(this_bot_closeddeals))
grandtotal_bot_sum = grandtotal_bot_sum + this_bot_sum
grandtotal_bot_closed_sum = grandtotal_bot_closed_sum + this_bot_closed_sum
grandtotal_bot_reserved_sum = grandtotal_bot_reserved_sum + this_bot_reserved_sum
this_bot_opendeals = 0
this_bot_closeddeals = 0
this_bot_closed_sum = 0
this_bot_reserved_sum = 0
this_bot_sum = float(this_profitusd)
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd)
this_bot_closeddeals = 1
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd)
this_bot_opendeals = 1
print("----------------------------------------------------------------")
print("BotName: " + str(deal['bot_name']), end = '')
try:
error, bot = p3cw.request( entity='bots', action='show', action_id=str(deal['bot_id']) )
print(" # ENABLED: " + str(bot['is_enabled']))
except:
print(" # ENABLED: DELETED")
if argument2 != "totals":
print("Start: " + str(deal['created_at']) + " # Stop: " + '%-24s' % str(deal['closed_at']) + " # Pair: " + '%-11s' % str(deal['pair']) + " # Status: " + '%-11s' % str(deal['status']) + " # SO: " + str(deal['completed_safety_orders_count']) + "(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']) + " # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD")
else:
this_bot_sum = float(this_profitusd) + this_bot_sum
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd) + this_bot_closed_sum
this_bot_closeddeals = int(this_bot_closeddeals) + 1
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd) + this_bot_reserved_sum
this_bot_opendeals = int(this_bot_opendeals) + 1
if argument2 != "totals":
print("Start: " + str(deal['created_at']), end = '')
print(" # Stop: " + '%-24s' % str(deal['closed_at']), end = '')
print(" # Pair: " + '%-11s' % str(deal['pair']), end = '')
print(" # Status: " + '%-11s' % str(deal['status']), end = '')
print(" # SO: " + str(deal['completed_safety_orders_count']), end = '')
print("(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']), end = '')
print(" # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD", end = '')
print("")
if me_want == "active":
if str(deal['closed_at']) == "None":
if deal['bot_name'] != prev_botname:
if this_bot_sum != 0:
print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')) + " # Reserved: " + str(format(this_bot_reserved_sum, '.2f')) + " # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')))
grandtotal_bot_sum = grandtotal_bot_sum + this_bot_sum
grandtotal_bot_closed_sum = grandtotal_bot_closed_sum + this_bot_closed_sum
grandtotal_bot_reserved_sum = grandtotal_bot_reserved_sum + this_bot_reserved_sum
this_bot_closed_sum = 0
this_bot_reserved_sum = 0
this_bot_sum = float(this_profitusd)
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd)
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd)
print("----------------------------------------------------------------")
print("BotName: " + str(deal['bot_name']), end = '')
try:
error, bot = p3cw.request( entity='bots', action='show', action_id=str(deal['bot_id']) )
print(" # ENABLED: " + str(bot['is_enabled']))
except:
print(" # ENABLED: DELETED")
print("Start: " + str(deal['created_at']) + " # Stop: " + '%-24s' % str(deal['closed_at']) + " # Pair: " + '%-11s' % str(deal['pair']) + " # Status: " + '%-11s' % str(deal['status']) + " # SO: " + str(deal['completed_safety_orders_count']) + "(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']) + " # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD")
else:
this_bot_sum = float(this_profitusd) + this_bot_sum
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd) + this_bot_closed_sum
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd) + this_bot_reserved_sum
print("Start: " + str(deal['created_at']) + " # Stop: " + '%-24s' % str(deal['closed_at']) + " # Pair: " + '%-11s' % str(deal['pair']) + " # Status: " + '%-11s' % str(deal['status']) + " # SO: " + str(deal['completed_safety_orders_count']) + "(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']) + " # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD")
elif me_want == "all":
show_openclosed = True
if deal['bot_name'] != prev_botname:
if this_bot_sum != 0:
#print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')) + " # Reserved: " + str(format(this_bot_reserved_sum, '.2f')) + " # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')))
print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')), end = '')
print(" # Reserved: " + str(format(this_bot_reserved_sum, '.2f')), end = '')
print(" # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')), end = '')
print(" # OpenDeals: " + str(this_bot_opendeals), end = '')
print(" # ClosedDeals: " + str(this_bot_closeddeals))
grandtotal_bot_sum = grandtotal_bot_sum + this_bot_sum
grandtotal_bot_closed_sum = grandtotal_bot_closed_sum + this_bot_closed_sum
grandtotal_bot_reserved_sum = grandtotal_bot_reserved_sum + this_bot_reserved_sum
this_bot_opendeals = 0
this_bot_closeddeals = 0
this_bot_closed_sum = 0
this_bot_reserved_sum = 0
this_bot_sum = float(this_profitusd)
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd)
this_bot_closeddeals = 1
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd)
this_bot_opendeals = 1
print("----------------------------------------------------------------")
print("BotName: " + str(deal['bot_name']), end = '')
try:
error, bot = p3cw.request( entity='bots', action='show', action_id=str(deal['bot_id']) )
print(" # ENABLED: " + str(bot['is_enabled']))
except:
print(" # ENABLED: DELETED")
print("Start: " + str(deal['created_at']) + " # Stop: " + '%-24s' % str(deal['closed_at']) + " # Pair: " + '%-12s' % str(deal['pair']) + " # Status: " + '%-11s' % str(deal['status']) + " # SO: " + str(deal['completed_safety_orders_count']) + "(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']) + " # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD")
else:
this_bot_sum = float(this_profitusd) + this_bot_sum
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd) + this_bot_closed_sum
this_bot_closeddeals = int(this_bot_closeddeals) + 1
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd) + this_bot_reserved_sum
this_bot_opendeals = int(this_bot_opendeals) + 1
print("Start: " + str(deal['created_at']) + " # Stop: " + '%-24s' % str(deal['closed_at']) + " # Pair: " + '%-12s' % str(deal['pair']) + " # Status: " + '%-11s' % str(deal['status']) + " # SO: " + str(deal['completed_safety_orders_count']) + "(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']) + " # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD")
else:
if str(me_want) in str(deal['created_at']) or str(me_want) in str(deal['closed_at']):
show_openclosed = True
if deal['bot_name'] != prev_botname:
if this_bot_sum != 0:
#print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')) + " # Reserved: " + str(format(this_bot_reserved_sum, '.2f')) + " # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')))
print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')), end = '')
print(" # Reserved: " + str(format(this_bot_reserved_sum, '.2f')), end = '')
print(" # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')), end = '')
print(" # OpenDeals: " + str(this_bot_opendeals), end = '')
print(" # ClosedDeals: " + str(this_bot_closeddeals))
grandtotal_bot_sum = grandtotal_bot_sum + this_bot_sum
grandtotal_bot_closed_sum = grandtotal_bot_closed_sum + this_bot_closed_sum
grandtotal_bot_reserved_sum = grandtotal_bot_reserved_sum + this_bot_reserved_sum
this_bot_opendeals = 0
this_bot_closeddeals = 0
this_bot_closed_sum = 0
this_bot_reserved_sum = 0
this_bot_sum = float(this_profitusd)
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd)
this_bot_closeddeals = 1
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd)
this_bot_opendeals = 1
print("----------------------------------------------------------------")
print("BotName: " + str(deal['bot_name']), end = '')
try:
error, bot = p3cw.request( entity='bots', action='show', action_id=str(deal['bot_id']) )
print(" # ENABLED: " + str(bot['is_enabled']))
except:
print(" # ENABLED: DELETED")
print("Start: " + str(deal['created_at']) + " # Stop: " + '%-24s' % str(deal['closed_at']) + " # Pair: " + '%-12s' % str(deal['pair']) + " # Status: " + '%-11s' % str(deal['status']) + " # SO: " + str(deal['completed_safety_orders_count']) + "(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']) + " # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD")
else:
this_bot_sum = float(this_profitusd) + this_bot_sum
if deal['finished?'] == True:
this_bot_closed_sum = float(this_profitusd) + this_bot_closed_sum
this_bot_closeddeals = int(this_bot_closeddeals) + 1
elif deal['finished?'] == False:
this_bot_reserved_sum = float(this_profitusd) + this_bot_reserved_sum
this_bot_opendeals = int(this_bot_opendeals) + 1
print("Start: " + str(deal['created_at']) + " # Stop: " + '%-24s' % str(deal['closed_at']) + " # Pair: " + '%-12s' % str(deal['pair']) + " # Status: " + '%-11s' % str(deal['status']) + " # SO: " + str(deal['completed_safety_orders_count']) + "(+" + str(deal['completed_manual_safety_orders_count']) + ")/" + str(deal['max_safety_orders']) + " # Profit: " + '%6s' % str(this_profitpst) + "% / " + str(this_profitusd) + " USD")
prev_botname = deal['bot_name']
if this_bot_sum != 0:
# print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')) + " # Reserved: " + str(format(this_bot_reserved_sum, '.2f')) + " # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')))
print("BotCompletedSum: " + str(format(this_bot_closed_sum, '.2f')), end = '')
print(" # Reserved: " + str(format(this_bot_reserved_sum, '.2f')), end = '')
print(" # IfPanicSellAll: " + str(format(this_bot_sum, '.2f')), end = '')
if show_openclosed == True:
print(" # OpenDeals: " + str(this_bot_opendeals), end = '')
print(" # ClosedDeals: " + str(this_bot_closeddeals), end = '')
print("")
grandtotal_bot_sum = grandtotal_bot_sum + this_bot_sum
grandtotal_bot_closed_sum = grandtotal_bot_closed_sum + this_bot_closed_sum
grandtotal_bot_reserved_sum = grandtotal_bot_reserved_sum + this_bot_reserved_sum
print()
print('##########################################################################################')
print("TotalCompleted : " + str(format(grandtotal_bot_closed_sum, '.2f')))
print("TotalReserved : " + str(format(grandtotal_bot_reserved_sum, '.2f')))
print("TotalIfPanic : " + str(format(grandtotal_bot_sum, '.2f')))