Git Product home page Git Product logo

node-binance-trader's Introduction

Node Binance Trader NBT

Version 0.2.4

Donate NIM

NBT is an open cryptocurrency trading bot development framework for the Binance exchange.

NBT includes 3 main JS scripts:

  • the server:

    • to track a selection of asset pairs and record all binance api data (candles, depths, trades) into a Postgres database.
    • to detect buy or sell signals
    • (optional) to send trading signals to the NBT Hub / Bitcoin vs. Altcoins to monitor performances and auto trade those signals (virtually or for real).
  • the trader: Deploy

    • this script allows you to auto trade the signals received from the NBT hub or your own server. this script can run locally or on cloud services like Heroku. This new auto trader script allows you to trade with leverage when the pair is available for margin trading.
  • the backtest :

    • to backtest your strategies on the historical tick data (Postgres database) recorded by the server.

Requirements

  • Git (see if it is already installed with the command: git --version)
  • Node.JS (see if it is already installed with the command: npm --version)

Installation ๐Ÿ“ฆ

git clone https://github.com/jsappme/node-binance-trader
cd node-binance-trader
npm i --unsafe-perm

Usage โšก๏ธ

Before everything, please review the source code of the JS scripts (server.js, trader.js) and then add your secret data to .env.

To kickstart, just duplicate the .env.example, name it .env and insert your secret values:

cp .env.example .env
$EDITOR .env

Never check in your .env file! It contains your most private information.

This project can be used as a Docker container! Use the docker run commands below, after building the container: docker build -t jsappme/node-binance-trader .

To start the server to save pair data, define strategies and emit trading signals:

npm run start
// or
docker run -d --name node-binance-trader -v "$PWD/.env:/srv/app/.env" -p 4000:4000 jsappme/node-binance-trader npm run start

To start the auto trader to monitor strategies and signals received from the server or the NBT Hub:

Important note: Always make sure to have some BNB available on your corresponding wallet to pay for the fees.

npm run trader
// or
docker run -d --name node-binance-trader -v "$PWD/.env:/srv/app/.env" jsappme/node-binance-trader npm run trader

To backtest strategies using the data recorded by the server:

npm run backtest
// or
docker run -d --name node-binance-trader -v "$PWD/.env:/srv/app/.env" jsappme/node-binance-trader npm run backtest

Web Socket API specifications ๐Ÿ“ก

Feel free to connect your Node.js scripts to the NBT hub Websocket server to monitor the performance of your signals and strategies on BvA

From your NBT Server, you can:

Send a Buy Signal to the NBT hub:

const buy_signal = {
    key: bva_key,
    stratname: stratname,
    pair: pair,
    buy_price: first_ask_price[pair], //optional
    message: Date.now(), //optional
    stop_profit: Number(stop_profit[pair+signal_key]), //optional
    stop_loss: Number(stop_loss[pair+signal_key]), //optional
}
socket_client.emit("buy_signal", buy_signal)

Send a Sell Signal to the NBT hub:

const sell_signal = {
    key: bva_key,
    stratname: stratname,
    pair: pair,
    sell_price: first_bid_price[pair] //optional
}
socket_client.emit("sell_signal", sell_signal)

You can also communicate via the NBT hub to your auto trader to track your traded signals.

From your NBT Trader, you can:

Receive a Buy Signal from the NBT hub, to trade a signal from a strategy selected on BvA.

socket.on('buy_signal', async (signal) => {
    console.log(signal.userid)
    console.log(signal.nickname)
    console.log(signal.stratid)
    console.log(signal.stratname)
    console.log(signal.pair)
    console.log(signal.price) // buy price
    console.log(signal.new)  //new signal or closing an existing signal
})

Receive a Sell Signal from the NBT hub, to trade a signal from a strategy selected on BvA.

socket.on('sell_signal', async (signal) => {
    console.log(signal.userid)
    console.log(signal.nickname)
    console.log(signal.stratid)
    console.log(signal.stratname)
    console.log(signal.pair)
    console.log(signal.price) // buy price
    console.log(signal.new)  //new signal or closing an existing signal
})

Send a Traded Buy Signal to the NBT hub:

const traded_buy_signal = {
    key: bva_key,
    stratname: signal.stratname,
    stratid: signal.stratid,
    trading_type: user_payload[tresult].trading_type,
    pair: signal.pair,
    qty: Number(user_payload[tresult].buy_amount)
}
socket.emit("traded_buy_signal", traded_buy_signal)

Send a Traded Sell Signal to the NBT hub:

const traded_sell_signal = {
    key: bva_key,
    stratname: signal.stratname,
    stratid: signal.stratid,
    trading_type: user_payload[tresult].trading_type,
    pair: signal.pair,
    qty: Number(user_payload[tresult].buy_amount),
}
socket.emit("traded_sell_signal", traded_sell_signal)

Disclaimer ๐Ÿ“–

I am not responsible for anything done with this bot.
You use it at your own risk.
There are no warranties or guarantees expressed or implied.
You assume all responsibility and liability.

Final Notes ๐Ÿ™

Feel free to fork and add new pull request to this repo. If you have any questions/suggestions, or simply you need some help building your trading bot, or mining historical data or improving your strategies using the latest AI/ML algorithms, please feel free to contact me.

If this repo helped you in any way, you can always leave me a BNB tip at 0xf0c499c0accddd52d2f96d8afb6778be0659ee0c

GETTING IN TOUCH ๐Ÿ’ฌ

Discord chat

node-binance-trader's People

Contributors

dargmuesli avatar bitcoinvsalts avatar thejoeschr avatar insertmike avatar plasto13 avatar joeschr avatar havardox avatar kalinbas avatar douglascrp avatar imgbotapp avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.