askmike / gekko

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

How to exit from a strategy ? #2869

Closed Tralala44 closed 4 years ago

Tralala44 commented 5 years ago

Hello People, i've tried so far on my own, but i need some help and o hope someone will be able to help me. A big thanks in advance ! :)

I'm submitting a ... [ ] bug report [X ] question about a way to exit of a simple strategy by command line

Action taken (what you did) i used a simple strategy to buyat/sellat a specific price and it works but i can't exit from gekko it still "looping" ; i tried to put some "return" but without any luck.

Expected result (what you hoped would happen) after executed the node gekko --config buy.js or sell.js, it executes the order specified in the above strategy and gekko closes itself.

Actual result (unexpected outcome) the use of the command line works, buy or sell orders are fullfilled but gekko remains up.

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, etc) Here the strategy used and juste before logs of the gekko command line after that the trade has been made : 2019-10-31 19:25:55 (DEBUG): Requested ZRX/BTC trade data from Binance ... 2019-10-31 19:25:55 (DEBUG): Processing 2 new trades. From 2019-10-31 18:25:35 UTC to 2019-10-31 18:25:45 UTC. (a few seconds) 2019-10-31 19:26:15 (DEBUG): Requested ZRX/BTC trade data from Binance ... 2019-10-31 19:26:15 (DEBUG): No new trades. 2019-10-31 19:26:35 (DEBUG): Requested ZRX/BTC trade data from Binance ... 2019-10-31 19:26:35 (DEBUG): Processing 1 new trades. From 2019-10-31 18:26:19 UTC to 2019-10-31 18:26:19 UTC. (a few seconds) Sell Price: 0.00002999 2019-10-31 19:26:55 (DEBUG): Requested ZRX/BTC trade data from Binance ... 2019-10-31 19:26:55 (DEBUG): Processing 1 new trades. From 2019-10-31 18:26:42 UTC to 2019-10-31 18:26:42 UTC. (a few seconds) 2019-10-31 19:27:15 (DEBUG): Requested ZRX/BTC trade data from Binance ... 2019-10-31 19:27:15 (DEBUG): Processing 1 new trades. From 2019-10-31 18:27:15 UTC to 2019-10-31 18:27:15 UTC. (a few seconds) Sell Price: 0.00003 ^C ############################## strategy used####################### // Create strat var strat = {};

// Prepare everything strat.init = function(){ this.requiredHistory = this.tradingAdvisor.historySize;

    // Options
this.debug = true; // Debug? If false - improves performance in backtests (use console.log or log.info)
    this.dealNumber = 0;

    // Vars
    this.lastAction = 'sell';

    // Settings
    this.buyPrice = '0.000XXXX';

}

// Warmup and every new candle strat.update = function(candle) { this.actualPrice = candle.close; }

// War strat.check = function() { // Long if ((this.actualPrice <= this.buyPrice) && (this.lastAction === 'sell')){ this.advice('long'); this.lastAction = 'buy';

            // Debug
            if (this.debug === true){
                    this.dealNumber++;
                    console.log('~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~');
                    console.log('Deal Number:', this.dealNumber);
                    console.log('Buy Price:', this.actualPrice);
            }

// return; } } //return;

werlang commented 5 years ago

I think strategies are supposed to keep running forever on its own. You are supposed to create a logic to make solid decisions for when to buy or sell and make it profitable. If you want to make it to take only X trades then stop doing trades you can easily put like a counter in its logic. But if you really want to stop it, you can use the UI to stop a running strategy manually.

stale[bot] commented 4 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.