Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runs for a while, then gets logged out? #2

Closed
jwest31337 opened this issue Nov 28, 2022 · 5 comments
Closed

Runs for a while, then gets logged out? #2

jwest31337 opened this issue Nov 28, 2022 · 5 comments
Assignees

Comments

@jwest31337
Copy link

Hello, I'm relatively new to GitHub and haven't submitted any sort of error feedback before. I downloaded and ran this bot code, which seems to work anywhere from 1 -5'ish minutes, before it repeatedly logs me out. I can immediately re-run the program, but it requires putting in the 2FA code from my phone every time. Here's an example of the error I keep getting when it bombs out:

An error occured: stopping process
logout successful
Traceback (most recent call last):
File "/home/jwest/Robinhood-Crypto-Autotrader/main.py", line 504, in
tr.sell_times[i][tr.convert_timestamp_to_datetime(crypto_historicals[i][backtest_index]['begins_at'])] = 'unable_to_sell'
NameError: name 'crypto_historicals' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/jwest/Robinhood-Crypto-Autotrader/main.py", line 590, in
rh.export.export_completed_crypto_orders('./', 'completed_crypto_orders')
File "/home/jwest/.local/lib/python3.10/site-packages/robin_stocks/robinhood/helper.py", line 31, in login_wrapper
raise Exception('{} can only be called when logged in'.format(
Exception: export_completed_crypto_orders can only be called when logged in

I can't tell if it's executing a specific step when it crashes out, but it won't seem to run for more than 5'ish minutes at a time. Thanks!

@tyler-pruitt tyler-pruitt self-assigned this Nov 28, 2022
@tyler-pruitt
Copy link
Owner

Hi jwest31337,

Thank you very much for sending me this error feedback. I was able to implement fixes to resolve both issues that you have sent me and I have just updated my main branch with the solutions. Therefore, if you reclone or redownload the code used in my repository as of now, these errors should no longer occur.

I would like to inform you that my Python package for this program (https://github.com/tyler-pruitt/robinhood_crypto_trader) is much more robust and systematic. I highly recommend using the official Python package instead of the code is this repository. You can install this Python package through pip (https://pypi.org/project/robinhood-crypto-trader/).

If you are interested, I can explain what was going wrong and how I implemented solutions to fix the errors.

  1. In regards to the first error message that you wrote about, it happened to be a simple few lines of code in main.py around line 504 that were there by mistake due to the coping and pasting from other areas of the code base that were similar. At line 504, we know that is_live = True so therefore the mode is not "BACKTEST" and hence crypto_historicals would not be needed and accordingly it was never assigned in the first place, as it should. There was an if-else statement at line 504 that really should of just been a single line of code, i.e. no conditional. Therefore, I just deleted the excess code there.

  2. In regards to the second error message, I simply forgot to consider that exporting logs of completed crypto orders requires the user to be logged in. It is required because the program has to retrieve your order history with your authentication. To fix this, I simply switched the order of the export completed crypto orders statement with the logout statement so that latter precedes the former. These changes took place in the exception handling for the program due to the user ending the program, unexpected errors, and other error catches that I have newly implemented. I have implemented exception handling for KeyError and TypeError in case Robinhood or the web server has errors. I have implemented the code so that if a temporary or inconsequential errors, such as 500 or 503 errors, occur then the code will continue running and the autotrader will continue making trades without the hassle of logging the user and having to run the code again and type in the 2FA code.

Please let me know if these errors persist or if new errors occur.

@jwest31337
Copy link
Author

Aha you did it! I re-cloned the repo and pip3 installed the robinhood-crypto-trader Python module, and it's running like a champ now! I'm letting the bot play around with a couple bucks, I'll update you on how it goes over the next week. Thanks for fixing this!

@tyler-pruitt
Copy link
Owner

I am glad to hear that it is running smoothly now! How has the trading been going?

@jwest31337
Copy link
Author

I've tried running it in a few experiments, and here's what I can report back so far:

The code doesn't seem to crash at all. Once the 2FA code has been provided for the account, it seems to function just fine. I did run into a single scenario where the bot had tied up all the available funds in buying operations, and then had a single transaction that repeatedly failed over and over again, flooding me with notifications. I had to kill the program from running, and cancel the attempted buy order. (Maybe the bot was trying to buy with insufficient funds?)

I've tried letting it run with both a single Crypto currency, and also a mixed grab bag of DOGE, ETH and LTC. It seems to very slowly bleed money until it gets to the point where it hits the limit where it marks funds exhausted, and then the program exits out. I've also tried killing it mid-trade operation when I thought it was on "a hot streak" , but if left to its own devices, it seems to end up very slowly trickling cash. I've been playing around throwing $50 at it, and it's lost anywhere between $5'ish to $15'ish a run, when I let it run for a 24 hour period.

Have you released any updates to the code? I'm still running the original repo that I snagged when I first submitted my message. Thanks for checking back in!

@tyler-pruitt
Copy link
Owner

tyler-pruitt commented Jan 7, 2023

Hey! Thank you for the very interesting feedback!

That is great to hear that at least the code is not crashing at all. My apologies about the nonstop notifications, I didn't know that failed orders would produce notifications. I would like to inform you that I am no longer going to keep this repository (tyler-pruitt/Robinhood-Crypto-Autotrader) up-to-date with bug fixes and optimizations. Instead, I intend to keep the Python package for this project and its respective repository (tyler-pruitt/robinhood_crypto_trader) for this project more up-to-date. Although, I would encourage you, should you have the desire, to join me in the latter repository as a contributor as I don't have much time now to work on it. Anything helps and is much appreciated.

I think those problems are happening because the buying operations are either limit order by price or market order by price. When the cash being used to by crypto isn't low, then there aren't any problems because you can buy a relatively large amount of crypto. However, the problem arises when either the dollar amount goes below a minimum value (typically $0.01 or $0.02 for most cryptocurrencies) or when the amount of crypto that the cash gets you is below a minimum threshold value (e.g. 500 Shiba Inu or 0.000001 Bitcoin). Fortunately, these latter minimum cryptocurrency values can be found by running robin_stocks.robinhood.crypto.get_crypto_info(symbol). Unfortunately, I am not able to find the minimum dollar amount for a purchase for a specific crypto (i.e. $0.02 for Bitcoin) besides looking it up manually on the Robinhood app on my phone. One solution I can implement is setting a minimum dollar amount to spend on a specific crypto purchase, such as $0.02. In this way, purchase orders can only go through if there is at least $0.02 in cash remaining. Since the buying operations are by price and not by quantity, the scenario in which a buy order fails because it is purchasing too little quantity of crypto does not occur. This is to say that the program never tries to specifically buy exactly 488 Shiba Inu and fails due to the limit being 500 Shiba Inu because all buy operations are by price. In order to make these buy operations more robust, I can implement more buying options to enable the user to decide if they want to buy by price or buy by quantity of cryptocurrency. Interestingly, the reason why this does not happen for the sell operations is because they are sell by quantity. On Robinhood, there are no boundaries for how little cryptocurrency you can sell or for how little money you can receive from selling cryptocurrency. Oddly enough, it is possible to sell a very little amount of crypto for less than one cent and after everything has settled you will receive nothing, i.e. $0.00. After giving these problems more thought as I have been writing this message, I think that it would also be good to give the user more freedom in their sell operations by making them both by price and by quantity. Of course, these changes to the sell operations and the buy operations depend on the supporting package robin_stocks having the necessary functions.

In regards to the slow drying up of funds, I think this is simply due to the strategy not being that effective. I am curious as to which strategy you used. Although my original central goal for this project was not to find a perfect strategy but rather produce a very modular and secure program to automatically trade cryptocurrency, I want to make this project as profitable as possible. If you know of any better strategies or have any ideas that can be implemented into a strategy, please let me know. I think that this project would be much better if the strategy used to make purchase orders and sell orders was very lucrative.

I strongly recommend using the Python package instead of the independent code used from cloning this repository, but ultimately, the choice is up to you. Tonight, I have updated the repository for the Python package (tyler-pruitt/robinhood_crypto_trader) to handle precision and rounding much more carefully. This being said, these changes still need to be tested before updating the Python package on PyPI. I still need to implement the changes to the buy and sell operations that I have mentioned earlier in this message. Thank you for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@tyler-pruitt @jwest31337 and others