A simple, stupid CLI/Telegram bot for tracking financial markets. FnGoBot can be run as a standalone CLI program, or as a Telegram chatbot. Both versions share the same text interface (see bot
package).
FnGoBot is my practice project for designing more complicated software, parsing JSON responses, and using external libraries. It developed from an ugly single-file program into a much more normal looking Go project.
The Telegram part is made possible with this amazing Go Telegram bot library. It fetches quotes from Yahoo! Finance (via finance-go), Binance, Coinbase, Satang, and Bitkub.
- This bot is currently in use in my friends' circle doing real trades, so the command-line patterns are not to be changed.
For Yahoo! Finance API. This is the default security quote source.
For Yahoo! Finance cryptocurrency API. This source is activated with a crypto
switch in the command.
FnGoBot's Binance API data fetcher. This source is activated with a binance
switch in the command.
FnGoBot's Coinbase API data fetcher. This source is activated with a coinbase
switch in the command. Coinbase quotes are currently THB denominated, although this may change in the future, perhaps with adding currency configuration.
FnGoBot's satangcorp.com API data fetcher. This source is activated with a satang
switch in the command. Satang quotes are only THB denominated
FnGoBot's bitkub.com API data fetcher. This source is activated with a bitkub
switch in the command. Bitkub quotes are only THB denominated.
-
Clone this repository
-
Provide your bot's configuration
-
Run the bot with
go run ./cmd/fngobot
orgo run ./cmd/fngobot-cli
, or build and run the binaries -
If the bot successfully initializes, you may now start using the bot
-
Start chatting with the bot. Send
/help
to get command-line help
FnGoBot uses Viper to manage configuration. The default config file is $HOME/.config/fngobot/config.yml
, but -c <config file path>
command-line option can also be used to load different configuration.
Default configuration type is YAML, but other file types like JSON can also be used.
Only YAML and JSON are tested for FnGobot, and TOML is not supported because Telegram bot token strings contain special character
:
.
To use other configuration types (must be supported by Viper), specify the configuation file with -c <config file>
:
$ go run ./cmd -c path/to/config.json;
Or change the default filename in cmd/main.go
to your desired file extension.
-
gopkg.in/tucnak/telebot.v3
Telegram bot framework -
github.com/piquette/finance-go
Yahoo! Finance data library -
github.com/google/uuid
Google UUID library -
github.com/spf13/viper
Configuration library -
golang.org/x/text/message
andgolang.org/x/text/language
for thousands operator (,
)
The chat will look like a CLI program. The bot supports 3 commands: /quote
, track
, and /alert
. Source switches can be used in all commands to set quote source.
The general syntax for /quote
is
/quote [source switch] <ticker> [ticker..]
The example below will quote BBL.BK, KBANK.BK, KKP.BK from Yahoo! Finance:
/quote bbl.bk kbank.bk kkp.bk
The general syntax for /track
is
/track [source switch] <ticker> [ticker..] <rounds>
The example below will track BTC-USD crypto pair for 2 times, each one minute apart:
/track crypto btc-usd 2
/alert
can handle one more switch - a bid/ask switch. This is because /alert
can be used against last price and best bid/ask prices. If a bid/ask switch is used, it will alert based on bid or ask prices, if the bid/ask switch is not present, it will alert based on last price.
The general syntax for /alert
is
/alert [source switch] <ticker> [bid/ask switch] <greater/smaller> <target price>
The two modes of /alert
are not supported all quote sources - for example, Yahoo! Finance (crypto) does not support alert with bid/ask, while Satang source does not support alert with last price.
The example below will make the bot alert if BBL.BK 'last' price is greater than 120:
/alert bbl.bk > 120
The example below will make the bot alert if BBL.BK 'ask' price is smaller than 115:
/alert bbl.bk ask < 115
The example below will make the bot alert if BTC-USD (from Yahoo! Finance crypto) is greater than 30,000:
/alert crypto btc-usd > 30000
The example below will make the bot alert if BTC (From Binance) last price is smaller than 30,000:
/alert binance btc < 30000
The example below will make the bot alert if BTC (From Coinbase) bid price is smaller than 30,000:
/alert coinbase btc-usd bid < 30000
The example below will make the bot alert if BTC (From Bitkub.com) bid price is smaller than 30,000:
/alert bitkub btc-usd bid < 30000
/handlers
is used to get all running handlers in JSON format.
/handlers
/stop
is used to stop a running handler. Let's say we have an alerting handler whose UUID is cfd337b7, to stop it, send:
/stop cfd337b7
After editing the code, you probably want to run tests on these packages before you start using FnGoBot.
The parse
package provides command parsing for both CLI and Telegram versions. This means that they both share the same text interface.
The bot
package defines logic for handling alerts, price tracking, and quoting, and is also used by both CLI and Telegram versions.
The fetch
package, which fetches data from remote APIs, provides an interface (fetch.Quoter
) to all quotes processed by FnGoBot.