robinhood-unofficial / pyrh

Python Framework to make trades with the unofficial Robinhood API
https://pyrh.readthedocs.io/en/latest/
MIT License
1.79k stars 605 forks source link

place_limit_buy_order fails with no error when ask_price is a variable #249

Closed benkelley1979 closed 4 years ago

benkelley1979 commented 4 years ago

Win10 / Python 3.8.2 / working in IDLE x64

TL;DR: I can make place_limit_buy_order work from IDLE console when I enter ask_price manually as a float value. The place_limit_buy_order command fails once I use a variable for ask_price I encountered similar issues with place_buy_order

float(quote.get('last_trade_price'))

1.7502

type(float(journal.Price[len(journal.index)-1]))

<class 'float'>

rh.place_limit_buy_order('https://api.robinhood.com/instruments/**GUID**/', 'XTNT', 'GFD', float(journal.Price[len(journal.index)-1]), 5)

no response at all

rh.place_limit_buy_order('https://api.robinhood.com/instruments/**GUID**/', 'XTNT', 'GFD', 1.70, 5)

<Response [201]>

My desired result is to pull instrument_URL symbol price quantity from lists. Nothing else seems to cause an issue except for price

lmk if you need clarification or would like to see my entire code.

davidwang20 commented 4 years ago

also having this issue, it is very strange. Is also the case for place_limit_sell_order as a matter of fact.

davidwang20 commented 4 years ago

Actually, I think i figured out what it is. Try truncating your float variable to 2 decimal places. That fixed it for me

benkelley1979 commented 4 years ago

Hi @davidwang20 I had actually stumbled onto this earlier today and hadn't updated this post yet. I'm glad you got it going too! I would like to understand if this is a limitation of pyrh or of Robinhood's API. When using the mobile app or website I can set orders to 4 decimal places. If possible I would like that option. Also, shouldn't there be an error returned? I am not importing pyrh.Exceptions. Could that be the issue?

benkelley1979 commented 4 years ago

Actually, I think i figured out what it is. Try truncating your float variable to 2 decimal places. That fixed it for me

I found it helpful to create round_down and round_up functions. round_down to 2 decimals for limit sell and round_up to 2d for limit buy. This gives you the best chance at executing immediately

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.

stale[bot] commented 4 years ago

Closing this issue automatically because it has not had any activity since it has been marked as stale. If you think it is still relevant and should be addressed, feel free to open a new one.