DEV Community

Cover image for Get Alerts and Adjust TP on 3Commas Based on SOs
Nobbi's Crypto
Nobbi's Crypto

Posted on • Updated on

Get Alerts and Adjust TP on 3Commas Based on SOs

A very unwieldy title, I know. But I couldn't think of a better one. The topic is also very specific to my requirements, but maybe it will help someone.


The Situation

I'm running several Urma v3 Lite (update 2021-10-27: apparently the creator took that site offline) bots on 3Commas. If you don't know what I'm talking about then stop here, this blog post is not for you ;-)

Anyway, if you are familiar with Urma v3 Lite bots you know that they often get stuck after the 4th safety order (SO) as the spacing between the SOs is large. And if it goes down to the 5th or even the 7th SO, a bounce is very common.

Hence I needed two things:

  1. Alerts whenever the 4th SO is completed. So that I don't need to check 3Commas the whole time. I then can play with manual safety orders to bring the deal into profit more quickly.
  2. Adjust the take profit (TP) value starting with the 5th SO. I usually go with 1.5% TP, but the value should be higher depending on the SO.

The Solution

I wrote a Python script which does exactly the above. You can find it in my GitHub repo. I'm not a Python expert, but the script gets the job done.

The script checks all active deals whether they have 4 or more SOs completed. If yes, you get an alert. The deal ID is then saved so that you don't get further alerts for that deal. Then, it checks if 5 or more SOs are completed and sets the TP accordingly. I'm running the script every 15 minutes via cron on a Ubuntu VPS.

You need to have Python and py3cw installed.

The alerts are send to Discord. Read here why and how.

The script has a variable section which you need to modify. There are a lot of comments in the script so I won't go over the variables here. Below the variable section for your reference.

# 3Commas API info
# BOTS_READ permissions are mandatory
# BOTS_WRITE permissions are only needed if you want to adjust the take profit value
API_Key = ''
API_Secret = ''
account_id = ''

# Discord webhook for notifications
DiscordWebhook = ''

# Adjust TP, too?
adjust_TP = True # Can be True or False

# Adjust TP percentages when SO is completed
TPSO5 = 3 # Safety order 5
TPSO6 = 7 # Safety order 6
TPSO7 = 10 # Safety order 7

# Trailing settings
trailing_enabled = False
trailing_deviation = 0
Enter fullscreen mode Exit fullscreen mode

Discussion (4)

donwhalex profile image

Hi @nobbi thanks for the good work. I created an alert on Tradingview which is supposed to stop my 3Commas Bot when the market is going down, but I also want to change the Take Profit of existing deals created by the Bot when the alert is sent.

Please advise me on how I can achieve the change of TP by the use of script. Thank you.

nobbi profile image
Nobbi's Crypto Author

I like crypto and scripting. If my stuff makes you money, please consider supporting me.

  • USDT (TRC20) - TMAroqHEg7Z41x8fhY14Xp4R9FtzWkFMpR
  • BTC - bc1qh45t0q0vgazf6l8qe8wf3ek6j3d7pr8awu5rgr
  • ETH - 0x9686360226dAedEf32E904CF3ecEcf6EE4fC31e5
pablollorens profile image
Pablo Llorens

Hi! Sorry but I did not find the configuration for "Urma v3 Lite" could you share it here?

nobbi profile image
Nobbi's Crypto Author

Apparently, the creator took the website offline. I updated the article accordingly.