Ejemplo n.º 1
0
  private boolean initializeOutstanding2(
      DataGrid grid,
      boolean ascend,
      boolean caseOn,
      BuySellType buySellType,
      BuySellType editOutstandingOrderBuySellType,
      IOpenCloseRelationSite openCloseRelationSite,
      Order mapOrder) {
    Boolean isSpot =
        openCloseRelationSite.getOrderType() == null
            ? null
            : openCloseRelationSite.getOrderType().isSpot();
    this.setOutstandingOrders(
        buySellType,
        mapOrder,
        isSpot,
        openCloseRelationSite.isMakeLimitOrder(),
        openCloseRelationSite.isDelivery());
    HashMap<Guid, RelationOrder> editOutstandingOrders =
        this.getEditOutstandingOrders(editOutstandingOrderBuySellType, mapOrder);
    boolean hasChange = this.hasChange(grid, editOutstandingOrders);

    if (hasChange) {
      this.unbindOutstanding();
      this._outstandingKey = Guid.newGuid().toString();
      this._bindingSourceForOutstanding = new tradingConsole.ui.grid.BindingSource();

      boolean isMakeOrder2 =
          this._settingsManager.get_Customer().get_SingleAccountOrderType() == 2
              || this._settingsManager.get_Customer().get_MultiAccountsOrderType() == 2;

      RelationOrder.initialize(
          isMakeOrder2,
          grid,
          this._outstandingKey,
          editOutstandingOrders.values(),
          this._bindingSourceForOutstanding,
          openCloseRelationSite,
          editOutstandingOrderBuySellType);

      int column = this._bindingSourceForOutstanding.getColumnByName(OutstandingOrderColKey.IsBuy);
      if (column != -1) {
        grid.sortColumn(column, false, ascend);
        TableColumnChooser.hideColumn(grid, column);
      }
    } else {
      this._outstandingKey = grid.get_BindingSource().get_DataSourceKey();
      this._outstandingOrders.clear();
      for (int row = 0; row < grid.getRowCount(); row++) {
        RelationOrder relationOrder = (RelationOrder) (grid.getObject(row));
        this._outstandingOrders.put(relationOrder.get_OpenOrderId(), relationOrder);
      }
    }

    return hasChange;
  }
Ejemplo n.º 2
0
 public BigDecimal getSumLiqLots() {
   BigDecimal sumLiqLots = BigDecimal.ZERO;
   for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
       iterator.hasNext(); ) {
     RelationOrder relationOrder = iterator.next();
     if (relationOrder.get_IsSelected() && relationOrder.get_LiqLot() != null) {
       sumLiqLots = sumLiqLots.add(relationOrder.get_LiqLot());
     }
   }
   return sumLiqLots;
 }
Ejemplo n.º 3
0
 public BigDecimal getTotalCloseLotOfFullClose() {
   BigDecimal sumLiqLots = BigDecimal.ZERO;
   for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
       iterator.hasNext(); ) {
     RelationOrder relationOrder = iterator.next();
     if (relationOrder.isFullClose()) {
       sumLiqLots = sumLiqLots.add(relationOrder.get_LiqLot());
     }
   }
   return sumLiqLots;
 }
Ejemplo n.º 4
0
 public BigDecimal getQuoteLotForDirectLiq(boolean isSpotTrade, Boolean isMakeLimitOrder) {
   BigDecimal quoteLot = BigDecimal.ZERO;
   for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
       iterator.hasNext(); ) {
     RelationOrder relationOrder = iterator.next();
     quoteLot =
         quoteLot.add(
             relationOrder.get_OpenOrder().getAvailableLotBanlance(isSpotTrade, isMakeLimitOrder));
   }
   return quoteLot;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
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);
        // }
      }
    }
  }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
0
  public HashMap<Guid, RelationOrder> getPlaceRelation() {
    HashMap<Guid, RelationOrder> placeRelation = null;

    HashMap<Guid, RelationOrder> outstandingOrders = this.getOutstandingOrders();
    for (RelationOrder relationOrder : outstandingOrders.values()) {
      if (relationOrder.get_IsSelected()
          && relationOrder.get_CloseLot().compareTo(BigDecimal.ZERO) > 0) {
        if (placeRelation == null) placeRelation = new HashMap<Guid, RelationOrder>();
        placeRelation.put(relationOrder.get_OpenOrderId(), relationOrder);
      }
    }

    return placeRelation;
  }
Ejemplo n.º 9
0
  public void cleanOutStandingTable(boolean closeAllSell) {
    ArrayList<Guid> toBeRemoved = new ArrayList<Guid>();
    for (Iterator<RelationOrder> iterator = this._outstandingOrders.values().iterator();
        iterator.hasNext(); ) {
      RelationOrder relationOrder = iterator.next();
      if (relationOrder.get_OpenOrder().get_IsBuy() == closeAllSell) {
        toBeRemoved.add(relationOrder.get_OpenOrder().get_Id());
        this._bindingSourceForOutstanding.remove(relationOrder);
      }
    }

    for (Guid id : toBeRemoved) {
      this._outstandingOrders.remove(id);
    }
  }
Ejemplo n.º 10
0
 private boolean hasChange(DataGrid grid, HashMap<Guid, RelationOrder> relationOrders) {
   if (grid.get_BindingSource() == null || grid.getRowCount() != relationOrders.size()) {
     return true;
   } else {
     int openOrderSummaryColumn = -1;
     for (int column = 0; column < grid.getColumnModel().getColumnCount(); column++) {
       if (grid.getColumnModel()
           .getColumn(column)
           .getIdentifier()
           .equals(OutstandingOrderColKey.OpenOrderSummary)) {
         openOrderSummaryColumn = column;
         break;
       }
     }
     for (int row = 0; row < grid.getRowCount(); row++) {
       RelationOrder realtionOrder = (RelationOrder) grid.getObject(row);
       Guid openOrderId = realtionOrder.get_OpenOrderId();
       RelationOrder realtionOrder2 = relationOrders.get(openOrderId);
       if (realtionOrder2 == null
           || realtionOrder2.getAvailableCloseLot().compareTo(realtionOrder.getAvailableCloseLot())
               != 0
           || (openOrderSummaryColumn > -1
               && !realtionOrder2
                   .get_OpenOrderSummary()
                   .equals(grid.getValueAt(row, openOrderSummaryColumn).toString()))) {
         return true;
       }
     }
   }
   return false;
 }
Ejemplo n.º 11
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.º 12
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.º 13
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;
  }
Ejemplo n.º 14
0
 public void unbindOutstanding() {
   if (!StringHelper.isNullOrEmpty(this._outstandingKey)
       && this._bindingSourceForOutstanding != null) {
     RelationOrder.unbind(this._outstandingKey, this._bindingSourceForOutstanding);
   }
 }
Ejemplo n.º 15
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);
                }
              }
            }
          }
        }
      }
    }
  }
Ejemplo n.º 16
0
 private boolean isOpen() {
   for (RelationOrder relation : this._outstandingOrders.values()) {
     if (relation.get_IsSelected()) return false;
   }
   return true;
 }