Skip to content
Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance ... (public edition)
JavaScript HTML Other
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
command backfill support for bitmex Dec 26, 2018
dict store order state in manager Aug 16, 2019
documentation update image Jun 10, 2019
event cleanup orders after position was closed #51 Jun 12, 2019
exchange dont use old coinbase fills for profit calculation Aug 17, 2019
modules replace event usage for candle resample Aug 18, 2019
notify feature notify telegram, update npm packages Apr 30, 2019
patches provide patch-package to fix sqlite3-transaction issues Apr 29, 2019
storage some code cleanup for using constants Jul 13, 2019
templates add missing market close on ui Jul 3, 2019
test dont use old coinbase fills for profit calculation Aug 17, 2019
utils use sqlite3-better for performance Aug 18, 2019
var update .gitignore Apr 28, 2019
web/static fix button debug toggle all Apr 28, 2019
.dockerignore update nodejs dependencies (#58) Jun 29, 2019
.gitignore update .gitignore Apr 28, 2019
.travis.yml update nodejs dependencies (#58) Jun 29, 2019
CODE_OF_CONDUCT.md add license file Sep 25, 2018
Dockerfile update nodejs dependencies (#58) Jun 29, 2019
LICENSE add license file Sep 25, 2018
README.md hint in readme about compile tulip Jul 3, 2019
bitbucket-pipelines.yml node update Jun 29, 2019
bot.sql fix trading strategy Mar 31, 2019
conf.json.dist provide a "desk" to show multiple charts Jul 1, 2019
docker-compose.yml update nodejs dependencies (#58) Jun 29, 2019
index.js update nodejs dependencies (#58) Jun 29, 2019
instance.js.dist provide pair lazy loading example for Binance Apr 18, 2019
package-lock.json add better-sqlite3 Aug 18, 2019
package.json add better-sqlite3 Aug 18, 2019

README.md

Crypto Trading Bot

Build Status

A work in progress Cryptocurrency for common exchanges like Bitfinex, Bitmex and Binance. As most trading bots just provide basic buy and sell signals they provide many stuff to get profitable eg exchange orders like stop-losses or stop-limits are not supported by main bots. Also the limitation of fixed timeframe and technical indicators must be broken

Not production ready only basic functionality

Features

  • Fully use Websocket for exchange communication to react as fast as possible on market
  • Multi pair support in one instance
  • sqlite3 storage for candles, tickers, ...
  • Webserver UI
  • Support for going "Short" and "Long"
  • Signal browser dashboard for pairs
  • Slack and email notification
  • Join foreign exchange candles (eg. Trade on Bitmex with the faster moving Binace trades / candles)
  • TODO: Show possible arbitrage trades

Exchanges

TODOS:

Technical stuff and packages

How to use

[optional] Preinstall

The tulip library is used for indicators; which sometimes is having some issues on npm install because of code compiling:

Install build tools

sudo apt-get install build-essential

Also the build from source is not supporting all nodejs version. It looks like versions <= 10 are working. You can use nodejs 12 if you compiled it once via older version.

Install packages

➜ npm install --production
➜ npm run postinstall

Create instance file for pairs and changes

cp instance.js.dist instance.js

Provide a configuration with your exchange credentials

cp conf.json.dist conf.json

Create a new sqlite database use bot.sql scheme to create the tables

sqlite3 bot.db < bot.sql

Lets start it

node index.js trade

How to use: Docker

For initialize the configuration once

➜ cp instance.js.dist instance.js && cp conf.json.dist conf.json && sqlite3 bot.db < bot.sql
➜ docker-compose build
➜ docker-compose up -d

After this you can use docker-compose which will give you a running bot via http://127.0.0.1:8080

Setting Up Telegram Bot

First, you'll need to create a bot for Telegram. Just talk to BotFather and follow simple steps until it gives you a token for it. You'll also need to create a Telegram group, the place where you and crypto-trading-bot will communicate. After creating it, add the bot as administrator (make sure to uncheck "All Members Are Admins").

Retrieving Chat IDs

Invite @RawDataBot to your group and get your group id in sended chat id field

Message
 ├ message_id: 338
 ├ from
 ┊  ├ id: *****
 ┊  ├ is_bot: false
 ┊  ├ first_name: 사이드
 ┊  ├ username: ******
 ┊  └ language_code: en
 ├ chat
 ┊  ├ id: -1001118554477
 ┊  ├ title: Test Group
 ┊  └ type: supergroup
 ├ date: 1544948900
 └ text: A

Look for id: -1001118554477 is your chat id (with the negative sign).

Webserver

Some browser links

Security / Authentication

As the webserver provides just basic auth for access you should combine some with eh a https for public server. Here s simple proxy_pass for nginx.

# /etc/nginx/sites-available/YOURHOST
server {
    server_name YOURHOST;

    location / {
        proxy_pass http://127.0.0.1:8080;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/YOURHOST/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/YOURHOST/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

You should also set the listen ip to a local one

# config.json
webserver.ip: 127.0.0.1

Webserver UI

Backtesting

Currently there is a the UI for backtesting

Result Page

Webserver UI

Fill data

node index.js backfill -e bitmex -p 1m -s XRPZ18

Strategies

For custom strategies use var/strategies folder.

Find some example strategies inside modules/strategy/strategies

Tools / Watchdog

  • order_adjust Keep open orders in bid / ask of the orderbook in first position

Watchdog

  • stoploss provide general stoploss order in percent of entry price (Exchange Order)
  • risk_reward_ratio Creates Risk Reward order for take profit and stoploss (Exchange Order Limit+Stop)
  • stoploss_watch Close open position if ticker price falls below the percent lose; use this for exchange that dont support stop_loss order liek Binance
    'watchdogs': [
        {
            'name': 'stoploss',
            'percent': 3,
        },
        {
            'name': 'risk_reward_ratio',
            'target_percent': 6,
            'stop_percent': 3,
        },
        {
            'name': 'stoploss_watch',
            'stop': 1.2,
        }        
    ],

Trading

Capital

To allow the bot to trade you need to give some "playing capital". You can allow to by via asset or currency amount, see examples below. You should only provide one of them, first wins.

    c.symbols.push({
        'symbol': 'BTC-EUR',
        'exchange': 'coinbase_pro',
        'trade': {
            'capital': 0.015, // this will buy 0.015 BTC
            'currency_capital': 50,  // this will use 50 EUR and buys the equal amount of BTC (example: BTC price 3000 use 50 EUR. will result in 0.016 BTC)
        },
    })

Margin / Leverage

Per pair you can set used margin before orders are created; depending on exchange

    c.symbols.push({
        'symbol': 'BTCUSD',
        'exchange': 'bitmex',
        'extra': {
            'bitmex_leverage': 5,
        },
    })
    
    c.symbols.push({
        'symbol': 'EOSUSD',
        'exchange': 'bybit',
        'extra': {
            'bybit_leverage': 5,
        },
    })    

Signals

Slack

Webserver UI

Tests

npm test

Related Links

Trading Bots Inspiration

Other bots with possible design pattern

Strategies

Some strategies based on technical indicators for collection some ideas

You can’t perform that action at this time.