Open stevecolby opened 3 years ago
You'll want to read this: #220
It also happen with BTC if you try to buy a fractional share that's too small. Since Bitcoin's now in the 5 figures, buying, say, $10 worth sometimes leads to the same error because the fractional share is such a small fraction. I've also received the same error "Order quantity has invalid increment" because it's too small (opposite of DOGE I guess).
You can do this:
>>> from decimal import Decimal
>>> import robin_stocks.robinhood as rh
...
>>> info = rh.get_crypto_info("DOGE")
>>> quantity_precision = abs(Decimal(info["min_order_quantity_increment"].rstrip("0")).as_tuple().exponent)
>>> usd_amount = 10
>>> curr_price = 0.510713
>>> purchase_quantity = round(usd_amount / curr_price, quantity_precision)
>>> rh.order_buy_crypto_by_quantity(symbol="DOGE", quantity=purchase_quantity)
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 doing essentially what aaroncouch is suggesting, namely converting usd to a quantity based off the current price and then rounding by the minimum increment.
Tried to place a limit order on DOGE but am unable to. I run the following command:
purchase = rs.orders.order_buy_crypto_limit_by_price("DOGE", float(5), float(0.058501))
And the response received is "Order quantity has invalid increment."