webhook.py - cyberjunky/3commas-cyber-bots GitHub Wiki

Trigger bot helper named webhook.py

Type = trigger web-hook

What does it do?

It will run a small web-server process awaiting calls from external services to control 3Commas bots and deals.

How does it work?

Parse incoming trigger messages in JSON format (see below), check the format of message for BTC_xxx or USDT_xxx pairs, it will also change pair to -for example- BUSD_xxx if bot uses a different base coin. 3Commas blacklist and market are also checked.

The bot(s) need to have "Manually/API (Bot won't open new trades automatically)" as trigger.

Configuration

The webhook bot helper config file uses this layout: [settings]

  • timezone - timezone. (default is 'Europe/Amsterdam')
  • debug - set to true to enable debug logging to file. (default is False)
  • logrotate - number of days to keep logs. (default = 7)
  • 3c-apikey - your 3Commas API key value.
  • 3c-apisecret - your 3Commas API key secret value.
  • 3c-apikey-path - path to your own generated RSA private key, or empty.
  • notifications - set to true to enable notifications. (default = False)
  • notify-urls - one or a list of apprise notify urls, each in " " seperated with commas. See Apprise website for more information.

[webserver]

  • baseurl - the base url the webserver listens on (default is a uniquely generated uuid)
  • port - the port the webserver listens on (default is 8090, must be higher than 1024 is run an non-root)
  • ssl - use the certifcates below to protect traffic and run on https:// (default = False)
  • certfile - the full path to the certificate file generated for the (sub)domain
  • privkey - the full path to the private key file generated for the (sub)domain (store this file as safe as possibly)

[webhook_<random unique string or name>]

  • control-botids - a list of bot (USDT multipair) id's to use to control bots (enable/disable).
  • usdt-botids - a list of bot (USDT multipair) id's to use for open en closing deals. (can also be using BUSD)
  • btc-botids - a list of bot (BTC multipair) id's to use for open en closing deals.

Example: (keys are bogus)

[settings]
timezone = Europe/Amsterdam
debug = False
logrotate = 14
3c-apikey = 4mzhnpio6la4h1158ylt2
3c-apisecret = 4mzhnpio6la4h1158ylt4mzhnpio6la4h1158ylt4mzhnpio6la4h1158ylt4mzhnpio6la4h1158ylt4mzhnpio6la4h1158ylt4mzhnpio6la4h1158ylt4mzhnpio6la4h1158ylt4mzhnpio6la4h1158ylt
3c-apikey-path = 
notifications = True
notify-urls = [ "tgram://9995888120:BoJPor6opeHyxx5VVZPX-BoJPor6opeHyxx5VVZPX/" ]

[webserver]
baseurl = 23ca6f7c-91c9-11ec-8fb4-03ffe0131422
port = 8090
; Use ssl certificates when connected to the internet!
ssl = True
certfile = /etc/letsencrypt/live/yoursub.domain.nl/fullchain.pem
privkey = /etc/letsencrypt/live/yoursub.domain.nl/privkey.pem

[webhook_724959a4-f50c-40e9-91b3-e9c48136e611]
control-botids = [7129825]
usdt-botids = [7129815]
btc-botids = []
comment = Just a description of this section

Format of the webhook calls (POST):

Trigger bot(s) for buy or sell under "webhook_724959a4-f50c-40e9-91b3-e9c48136e6a9" config section usdt-botids for usdt pairs btc-botids for btc pairs

{
 "token": "724959a4-f50c-40e9-91b3-e9c48136e619",
 "action": "buy",
 "pair": {{ticker}}
}
{
 "token": "724959a4-f50c-40e9-91b3-e9c48136e619",
 "action": "sell",
 "pair": {{ticker}}
}

Enable/start or disable/stop bot(s) under "webhook_c0e447ca-91af-11ec-8f4b-6b8f5405da4b" config section Using bots configured under control-botids

{
 "token": "c0e447ca-91af-11ec-8f4b-6b8f5405da1b",
 "action": "enable"
}
{
 "token": "c0e447ca-91af-11ec-8f4b-6b8f5405da1b",
 "action": "disable"
}

Example output