コード例 #1
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;
  }
コード例 #2
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);
      }
    }
  }