Note: This project started as a Thesis project at ČVUT FIT. Assignment of diploma thesis here (early stage was developed during CVUT Python Course).
Coinrat is modular auto-trading platform focused on crypto-currencies. This repository is contains platform itself and also default plugins for basic usage and inspiration. There is also UI-App to help with running simulations and to visualize results.
:squirrel: DISCLAIMER: The software is provided "as is", without warranty of any kind. For more see: LICENSE
‼️ Be very cautious what you run against real Stock Market account. Test your strategy and configuration well before real trading.‼️ Protect API KEYS make sure you NEVER expose.env
file to anyone. If you run this on server, make sure it's well secured.‼️ Never expose UI nor port for socket connection on the production server.- If you need running socket server in production, ALWAYS run UI-App locally and use ssh tunnel.
- Make sure that socket server is NEVER accessible from the internet.
‼️ Important: This project is still in alpha! Use code directly frommaster
branch.
- Install InfluxDB: here
- Start:
sudo service influxdb start
curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE DATABASE coinrat"
- For development usage you can use
root
, but always create separate user with limited access per database in PRODUCTION:- Create user:
curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE USER coinrat WITH PASSWORD '<password>'"
- Grand this user with R+W access to the database:
curl -XPOST "http://localhost:8086/query" --data-urlencode 'q=GRANT ALL ON "coinrat" TO "coinrat"'
- Create user:
- Start:
- Install RabbitMQ 🐰 official instructions.
- Install MySQL database (MySQL, MariaDB, Percona, ...) and create
coinrat
database and user with write access for it. Add configuration into.env
- Make sure you have pipenv
- Install dependencies:
pipenv install
(use--dev
if you want to develop and also run tests). See Troubleshooting in case of errors. - Provide configuration
cp .env_example .env
- Run MySQL database migrations:
pipenv run coinrat database_migrate
.
Platform has five plugin types that are registered in setup.py
:
coinrat_market_plugins
- This plugin provides one or more stock-market connections (Bitfinex, Bittrex, ...) and platform uses those plugin to create order, check balances, ...- You can check available markets by:
pipenv run coinrat markets
- You can check available markets by:
coinrat_synchronizer_plugins
- This plugin is responsible for pumping stock-market data (candles) into platform. Usually one module contains both market and synchronizer plugin (for stock-market modules). But for read only sources (eg. cryptocompare.com) can be provided solely in the module.coinrat_strategy_plugins
- Most interesting plugins. Contains trading strategies. Strategy runs with one instance of candle and order storage, but can use multiple markets (for Market Arbitrage, etc...)- You can check available strategies by:
pipenv run coinrat strategies
- You can check available strategies by:
coinrat_candle_storage_plugins
,coinrat_order_storage_plugins
,coinrat_portfolio_snapshot_storage_plugins
- Storage plugins for the data. There is default implementation for InfluxDB.
IMPORTANT: If you want use Cryptocompare data pleas read their conditions fist. They provide their data under Creative Commons - Attribution Non-Commercial license. So its free for non-commercial purposes.
Each strategy (or market) can have special configuration. You can see it by running
pipenv run coinrat market <market_name>
/ pipenv run coinrat strategy <strategy_name>
.
You can create JSON file with specific properties and provide it via -c
option to run_strategy
command.
(Markets have configuration, but providing it into
run_strategy
command is not implemented yet. See #18 for more info and workaround.)
Fist, we need stock-market data. There are two synchronizers in default plugins:
pipenv run coinrat synchronize bittrex bittrex USD BTC --candle_storage influx_db
pipenv run coinrat synchronize cryptocompare bittrex USD BTC --candle_storage influx_db
This process must always be running to keep you with current stock-market data.
Once we have data you can see them in the UI-App.
- Start socket server:
pipenv run coinrat start_server
and keep it running (You can configure the port of the socket server in.env
) . - For strategy simulation started from UI-App, we need to have process that will handle them. Start one by:
pipenv run coinrat start_task_consumer
. - Follow instructions here to install and run the UI-App.
‼️ This will execute strategy against real market! One good option for testing (if market does not provide test account) is to create separate account on the stock-market with very limited resources on it.
Run one of default strategies with this command: pipenv run coinrat run_strategy double_crossover USD BTC bittrex --candle_storage influx_db --order_storage influx_db_orders-A --market_plugin coinrat_bittrex
- OSError: mysql_config not found → Install:
sudo apt-get install libmysqlclient-dev
- Error: the command coinrat could not be found within PATH or Pipfile's [scripts]. → Specify python (3.5+) version. For example:
pipenv --python 3.6 install
- Failed building wheel for mysqlclient →
sudo apt-get install python3.6-dev libmysqlclient-dev
- ERROR: For market "bittrex" no candles in storage "influx_db". → No data for given market, storage and selected time period / your time interval is too small.
- Every second candle is missing. → See #29.
- There is visualization tool for Influx DB called Chronograf, it can be useful for visualizing data too.