private HashMap<Guid, RelationOrder> getEditOutstandingOrders(
     BuySellType buySellType, Order mapOrder) {
   HashMap<Guid, RelationOrder> editOutstandingOrders;
   if (buySellType == BuySellType.Both) {
     editOutstandingOrders = this._outstandingOrders;
     for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
         iterator.hasNext(); ) {
       RelationOrder relationOrder = iterator.next();
       if (mapOrder != null) {
         relationOrder.set_IsSelected(true);
       }
     }
   } else {
     editOutstandingOrders = new HashMap<Guid, RelationOrder>();
     for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
         iterator.hasNext(); ) {
       RelationOrder relationOrder = iterator.next();
       if (mapOrder != null) {
         relationOrder.set_IsSelected(true);
       }
       if (buySellType == BuySellType.Buy && relationOrder.get_IsBuy()) {
         editOutstandingOrders.put(relationOrder.get_OpenOrderId(), relationOrder);
       } else if (buySellType == BuySellType.Sell && !relationOrder.get_IsBuy()) {
         editOutstandingOrders.put(relationOrder.get_OpenOrderId(), relationOrder);
       }
     }
   }
   return editOutstandingOrders;
 }
  public void setDefaultLiqLotForOutStanding(
      BuySellType buySellType,
      boolean isSelectedRelationOrder,
      boolean isSpotTrade,
      Boolean isMakeLimitOrder) {
    for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
        iterator.hasNext(); ) {
      RelationOrder relationOrder = iterator.next();

      relationOrder.set_IsSelected(isSelectedRelationOrder);
      BigDecimal liqLot =
          relationOrder.get_OpenOrder().getAvailableLotBanlance(isSpotTrade, isMakeLimitOrder);
      if (this._outstandingOrders.values().size() == 1) {
        TradePolicyDetail tradePolicyDetail = this.getTradePolicyDetail();
        liqLot = AppToolkit.fixCloseLot(liqLot, liqLot, tradePolicyDetail, this._account);
      }

      boolean isBuy = (buySellType == BuySellType.Buy);
      if (buySellType == BuySellType.Both) {
        relationOrder.set_LiqLot(liqLot);
        // Update Outstanding Order UI
        relationOrder.update(this._outstandingKey);
      } else if (relationOrder.get_IsBuy() != isBuy) {
        relationOrder.set_LiqLot(liqLot);
        // Update Outstanding Order UI
        // maybe not binding
        // if (this._isBuyForCurrent != isBuy)
        // {
        relationOrder.update(this._outstandingKey);
        // }
      }
    }
  }
  public BigDecimal closeAll() {
    BigDecimal totalLiqLot = BigDecimal.ZERO;
    for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
        iterator.hasNext(); ) {
      RelationOrder relationOrder = iterator.next();
      if (this._isBuyForCurrent != relationOrder.get_IsBuy()
          || (this._isForDelivery && relationOrder.get_IsBuy())) {
        totalLiqLot = totalLiqLot.add(relationOrder.get_LiqLot());
      }
    }
    TradePolicyDetail tradePolicyDetail =
        this._settingsManager.getTradePolicyDetail(
            this._account.get_TradePolicyId(), this._instrument.get_Id());
    totalLiqLot =
        this._isForDelivery
            ? AppToolkit.fixDeliveryLot(totalLiqLot, tradePolicyDetail)
            : totalLiqLot; // AppToolkit.fixLot(totalLiqLot, false, tradePolicyDetail, this);
    BigDecimal totalLiqLot2 = totalLiqLot;

    for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
        iterator.hasNext(); ) {
      RelationOrder relationOrder = iterator.next();
      if (this._isBuyForCurrent != relationOrder.get_IsBuy()
          || (this._isForDelivery && relationOrder.get_IsBuy())) {
        BigDecimal liqLot = relationOrder.get_LiqLot();
        liqLot = totalLiqLot.compareTo(liqLot) > 0 ? liqLot : totalLiqLot;
        relationOrder.set_LiqLot(liqLot);
        totalLiqLot = totalLiqLot.subtract(liqLot);
        relationOrder.set_IsSelected(true);
        relationOrder.update(this._outstandingKey);

        if (totalLiqLot.compareTo(BigDecimal.ZERO) <= 0) break;
      }
    }

    if (this._isBuyForCurrent) {
      this._buyLot = totalLiqLot2;
    } else {
      this._sellLot = totalLiqLot2;
    }
    return totalLiqLot2;
  }
  public void setOutstandingOrdersForMakeLiquidationOrder(
      Instrument instrument, boolean forMakeOrderForm) {
    if (this._outstandingOrders.size() > 0) {
      return;
    }
    for (Iterator<Order> iterator = this._tradingConsole.get_OpenOrders().values().iterator();
        iterator.hasNext(); ) {
      Order order = iterator.next();
      if (!order.canClose()) continue;

      if (order.get_Transaction().get_Instrument() == instrument
          && order.get_Transaction().get_Account() == this._account) {
        if (!forMakeOrderForm
            || order.getAvailableLotBanlance(false, null).compareTo(BigDecimal.ZERO) > 0) {
          Guid orderId = order.get_Id();
          RelationOrder outstandingOrder =
              new RelationOrder(this._tradingConsole, this._settingsManager, order);
          outstandingOrder.set_IsSelected(order.get_Close());
          this._outstandingOrders.put(orderId, outstandingOrder);
        }
      }
    }
  }