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

Trailing Stop loss function - payload issue #462

Open
Robiemaan opened this issue Feb 13, 2024 · 0 comments
Open

Trailing Stop loss function - payload issue #462

Robiemaan opened this issue Feb 13, 2024 · 0 comments

Comments

@Robiemaan
Copy link

Has anyone gotten the trailing stop loss function to work?

import robin_stocks as r
login = r.robinhood.login([uname],[pw],expiresIn=1000000)
sellorder = r.robinhood.orders.order_sell_trailing_stop(symbol='AAPL', quantity=1, trailAmount=5, trailType='percentage', timeInForce='gtc', jsonify=True)

It returns:

WARNING: priceType should be "ask_price" or "bid_price". You entered "True"
404 Client Error: Not Found for url: https://api.robinhood.com/accounts/gtc
{'account': ['This field may not be null.'],
 'time_in_force': ['"False" is not a valid choice.']}

Clearly there's something wrong with how the parameters are handled within the library and then sent to the RH endpoint.

I decided to dig in and try the REST API function manually by defining the payload dict myself:

payload = {
        'account': account['url'],
        'instrument': r.robinhood.orders.get_instruments_by_symbols(ticker, info='url')[0],
        'symbol' : ticker,
        'price' : 1,
        'quantity': quantity,
        'ref_id': str(uuid4()),
        'type': 'market',
        'trailing_peg' : {'type': 'percentage', 'percentage': str(5)},
        'stop_price': stopPrice,
        'time_in_force': 'gtc', 
        'trigger': 'stop', 
        'side': 'sell', 
        'order_form_version': 4, 
    }

    url = r.robinhood.orders.orders_url()
    print(payload)
    data = r.robinhood.request_post(url, payload, json=True, jsonify_data=True)
    return data

However, it returns:

{'non_field_errors': ['Stop market sell order requested, but price provided.']}

If I remove the stop_price it says:

{'non_field_errors': ['Stop limit order requested, but no stop price provided.']}

What am I doing wrong here?

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

1 participant