-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathupdate_bots_py
132 lines (113 loc) · 3.62 KB
/
update_bots_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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from py3cw.request import Py3CW
from time import sleep
#playin around with 3commas api
#this scripts assumes that you are trading USDT pairs.
#put in your key and secret from 3commas
key = ''
secret = ''
p3cw = Py3CW(
key=key,
secret=secret,
request_options={
'request_timeout': 10,
'nr_of_retries': 1,
'retry_status_codes': [502]
}
)
def getAccounts():
error, data = p3cw.request(
entity='accounts',
action=''
)
accounts=[]
for account in data:
account_id = account['id']
exchange_name = account['name']
accounts.append({'id':account_id,'exchange_name':exchange_name})
return accounts
def getDealData(account_id):
error, data = p3cw.request(
entity='deals',
action='',
payload={
"scope": 'active',
"account_id" : account_id
}
)
return data
def getBotData(account_id):
error, data = p3cw.request(
entity='bots',
action='',
payload={
#"scope": 'enabled',
"account_id" : account_id
}
)
return data
def updateBot(bot_id,bot_data):
error, data = p3cw.request(
entity='bots',
action='update',
action_id = str(bot_id),
payload=bot_data
)
print(error)
print (data)
def createBot(bot_data):
error, data = p3cw.request(
entity='bots',
action='create_bot',
payload=bot_data
)
print(error)
print (data)
def updateDeal(deal_id,deal_data):
error, data = p3cw.request(
entity='deals',
action='update_deal',
action_id = str(deal_id),
payload=deal_data
)
print(error)
print (data)
#1 Get the ID of the account (exchange) you want to update the bots!
#print (getAccounts())
#2 get the data of all bots, you have to remove the # and fill in the id of the account
bot_data = getBotData(your_account_id)
#3 loop through all the bots, i gave my bots hashtags to find e.g. my standard bots...
for bot in bot_data:
#4 find all bots with the hashtag = #std
if bot['name'].find('#std') != -1:
print (bot['name'])
#5 i want to update my safety_order from 15.0 to 20.0 if it's 15.0
if bot['safety_order_volume']== '15.0':
bot['safety_order_volume']= '20.0'
#6 to update a bot, we need the id of the bot = bot['id'] and the whole bot-data which is in "bot"
updateBot(bot['id'],bot)
#break ends the for loop... be careful!!!! you have to know what you are doing.. if you remove this... it will loop through all #std bots...
#break
# Example for creating a new simple bot based on an template.. you have to create one and name it whatever_bot #template..
# bot_data = getBotData(your_account_id)
# for bot in bot_data:
# if bot['name'].find('#template') != -1:
# print (bot)
# #All we have to change is the pair...a correct pair would be ['USDT_SOL'] or ['BUSD_ADA']
# bot['pairs'] = ['BUSD_ADA']
# #and give it a new name!!!
# bot['name'] = "ADA/BUSD #std"
# #lets create it..
# createBot(bot)
# break
# for the udpateDeal function the idea is to increase the TP if the amount of SO is like 10 or so..
# deal_data = getDealData(your_account_id)
#
# for deal in deal_data:
# #find the deal with the hashtag #adv
# if deal['bot_name'].find('#adv') !=-1:
# if deal['completed_safety_orders_count'] > 10:
# deal['take_profit']='5.0'
# updateDeal(deal['id'],deal)
# break