Binance API cannot be used to trade.
Binance API is down! unable to call getBalance, retrying in 20s
[ { currency: 'USDT', asset: 'ETH' } ]
An error occurred { Error: binance {"code":-1021,"msg":"Timestamp for this request is outside of the recvWindow."}
at binance.handleErrors (/Users/brucelee/projects/eth/zenbot/node_modules/ccxt/js/binance.js:863:31)
at response.text.then (/Users/brucelee/projects/eth/zenbot/node_modules/ccxt/js/base/Exchange.js:513:18)
at
at process._tickCallback (internal/process/next_tick.js:182:7) constructor: [Function: InvalidNonce] }
Is your systemdate correct? Do you have an NTP client running?
It's correct. NTP is default running in MacOS, which is using 'time.apple.com'.
I have the same issue on both Windows and Mac with zenbot on Docker.
Binance API is down! unable to call getBalance, retrying in 20s
[ { currency: 'USDT', asset: 'EOS' } ]
An error occurred { Error: binance {"code":-1021,"msg":"Timestamp for this request was 1000ms ahead of the server's time."}
at binance.handleErrors (/app/node_modules/ccxt/js/binance.js:863:31)
at response.text.then (/app/node_modules/ccxt/js/base/Exchange.js:513:18)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) constructor: [Function: InvalidNonce] }
Mac is set to update time from Apple, Windows from time.nist.gov. However, the problem seems to be related to the time in the Docker container.
On my Windows machine:
see: this post
14:48:28 ~/Documents/Repos/zenbot (dev)
$ docker exec -it zenbot_server_1 date
Tue Jul 10 18:48:52 UTC 2018
Possibly because...
14:48:52 ~/Documents/Repos/zenbot (dev)
$ docker exec -it zenbot_server_1 cat /etc/timezone
cat: can't open 'C:/Program Files/Git/etc/timezone': No such file or directory
From a shell in the container, I tried to resolve with...
/app # apt-get install -y wget python python-dev unzip gcc ntp
but
/bin/sh: apt-get: not found
From here I tried...
/app # ntpstat
but
/bin/sh: ntpstat: not found
and...
/app # yum install ntp
similarly results in,
/bin/sh: yum: not found
Then I tried a javascript package from (here)[https://www.npmjs.com/package/ntp-client], but...
/app # npm install ntp-client
npm ERR! code ENOGIT
npm ERR! No git binary found in $PATH
npm ERR!
npm ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-07-10T19_18_52_107Z-debug.log
I could probably fight my way through installation of an ntp updating tool, but the Windows server container is built on image: deviavir/zenbot:unstable so the change should be tested and included in that image rather than post-hoc in docker-compose-windows.yml.
I would be happy to test potential Windows solutions.
As for Mac, Docker pushed solution in 17.05.0-ce-mac9 in 05/2017. I need to check what version I'm on, but I would think that I should be beyond that build. My plan for later tonight is to append to the volumes key in docker-compose.yml as such:
volumes:
- ./:/app/
- /app/node_modules/
- /app/dist/
# Avoid syncing database to our server
- /app/database/
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
Alternatively, I have seen discussion of the binance api being especially time sensitive and a potential solution is here.
My version of Docker for Mac is 18.03.1-ce-mac65 which should presumably contain the time fix referenced above.
Here's the time in the container vs my system.
19:33:02 ~/Documents/Repos/zenbot (npt)
$ docker exec -it zenbot_server_1 date
Tue Jul 10 23:33:09 UTC 2018
19:33:07 ~/Documents/Repos/zenbot (npt)
$ docker exec -it zenbot_server_1 cat /etc/timezone
cat: can't open '/etc/timezone': No such file or directory
I was not able to bind time information from the host as,
ERROR: for server Cannot create container for service server: cannot mount volume over existing file, file exists /var/lib/docker/overlay2/35cab6714236b9e5df08232d3e5130b09fc4a77a7421d75261a65e12029acf4c/merged/etc/localtime
At this point. I'm stuck. Can someone else confirm that Docker containers are a worm hole in time or point me in the right direction?
From this post it seems that time in the docker for mac container drifts away from the system time. There may be a more elegant solution, but I added a new command to the Makefile which forces and update to the container time.
After executing make time-sync the container time is close enough to system time to get Binance trades working.
I pushed this solution in PR #1659
@jraviotta Thanks Jraviotta, I will try.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
From this post it seems that time in the docker for mac container drifts away from the system time. There may be a more elegant solution, but I added a new command to the
Makefilewhich forces and update to the container time.After executing
make time-syncthe container time is close enough to system time to get Binance trades working.I pushed this solution in PR #1659