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.71k stars 463 forks source link

Issue with setting a stop loss price #99

Open bspallholtz opened 4 years ago

bspallholtz commented 4 years ago

I am trying to loop through my open positions and set a trailing stop loss price of 10% off the current price.

Here is my code , get_cp: is another function that gets the current price of a given symbol is_buy: is a function that based on several factors determines if a given symbol is still a buy or not

robin_stocks.login(username, password)
for symbol in holdings:
      quantity = float(holdings[symbol]['quantity'])
      quantity = round(quantity, 0)
      quantity = int(quantity)
      current_return = float(holdings[symbol]['percent_change'])
      if current_return < -10:
          cp = get_cp(symbol)
      if is_buy(symbol) is True:
          stopPrice = cp * .9
      else:
          stopPrice = cp * .97
      stopPrice = round(stopPrice, 2)
      print("I would try and set SLP for %s at %f for quantity %i" % ( symbol, stopPrice, quantity))
      order = robin_stocks.orders.order_sell_stop_loss(symbol, quantity, stopPrice, timeInForce='gtc', extendedHours=True)

This is the return I get

I would try and set SLP for KALV at 6.550000 for quantity 5
{'non_field_errors': ['Stop market sell order requested, but price provided.']}
bspallholtz commented 4 years ago

I've also tried these two functions

robin_stocks.orders.order_buy_stop_loss 
robin_stocks.orders.order(symbol, quantity, orderType, trigger, side, limitPrice=None, stopPrice=stopPrice, timeInForce='gtc', extendedHours=False)