JestonBlu / RobinHood

An R interface for the RobinHood.com no commision investing site
https://jestonblu.github.io/RobinHood/
GNU Lesser General Public License v3.0
45 stars 12 forks source link

Issue with Placing Stop Orders Using place_order() #122

Closed kmohammadi6 closed 3 years ago

kmohammadi6 commented 3 years ago

Hello! I am having an issue placing a stop loss order using the place_order(RH) function. If I put in a price in place_order(RH) the function will run, but I receive an non-field error that reads, "Stop market sell order requested, but price provided." I have tried to run the function without providing a price variable, and setting it equal to NULL, but the function errors saying it needs a price. The following is an example of what I am trying to do:

current.positions = get_positions(RH)

temp.sell = place_order(RH,
                        symbol="ALB",
                        type = 'market',
                        trigger = 'stop',
                        stop_price = round((current.positions$average_buy_price[1])*.97,2),
                        time_in_force = "gtc",
                        price = round((current.positions$average_buy_price[1])*.97,2),
                        quantity = as.integer(current.positions$quantity[1]),
                        side = 'sell')

And the following is the output from the function:

$non_field_errors
[1] "Stop market sell order requested, but price provided."

$updated_at
POSIXct of length 0

$last_transaction_at
POSIXct of length 0

$created_at
POSIXct of length 0

$fees
numeric(0)

$cumulative_quantity
numeric(0)

$stop_price
numeric(0)

$reject_reason
numeric(0)

$price
numeric(0)

$average_price
numeric(0)

$quantity
numeric(0)

I have tried using both the CRAN and Github versions of the package and have faced the same issue. I am trying to figure out if this is user error or an issue with the package. Thanks in advance for your help!

JestonBlu commented 3 years ago

@kmohammadi6 thanks for the input. I think this is something i can improve to handle better inputs, but essentially you would need to provide price = NA for it to work properly. See below.

place_order(RH,
            symbol="DAL",
            type = 'market',
            trigger = 'stop',
            stop_price = round((get_positions(RH)$average_buy_price[1])*.97,2),
            time_in_force = "gtc",
            price = NA,
            quantity = as.integer(get_positions(RH)$quantity[1]),
            side = 'sell')
JestonBlu commented 3 years ago

@kmohammadi6 I have made a couple of changes to the docs to make it easier to use. I also made price = NA by default so you wont have to specify it anymore for stop orders.