Skip to content

🤖💰 A cryptocurrency Trading Bot for Binance with a Django interface

License

Notifications You must be signed in to change notification settings

JBthePenguin/DjangoTradingBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DJANGO TRADING BOT

A bot trader with a Django interface for the Binance's markets. It's intended to work with cryptocurrencies Bitcoin(BTC), Ethereum(Eth) and Binance coin(BNB), the latter allowing to benefit a 25% discount on the transaction fees applied by Binance. If you want to use it with others, you’ll have to adapt the code...
Completely ignoring fluctuations in the BTC/$, ETH/$ and BNB/$ markets, it's more a miner than a trader with the aim of generating BTC, ETH and BNB. So PAY ATTENTION to its use if you want to get rich with profits in $.
Finally, you need a binance account with a minimum balance of 1.05 BNB and the equivalent in BTC and ETH.

For example, if the price on BNB/BTC market is 0.0026057 and 0.138650 on BNB/ETH market
you must have at least 0.00278985 BTC, 0.1455825 ETH and 1.05 BNB

TRADING STRATEGY

To be clear, I am not a trader and the following strategy may seem to simple, or even inapropriate. So, feel free to improve it and let me know if you do.
The bot sends a request to the binance-api to recover the prices of the markets BNB/BTC, ETH/BTC and BNB/ETH. It makes a calculation, taking into account the fees, to determine whether a three-pair triangulation opportunity with a profit is possible:

  • if not, it returns a request to the api again, and again... until one came along.
  • if that's the case, it opens a trade, that is to say places an order on each market, and waits for the three to be completed before looking again for an opportunity.

‼️The waiting time can vary from one second to days, and in absolute terms, an order may never be completed: that's the RISK.

Every four or five trades, the bot balances the earnings of each of the cryptocurrencies using an offset on the amount of BNB to trade.

INSTALLATION

PostgreSQL database

❗maybe you have to install PostgreSQL

Connect to PostgreSQL client, create database and new user with privileges:

$ sudo su - postgres
postgres@somewhere:~$ psql
postgres=# CREATE USER "django_trading_bot";
postgres=# ALTER USER django_trading_bot WITH PASSWORD 'cool';
postgres=# CREATE DATABASE "db_django_trading_bot";
postgres=# GRANT ALL PRIVILEGES ON DATABASE db_django_trading_bot TO django_trading_bot;
postgres=# \q
postgres@somewhere:~$ exit

Application, virtual environment, requirements and tables

❗maybe you have to install virtualenv

Clone the folder, go inside, create a virtual environment for Python with virtualenv and activate it:

$ git clone https://github.com/JBthePenguin/DjangoTradingBot.git
$ cd DjangoTradingBot
$ virtualenv -p python3 env
$ source env/bin/activate

Install all necessary dependencies (django, django-debug-toolbar, psycopg2-binary, python-binance):

For python-binance, you need to install python3-dev

(env)$ sudo apt-get install python3-dev
(env)$ pip install -r requirements.txt

Create tables:

(env)$ python manage.py makemigrations
(env)$ python manage.py migrate

Settings

Create a "superuser" account:

(env)$ python manage.py createsuperuser

Start the server:

(env)$ python manage.py runserver

Connect to the admin site http://127.0.0.1:8000/admin/ and add:

  • one bot: don't check is working, enter the quantity of BNB to trade and the date when you start your bot at the first time.

The quantity of BNB must be an integer and for the fees you need quantity x 1.05 as minimum balance.
For example, if you want to trade 2 BNB, you need more than 2.10 BNB and the equivalent in BTC and ETH.

Bot in admin interface

  • one binance key pair: your API and Secret keys. How to create API on binance?
    Keys in admin interface
  • three currencies: the first with name Bitcoin and symbol BTC in position 1, the second with name Ethereum and symbol ETH in position 2, the third with name Binance coin and symbol BNB in position 3.
    Currencies in admin interface
  • three markets: the first with symbol BNBBTC in position 1, the second with symbol ETHBTC in position 2 and the third with symbol BNBETH in position 3.
    Markets in admin interface
  • two banks: one with name now and the other with name start, with the same amount for each currency: your start bank.
    Banks in admin interface
  • one offset: enter 1 for trade number and 0 for bnb.
    Offset in admin interface
  • one error: enter error for type.
    Error in admin interface

USING

Go to http://127.0.0.1:8000/ to see the visitor interface...
Visitor interface ... and http://127.0.0.1:8000/admin/visitorapp/bot/ to start and stop the bot from the admin site by clicking on the button.
Start the bot in admin interface Stop the bot in admin interface

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.

PLANNED IMPROVEMENTS

  • Create tests.
  • Use other cryptocurrencies by simply adding them from the admin interface and so be able to search for opportunities and trade in other markets at the same time.
  • Add other trading strategies.
  • Improve error management when the bot is running.
  • Set up multiprocessing to open the 3 orders of a trade.

DONATION

If it has been profitable for you and/or you absolutely want to make a donation so that can pay me a training as a trader:metal:

About

🤖💰 A cryptocurrency Trading Bot for Binance with a Django interface

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published