Skip to content

Troubleshooting

chrisleekr edited this page Oct 19, 2021 · 24 revisions

How to get the error message

Firstly, if you are not developing this bot, then you should use docker-compose.server.yml.

docker-compose -f docker-compose.server.yml pull
docker-compose -f docker-compose.server.yml up -d

Secondly, you must configure the environment parameter correctly. Refer https://github.com/chrisleekr/binance-trading-bot#how-to-use

If you have an issue accessing the frontend or something went wrong, the first thing you should do is whether docker containers are running correctly.

$ docker ps -a                                                                                                                                               
CONTAINER ID   IMAGE                                   COMMAND                  CREATED          STATUS          PORTS                                   NAMES
0603ab912881   mongo:3.2.20-jessie                     "docker-entrypoint.s…"   40 seconds ago   Up 39 seconds   27017/tcp                               binance-mongo
4d5e2c64cfde   redis:6.2                               "docker-entrypoint.s…"   40 seconds ago   Up 39 seconds   6379/tcp                                binance-redis
d924f279a5cb   chrisleekr/binance-trading-bot:latest   "docker-entrypoint.s…"   40 seconds ago   Up 39 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   binance-bot

If one of the containers is not up and running, then get the logs of the container.

$ docker logs <container-name> --tail=1000 > error.log
$ cat error.log

i.e.

$ docker logs binance-bot --tail=1000 > error.log
$ cat error.log

If you see an error message that you don't understand, first search whether other traders had the same issue or not. If you cannot find the issue the same as you, then open a new issue with the log message. Please make sure the issue is related to the bot.

If the error log is very long, then use https://gist.github.com/ or https://pastebin.com/

If you want to reset everything and start again, refer this section.

How to get the logs by installing bunyan npm package

In case things go the unexpected way, or you are asked by someone to provide logs of your bot in the issues area, kindly install bunyan through npm, using the following command:

npm install -g bunyan

and once its completed, execute the following command in order to have the 1000 latest lines of the logfile, shown:

docker logs binance-bot --tail=1000 | bunyan

If you want to get specific symbol's log, then use following command:

docker logs binance-bot -f --tail=1000 | bunyan -c 'this.symbol === "BTCUPUSDT"'

Or if you want to get specific symbol's step log, then you can use following command:

docker logs binance-bot -f --tail=1000 | bunyan -c 'this.symbol === "BTCUPUSDT" && this.stepName === "determine-action"'

For the step name, you can find from https://github.com/chrisleekr/binance-trading-bot/blob/master/app/jobs/trailingTrade.js#L42

Pasting the output at an issue reply, will give useful information regarding your container and will probably be the only step needed in order to identify the cause of the issue.

How to disable local tunnel

The local tunnel is a good way to expose your bot to the public; thus, you can access your frontend everywhere.

Learn more about the local tunnel in the official package - https://github.com/localtunnel/localtunnel

However, due to an unexpected issue with the local tunnel or you may not want to expose the bot to the public, then you can disable by updating the environment parameter, which you can find in this file. - https://github.com/chrisleekr/binance-trading-bot/blob/master/config/custom-environment-variables.json#L41

Follow below steps to disable the local tunnel:

  1. Update .env file
BINANCE_LOCAL_TUNNEL_ENABLED=false
BINANCE_LOCAL_TUNNEL_SUBDOMAIN=default
  1. Restart docker container
$ docker-compose -f docker-compose.server.yml up -d 

Slack integration

The bot notifies buy/sell actions to the Slack channel if you configure, which give you the notification when the action is executed.

You can learn how to create incoming webhooks for Slack on their official website - https://slack.com/intl/en-au/help/articles/115005265063-Incoming-webhooks-for-Slack

Once you create the incoming webhooks, then you will get the webhook URL.

  1. Update .env file
BINANCE_SLACK_WEBHOOK_URL=<Webhook URL>
BINANCE_SLACK_CHANNEL="#binance"
BINANCE_SLACK_USERNAME=Chris
  1. Restart docker container
$ docker-compose -f docker-compose.server.yml up -d 

Alpine's APKINDEX.tar.gz temporary error (try again later)

Edit Dockerfile

Add

RUN echo -e "http://nl.alpinelinux.org/alpine/v3.11/main\nhttp://nl.alpinelinux.org/alpine/v3.11/community" > /etc/apk/repositories

Before

RUN apk add --no-cache make gcc g++ python

How to fix Docker hanging at 'fetch' packages

If you install the binance-trading-bot to a any machine which has custom MTU to the host interface (different from 1500 which is standard), you may encounter an issue when building the docker image, mainly in step 2/33 when the system tries to fetch APKINDEX that the download never finishes and it's hanging for minutes or hours.

You need to check your MTU of main host network interface, see example below:

ip a

Outcome

2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1442 qdisc fq_codel state UP group default qlen 1000

By default, docker installation creates a docker0 network interface which has MTU of 1500. In the case above, the docker0 interface must also have MTU 1442 as the host interface.

To do this, edit daemon.json, depending on your OS and installation this can be in multiple locations, please check official Docker documentation to see where to find it and modify it as below:

{
    "log-level":        "error",
    "storage-driver":   "overlay2",
    "mtu": 1442
}

You might have different configuration in your Docker settings file, you only need to add the third line specifying the MTU for docker0 interface. Once again, MAKE SURE which is the MTU of your physical interface so you match it for docker0 interface to be the same.

UPDATE 14.05.2021: On bridged mode networking (configured in docker-compose.yml file) , the containers are started as "veth" interfaces all together grouped in a "br0" bridge, and disregarding the setting above. The setting above is only used on "host networking" where all containers are using "docker0" interface.

Here you need to edit "docker-compose.server.yml" and down to the bottom where the networks are defined, make sure it looks like this:

networks:
  internal:
    driver: bridge
    driver_opts:
        com.docker.network.driver.mtu: 1442

As you can see, there are 2 lines added, "driver_opts" which says that the following value will be a driver option to setup, and "com.docker.network.driver.mtu" which is the actual configuration to modify. Here, change "1442" to whatever custom MTU you have on your VM host interface.

This issue happens mostly when deploying the bot on instances in public clouds like Azure/Openstack/AWS/OCI where the networking is SDN and it provides custom MTU to instances/VM because of encapsulation configuration on the underlaying infrastructure.

How to fix clock desync

When using docker on windows / docker on mac, it may be the case that the system clock of docker is not synced with the respective host system. This results in API errors (The call is made 1000ms in the future, or something similar).

On windows, you can do:

wsl --shutdown

and the restart the Docker backend via the windows notification.

On Mac you'll need to restart docker and it's VM.

You can check the clock with: docker run --rm -it alpine:latest /bin/sh and then in the running machine: while true; do date; sleep 1; done; to print out the date each second. It should be the same as the synchronized host clock.

Execution failed Code: -2010

It means wrong configuration on Global Settings https://github.com/chrisleekr/binance-trading-bot/issues/165

Solution: Read again README.md https://github.com/chrisleekr/binance-trading-bot#sell-signal

Setup cronjob or scheduled task to restart the bot periodically

We can setup a cronjob or scheduled task depending on the environment where the bot is running on (Unix-like environment or Windows), to restart the bot periodically (which may solve some issues).

Cronjob for Unix environments

Refer: https://crontab.guru/

$ sudo su
$ crontab -e

0 * * * * /usr/bin/docker restart binance-bot tradingview

Scheduled Task for Windows environments

Refer (for command line): https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks-create

The equivalent of cronjobs in Windows are Scheduled Tasks, you can open its GUI in Windows by searching by name or following the steps:

  • Windows 11: Start -> Control Panel -> Windows Tools -> Schedule tasks
  • Windows 10: Start -> Control Panel -> Administrative Tools -> Schedule tasks

You can also set a scheduled task same as the cronjob above with a command like this:

schtasks /create /tn "Restart Binance Bot" /tr "docker restart binance-bot tradingview" /sc daily /st 00:00

Where:

  • /tn: Specifies a name for the task.
  • /tr: Specifies the program or command that the task runs.
  • /sc: Specifies the schedule type (see refer for supported values).
  • /st: Specifies the start time for the task, using the 24-hour time format, HH:mm.

Building docker image under Windows with PowerShell

npm run docker:build:win

By default it will build production, to build development, use:

npm run docker:build:win -- -env dev

Binance API error - EAI_AGAIN

Occasionally, the bot sends the following errors to Slack. This is not a bot issue. It means the bot could not receive the response from Binance API within the expected time. The cause of this issue can be:

  • Slow network between the bot and Binance API
  • Server performance
  • Binance API may be down (never happened yet)
Execution failed (00:39:23.138)
Job: Trailing Trade Indicator
Code: EAI_AGAIN
Message:
request to https://api.binance.com/api/v3/account?timestamp=1621557558124&signature=xxx failed, reason: getaddrinfo EAI_AGAIN api.binance.com
Stack:
FetchError: request to https://api.binance.com/api/v3/account?timestamp=1621557558124&signature=xxx failed, reason: getaddrinfo EAI_AGAIN api.binance.com
    at ClientRequest.<anonymous> (/srv/node_modules/node-fetch/index.js:133:11)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

How to reset all configurations and start again

For some reason, if you want to restart everything again, then simply run the following commands:

$ docker-compose -f docker-compose.server.yml down -v
$ docker-compose -f docker-compose.server.yml pull
$ docker-compose -f docker-compose.server.yml up -d

If you want to remove all images and volumes, then do these commands:

$ docker-compose -f docker-compose.server.yml down -v
$ docker system prune --volumes -a
$ docker-compose -f docker-compose.server.yml pull
$ docker-compose -f docker-compose.server.yml up -d

Why the bot didn't sell all coins when I configured 100% to sell?

The question seems to be raised frequently. So here is the reason why it didn't sell all of the coins when you configured 100% to sell.

The code for selling the coin is here - https://github.com/chrisleekr/binance-trading-bot/blob/master/app/cronjob/trailingTrade/step/place-sell-order.js

The key points are:

  • The bot will deduct the commission 0.1% from the order quantity.
  • If the step size of the symbol is 1, then most likely you will leave 1 base asset.
  • This calculation applies the same when you trade in Binance.

Let me explain further with examples. Note that the below example may change if Binance updates its symbol information.

You can do the calculation in CodePen - https://codepen.io/chrisleekr/full/mdMEEKj

The below calculation is using following grid trade percentages:

  • Stop percentage: 0.98 (98%)
  • Limit percentage: 0.97 (97%)
  • Sell percentage: 1 (100%)

BNBUSDT

Sell configuration is:

Tick size (price precision): 0.10000000 = 1
Step size (lot precision): 0.00100000 = 3

Sell trigger price: 487.5 USDT
Balance before sell: 0.029 BNB
Estimated USDT: 487.5 USDT * 0.029 BNB = 14.1375 USDT

Sell order params will be:

Stop price: 477.7 USDT
Limit price: 472.8 USDT
Order quantity: 0.028 BNB
Estimated after sell: 13.2384 USDT

FTMBUSD

Sell configuration is:

Tick size (price precision): 0.00010000 = 4
Step size (lot precision): 1.00000000 = 0

Sell trigger price: 2.3 BUSD
Balance before sell: 9 FTM
Estimated BUSD: 487.5 BUSD * 9 FTM = 20.7 BUSD

Sell order params will be:

Stop price: 2.254 BUSD
Limit price: 2.231 BUSD
Order quantity: 8 FTM
Estimated after sell: 17.848 BUSD