askmike / gekko

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

Proxy support for exchanges? #2194

Closed xFFFFF closed 6 years ago

xFFFFF commented 6 years ago

As we know exchanges has ratelimits and some has very high. What do You think about http proxy support for connection localhost->exchange? @askmike ?

I checked and Binance support proxy, but Binance has low ratelimit in opposite to Bitfinex API, here param from bitfinex-api-node:

class RESTv2 {
....
   * @param {Object} opts.agent - optional node agent for connection (proxy)

https://github.com/bitfinexcom/bitfinex-api-node/blob/727c60d58047e802018bb54d13778bd6e075361f/lib/transports/rest2.js

Proxy could be set in config file of bot.

askmike commented 6 years ago

If you have a proxy rate limits apply just the same, right? So you need multiple and rotate if you are hitting limits. Also a proxy means your calls will be slower and if something happens to the proxy your calls might never finish at all.


Gekko as a project is designed for algorithms that trade medium to long term. If you want to do things that require a lot of API calls (a lot of trades, very tight orderbook play) you probably don't want to uses Gekko since it only deals with 1 minute candles (from the strat perspective).

That said: I'm working on Gekko Broker which is an independent library that does all API interaction with exchanges. Hopefully other projects will use it as well. I rarely run around ratelimits when I'm writing bots (unless I am market making and I'm having a lot of orders in the book at all times, or when I am doing arbitrage). This is how I am planning Gekko Broker:


And only after that if rate limits are a problem we should look into advanced ways of solving them imo.

xFFFFF commented 6 years ago

I meant that in every CLI configuration file, I could set up other proxies to connect to exchange. I do not know if it's possible... Limit is per IP but ratelimit is this same for all IPs.

I use 10 minute candles and my strategies generate on average 1.5 trades per day. However, for example, for Binance, I have more than 20 instances of gekko running.

Im not sure maybe I'm using wrong tickrate settings. I asked about it in issue #2141 , but no one answered. My tickrate is 2-5 seconds and cancelOrderDelay is 15-25 seconds. Why such a low tickrate? Because it seems to me (I asked about it in the issue mentioned above) that the gekko at cancel and readd order does not send an API request for a new price. If I'm wrong, say it and I will use tickrate = cancelOrderDelay and I will not need a proxy in the near future.

askmike commented 6 years ago

First things first: not all rate limits have to do with your IP address (only poloniex does this as far as I know). Most exchanges rate limit on account basis, and some on API key basis.

To answer your question from #2141:

Yes: When gekko gets a signal to buy it will:

  1. query account balances
  2. query ticker
  3. create order at top of the orderbook.
  4. (wait x seconds)
  5. query ticker again
  6. query order again
  7. if order is taken: finished (just a few API calls more to get details on the completed trade)
  8. if the order is still at the top: go to step 4.
  9. if the order is not at the top, cancel and go to step 3.

And that loops until the order is completed.


Because it seems to me (I asked about it in the issue mentioned above) that the gekko at cancel and readd order does not send an API request for a new price.

It gets the price it wants to trade at from the ticker, so whenever it cancels it SHOULD recreate the order at ta different price. If it doesn't do that it's a bug.


Sorry but I'm not understanding it: Why do you think you need a proxy?

xFFFFF commented 6 years ago

For be sure: query ticker =! tick (which rate I set in config file)? Tick (which are printing in debug mode) havent any influence on price for creating orders? Or another: settings in config.js cancelOrderDelay = 20 second, tickrate = 500 second will allow me to recreate the order every 20 seconds (assuming that the exchange price has changed)?

Ratelimit - maybe officially. I tried to run 2 gekko instances on the same API key from one host and after a few minutes I got a ban. I now use 3 instances, but on three hosts and it works ok. Other confirmations: https://www.bitfinex.com/posts/188 - "per IP" https://github.com/ctubio/Krypto-trading-bot/issues/52#issuecomment-315495828 - its market making bot

Yes, the gekko recreate order only when the price has changed. Everything is ok. Your "algorithm" has explained to me almost (the first question) everything.

I wrote: "DONT need a proxy" :)

stale[bot] commented 6 years ago

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. If you feel this is very a important issue please reach out the maintainer of this project directly via e-mail: gekko at mvr dot me.