[TECH TUT] Updating a old exchange integration to Gekko 0.6+
#1
This is a technical guide that explains how to migrate legacy exchange wrapper files to new Gekko Broker wrapper files used by Gekko +0.6. This is meant for technical contributors to Gekko who want to update an old exchange integration into Gekko. This isn't an exact guide but it roughly covers the things you need to fix.

All exchange wrappers can be found here: https://github.com/askmike/gekko/tree/de...e/wrappers

- All files ending with .js.old are old wrappers not updated yet.
- All files ending with .js are new wrappers not are working with Gekko 0.6 or higher.

If you want to update an outdated wrapper you need to do a few things:

- Remove all requires to any files outside the `gekko/exchange` directory, such as log and util (the wrappers are now part of a standalone library called Gekko Broker).
- Some function signatures have changed, such as:
  - checkOrder: the callback needs to be passed on object describing partial fills & order rejection
  - cancelOrder: the callback needs to be passed err as well as a "filled" boolean and optionally more data regarding partial fills.
- Error handling works different now, you need to create a function that will handle correct (non error result) and you will need to create a global function that will process the exchange SDK output and normalize error types for the new retry system.

You can look at existing updated implementations for example, and be sure to check out the wrapper reference here: https://gekko.wizb.it/docs/extending/add...hange.html
  Reply
#2
Hi

I'm trying to add a new exchange to gekko, I've already followed the instructions on the site about adding a exchange.

All good up tu here, I was just wondering how can I test all the functions without having to create a tradebot? And waiting for the strategy to sell or buy?

Thank you
  Reply
#3
Quote:All good up tu here, I was just wondering how can I test all the functions without having to create a tradebot? And waiting for the strategy to sell or buy?

At some point we do need to test the API calls to buy and sell, some exchanges provide a test/sandbox environment with fake money for this. But if the exchange doesn't: someone at some point will need to create an order to see if it works properly.

As for easy testing without a gekko strat: the trading is done by Gekko Broker. You can simply create a Gekko Broker to test the buying and selling, if that works correctly you don't have to worry about the rest of Gekko (strategies and such). See an example here: https://gekko.wizb.it/docs/gekko-broker/...ml#Example
  Reply
#4
@askmike thanks for the info, the gekko-broker helped me a lot.

I just have one quick question to see if you could help me, the exchange I'm working with there API calls are kind of slow, specially when the bot cancels a order and instantly starts a new one, I get a lot of the error "insufficientFunds" (I copied most of the code from binance.js). I'm currently using the retry library it kind of works, but a some point it fails after many attempts..

Is there a way to tell a the bot that when it cancels a order to wait about 1.5 second before starting the next order?

Thanks

EDIT: I think I just found it, on exchangeUtils.js I found under errors err.backoffDelay, but that helps once it fails, how can i apply as soon the cancel is done
  Reply
#5
You can set a timeout yourself in the buy call for example, so it looks like something like this:

Code:
Trader.prototype.buy = function(price, amount, callback) {
    setTimeout(() => {
      // your code
    }, 2000)
}
  Reply


Forum Jump:


Users browsing this thread: