Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
  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);
        // }
      }
    }
  }
Exemplo n.º 3
0
  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;
  }
Exemplo n.º 4
0
 public BuySellType GetBuySellForCloseAll() {
   boolean hasIsBuy = false;
   for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
       iterator.hasNext(); ) {
     RelationOrder relationOrder = iterator.next();
     if (relationOrder.get_IsBuy()) {
       hasIsBuy = true;
     } else if (hasIsBuy) {
       return BuySellType.Both;
     }
   }
   return hasIsBuy ? BuySellType.Sell : BuySellType.Buy;
 }
Exemplo n.º 5
0
 public BigDecimal getSumLiqLots(boolean isBuy) {
   BigDecimal sumLiqLots = BigDecimal.ZERO;
   for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
       iterator.hasNext(); ) {
     RelationOrder relationOrder = iterator.next();
     if (relationOrder.get_IsBuy() == !isBuy && relationOrder.get_IsSelected()) {
       if (relationOrder.get_LiqLot() != null) {
         sumLiqLots = sumLiqLots.add(relationOrder.get_LiqLot());
       }
     }
   }
   return sumLiqLots;
 }