How to prevent a gekko strategy from opening with a sell

Typically you’re going to start a strategy against a trading account that holds one side of the trading pair you are trading against. This means that if you are going to trade ETH/BTC you will start with ETH (the asset) in your trading account and zero Bitcoin (the currency).

Because Gekko doesn’t link your trading account to the trading strategy you can run into problems in 3 scenarios:

  1. When you first start your strategy Gekko may try and sell the currency first, which is not going to work given you have started with zero Bitcoin (the currency).
  2. When Gekko crashes (yes this happens!) or something else stops your Gekko instance while your strategy holds ETH (the asset).
  3. When Gekko crashes (yes this happens!) or something else stops your Gekko instance while your strategy holds BTC (the currency).

What is the solution?

Ensure your strategy knows which trade type to make first. This is actually really straight forward.

  1. Set a “firsttimetradetype” variable as “buy” (if you hold asset) in the Strategy config.
  2. Set a “firsttimetrade” variable as boolean false.
  3. Then inside the Strategy buy / sell logic check which is the type to trade first, and the “firsttimetrade” variable being false. If so then perform the trade and set the “firsttimetrade” to true.

In the event that Gekko crashes and you are left with currency and zero asset then you can switch the “firsttimetradetype” variable to sell.

In conclusion

The bottom line here is this initially seems like a simple problem to solve, but because Gekko separates the Trading (and trading account) from the Strategy the reality is there not a hands free solution.

The separation of trading, trading account and strategy is a fundamental weakness of the trading bot and it will be interesting to see how people try and solve it moving forward.

Leave a Reply

Your email address will not be published. Required fields are marked *