Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug found: Incorrect Arguments in order_sell_stop_loss Function #455

Open
humza-sami opened this issue Dec 24, 2023 · 2 comments
Open

Bug found: Incorrect Arguments in order_sell_stop_loss Function #455

humza-sami opened this issue Dec 24, 2023 · 2 comments

Comments

@humza-sami
Copy link

The order_sell_stop_loss function in orders.py is calling the order function with incorrect arguments. This leads to a TypeError when attempting to use the order_sell_stop_loss function.

I am using this to place stop loss.

Steps to Reproduce:

  1. Use the order_sell_stop_loss function:

    order = rs.robinhood.order_sell_stop_loss("SNDL", "1", 1.45)

Error:

Traceback (most recent call last):
  File "your_script.py", line 1, in <module>
    order = rs.robinhood.order_sell_stop_loss("SNDL", "1", 1.45)
  File "~\anaconda3\Lib\site-packages\robin_stocks\robinhood\helper.py:33", in login_required.<locals>.login_wrapper(*args, **kwargs)
    30 if not LOGGED_IN:
    31     raise Exception('{} can only be called when logged in'.format(
    32         func.__name__))
---> 33 return(func(*args, **kwargs))
  File "~\anaconda3\Lib\site-packages\robin_stocks\robinhood\orders.py:634", in order_sell_stop_loss(symbol, quantity, stopPrice, account_number, timeInForce, extendedHours, jsonify)
    610 @login_required
    611 def order_sell_stop_loss(symbol, quantity, stopPrice, account_number=None, timeInForce='gtc', extendedHours=False, jsonify=True):
    612     """Submits a stop order to be turned into a market order once a certain stop price is reached.
    613
    614     :param symbol: The stock ticker of the stock to sell.
    (...) 
    632
    633     """
--> 634     return order(symbol, quantity, "sell", account_number, None, stopPrice, timeInForce, extendedHours, jsonify)
  File "~\anaconda3\Lib\site-packages\robin_stocks\robinhood\helper.py:33", in login_required.<locals>.login_wrapper(*args, **kwargs)
    30 if not LOGGED_IN:
    31     raise Exception('{} can only be called when logged in'.format(
    32         func.__name__))
---> 33 return(func(*args, **kwargs))
  File "~\anaconda3\Lib\site-packages\robin_stocks\robinhood\orders.py:837", in order(symbol, quantity, side, limitPrice, stopPrice, account_number, timeInForce, extendedHours, jsonify, market_hours)
    834 else:
    835     price = round_price(next(iter(get_latest_price(symbol, priceType, extendedHours)), 0.00))
    836 payload = {
--> 837     'account': load_account_profile(account_number=account_number, info='url'),
    838     'instrument': get_instruments_by_symbols(symbol, info='url')[0],
    839     'symbol': symbol,
    840     'price': price,
    841     'quantity': quantity,
    842     'ref_id': str(uuid4()),
    843     'type': orderType,
    844     'stop_price': stopPrice,
    845     'time_in_force': timeInForce,
    846     'trigger': trigger,
    847     'side': side,
    848     'market_hours': market_hours, # choices are ['regular_hours', 'all_day_hours']
    849     'extended_hours': extendedHours,
    850     'order_form_version': 4
    851 }
    852 # adjust market orders
    853 if orderType == 'market':
  File "~\anaconda3\Lib\site-packages\robin_stocks\robinhood\helper.py:33", in login_required.<locals>.login_wrapper(*args, **kwargs)
    30 if not LOGGED_IN:
    31     raise Exception('{} can only be called when logged in'.format(
    32         func.__name__))
---> 33 return(func(*args, **kwargs))
  File "~\anaconda3\Lib\site-packages\robin_stocks\robinhood\profiles.py:64", in load_account_profile(account_number, info)
    6 @login_required
    7 def load_account_profile(account_number=None, info=None):
    8     """Gets the information associated with the accounts profile, including day
    9     trading information and cash being held by Robinhood.
    10     (...)
    62
    63     """
--> 64     url = account_profile_url(account_number)
    65     if account_number is not None:
    66          data = request_get(url)
  File "~\anaconda3\Lib\site-packages\robin_stocks\robinhood\urls.py:19", in account_profile_url(account_number)
    17 def account_profile_url(account_number=None):
    18     if account_number:
--> 19         return('https://api.robinhood.com/accounts/'+account_number)
    20     else:
    21         return('https://api.robinhood.com/accounts/')

Order function declartion:

def order(symbol, quantity, side, limitPrice=None, stopPrice=None, account_number=None, timeInForce='gtc', extendedHours=False, jsonify=True, market_hours='regular_hours'):

While its call in order_sell_stop_loss function:

order(symbol, quantity, "buy", account_number, None, stopPrice, timeInForce, extendedHours, jsonify)

This error is solved by passing correct order arguments in order_sell_stop_loss function. I am going to update the function arguments and will create a pull request. @jmfernandes

@humza-sami
Copy link
Author

@jmfernandes Please check this PR

@sanathnair09
Copy link
Contributor

@jmfernandes I believe we can close this issue as it was resolved in this merged #468

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants