take_profit_request = TakeProfitRequest(limit_price=c + 0.1)
stop_loss_request = StopLossRequest(stop_price=c - 10)
hello, im trying to order a market order that take profit when my stock price moves up $0.1 and down when the price drops $10. my current order:
market_order_data = MarketOrderRequest(
# Market order
market_order = trading_client.submit_order(
the issue I’m having is the code just sells the position automatically and does not wait for the stop loss. I don’t want to submit a bracket order. any guidance in the right direction would be greatly appreciated. I just really so not think I’m understanding either profit or stop loss request.
@AASAAQWE What you want is a One-Cancels-Other (OTO) order. This actually submits two orders - a limit order (ie a ‘take profit’) and a stop loss order. It isn’t well documented but this is specified like this
from alpaca.trading.client import TradingClient
from alpaca.trading.requests import LimitOrderRequest, StopLossRequest, TakeProfitRequest
from alpaca.trading.enums import OrderSide, OrderClass, TimeInForce
ALPACA_API_KEY = 'xxxxx'
ALPACA_API_SECRET_KEY = 'xxxxx'
client = TradingClient(api_key=ALPACA_API_KEY, secret_key=ALPACA_API_SECRET_KEY)
# OCO order must have the limit order as the 'parent' order
my_symbol = 'SPY'
my_qty = 1
my_limit_price = c + .10
my_stop_price = c - 10.00
my_oco_order = client.submit_order(LimitOrderRequest(
order_class = OrderClass.OCO,
By convention the order type is specified as a limit order, but by indicating
order_class = OrderClass.OCO it will create the take profit and stop loss orders as desired. The reason your code immediately sold was 1) you specified a MarketOrderRequest and 2) you didn’t indicate
OrderClass.OCO so the stop loss order was never created.
Interesting. I understand, Thank you.
trailing_price_data = TrailingStopOrderRequest(
trail_price=trail_p, # hwm * 0.99
trailing_price_order = trading_client.submit_order(
could you also provide some insight into this order, if you dont mind? trail_p is 0.1* of the current price of the stock. this order has no stop loss, but the program keeps selling the order. I just want the order to sell when there is only a profit, hence me removing any stop loss risk management. any insight would be appreciated.