BitVision is a real-time charting and trading dashboard for Bitstamp that works entirely in the terminal. It comes with an automated trading bot that uses machine learning to forecast price movements and place risk-adjusted daily trades.
Unlike other systems, there's no need to host a server or edit tedious setup files. After installing, simply run
$ bitvision to start using the dashboard.
BitVision's key features are:
Disclaimer: BitVision is still in alpha. Some of the trading features are buggy and not fully tested; see all known bugs here. Use at your own risk!
$ npm i bitvision -g
$ bitvision to boot up the dashboard.
If you want to enable trading, follow these instructions to acquire a Bitstamp API key and secret:
Once activated, just press
L in the dashboard and a modal will pop-up asking you for your customer ID, API key, and secret. These will be stored locally on your machine, so be sure to keep them safe.
You can download the color profile used in this demo here.
The command-line interface is built on the Blessed.js library. The trading and charting architecture is built on the SciPy stack. An overview of the BitVision setup is shown below:
The BitVision architecture revolves around the Store, which is a local directory of JSON files used to achieve persistence of the application state (Bitstamp credentials, autotrading status, etc.) and data to be displayed on the dashboard. When a user triggers an event, like placing an order or refreshing the charts, a child process is spawned to execute the appropriate service (a Python module), which then updates the store with new data or an error flag.
Services are organized into three modules: the retriever, trader, and automated trading engine. The retriever fetches ticker data, portfolio data, and transaction history from Bitstamp, blockchain data (hash rate, difficulty, etc.) from Quandl, and Bitcoin-related headlines from Coindesk. The trader wraps the Bitstamp REST API and serves to authenticate the user's credentials, place buy or sell orders, and toggle automated trading. Lastly, the automated trading engine is a machine learning system that attempts to predict the sign of the next-day change in Bitcoin price and place trades accordingly.
Behind the scenes is a Logistic Regression model that's trained on a feature set of historical candlestick data, technical indicators, and blockchain data. When the engine is toggled on, a daily cron job is scheduled that (re)trains the model, predicts a price change, and places a risk-adjusted buy or sell order, depending on the prediction.
Technical indicators were chosen as part of the feature set because they help reduce noise in candlestick data and may reveal price patterns for the model to learn, if any exist. These particular indicators were chosen to give insight into price momentum, volatility, trends, and whether the cryptocurrency is overbought or oversold:
Note that, in a perfectly efficient market, the future price of a publicly traded asset is not statistically dependent on past prices; the price follows a "random walk," and it's impossible to reliably leverage technical analysis to beat the market. Now, efficient market theory suggests that the U.S. stock market is at least a semi-efficient market, and so we still consider this feature set because many traders utilize technical analysis in their trading strategies and there may exist a relationship between signals from indicators and executed trades, regardless of whether the signals themselves are accurate.
Unlike other publicly traded assets, all Bitcoin-related fundamental data is available online, in the form of currency statistics, block details, mining information, network activity, and wallet activity. The following Blockchain variables are considered:
|Confirmation Time||Median time for a transaction to be accepted into a mined block and added to the public ledger.|
|Block Size||Average block size in MB.|
|Average Transaction Cost||Total miner revenue divided by number of transactions.|
|Difficulty||How difficult it is to find a new block.|
|Transaction Value||Total estimated value of transactions on the blockchain.|
|Hash Rate||Estimated number of giga-hashes per second the BTC network is performing.|
|Transactions per Block||Average number of transactions per block.|
|Unique Addresses||Total number of unique addresses used on the blockchain.|
|Total BTC||Total number of Bitcoins that have already been mined.|
|Transaction Fees||Total value of all transaction fees paid to miners.|
|Transactions per Day||Total number of unique Bitcoin transactions per day.|
A number of standard preprocessing steps are taken before training the model:
Additionally, since the price of Bitcoin has generally increased over time, the training set is balanced (using the random undersampling method) to prevent the model from learning a bias for positive predictions.
And lastly, a grid search is performed to find optimal hyper-parameter values for the Logistic Regression, and found them to be:
Three models were trained on 80% of the dataset and tested on 20% before deciding on the Logistic Regression. The results:
|Model||Accuracy||Precision (PPV)||Specificity (TNR)||Recall (TPR)|
|Gradient Boosting Machine||53.8%||53.9%||54.5%||53.1%|
|Random Forest Classifier||50.5%||50.5%||52.6%||48.3%|
As can be seen, the Logistic Regression had the highest overall accuracy, and highest accuracy in predicting uptrends, but also the lowest accuracy in predicting downtrends.
The trading engine is a proof of concept, not something you should trust to make money. Nevertheless, a number of interesting improvements could be made to the system:
Aside from the trading engine, there are several improvements that can be made to the BitVision architecture. One long-term goal is to rewrite all the services in Node.js instead of Python, to avoid all the complications that come with cross-language execution. But if you're looking for a smaller issue to help with, plenty can be found here.