tudorelu / pyjuque

⚡ Open Source Algorithmic Trading Bot for Python.
MIT License
456 stars 90 forks source link

Bot does not stop with Ctrl+C? #27

Open Jsalaz1989 opened 2 years ago

Jsalaz1989 commented 2 years ago

Hello,

I have the typical loop in my file:

def main():
    bot_controller = defineBot(bot_config)

    while True:
        try:
            bot_controller.executeBot()
        except KeyboardInterrupt:
            return

        sleep(15)

However, when I hit ctrl+c the terminal appears to react but not actually stop the program: image

Am I misunderstanding something?

Thanks

Jsalaz1989 commented 2 years ago

tudor pls

tudorelu commented 2 years ago

Hey hey, so you see how 'sleep(15)' is outside the scope of 'try'? You want to put it inside, so the KeyboardInterrupt will work while the bot is waiting.

try:
    bot_controller.executeBot()
    sleep(15)
except KeyboardInterrupt:
    return
Jsalaz1989 commented 2 years ago

That's like the first thing I tried. If I bring in the sleep(15) inside the try it won't even react to the Ctrl+C. The terminal never stops showing the "Executed the bot loop. Now waiting...". The following screenshot is after trying to send Ctrl+C multiple times to the terminal.

image

tudorelu commented 2 years ago

Maybe try these SO answers: https://stackoverflow.com/a/5114409/4468246 https://stackoverflow.com/a/47495035/4468246

Jsalaz1989 commented 2 years ago

I think it's more of an issue with your logging of "Executed the bot loop. Now waiting...". Look at this:

image

After ctrl+c the first time you can see it prints the "inside except". However, after that, your logging is still spinning with the "Executed the bot loop. Now waiting..." and even if I try ctrl+c again, it doesn´t react in any way.

tudorelu commented 2 years ago

Oh that makes sense, it's probably to do with yaspin (the spinner/logger)

Jsalaz1989 commented 2 years ago

While you're looking into that, would it also make sense to look into the following?

When the bot places a sell order, it repeatedly prints out "OPEN SELL order on...":

image

It just keeps filling up the terminal with it. Wouldn´t it be better to just print it once and then if anything new happens, print the new change?