askmike / gekko

A bitcoin trading bot written in node - https://gekko.wizb.it/
MIT License
10.08k stars 3.93k forks source link

Binance in gekko is too unstable #1663

Closed joaosauer closed 6 years ago

joaosauer commented 6 years ago

Hi,

I'm really trying to do my best, but gekko + binance is impossible to be used in live trade. It's just crashes after crashes. I already got the PR 1550, that was suppose to fix it, but still have a lot of crashes. The last one I will post here, but there is also error in the roundtrip values. The start and end dates are invalid ones, like 49997 as year. Can we please merge all the PRs that are in the queue to finally have a version that maybe will have all the possible solutions and filter only the latest ones? The latest error: `/home/pi/gekko/exchanges/binance.js:67 if(!_.isEmpty(body.code)) { ^

TypeError: Cannot read property 'code' of undefined at /home/pi/gekko/exchanges/binance.js:67:24 at Request.request [as _callback] (/home/pi/gekko/node_modules/binance/lib/rest.js:66:21) at self.callback (/home/pi/gekko/node_modules/request/request.js:186:22) at Request.emit (events.js:159:13) at ClientRequest. (/home/pi/gekko/node_modules/request/request.js:816:16) at Object.onceWrapper (events.js:254:19) at ClientRequest.emit (events.js:159:13) at TLSSocket.emitTimeout (_http_client.js:710:34) at Object.onceWrapper (events.js:254:19) at TLSSocket.emit (events.js:159:13) RECEIVED ERROR IN GEKKO 1729509079168632 Child process has died. `

mboremski commented 6 years ago

@cmroche, @askmike I totally agree. This project is really really amazing, but at this moment a lot of things are outstanding. (at least 7 PR for binance)

For me it took a week to get binance working and it was hard to find the right issue, PR and so on that has to be implemented by hand. I finally got it working and it now is trading, but there are still bugs (can confirm the 49997year-Problem / importing still buggy)

If there is not a version 0.6 (or a 5.12?) at the horizon, could you at least try to get the develop-branch to a actual state?

Thanks alot..

cryosx commented 6 years ago

@mboremski

Can you make your files available? Can't get Binance to work. Or maybe instructions on which PRs to merge with.

mboremski commented 6 years ago

1st have a look on delvelop-branch. They yust merged #1568 and #1508 there. That might help. If not, I'll have a look on what have been done to make it work.

joaosauer commented 6 years ago

Just test what @mboremski suggested and is still crashing:

RECEIVED ERROR IN GEKKO 692182055050664

Gekko encountered an error and can't continue

Gekko encountered an error and can't continue

Error:

[binance.js] undefined

Meta debug info:

Gekko version: v0.5.11
Nodejs version: v8.5.0

In the logs there are no more info about the crash... :(

mboremski commented 6 years ago

I had a look at my "handmade" branch. Its basing on #1550 and the corrosponding download.

mboremski commented 6 years ago

so step by step (fyc):

pls tell us if its working for you too...

cryosx commented 6 years ago

Okay, just followed your instructions. I'll see how it goes.

cmroche commented 6 years ago

@joaosauer @mboremski

one additional step, update the binance module to fix the 'undefined' when there is an error

npm install binance@1.2.2

cryosx commented 6 years ago

my first run seems to have not traded anything and it popped up

ERROR: Failed to tick in time, see https://github.com/askmike/gekko/issues/514 for details

Updated the binance module with this most recent attempt but so far no trades, just candle data.

mboremski commented 6 years ago

no trades, just candle data.

Did you backtest your configuration and verified there would have been trades?

cryosx commented 6 years ago

okay it does trade, just seems the stochastic indicator with the tulip module is different on my windows computer vs my mac. doesn't seem to update right on the mac and so the stochastic K value has the typo this.tulipIndicators.stoch.result.sotchK instead of stochK.

mboremski commented 6 years ago

Happy to hear that. Please search if there is an issue for your remaining problem. I think this dont belong to this issue.

What about you @joaosauer?

ansonphong commented 6 years ago

This issue is fixed with this PR: https://github.com/askmike/gekko/pull/1674

joaosauer commented 6 years ago

Sorry, I will test today night the latest develop version and let you know asap. (during weekend I was away from computer.... :) )

storshun commented 6 years ago

After trying binance@1.1.0, and continuing to encounter this problem, then updating to binance@latest, I still seem unable to reliably run gekko. I didn't want to open another issue in the event my problem is covered here, and I'm just missing the obvious. I've run both on develop and origin/stable, and about 90% of the time, I can't start a Gekko bot. On the off chance one does start, it dies with the "encountered an error and can't continue" message in less than an hour, or a child dies, which I'm guessing is the monitor, since that's the piece missing after I refresh the "live gekkos" page. I'm using CCI method on binance, 1 minute candles and a 90 minute history. I'm open to ideas to solve. Running the browser UI, not command line.

Gekko encountered an error and can't continue

Gekko encountered an error and can't continue

Error:

[binance.js] Response code 400

Meta debug info:

Gekko version: v0.5.12
Nodejs version: v9.4.0
joaosauer commented 6 years ago

In my case, the crash was different, and happened only when trying to run the live trade.

  --> POST /api/startGekko 200 10ms 370b
RECEIVED ERROR IN GEKKO 358507464431526

Gekko encountered an error and can't continue

Gekko encountered an error and can't continue

Error:

[binance.js] undefined

Meta debug info:

Gekko version: v0.5.12
Nodejs version: v8.5.0
joaosauer commented 6 years ago

Actually, I was just re-reading the steps and actually, you are suggesting to use the cmroche fork. But I don't think that this fork does have all the other fixes made to the gekko? I mean, he forked a more than 1 year ago. Are you sure that all the fixes made to gekko during this time was merged from oficial gekko to his fork? I would prefer to see the fixes for binance being merged to the main fork, to then check if was really working or not. Otherwise, we will never know what was fixed or not.

joaosauer commented 6 years ago

Ok, after updating the binance package to the latest one, I'm getting the same as @storshun:

RECEIVED ERROR IN GEKKO 107574314509415

Gekko encountered an error and can't continue

Gekko encountered an error and can't continue

Error:

[binance.js] Response code 400

Meta debug info:

Gekko version: v0.5.12
Nodejs version: v8.5.0
joaosauer commented 6 years ago

Good news In my case, the error 400 was because my computer was 2 secs wrong with an atomic time server. I use mac and after update the time, it's now working for me. (No trader yet, but I will keep you updated)

Cheers, Joao

storshun commented 6 years ago

I have no time drift, according to time.gov, so I don't think that's the nature of my problem. I switched branches to the hotfix/binance-btc/usdt and relaunched. Seems like it's working now. Or at least, it's not throwing errors. We'll see if it's still running when I wake up in 3 hours.

unstephenk commented 6 years ago

updating binance with npm install and restarting the machine worked.

storshun commented 6 years ago

I've discovered clock drift is my biggest enemy. Even using "set time automatically" leaves me about 1.7 seconds adrift from server time after so many days of windows running. I manually set the time in Windows and it solved the problem, regardless the version of Binance NPM I use. Here's hoping my CPU doesn't drift too much on its own. If anyone knows a good way to lock-step the windows time to NIST time, I'm open to ideas. :)

cmroche commented 6 years ago

That is a surprising amount of clock drift. Typically NTP is supposed to compute your clock skew and compensate for it which should keep you well under a second of drift, the only thing I can think of is that your system is unable to access network time services, or that you have it disabled, or maybe the timeserver you are using is not great :P

You could increase the recvWindow though which would allow a greater amount of error. In the binance.js file look for a parameter near the top recvWindow which is defaulted to 60000 or one minute. Increase this to say 5 minutes 300000 and it should resolve your problem.

Edit: You said you skewed by 1.7 second, not minutes. Is that correct? Minutes could be explained by this... well try the change anyway, let me know if it resolves the problem or not please.

cmroche commented 6 years ago

OK, just did a bit more research, thread on CCXT people are reporting the same problem. https://github.com/ccxt/ccxt/issues/936 apparently there is another timer which requires all timestamps to be withing 1 second of their server time. In Windows 10 this is an issue becuase the time sync only runs once a day and if your clock has enough skew you will hit this issue.

The only solution is to update the time sync intervals on the users PC, see:

http://www.thewindowsclub.com/change-internet-time-update-interval-windows

https://www.opentechguides.com/how-to/article/windows-10/121/windows-10-internet-time.html

storshun commented 6 years ago

Wow, thanks for digging into this more! My clock definitely has enough skew apparently. I'm still getting error 400s, even though my clock is synchronizing to NIST every 3 minutes. I find it hard to believe that I'm getting out of lockstep by a second within only 180 seconds, but I guess it's possible. I'm using a program called "Dimension 4" to synchronize now, and have moved the update to:

  1. Sync every 60 seconds
  2. Always sync from the same known-good server

Hopefully this resolves the problem. If it doesn't, well, we'll cross that bridge when we get to it. :)

storshun commented 6 years ago

Is there a way to turn on a log in Gekko so that I can see the time of failure? I'd like to track how long the bot runs, because over the last several days, I've only been able to execute a buy order via the bot, and then at some point during the work day, I lose faith the bot is still running and manually execute my sell order. I get home in the evening to discover the bot did indeed die.

In all honesty, if it could write a heartbeat to a log, then I could sync that log to a network resource and monitor it throughout the day, I could see the last time a heartbeat was sent.

EDIT: Now that I'm sitting here thinking about it, is the answer really just better error handling? Sure, the connection may throw an error, but it seems like that should be recoverable, rather than the bot just puking and dying.

cmroche commented 6 years ago

@storshun Possibly it could be fixed, but it would mean implement a time syncrhonization client directly into the binance module, then modifying that to read this synchronized value as opposed to reading the system time. Given the difficulties this may not be unreasonable, but it is a bit outside the scope of Gekko. I think you would need to implement it directly as part of this project https://github.com/aarongarvey/binance

Edit, I've opened an issue there to discuss the issue with the project maintainer.

storshun commented 6 years ago

Understood. Thanks for your help in getting this resolved. I added some info into #1712 as well with how I resolved it with a time sync client. So far, the platform has been infinitely more stable than in all days prior. Got an xrp or eth address I could give you a tip?

cmroche commented 6 years ago

Folks, to simplify things a bit I'm going to move the conversation about time sync issue over to issue #1712. An update will come this afternoon likely with a time sync feature to help manage this.

askmike commented 6 years ago

@joaosauer: @cmroche's fix has been merged into develop, please try that and report back if the problem still persists.