LasticotSoftware / Astibot

Astibot is a simple, visual and automated trading software for Coinbase Pro cryptocurrencies (Bitcoin trading bot)
MIT License
206 stars 49 forks source link

TransactionManager crashes on CancelOngoingLimitOrder #5

Closed yoitcc closed 3 years ago

yoitcc commented 3 years ago

Hi,

I think there is a reference error at:

https://github.com/LasticotSoftware/Astibot/blob/17b98f0bad17652a40d418bc8b75c309a30a6794/src/TransactionManager.py#L564

All other calls to GDAX_CancelOngoingLimitOrder() in TransactionManager.py are made to self.theGDAXControler.

The corresponding error message of it in live trading: `TRNM - threadOrderPlacing: Buy order replace is needed. Current Bid is 1159.73, Best order book bid is: 1159.98 TRNM - threadOrderPlacing: Placing / Replacing a Buy limit order on the top of the order book TRNM - computeBuyCapabilityInCrypto: capability is 0.04741069003720261 (current balance is 54.99 + 49.74 (hold)) TRNM - threadOrderPlacing: live best bid price too high: cancel order Exception in thread Thread-2: Traceback (most recent call last): File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/usr/lib/python3.8/threading.py", line 1254, in run self.function(*self.args, **self.kwargs) File "/home/oswald/Projects/astibot/Astibot/src/TransactionManager.py", line 564, in threadOrderPlacing self.GDAX_CancelOngoingLimitOrder() AttributeError: 'TransactionManager' object has no attribute 'GDAX_CancelOngoingLimitOrder'

`

What I can recollect about the state and actions of the Bot: It sent two Limit Orders to Buy at 1159.73€ on Coinbase, which went through. Afterwards the UI was still showing: "Waiting to BUY ..." and the Live Price froze, although it still showed the green 'updating' text in the bottom right regularly. I think it even showed the new Coinbase Balance, althought I might have only noticed this after pressing the Stop Button.

I changed the line #564 in my local files and will restart the Bot, hope it works better this time ;) It is a very nice looking UI and the simulation are easily played with ;) thank you very much for creating it!

My only direct question so far: Does the Bot really crash unrecoverably if the TransactionManager throws an Exception like this? (I have the lurking feeling, that I prematurely stopped trading and closed the bot too soon...)

Thanks for your time, have a nice day, oswald

LasticotSoftware commented 3 years ago

Hi, thank you for your message and bug report.

I confirm that GDAX_CancelOngoingLimitOrder() in TransactionManager shall be called on the 'theGDAXControler' instance. I'm working on a few fixes and I will include this one as well. I'm sorry I left an issue so obvious in the code, but I lack time to test and debug the project. I will push some corrections as soon as I can.

For your question, yes unfortunately an exception like this will unrecovably crash the bot. Keeping the bot running on critical errors like this is difficult: the error itself would have to be analyzed dynamically when it occurs so that the bot would choose a good escape or catch-up strategy to avoid money loss. But I agree on the fact that we could simply add more robustness on multiple parts of the code!

Have a nice day

yoitcc commented 3 years ago

Thank you for your fast reply! Glad I could raise it to your knowledge, looking forward to your fixes :)

Error handling is always difficult :D but I enjoyed reading your code, surprising to me, I understood a lot going on ;)

Thank you for all your work, I hope you enjoy it! Best wishes, oswald

PS.: Please close the issues as you see fit, I have no idea whats appropriate ;)

LasticotSoftware commented 3 years ago

I'm happy to hear that you understood a lot of my code!

I pushed somes fixes (including a correction of the bug you reported), let me know if it's better and feel free to recreate an issue if needed ;)