Skip to content

edghyhdz/crypto_monitor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-time Crypto Currency Monitor

This monitor is a command line dashboard, it uses ncurses, in combination with the Binance API where it fetches all the data from.

Crypto currency data is readily available from Binance API end points, not only that, but we are able to make a ludicrous amount of requests (up to 1200 request weight per minute!). We can take profit of that and develop cool tools, such as this present command line dashboard.

Right now it can also be linked to your personal Binance portfolio using your api key and api secret key. It will only display your current portfolio cryptos, as well as an overview of the total value in USDT

Crypto Monitor

Conntact me on twitter Tweet | Create an issue


Table of Contents

  1. Disclaimer
  2. Description
  3. Usage
  4. Dependencies
  5. Installation
  6. References
  7. Author

Disclaimer

I know cryptocurrency might be a hot polarizing topic. This project was done to exploit the fine resolution data that is easily accessible for everyone. Crypto trading should not be seen as a game at all.

I am by no means a crypto currency expert. This project was done out of curiosity and the fact that there is a lot of data to fetch out there, which made a project like this interesting to do.

The usage you might give to the application is at your own risk. Crypto currency trading is not a game and should not be seen as one.

Description

This command line dashboard was built using ncurses, in combination with Binance API.

Crypto currency data is fetched using the following Binance API end points:

  1. https://api.binance.com/api/v3/aggTrades
  2. https://api.binance.com/api/v3/ticker/price
  3. https://api.binance.com/api/v3/ticker/account (HMAC SHA256)1

1 Requires HMAC SHA256 signature

End points 1 and 2 are used to get historical data, aggTrades is used within the code to get all aggregrated currencies that should be listed in Orchestrator.cpp::Orchestrator::currencies vector,

Orchestrator::Orchestrator(bool wallet) : _wallet(wallet){
  std::vector<std::string> currencies{"BTCUSDT", "REEFUSDT"};
  ...
 
}

You can add more to the currencies vector, these will be queried once every 10 seconds. This task is launched in threads, meaning that the requests to binance will be done in parallel (in case you are querying more than one currency). It is important to notice that you have a request weight limit! More info on that on the official Binance API website

End point 2, is the one used to fetch the data that is used for the dashboard. This one is querying data every two seconds.

The third endpoint will only work if you set to true the WALLET variable in Variables.h. To do so you need to add the -DWALLET=true option when making the executable via cmake.

#define WALLET false

It is per default in false. If you do change it to true, please notice that you have to add the following env variables into your .bashrc file.

BINANCE_API_KEY="YOUR API KEY"
BINANCE_API_SECRE="YOUR API SECRET"

These will be used eventually in QueryCrypto.cpp::QueryCrypto::getRequest(),

  ...
  // Headers and set up signature
  if (wallet){
    const char *API_KEY = std::getenv("BINANCE_API_KEY");
    const char *API_SECRET = std::getenv("BINANCE_API_SECRET");

Adding your api key information will make the dashboard able to display your current wallet information, as displayed below,

Wallet Tracker

Displaying then, information related to all currencies you hold plus the total potfolio value in usdt. There is some information that will be always displayed as per default, this being the current request weight, that resets to 0 every 1 minute.

Usage

Tested in linux only

Starting the dashboard

source cryptomonitor

The dashboard will show in the terminal with some default coins to display. It might take a couple of seconds until it has requested some data from the Binance api end point to fully display a crypto currency time series.

Selecting different currencies

Click F1, this will open a selection window (modified code from flarn2006's repo)

Selection Window

You can select up to 3 different cryptos to display on the dashboard.

You can also select the amount of data to display. The deault is 180 data points. That corresponds to 360 seconds of data, or a 6 minute window frame.

Dependencies

  1. ncurses sudo apt install libncurses5-dev libncursesw5-dev
  2. libcurl sudo apt-get install -y libcurl-dev
  3. Open SSL sudo apt-get install libssl-dev
  4. cmake sudo apt-get -y install cmake

Installation

Clone this repository like so,

git clone https://github.com/edghyhdz/crypto_monitor.git

Once inside the root project folder crypto_monitor,

# Lets start by creating the build directory
mkdir build && cd build

# If you dont want to enable any Binance wallet
# then just run
cmake ..

# If you want to enable your binance wallet and 
#you have input your API details (key and secret)
cmake .. -DWALLET=true

# Finally
source install.sh

install.sh will run the final installation that will create a terimal shortcut named cryptomonitor.

The final project folder structure is the following,

.
├── ...
├── build                     # Directory were project was built
│   ├── executable            # Executable location
│       ├── data_test         # csv data used by the dashboard <- all data will be in these two folders
│       └── data_aggregated   # aggregated csv data -not used by the dashboard-
└── ...

If everything was done allright, you should be able to run the dashboard by doing the following,

source cryptomonitor

References

There was one incredible repository I happen to come accross, this was flarn2006's repository MiscPrograms.

This repo included an amazing script to do plots using the ncurses library. I took parts of his/her script, particularly this one graph.c, and adapted it to plot in a real-time basis.

All other references can be found inside the code.

Author

Edgar Hernandez