jmfernandes / robin_stocks

This is a library to use with Robinhood Financial App. It currently supports trading crypto-currencies, options, and stocks. In addition, it can be used to get real time ticker information, assess the performance of your portfolio, and can also get tax documents, total dividends paid, and more. More info at
http://www.robin-stocks.com
MIT License
1.74k stars 467 forks source link

Crypto Order Quantity/Pricing #278

Open cheekylions opened 3 years ago

cheekylions commented 3 years ago

I've been doing some research on how Crypto Order pricing is managed by the Robinhood app and it seems each coin is limited to a different rounding.

ETC, for example, limits to somewhere near 0.01 (though the Minimum price is often rounded up or down) and ETH limits to 0.0001. There's no obvious link to price in the way this works, as coins with low value sometimes have a shorter rounding and coins with higher value sometimes have a shorter rounding. DOGE is special in that it doesn't offer any fractional buying.

It would seem to me that the best way to handle these inexplicable differences would be to create a dictionary of known coins and their rounding limits and build that into the rounding algorithm. This isn't unwieldy at the moment. I have a list now of the coins and their rounding limits as of now -- but will that change in the future?

I'm just a nerd with a Python problem. Sorry if this isn't the right place to have this discussion.

mblackbourne commented 3 years ago

This may help you out.

price = float(rs.robinhood.crypto.get_crypto_quote('DOGE').get('ask_price'))
shares = round(100.00/price, 0)
rs.robinhood.orders.order_sell_crypto_by_quantity('DOGE', shares)

Good Luck!

cheekylions commented 3 years ago

I appreciate that, but it wasn't really what my post is regarding. I'm sure someone will find your snippet incredibly useful though.

emwitchcraft commented 3 years ago

If you call get_crypto_positions () and look through the results, you'll see nested in the 'currency' key's value a dict with an 'increment' key. That value is the minimum quantity/coin increment for buy and sell orders through the api (oddly enough it's different on the app i.e. you can buy and sell fractional doge through it).

A couple share the same value, but otherwise they all have different minimum increments. I think the rounding method in the robin_stocks module worked in almost all cases simply by rounding off enough decimal places that the quantity ordered was always dividable by the minimum increment, except in the case of doge which has a minimum increment of 1.

I've been scootin my way around this for doge by dividing how much I want to buy or sell in usd by the current exchange price, rounding that result to an integer, then using one of the 'by quantity' variations of the ordering calls, rather than the 'by price' versions.