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

Overview

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

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

You might also like...

A community contributed game system for Pathfinder Second Edition.

The Official Pathfinder Second Edition Game System for FoundryVTT This system uses trademarks and/or copyrights owned by Paizo Inc., which are used wi

Jan 5, 2023

The SheetJS Community Edition offers battle-tested open-source solution

The SheetJS Community Edition offers battle-tested open-source solutions for extracting useful data from almost any complex spreadsheet and generating new spreadsheets that will work with legacy and modern software alike.

Dec 29, 2022

A simple backend app for managing invoices and tracking their payments for the Monero cryptocurrency.

Simpla Vendejo API This app runs a view-only Monero wallet to verify payments and keeps track of them in a MySQL database. /create_invoice Method: POS

Jun 30, 2022

🔑 Keagate is an open-source, high-performance alternative to popular cryptocurrency payment gateways such as Coinbase Commerce, CoinGate, BitPay, NOWPayments, CoinRemitter, CoinsPaid and more.

🔑 Keagate is an open-source, high-performance alternative to popular cryptocurrency payment gateways such as Coinbase Commerce, CoinGate, BitPay, NOWPayments, CoinRemitter, CoinsPaid and more.

⛩️ Keagate – A High-Performance Cryptocurrency Payment Gateway 🚧 This project is actively in development 🚧 Table of Contents About the Project Purpo

Jan 3, 2023

An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop

An implementation of the Dungeons & Dragons 5th Edition game system for Foundry Virtual Tabletop.

Jan 2, 2023

Use thirdweb's token, edition drop, and a custom contract using thirdweb deploy to build a Play-to-Earn game!

Use thirdweb's token, edition drop, and a custom contract using thirdweb deploy to build a Play-to-Earn game!

thirdweb Play-to-Earn Example This example project is a simple Play-to-Earn (P2E) game! The Idea The game is a "mining" game, where your character min

Jan 2, 2023

Build a Blockchain and Cryptocurrency from Scratch

This is a proof of work blockchain. With a fixed price reserve currency. Miners and node operators are needed. To get started follow the instructions in the main readme.md

Nov 10, 2022

A module for modifying sheet rolling functions on Foundry VTT Character sheets for D&D 5th Edition.

A module for modifying sheet rolling functions on Foundry VTT Character sheets for D&D 5th Edition.

Ready Set Roll for 5e - FoundryVTT Module Ready Set Roll is a Foundry VTT module that accelerates the built in rolling system of the Foundry DnD5e sys

Dec 12, 2022

JellyChain1 is a blockchain network platform that supports smart contracts and can act as a payment system/cryptocurrency

JellyChain1 is an experimental blockchain network, that will serve as a starter blockchain test network and scale out database software and other applications. JellyChain1 is created to cut energy costs when mining transactions on the blockchain.

Dec 1, 2022
Owner
null
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Ethereum chain sniperbot for tokens. This bot sniffs the mempool for pending transactions for trading enabled and also liquidity add functions.

Ethereum chain sniperbot for tokens. This bot sniffs the mempool for pending transactions for trading enabled and also liquidity add functions.

null 12 Dec 5, 2022
Simple trading bot that utilize Jupiter SDK on Solana blockchain.

solana-jupiter-bot CAUTION! Use at Your own risk! I take no responsibility for your transactions! ⚠️ EPILEPSY WARNING - CLI UI is constantly refreshed

Pawel Mioduszewski 13 Dec 27, 2022
Use pulsar to make custom trading strategy that uses Flashloans at low cost. No contract deployment required.

PULSAR Pulsar is a contract that will let you execute custom call on the blockchain and let you make use of the Flasloans in your trading sequences. Y

idecentralize.finance 9 Jun 6, 2022
A simple NFT trading and breeding platform for demonstration purposes.

?? boxyz I know it sounds strange, but maybe these boxes can breed and have children. They can be sold as well. boxyz is a fun project to trade and br

cetin 8 Dec 12, 2022
[Book] 2019 edition of our front-end development handbook

Front-End Developer Handbook 2019 Written by Cody Lindley Sponsored by Frontend Masters, advancing your skills with in-depth, modern front-end enginee

Frontend Masters 4.1k Dec 28, 2022
Code Scanning/SAST/Static Analysis/Linting using many tools/Scanners with One Report - Scanmycode Community Edition (CE)

Star it If you like it, please give it a GitHub star/fork/contribute. This will ensure continous development ⭐ TLDR; To install it. Install docker and

Marcin Kozlowski 351 Dec 29, 2022
Cryptostat is a Node.js based CLI that gets you the real-time stats of your favorite cryptocurrency.

Cryptostat-CLI Cryptostat is a Node.js based CLI that gets you the real-time stats of your favorite cryptocurrency. Installation Use the npm package m

Kunal Rohitas 5 Dec 15, 2022