updateOrderBrackets method

void updateOrderBrackets(
  1. String orderId, {
  2. double? takeProfitPrice,
  3. double? stopLossPrice,
  4. bool clearTakeProfit = false,
  5. bool clearStopLoss = false,
})

Updates or attaches Take Profit and/or Stop Loss brackets to an order.

Implementation

void updateOrderBrackets(
  String orderId, {
  double? takeProfitPrice,
  double? stopLossPrice,
  bool clearTakeProfit = false,
  bool clearStopLoss = false,
}) {
  final index = _orders.indexWhere((o) => o.id == orderId);
  if (index >= 0) {
    final existing = _orders[index];
    final updated = existing.copyWith(
      takeProfitPrice: clearTakeProfit
          ? () => null
          : (takeProfitPrice != null ? () => takeProfitPrice : null),
      stopLossPrice: clearStopLoss
          ? () => null
          : (stopLossPrice != null ? () => stopLossPrice : null),
    );
    _orders[index] = updated;
    onOrderModified?.call(updated);
    notifyListeners();
  }
}