Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jbelke/29dce65012c549477b3cadd7251881f7 to your computer and use it in GitHub Desktop.
Save jbelke/29dce65012c549477b3cadd7251881f7 to your computer and use it in GitHub Desktop.
How to run your down ticker bots!

Step 1: Download the ticker binary

Go to the github release page and find the latest release. For this example I will be using the v3.0.1 release.

Since we are targeting linux on an Intel CPU for this guide, copy the link for linux-amd64: discord-stock-ticker-v3.0.1-linux-amd64.tar.gz

Open a new terminal, and we will use wget to download the tar file: wget https://github.com/rssnyder/discord-stock-ticker/releases/download/v3.0.1/discord-stock-ticker-v3.0.1-linux-amd64.tar.gz

Now extract the binary using tar: tar zxf discord-stock-ticker-v3.0.1-linux-amd64.tar.gz

You should now have a file called discord-stock-ticker in your current directory.

Check you downloaded the correct version by executing the binary: ./discord-stock-ticker

It should print a message and hold: INFO[0000] Starting api server on localhost:8080...

Step 2: Create discord applications for your tickers

With the executable still running in your first terminal, open a new terminal session.

The executable you are running in your first terminal acts as a "manager" for all the ticker bots you want to create. We will use the exposed API to add and remove bots.

In this example, we will be creating a GME and a BTC ticker, to show how both stocks and cryptos work.

For every ticker you create you will need a unique discord bot. You can create bots by following the guide here.

Once you have your discord bot token, you can move onto the next step.

Step 3: Add a stock ticker

Now that you have the service running (on port 8080 for this example), we can start by creating a ticker for GME.

The data source for stock prices is yahoo finance, so you first need to find the stock symbol as shown on yahoo finance. Go to the yahoo finance website to find the stock you want to create a ticker for. GME is an example of a stock where the stock symbol and the symbol for the stock on yahoo finance are the same, GME. For some stocks the symbol on yahoo will be different. For example, to watch the S&P 500 the yahoo symbol is actaully ^GSPC: image

Now that we have our stock symbol GME and our discord bot token, we can craft the API call to create a bot.

The full list of payload options are listed here:

{
  "ticker": "pfg",                                  # string: symbol for the stock from yahoo finance
  "name": "2) PFG",                                 # string/OPTIONAL: overwrites display name of bot
  "set_color": true,                                # bool/OPTIONAL: requires set_nickname
  "decorator": "@",                                 # string/OPTIONAL: what to show instead of arrows
  "currency": "aud",                                # string/OPTIONAL: alternative curreny
  "activity": "Hello;Its;Me",                       # string/OPTIONAL: list of strings to show in activity section
  "set_nickname": true,                             # bool/OPTIONAL: display information in nickname vs activity
  "frequency": 10,                                  # int/OPTIONAL: seconds between refresh
  "discord_bot_token": "xxxxxxxxxxxxxxxxxxxxxxxx"   # string: dicord bot token
}

Lets fill out the options for our example GME ticker:

{
  "ticker": "GME",
  "set_color": true,
  "set_nickname": true,
  "frequency": 10,
  "discord_bot_token": "<your discord bot token>"
}

Now we can send the payload to the API using curl to create the bot:

curl -X POST -H "Content-Type: application/json" --data '{
  "ticker": "GME",
  "set_color": true,
  "set_nickname": true,
  "frequency": 10,
  "discord_bot_token": "<your discord bot token>"
}' localhost:8080/ticker

The curl call should reply with the ticker that was created:

{"ticker":"GME","name":"GME","nickname":true,"color":true,"decorator":"","frequency":10000000000,"currency":"USD","bitcoin":false,"activity":"","decimals":0}

Now if you bot is in a server, it should begin to change its name based on the price. If you add your bot to a server after you start the bot, you will need to restart the bot to pick up the new server.

Step 4: Crypto ticker

To add a crypto ticker, we instead need to get the coin name from coingecko, the data source for crypto prices.

The crypto name can very, it is rarely the coin symbol. For example, to create our BTC ticker we dont want to use "BTC", we will need to use "bitcoin".

To find the correct name to use find the coin on coingecko and copy the api id: image

Once you have the coin name from coingecko, the process is similar to above except the payload is slightly different:

{
  "name": "bitcoin",                                # string: name of the crypto from coingecko
  "crypto": true,                                   # bool: always true for crypto
  "ticker": "1) BTC",                               # string/OPTIONAL: overwrites display name of bot
  "set_color": true,                                # bool/OPTIONAL: requires set_nickname
  "decorator": "@",                                 # string/OPTIONAL: what to show instead of arrows
  "currency": "aud",                                # string/OPTIONAL: alternative curreny
  "bitcoin": true,                                  # bool/OPTIONAL: show prices in BTC
  "activity": "Hello;Its;Me",                       # string/OPTIONAL: list of strings to show in activity section
  "decimals": 3,                                    # int/OPTIONAL: set number of decimal places
  "set_nickname": true,                             # bool/OPTIONAL: display information in nickname vs activity
  "frequency": 10,                                  # int/OPTIONAL: seconds between refresh
  "discord_bot_token": "xxxxxxxxxxxxxxxxxxxxxxxx"   # string: dicord bot token
}

So our payload might look something like this:

{
  "name": "bitcoin",
  "crypto": true,
  "set_color": true,
  "set_nickname": true,
  "frequency": 10,
  "discord_bot_token": "<your discord bot token>"
}

And the curl call is also similar...

curl -X POST -H "Content-Type: application/json" --data '{
  "name": "bitcoin",
  "crypto": true,
  "set_color": true,
  "set_nickname": true,
  "frequency": 10,
  "discord_bot_token": "<your discord bot token>"
}' localhost:8080/ticker

The response should return the ticker you created:

{"ticker":"","name":"bitcoin","nickname":true,"color":true,"decorator":"","frequency":10000000000,"currency":"USD","bitcoin":false,"activity":"","decimals":0}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment