Ejemplo n.º 1
0
  // for Instrument code with "#"
  // for IsBuy = true:
  // SumBuy = all confirmed order.Buy.LotBalance + all unconfirmed order.Buy.Lot
  // SumSell = all confirmed order.Sell.LotBalance
  // for IsBuy = false:
  // SumSell = all confirmed order.Sell.LotBalance + all unconfirmed order.Sell.Lot
  // SumBuy = all confirmed order.Buy.LotBalance
  public GetSumLotBSForOpenOrderWithFlagResult getSumLotBSForOpenOrderWithFlag(boolean isBuy) {
    BigDecimal[] sumLot = new BigDecimal[] {BigDecimal.ZERO, BigDecimal.ZERO};
    boolean isExistsUnconfirmedOrder = false;
    HashMap<Guid, Transaction> accountInstrumentTransactions =
        this.getAccountInstrumentTransactions();
    for (Iterator<Transaction> iterator = accountInstrumentTransactions.values().iterator();
        iterator.hasNext(); ) {
      Transaction transaction = iterator.next();
      if (transaction.get_Phase() == Phase.Executed
          || transaction.get_Phase() == Phase.Placing
          || transaction.get_Phase() == Phase.Placed) {
        for (Iterator<Order> iterator2 = transaction.get_Orders().values().iterator();
            iterator2.hasNext(); ) {
          Order order = iterator2.next();
          if (order.get_LotBalance().compareTo(BigDecimal.ZERO) > 0) {
            if (isBuy) {
              if (order.get_IsBuy()) {
                if (transaction.get_Phase() == Phase.Executed) {
                  sumLot[0] = sumLot[0].add(order.get_LotBalance());
                } else {
                  sumLot[0] = sumLot[0].add(order.get_Lot());
                  isExistsUnconfirmedOrder = true;
                }
              } else {
                if (transaction.get_Phase() == Phase.Executed) {
                  sumLot[1] = sumLot[1].add(order.get_LotBalance());
                }
              }
            } else {
              if (order.get_IsBuy()) {
                if (transaction.get_Phase() == Phase.Executed) {
                  sumLot[0] = sumLot[0].add(order.get_LotBalance());
                }
              } else {
                if (transaction.get_Phase() == Phase.Executed) {
                  sumLot[1] = sumLot[1].add(order.get_LotBalance());
                } else {
                  sumLot[1] = sumLot[1].add(order.get_Lot());
                  isExistsUnconfirmedOrder = true;
                }
              }
            }
          }
        }
      }
    }

    return new GetSumLotBSForOpenOrderWithFlagResult(
        sumLot[0], sumLot[1], isExistsUnconfirmedOrder);
  }
Ejemplo n.º 2
0
  /*
  Remarks
  sum (SellLotBalance) = all confirmed order.Sell.LotBalance
    + unconfirmed order (stop).Sell.Lot
    + iif("MOC/MOO allow New" = False,
   unconfirmed order (MOO/MOC).Sell.Lot,
   0)

  sum (BuyLotBalance) = all confirmed order.Buy.LotBalance
    + unconfirmed order (stop).Buy.Lot
    + iif("MOC/MOO allow New" = False,
   unconfirmed order (MOO/MOC).Buy.Lot,
   0)
  */
  public BigDecimal[] getSumLotBSForMakeStopOrder() {
    BigDecimal[] sumLot = new BigDecimal[] {BigDecimal.ZERO, BigDecimal.ZERO};
    TradePolicyDetail tradePolicyDetail = this.getTradePolicyDetail();
    HashMap<Guid, Transaction> accountInstrumentTransactions =
        this.getAccountInstrumentTransactions();
    for (Iterator<Transaction> iterator = accountInstrumentTransactions.values().iterator();
        iterator.hasNext(); ) {
      Transaction transaction = iterator.next();
      if (transaction.get_Phase() == Phase.Executed) {
        for (Iterator<Order> iterator2 = transaction.get_Orders().values().iterator();
            iterator2.hasNext(); ) {
          Order order = iterator2.next();
          if (order.get_LotBalance().compareTo(BigDecimal.ZERO) > 0) {
            if (order.get_IsBuy()) {
              sumLot[0] = sumLot[0].add(order.get_LotBalance());
            } else {
              sumLot[1] = sumLot[1].add(order.get_LotBalance());
            }
          }
        }
      } else if (transaction.get_Phase() == Phase.Placing
          || transaction.get_Phase() == Phase.Placed) {
        for (Iterator<Order> iterator2 = transaction.get_Orders().values().iterator();
            iterator2.hasNext(); ) {
          Order order = iterator2.next();
          if (order.get_TradeOption() == TradeOption.Stop
              || (!tradePolicyDetail.get_IsAcceptNewMOOMOC()
                  && (transaction.get_OrderType() == OrderType.MarketOnOpen
                      || transaction.get_OrderType() == OrderType.MarketOnClose))) {
            if (order.get_IsBuy()) {
              sumLot[0] = sumLot[0].add(order.get_Lot());
            } else {
              sumLot[1] = sumLot[1].add(order.get_Lot());
            }
          }
        }
      }
    }
    return sumLot;
  }
Ejemplo n.º 3
0
 public BigDecimal[] getSumLotBSForOpenOrder() {
   BigDecimal[] sumLot = new BigDecimal[] {BigDecimal.ZERO, BigDecimal.ZERO};
   HashMap<Guid, Transaction> accountInstrumentTransactions =
       this.getAccountInstrumentTransactions();
   for (Iterator<Transaction> iterator = accountInstrumentTransactions.values().iterator();
       iterator.hasNext(); ) {
     Transaction transaction = iterator.next();
     if (transaction.get_Phase() == Phase.Executed) {
       for (Iterator<Order> iterator2 = transaction.get_Orders().values().iterator();
           iterator2.hasNext(); ) {
         Order order = iterator2.next();
         if (order.get_LotBalance().compareTo(BigDecimal.ZERO) > 0) {
           if (order.get_IsBuy()) {
             sumLot[0] = sumLot[0].add(order.get_LotBalance());
           } else {
             sumLot[1] = sumLot[1].add(order.get_LotBalance());
           }
         }
       }
     }
   }
   return sumLot;
 }
Ejemplo n.º 4
0
  // Used by Limit,MOO,MOC,MKT,OCO for mapOrder
  private void setOutstandingOrders(
      Order mapOrder, Boolean isSpot, Boolean isMakeLimitOrder, boolean isDelivery) {
    /*if (this._outstandingOrders.size() > 0 || this._account.get_Type() == AccountType.Agent)
    {
    	Iterator<RelationOrder> relationOrders = this._outstandingOrders.values().iterator();
    	while(relationOrders.hasNext())
    	{
    		relationOrders.next().set_IsMakeLimitOrder(isMakeLimitOrder);
    	}
    	return;
    }*/
    this._outstandingOrders.clear();
    Guid orderId = mapOrder.get_Id();
    RelationOrder outstandingOrder =
        new RelationOrder(
            this._tradingConsole,
            this._settingsManager,
            mapOrder,
            isSpot,
            isMakeLimitOrder,
            isDelivery);

    BigDecimal avaiableCloseLot = outstandingOrder.get_LiqLot();
    if (avaiableCloseLot.compareTo(BigDecimal.ZERO) > 0) {
      TradePolicyDetail tradePolicyDetail = this.getTradePolicyDetail();
      BigDecimal lot =
          isDelivery
              ? AppToolkit.fixDeliveryLot(avaiableCloseLot, tradePolicyDetail)
              : AppToolkit.fixCloseLot(
                  avaiableCloseLot, avaiableCloseLot, tradePolicyDetail, this._account);
      if (avaiableCloseLot.compareTo(lot) >= 0) {
        outstandingOrder.set_LiqLot(lot);

        if (!isDelivery) outstandingOrder.set_IsMakeLimitOrder(isMakeLimitOrder);
        this._outstandingOrders.put(orderId, outstandingOrder);
      }
    }
  }
Ejemplo n.º 5
0
  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);
        }
      }
    }
  }
Ejemplo n.º 6
0
  // exclude make Liquidation order and make Limit,MOO,MOC,MKT,OCO for mapOrder.....
  private void setOutstandingOrders(
      BuySellType buySellType, Boolean isSpot, Boolean isMakeLimitOrder, boolean isDelivery) {
    /*if (this._outstandingOrders.size() > 0 || this._account.get_Type() == AccountType.Agent)
    {
    	Iterator<RelationOrder> relationOrders = this._outstandingOrders.values().iterator();
    	while(relationOrders.hasNext())
    	{
    		relationOrders.next().set_IsMakeLimitOrder(isMakeLimitOrder);
    	}
    	return;
    }*/

    this._outstandingOrders.clear();
    HashMap<Guid, Transaction> accountInstrumentTransactions =
        this.getAccountInstrumentTransactions();
    for (Iterator<Transaction> iterator = accountInstrumentTransactions.values().iterator();
        iterator.hasNext(); ) {
      Transaction transaction = iterator.next();
      if (transaction.get_Phase().equals(Phase.Executed)) {
        for (Iterator<Order> iterator2 = transaction.get_Orders().values().iterator();
            iterator2.hasNext(); ) {
          Order order = iterator2.next();
          if (order.get_Phase() != Phase.Executed) continue;
          if (order.get_Transaction().get_Account().get_Type() == AccountType.Agent
              || order.get_Transaction().get_Account().get_Type() == AccountType.Transit) continue;

          BigDecimal availableLotBanlance = BigDecimal.ZERO;
          if (isDelivery) {
            if (order.canDelivery()) {
              availableLotBanlance = order.getAvailableDeliveryLot();
              if (availableLotBanlance.compareTo(BigDecimal.ZERO) > 0) {
                Guid orderId = order.get_Id();
                RelationOrder outstandingOrder =
                    new RelationOrder(
                        this._tradingConsole, this._settingsManager, order, false, null, true);
                this._outstandingOrders.put(orderId, outstandingOrder);
              }
            }
          } else {
            if (order.canClose()) {
              availableLotBanlance = order.get_LotBalance();
              if (isSpot != null)
                availableLotBanlance = order.getAvailableLotBanlance(isSpot, isMakeLimitOrder);

              if (availableLotBanlance.compareTo(BigDecimal.ZERO) > 0) {
                Guid orderId = order.get_Id();
                RelationOrder outstandingOrder =
                    new RelationOrder(this._tradingConsole, this._settingsManager, order);
                outstandingOrder.set_IsMakeLimitOrder(isMakeLimitOrder);
                if (buySellType.equals(BuySellType.Both)) {
                  this._outstandingOrders.put(orderId, outstandingOrder);
                } else if (order.get_IsBuy() && (buySellType.equals(BuySellType.Buy))) {
                  this._outstandingOrders.put(orderId, outstandingOrder);
                } else if (!order.get_IsBuy() && (buySellType.equals(BuySellType.Sell))) {
                  this._outstandingOrders.put(orderId, outstandingOrder);
                }
              }
            }
          }
        }
      }
    }
  }