• Stars
    star
    2,787
  • Rank 16,349 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance, Bybit ... (public edition)

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 Binance trades / candles)

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

The nodejs wrapper for tulipindicators is called Tulip Node (tuind), check out installation instructions there.

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

npm start

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

Log messages to Telegram

For example setup, check conf.json.dist file, log.telegram section , set chatId, token, level (default is info). Check more options https://github.com/ivanmarban/winston-telegram#readme

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

Web UI

Dashboard

Webserver UI

Trades / Positions / Orders

Webserver UI

Backtesting

Currently there is a the UI for backtesting

Webserver UI

Manual Orders

Webserver UI

Build In Strategies

Common strategy with indicators are inside, which most of the time are not profitable. See some more advanced strategy in the list below

Find some example strategies inside src/modules/strategy/strategies

Custom Strategies

For custom strategies use var/strategies folder.

# simple file structure
var/strategies/your_strategy.js

# or wrap strategy into any sub folder depth
var/strategies/my_strategy/my_strategy.js
var/strategies/subfolder1/our_strategy/our_strategy.js

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
  • trailing_stop Use native exchange trailing stop; if supported by exchange eg Bitfinex
    'watchdogs': [
        {
            'name': 'stoploss',
            'percent': 3,
        },
        {
            'name': 'risk_reward_ratio',
            'target_percent': 6,
            'stop_percent': 3,
        },
        {
            'name': 'stoploss_watch',
            'stop': 1.2,
        },
        {
            'name': 'trailing_stop',
            'target_percent': 1.2,
            'stop_percent': 0.5
        }
    ],

Tick Interval

Per default every strategy is "ticked" every full minute with a ~10sec time window. If you want to tick every 15 minutes or less see possible examples below.

Supported units are "m" (minute) and "s" (seconds)

{
  "strategies": [
    {
      "strategy": "cci",
      "interval": "15m"
    },
    {
      "strategy": "cci2",
      "interval": "30s"
    },
    {
      "strategy": "cci3",
      "interval": "60m"
    }
  ]
}

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)
            'balance_percent': 75,  // this will use 75 % of your exchange margin tradable balance. Currently implemented only on Bitfinex exchange.
        },
    })

Live Strategy

Every strategy stat should be live must be places inside trade.

{
  "trade": {
    "strategies": [
      {
        "strategy": "dip_catcher",
        "interval": "15m",
        "options": {
          "period": "15m"
        }
      }
    ]
  }
}

Inside logs, visible via browser ui, you can double check the strategies init process after the application started.

[info] Starting strategy intervals
[info] "binance_futures" - "ETHUSDT" - "trade" - init strategy "dip_catcher" (15m) in 11.628 minutes
[info] "binance_futures" - "BTCUSDT" - "trade" first strategy run "dip_catcher" now every 15.00 minutes

Full Trade Example

An example instance.js which trades can be found inside instance.js.dist_trade. Rename it or move the content to you file.

const c = (module.exports = {});

c.symbols = [
  {
    symbol: 'ETHUSDT',
    exchange: 'binance_futures',
    periods: ['1m', '15m', '1h'],
    trade: {
      currency_capital: 10,
      strategies: [
        {
          strategy: 'dip_catcher',
          interval: '15m',
          options: {
            period: '15m'
          }
        }
      ]
    },
    watchdogs: [
      {
        name: 'risk_reward_ratio',
        target_percent: 3.1,
        stop_percent: 2.1
      }
    ]
  }
];

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,
        },
    })

Tools

Fill data

outdated, but there as an automatic filling on startup ~1000 candles from the past (depending on exchange) and continuously fetched when running

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

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

More Repositories

1

idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
Java
896
star
2

idea-php-laravel-plugin

Laravel Framework Plugin for PhpStorm / IntelliJ IDEA
Java
571
star
3

uniswap-arbitrage-flash-swap

Uniswap flash swap arbitrage solidity contracts
JavaScript
385
star
4

idea-android-studio-plugin

Android Studio Plugin
Java
291
star
5

idea-php-annotation-plugin

Add PHP annotation support for PhpStorm and IntelliJ
Java
242
star
6

idea-php-toolbox

Collections of tools and improvements to make PhpStorm a little bit better
Java
157
star
7

idea-php-generics-plugin

Support generics types in PhpStorm via psalm / phpstan docblock
Java
144
star
8

idea-php-shopware-plugin

Shopware Plugin for PhpStorm which extends Symfony Plugin
Java
55
star
9

idea-php-symfony2-plugin-doc

Documentation only !!! for idea-php-symfony2-plugin
Python
49
star
10

idea-php-drupal-symfony2-bridge

PhpStorm plugin to support Symfony components inside Drupal 8
Java
34
star
11

idea-php-toolbox-json-files

PHP
25
star
12

torrent-announcer

Can simulate torrent client requests to a tracker and returns client ips
PHP
17
star
13

idea-php-oxid-plugin

Oxid Plugin for PhpStorm
Java
14
star
14

node-js-crypto-technical-analysis-candlestick-webserver

Candlestick Technical Analysis Http Server based on node.js
JavaScript
10
star
15

drupal-packagist

Provides a Composer packagist page for Drupal projects
PHP
8
star
16

behat-placeholder-extension

Behat placeholder extension
PHP
5
star
17

bittorrent-tracker

Simple BitTorrent Tracker / Proxy
PHP
5
star
18

solidity-multicall-contract

Contract to aggregate multiple contract web3-rpc requests into single request chunks
Solidity
4
star
19

idea-php-behat-plugin

IntelliJ IDEA / PhpStorm Behat Enhancement
Java
4
star
20

ZendDbBundle

Bundle that wraps ZendDb to Symfony2 and Doctrine
PHP
3
star
21

tgudy

TYPO3 Template and Extension
JavaScript
3
star
22

idea-localization-plugin

Extended translation / localization support for PhpStorm / IntelliJ for formats like XLF, XLIFF
Java
3
star
23

espend.de--Delicous-Bookmarks

Main Drupal module that works on b.espend.de to export HTML from Delicous Bookmarks
PHP
2
star
24

e2-fb

Facebook client for Enigma2 / Dreambox
Python
2
star
25

vavoo-iptv-stream-proxy

JavaScript
2
star
26

idea-twig-plugin

PhpStorm / IntelliJ Twig Extended Plugin improvements extracted from Symfony Plugin
Kotlin
2
star
27

Onlinestreams-for-D-Box2

Mediaportal fΓΌr Neutrino (D-Box2) mit Interface fΓΌr Popcorn Hour GerΓ€te: einfacher "OnlineStream Proxy" auf Basis des internen Movieplayers. Enthalten Scripts: Youtube, ZDFMediathek, MyVideo, Apple Trailer, Spiegel.TV, kino.de, Tv-Total.de alle in PHP
PHP
2
star
28

idea-badge

Provides badges support for statistics of IntelliJ IDEA / PhpStorm Plugin Repository
PHP
2
star
29

jquery.csspanel

A panel to manipulate simple CSS styles
PHP
1
star
30

http-segmenter

Stream video to your iPhone, iPad, iPod, iOS over http
C
1
star
31

autodesk-inventor-plot-class

This class does some plotting stuff for Autodesk Inventor
Visual Basic
1
star
32

jetbrains-enterprise-plugin-repository

XML API Project for a custom JetBrains Enterprise Plugin Repository
PHP
1
star
33

MyTubeExt

MyTubeExt - Devel fork of MyTube Enigma2 Extension
Python
1
star
34

idea-php-code-usage

Exports a PHP file structure to JSON
Java
1
star
35

vbnettools

Some VB.NET projects like HamachiBroadcastFixGUI
Visual Basic
1
star
36

autodesk-inventor-printbuttons

Configurable toolbar for Autodesk Inventor for plot and print on single button click
Visual Basic
1
star
37

sharemybox.net-enigma2-client

Python Client for sharemybox.net Dreambox and Enigma2 based receiver
Python
1
star
38

idea-php-symfony2-plugin-test

Symfony2 Standard Edition to reflect features and provide tests of PhpStorm Plugin
PHP
1
star