JestonBlu / RobinHood

An R interface for the RobinHood.com no commision investing site
https://jestonblu.github.io/RobinHood/
GNU Lesser General Public License v3.0
45 stars 12 forks source link

Buy in dollars rather than shares? #144

Closed shimonisrael closed 2 years ago

shimonisrael commented 2 years ago

Thanks for all your great work on this. I'm curious if I'm overlooking the ability to buy by dollar-value investment rather than by number of shares through the API. The website allows this, so I'm wondering if it's configurable in an R request. Any insight? Many thanks.

Dollars
JestonBlu commented 2 years ago

The last time i looked the api required you to submit a price and a quantity, so if I were to do something like that I would just back into it by dividing what you want to invest by a current quote. Here is an example.

Since you can buy fractional shares this should work, but you may have to trim the number of decimals depending on the security.

quote <- as.numeric(get_quote(RH, symbol = "F")[2])
dollars_to_invest <- 100
(qty <- dollars_to_invest / quote)
[1] 6.123699

place_order(RH, symbol = "F", type = "buy", price = quote, quantity = qty, ...)
shimonisrael commented 2 years ago

Very good. Makes sense and thanks for the quick response. There might some minor differences in the amount purchased, but a real time quote call should minimize that. Love the package.