DeviaVir / zenbot

Zenbot is a command-line cryptocurrency trading bot using Node.js and MongoDB.
MIT License
8.23k stars 2.03k forks source link

Kraken support #177

Closed Alexandre-io closed 7 years ago

Alexandre-io commented 7 years ago

Hi,

Could is it possible to re-add the support of kraken in v.4 ?

Thanks!

nibzo1 commented 7 years ago

I would also like this, I had a go at making it work by following GADX setup but got lost with some of the underlying functions I would have to implement.

Any advice on what we could do to get this working

DeviaVir commented 7 years ago

@nibzo1 I think there are a lot of lessons in this PR: https://github.com/carlos8f/zenbot/pull/162

nibzo1 commented 7 years ago

nice one, Ill have a look at this and see what I can pull from it. Hopefully I can get some minutes to try and move forward

Alexandre-io commented 7 years ago

@nibzo1 You can found the older version here: https://github.com/carlos8f/zenbot/tree/3.6/plugins/kraken

royteeuwen commented 7 years ago

Would really look forward to this too!

Alexandre-io commented 7 years ago

I have created the extension by reading the documentation but I don't have the time to test it right now. If someone have the time to review ( @carlos8f ? ): https://github.com/Alexandre-io/zenbot/commit/586bb694016efc5115655bdf29bdf188caf1ca06

nibzo1 commented 7 years ago

@Alexandre-io the code looks sound, I've tested and It start without error but backfill appears not to work. It just resorts to the console with

Download complete

nibzo1 commented 7 years ago

So after some further debugging I can see that about 1000 trades downloads. The getTrades() executes but no data is picked up in the mongodb or by the zenbot sim command

nibzo1 commented 7 years ago

@Alexandre-io tested further and I fixed a variable or two for you. https://github.com/Alexandre-io/zenbot/pull/1/commits/2a28d62bde7f9095642707907ecce1f6bbd89db3

With these fixes the bot will start trading but there is some data missing in the log output. Looks like something is still missing.

Alexandre-io commented 7 years ago

@nibzo1 thanks! My last commit fix the backfill & sim but I don't know if the "since" parameter of the kraken api is a timestamp or just an id.

fooness commented 7 years ago

@Alexandre-io & @nibzo1 Thank you very much for looking into this!

crubb commented 7 years ago

@Alexandre-io according to the documentation "since" seems to be an ID: https://www.kraken.com/help/api

nibzo1 commented 7 years ago

@Alexandre-io cool Ive taken your latest commit and sim & backfill appear to work now. I have kicked it off to trade now. Lest see what happens

So after some time of running my balance changed due to other trades outside of the zenbot trading pair. Looks like something is NULL. Ill add some debug and see it I can find out what it is,.

2017-05-28 14:58:18  147.15 XETH-ZEUR   -2.1%     4894      +      -0.2028           0.00 XETH  176.58 ZEUR   -52.2%  -51.2%
getBalance error:
undefined
Kraken API is down! unable to call getBalance, retrying in 10s

also

Kraken API is down! unable to call trade, retrying in 10s
crubb commented 7 years ago

@nibzo1: Same for me!

Alexandre-io commented 7 years ago

@nibzo1 @crubb the kraken api is not stable, the retry should do the job.

crubb commented 7 years ago

@Alexandre-io not a single trade went through for me, though

Alexandre-io commented 7 years ago

@crubb could you try my last commit plz ?

crubb commented 7 years ago

@Alexandre-io Argh, I sent you a PR https://github.com/Alexandre-io/zenbot/pull/2 just 5 minutes later ;)

Alexandre-io commented 7 years ago

@crubb thanks! but where did you found the "trading_agreement" parameter ? I'm unable to found it in : https://www.kraken.com/help/api#add-standard-order

crubb commented 7 years ago

On the page where you get the API key, I put the link in the conf-sample.js Are you on Discord?

nibzo1 commented 7 years ago

@Alexandre-io @crubb just seeing the changes you guys have added good job :+1:

I have pulled and kicked the bot off again. Will report back

crubb commented 7 years ago

@nibzo1: There are problems on getOrder as well, live trading won't work, yet

nibzo1 commented 7 years ago

Thanks for the heads up

My bot had also hit the Kraken rate limit, not sure what API calls were triggering this because there is generally a good bit of head room.

crubb commented 7 years ago

Currently the client is just retrying the API call, when it fails and then hitting the rate limit. It is assuming that the API was not reachable. But actually the Kraken API is reporting proper real errors, which the client is so far ignoring. I just removed all retries in my local code and I'm debugging further.

nibzo1 commented 7 years ago

Appreciate the update thanks, I wont get a chance to look at this until tomorrow now

crubb commented 7 years ago

Yo, buying and selling now works with the latest PR https://github.com/Alexandre-io/zenbot/pull/4. Now the problem is, that when an order is not filled quickly enough, checkOrder is getting called so often, that I frequently run into the Kraken API rate limit.

From https://github.com/carlos8f/zenbot/blob/2444a9e6c77eb78f2d640d41efbfd23522116e7f/lib/engine.js I gather that checkOrder should only be called every order_poll_time (which I left at the default of 5000 ms), but it is getting called way more often.

Any ideas?

Alexandre-io commented 7 years ago

Here is the PR for kraken :)

crubb commented 7 years ago

Yeah!

I just found another small problem with orders, which are rejected by Kraken as Post only order. Polo and GDax reject them instantly on AddOrder (that's where the engine.js logic catches them). Kraken accepts them and then instantly cancels them. I added some logic (no PR, yet), but so far I was not successful on forcing a 'post only' reject to happen. Any suggestions?

royteeuwen commented 7 years ago

How can this be solved if the kraken api error still occurs? Kraken API error - unable to call getTrades (Error: Kraken API returned error: API:Rate limit exceeded), retrying in 10s

DeviaVir commented 7 years ago

@royteeuwen probably not the answer you want to hear, but there's a pretty clever retry logic that tries to deal with this in the way that it's supposed to be dealt with.

That is the retrying in 10s that you see there. Technically there is nothing else we can do about that right now. If I'm wrong, please PR a fix- be happy to merge it.

royteeuwen commented 7 years ago

Well no for me thats fine, the only thing I would change then is the actual output that it doesn't log it as an error? Now it looks to be broken when using it, while you state it's made like that by design

screen shot 2017-06-03 at 12 49 55

Also the output of the sim seems to gotten messed up, see second screenshot

screen shot 2017-06-03 at 12 50 36
DeviaVir commented 7 years ago

@royteeuwen heh. that does end up a bit of a mess.

@crubb @Alexandre-io @nibzo1 any thoughts on how to resolve this, should we add a verbose option and hide this kind of information underneath that?

crubb commented 7 years ago

Hey

a) there seems to be a rate limit on the public API for backfilling, which is not documented. I will push a Pull Request with a "quick & dirty" rate limiting for backfilling. --> #217 b) Are the line breaks that ugly with sim of e.g. GDax as well, or only Kraken? Is that a docker issue? I mean the sim is not printing any error and that's the only place where the Kraken extension is writing something to the console itself.

tuxitor commented 7 years ago

Unix line termination is an LF, while Windows uses CRLF. That means line output from a NIX program could on certain occations could be shown like the example in a windows environment