img

How to Share Your Python Trading Bot Activity on Discord in 3 Minutes

img
valuezone 28 October 2022

How to Share Your Python Trading Bot Activity on Discord in 3 Minutes

Building your own Python Trading Bot can be a ton of fun. The process of building your own strategies, making tradesthen letting it run in the background can be incredible.

When you get it right, it’s also profitable!

So let’s learn how to share your Trading Bot activity on Discord.

Outcome

By the end of this episode, you’ll have your own Discord server up and running and be sharing live updates of your Trading Bot activity.

Here’s an example of one of my free channels here, with a snapshot of the current activity below:


Free Signal Bot on Discord, providing free signals for the USDJPY Raw currency pair. Part of the article How to Share Your Python Trading Bot Activity on Discord in 3 Minutes

About Discord

Discord is a great choice for creating a collaborative sharing platform for your trading bot. It offers a great range of features and easily accessible REST API allowing you to easily post messages to your channel. It is cross-platform and runs effectively in a browser if you choose.

With a couple of extra options (not covered here), you can extend Discord channel functionality to include slash commands and more.

Best of all, the free version has all the features you might want.

Create A Server

To get started, create a server in your Discord. To do this:

  1. Navigate to your Discord channel list
  2. Click the + button on the left for “Add a Server”
  3. Choose a template or Create My Own
  4. Follow the prompts

All done.

I’ve called my server Creative Appnologies.

Create a Channel

To create a channel:

  1. Navigate to your channel
  2. Choose the + sign in the TEXT CHANNELS section
  3. Choose a name
  4. Choose create

All done.

I called mine #free_indicators and you can access it here. It provides a list of signals on the USDJPY Raw foreign exchange (FOREX) pair.

Create a Webhook

The actual posting of text into your channel will be done with a webhook. Webhooks are a lightweight form of event-driven communications between two API’s — RedHat has a great write-up about them if you’d like to know more.

To create your webhook, select the gear icon from your channel, and choose ‘Edit Channel’


#free_indicators channel settings

Now:

  1. Navigate to ‘Integrations’
  2. Choose ‘Webhooks’
  3. Choose ‘New Webhook’
  4. Name your Webhook Bot
  5. Upload an image if you’d like :)
  6. Choose “Copy Webhook URL”

Python Code

The Python code for a generic webhook send is as follows:

from discordwebhook import Discord
# Function to send a message to Discord
def send_message_to_discord(message, webhook):
discord_send = Discord(url=webhook)
discord_send.post(content=message)
view rawsend_to_discord.py hosted with ❤ by GitHub
Function to send a message to Discord using a webhook. Part of the article How to Share Your Python Trading Bot Activity on Discord in 3 Minutes

And that’s it. Just a couple of lines of code.

  1. Message. This is the message to share.
  2. Webhook. This is the URL you copied earlier.

You can extend this function as needed. For instance, in the Discord channel I’ve shared, I undertake a couple of operations to create the correct string.