Skip to main content

Take-Profit and Stop-Loss Orders

Fubon Neo API supports take-profit and stop-loss orders attached to condition orders.

Take-profit/stop-loss mechanism: after a triggered condition order is filled, take-profit and stop-loss monitoring starts. When the take-profit condition is met, the stop-loss condition expires, and vice versa (the common OCO mechanism).

TPSL

Code Examples

# Define the condition
condition = Condition(
market_type = TradingType.Reference,
symbol = "2881",
trigger = TriggerContent.MatchedPrice,
trigger_value = "66",
comparison = Operator.LessThan
)

order = ConditionOrder(
buy_sell = BSAction.Buy,
symbol = "2881",
price = "66",
quantity = 1000,
market_type = ConditionMarketType.Common,
price_type = ConditionPriceType.Limit,
time_in_force = TimeInForce.ROD,
order_type = ConditionOrderType.Stock
)

# For a market take-profit or stop-loss order, set price to an empty string: ""

tp = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="85",
price="85",
# trigger=TriggerContent.MatchedPrice # Added in v2.2.0
)


sl = TPSLOrder(
time_in_force=TimeInForce.ROD,
price_type=ConditionPriceType.Limit,
order_type=ConditionOrderType.Stock,
target_price="60",
price="60",
# trigger=TriggerContent.MatchedPrice # Added in v2.2.0
)

tpsl = TPSLWrapper(
stop_sign= StopSign.Full,
tp=tp, # optional field
sl=sl, # optional field
end_date="20240517",
intraday =False # optional field
)


sdk.stock.single_condition(account, "20240426", "20240430", StopSign.Full, condition, order, tpsl)