Giter Club home page Giter Club logo

fngobot's Introduction

FnGoBot

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).

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.

  • Tested on Arch Linux and macOS.

  • This bot is currently in use in my friends' circle doing real trades, so the command-line patterns are not to be changed.

Quote sources

github.com/piquette/finance-go

For Yahoo! Finance API. This is the default security quote source.

github.com/piquette/finance-go/crypto

For Yahoo! Finance cryptocurrency API. This source is activated with a crypto switch in the command.

fetch/binance/binance.go

FnGoBot's Binance API data fetcher. This source is activated with a binance switch in the command.

fetch/coinbase/coinbase.go

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.

fetch/satang/satang.go

FnGoBot's satangcorp.com API data fetcher. This source is activated with a satang switch in the command. Satang quotes are only THB denominated

fetch/bitkub/bitkub.go

FnGoBot's bitkub.com API data fetcher. This source is activated with a bitkub switch in the command. Bitkub quotes are only THB denominated.

Overview

BotDiagram

Running your own bot

  • Clone this repository

  • Provide your bot's configuration

  • Run the bot with go run ./cmd or build and run the binary

  • 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.

Configuration file type

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.

External dependencies

  • 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 and golang.org/x/text/language for thousands operator (,)

Example commands

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

Other chat commands

/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

Important packages

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.

fngobot's People

Contributors

bgbaroo avatar soyart avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.