This Binance trading bot detects the most volatile cryptos to buy and later sell at predefined Take Profit / Stop Loss thresholds.

Overview

Binance-volatility-trading-bot-JS

I take the idea from this project. The original bot is written in Python. I quite like it so I re-write it in Java Script to fix some issues and add some improvements. Shoutout to CyberPunkMetalHead for such an awesome contribution

Here's the main functions of the bot:

  1. Listen to the prices on Binance for every interval of 4 minutes.
  2. Figure out which coin's price has increase by 3% in each interval and proceed to buy.
  3. Track the bought assets' prices every interval, sell at 6% profit or 3% stop loss.
  4. If you choose to keep holding the asset when it hits TP, that's possible in TRAILING_MODE
  5. Record sold assets so users can see which coins were sold at what profit, so they can refine variables and automatically exclude some pairs when trading.

All the of the variables: Budget, Interval, Take profit or Stop loss thresholds, The change in price to trigger the buy function... are configurable by the users

Installation

  1. Requirements:
  1. Download the project here

  2. Open the terminal at the root folder, run

    npm install

    to install necessary packages

  3. Create a new config.env file based on the config.env.example file at the root folder. Place your configurations there. Again, whoever has this file can place orders from your account
    To retrieve your Binance API Key and Secret on both Testnet and Mainnet, I find no better guide than this one over here

  4. The bot is default to run on the Testnet. If you want to switch to Mainnet, set the TEST_MODE constant (in the constants.js file) to false

    const TEST_MODE = false;

  5. Finally, to start the script, open your terminal and run

    npm run start

  6. To stop the bot, hit Ctrl + C combination in the terminal

Notes

  1. Create a config.env file in the root folder and place your configurations there. For the love of God don't expose this file since it contains your API keys.

  2. If you set the budget (QUANTITY) of 50 USDT, the bot will not spend more than 50 USDT on trading (It checks the current portfolio first before making the purchase decision).

  3. If the inital QUANTITY is 50 USDT and there are 2 coins to buy in that interval, the bot allocates 25 USDT for each coin order.

  4. If the inital QUANTITY is 50 USDT and there is one asset worths 30 USDT in the portfolio, the bot will spend 20 USDT for following orders.

  5. The bot is default to sell 99.5% of the bought amount. The reason is sometimes you can't sell 100% of an asset on Binance. If you have some BNBs to pay for transactions then you can set the 99.5% ratio to 100%. This is configurable.

  6. Generally, you better place an order with at least 11 USDT to be accepted by Binance.

  7. TRAILING MODE DESCRIPTION:
    This mode runs by default. Every time an asset hits the TP, the bot doesn't sell it immediately. The SL and TP threshold of that asset is increased. If an asset hits the SL, we sell (In fact, we just sell at SL).

    For example, BTCUSDT is bought at 100. TP is 106 (6%) and SL is 97 (3%). When it hits 106, the TP is adjusted to ~109 and SL is ~103. Whenever it hits SL (97 or 103...), the bot sells.

    Disable this feature by setting "TRAILING_MODE" (in the constants.js file) to false

  8. SAFE_MODE DESCRIPTION:
    This mode runs by default. To avoid the rapid ups and immediate downs within the next interval, after an asset is bought, the bot scan to check the asset price every 1 minute (1 is the default value, you can change the SCAN_INTERVAL in the config.env file). If the asset price hits SL threshold during that 1 minute, the bot will proceed to sell the asset.

    Disable this feature by setting "SAFE_MODE" (in the constants.js file) to false

Contribution

If you run into some issues or have some suggestions, feel free to open an issue at the project's repo. I would be more than happy to read/approve some pull requests :).

Comments
  • Multiple orders for a single symbol

    Multiple orders for a single symbol

    When a price continues to rise the bot will purchase further orders of a single symbol. This is recorded correctly in the current-orders.json but when it comes to selling it does not appear to process all orders.

    Suggested behaviour: when a stop loss is triggered for a symbol then all current orders for that symbol should be closed, not just the first on the list.

    good first issue 
    opened by daddywookie 6
  • Console output - add date/time and output all to a log file

    Console output - add date/time and output all to a log file

    When there is a long period where nothing happens it can be hard to keep track of the executions. It might be helpful to add a timestamp to the output to make it clearer what is happening and when.

    [2021/05/18 18:05:02] No coin has risen more than 5% in the last 5 minutes
    [2021/05/18 18:05:02] MATICUSDT price has hit SL threshold
    [2021/05/18 18:05:03] The asset MATICUSDT has been sold sucessfully at the profit of -5.72% and recorded in sold-assets.json
    [2021/05/18 18:05:03] Wait for the bot to gather data to check price volatility...
    

    Also, outputting the console to a .log file would help with troubleshooting. This might need to be configured with some form of log rotation.

    good first issue 
    opened by daddywookie 2
  • Account with insufficient balance warning is scary

    Account with insufficient balance warning is scary

    Receiving the following warning is very scary

    Error in executing buying volatiles function: "Error in executing buy function: {\"code\":-2010,\"msg\":\"Account has insufficient balance for requested action.\"}"

    Maybe this can be caught and replaced with something friendlier?

    Tried to buy but there was not enough funds available

    opened by daddywookie 2
  • Bad string type in sold-assets.json

    Bad string type in sold-assets.json

    • The sell_at key is returned as a text when it should be numeric
    • The profit key is a text with the % symbol. Should this be a simple numeric and leave the text formatting to the front end
    opened by daddywookie 2
  • Safe mode

    Safe mode

    SAFE MODE description: To avoid the rapid ups and immediate downs within the next interval, after an asset is bought, the bot scan to check the asset price every 1 minute (1 is the default value, you can change the SCAN_INTERVAL in the config.env file). If the asset price hits SL threshold during that 1 minute, the bot will proceed to sell the asset.

    opened by 21jake 0
  • Trailing feature

    Trailing feature

    Every time an asset hits the TP, the bot doesn't sell it immediately. The SL and TP threshold of that asset is increased. If an asset hits the SL, we sell (In fact, we just sell at SL).

    For example, BTCUSDT is bought at 100. TP is 106 (6%) and SL is 97 (3%). When it hits 106, the TP is adjusted to ~106 and SL is ~103. Whenever it hits SL (97 or 103...), the bot sells.

    opened by 21jake 0
  • How to get mor than 6 assets price

    How to get mor than 6 assets price

    { BNBUSDT: { price: '488.00000000', time: 1630134032907 }, BTCUSDT: { price: '48960.73000000', time: 1630134032907 }, ETHUSDT: { price: '900.00000000', time: 1630134032907 }, LTCUSDT: { price: '172.55000000', time: 1630134032908 }, TRXUSDT: { price: '0.08478000', time: 1630134032908 }, XRPUSDT: { price: '0.99990000', time: 1630134032908 } } i like to have all prices from pair USDT (>=220 assets)

    opened by coding60plus 0
  • Error in executing buying volatiles function:

    Error in executing buying volatiles function:

    [6/7/2021, 11:04:49 AM] Error in executing buying volatiles function: "Error in calculating quantity: "Current portfolio value exceeds the initial quantity, waiting for the current asset(s) to be sold first...""

    opened by ceyhanmolla 3
  • Interference between safe mode and price check

    Interference between safe mode and price check

    I'm seeing some double entries at the same time stamp which appears to be the INTERVAL script and the safe mode script running at the same time. See 11:16 on the following logs. The price increase calculations seem to be adding together as well.

    Purchased at: 0.3496 Max during ownership: 0.3850 (gain of 10.1%)

    [26/05/2021, 11:11:34] The price of RAMPUSDT has increased 6.78% within last 5 minutes... [26/05/2021, 11:11:34] Successfully place an order: {"symbol":"RAMPUSDT","quantity":142.93,"orderId":36363922,"bought_at":0.3496,"TP_Threshold":0.360088,"SL_Threshold":0.339112,"purchase_time":"26/05/2021, 11:11:34","purchase_time_unix":1622023894804,"updated_at":"26/05/2021, 11:11:34"} [26/05/2021, 11:12:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:13:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:14:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:15:33] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:16:33] The price of RAMPUSDT has increased 7.15% within last 5 minutes... [26/05/2021, 11:16:33] Error in executing buying volatiles function: "Error in calculating quantity: "Current portfolio value exceeds the initial quantity, waiting for the current asset(s) to be sold first..."" [26/05/2021, 11:16:33] The RAMPUSDT has hit TP threshold and we continue to hold as TRAILING MODE activated [26/05/2021, 11:16:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:16:34] The price of RAMPUSDT has increased 11.33% within last 5 minutes... [26/05/2021, 11:16:34] RAMPUSDT price hasn't hit SL or TP threshold, continue to wait... [26/05/2021, 11:16:34] Error in executing buying volatiles function: "Error in calculating quantity: "Current portfolio value exceeds the initial quantity, waiting for the current asset(s) to be sold first..."" [26/05/2021, 11:17:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:18:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:19:33] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:20:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:21:33] Wait for the bot to gather data to check price volatility... [26/05/2021, 11:21:34] RAMPUSDT price hasn't hit SL threshold during this scan and the asset is kept [26/05/2021, 11:21:34] RAMPUSDT price hasn't hit SL or TP threshold, continue to wait... [26/05/2021, 11:24:11] RAMPUSDT price has hit SL threshold [26/05/2021, 11:24:11] The asset RAMPUSDT has been sold sucessfully at the profit of 0.94% and recorded in sold-assets.json [26/05/2021, 11:24:11] RAMPUSDT price hasn hit SL threshold during this scan and the asset is sold [26/05/2021, 11:24:12] Error in scanning Error in selling asset when it hits SL threshold: Error in selling 142.93 of RAMPUSDT: {"code":-2010,"msg":"Account has insufficient balance for requested action."}

    opened by daddywookie 1
  • Feature: Set stop loss limit instead of waiting for next script run

    Feature: Set stop loss limit instead of waiting for next script run

    Issue: When a symbol's price is rapidly falling it can go far below the SL_Threshold before the script is run again and value is lost. This is worse if a longer interval is set.

    Possible fix: Use the Binance API to set a stop loss limit at the SL_Threshold.

    1. Initial SL limit is set when the order is placed
    2. After Interval the order status is checked. If it has been filled the order is moved from current to sold with the price data set
    3. If the order has not been filled the script runs as normal
    4. If the TP_Threshold has been reached the SL order is cancelled and a new one is sent for the newly calculated SL_Threshold

    Challenges:

    • This might require a separate table for the stop loss orders?
    • This might make the bot too responsive when a delay for the interval would allow the price to bounce back above the SL
    opened by daddywookie 1
  • Order not being removed from current-orders.json on sale

    Order not being removed from current-orders.json on sale

    When an order is sold the action goes through correctly but the order is not removed from current-orders.json. This results in the bot trying to repeatedly sell the item but not being able to as the Binance wallet no longer has the item to sell.

    opened by daddywookie 2
Owner
HTML Developer. Has some experience with JavaScript and PHP too. I love my code even sometimes they're messy.
null
A simple Discord chat guard bot.

Discord Chat Guard Bot Kurulum İlk olarak bilgisayarına Node JS indir. Daha sonra bir MongoDB hesabı oluştur ve connection linki al. Eğer bunu yapmayı

Theark 38 Sep 17, 2022
Self BOT - Whatsapp

Self bot modified by me How To install Touch Me!! Ingredient/Bahan > Android Version > termux > WhatsApp > 2 HandPhone > Laptop Version > Gunakan Ter

Orez Ganz 10 Jul 4, 2021
A Discord bot Client Console Website

Discord Bot Client Console A Discord bot Client Console Website made with html , css and js. And Easy Use and easy to run Setup ⚒ Import the Repo by t

Msv 13 Jan 6, 2023
A Twitter bot that automatically replies to tweets requesting COVID related resources with links containing information about the availability.

COVID-19 Bot A Twitter bot that automatically replies to tweets requesting COVID related resources with links containing information about the availab

null 18 Jun 3, 2021
Spotify SDK | Entity and Collection oriented | Browser and Node support!

Spotify SDK Unofficial SDK recommended for Spotify in his developer center Entity oriented SDK to work with the Spotify Web API. Entity oriented? What

Joel Lovera 226 Jan 2, 2023
JavaScript SDK Design Guide extracted from work and personal experience

JavaScript SDK Design Guide Introduction This guide provides an introduction to develop a JavaScript SDK. The best one sentence to describe an SDK is:

Huei Tan 1.3k Dec 30, 2022
Notion 3.4k Dec 30, 2022
Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Superalgos 3.1k Jan 1, 2023
Plant trees to harvest apples. Sell apples to buy upgrades. Sell apples and wares to make the most money and top the leaderboard!

Happy Harvesters Apple Orchard Game A browser based game that is also mobile friendly so you can finally say "How about THEM apples". Table of Content

Scott Rohrig 7 May 21, 2022
Multi-chain sniper bot to buy and sell tokens on ETH compatible chains. Features include instant or mempool sniping, rug protection, and sell management.

An open-source defi sniper. defi-sniper is free to download. NEW Community telegram group: https://t.me/+aBLUmP1UnypiNTVh Premium Services Now Availab

spacemonk 6 May 3, 2022
Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance, FTX, Bybit ... (public edition)

Crypto Trading Bot A work in progress Cryptocurrency for common exchanges like Bitfinex, Bitmex and Binance. As most trading bots just provide basic b

null 5 Dec 9, 2022
A bot to automatically DCA (Dollar-Cost Average) buy cryptocurrency on Binance

Binance DCA (Dollar-Cost-Averaging) Bot This bot allows you to sit back and relax while it automatically invests in cryptocurrency on the Binance exch

Luke Liasi 164 Jan 6, 2023
Spiner bot to buy and sell tokens on ETH and ERC compatible chains as soon as liquidity is added and trade is enabled.

An open-source defi sniper. open-sniper is free to download. Premium Services Now Available While open-sniper is free and open-source, if you want the

spacemonk 4 Apr 21, 2022
Buy and sell tickets in the form of NFTs on Meter blockchain.

MeterTickets Landing page website: https://metertickets.on.fleek.co Marketplace dapp: https://metertickets-marketplace.vercel.app/ Smart contracts Blo

Akhilesh Thite 2 Apr 10, 2022
⚡️The Fullstack React Framework — built on Next.js

The Fullstack React Framework "Zero-API" Data Layer — Built on Next.js — Inspired by Ruby on Rails Read the Documentation “Zero-API” data layer lets y

⚡️Blitz 12.5k Jan 4, 2023
An E-commerce website that allows to Buy/Sell products, designed to strengthen small vendors to enhance their business

Developed using MERN Stack, an E-commerce website that allows to Buy/Sell products, designed to strengthen small vendors to enhance their business, fu

Inderjit Shahi 5 Jun 25, 2022
Web Application to Buy/Sell Scrap Items

nexscrap-classified Description : Web Application to Buy/Sell Scrap Items Requisite : Make sure you have Python3 and Pip installed in your System How

Raunak Das 3 Oct 12, 2022
A WebApp that allows you to follow Cryptos' News and Stats

CryptoWatch A WebApp that allows you to follow Cryptos' News and Stats. Table of Contents About The Project Screenshots Built With Getting Started Pre

null 28 Aug 4, 2022
Dev Care - One stop solution to take care of your health as developers

Dev Care: One stop solution to take care of your health as developers ??‍?? One-stop solution to take care of your health as developers. Dev Care will

null 44 Dec 13, 2022
A simple template to get started with a non-profit website.

Next.js Non-Profit Website A non-profit website template powered by the Cosmic headless CMS. Uses Next.js, Tailwind CSS, and Stripe for donation payme

Cosmic 5 Sep 6, 2022