示例#1
0
文件: IBTrader.java 项目: klon/jtrade
  @Override
  public void openOrder(int orderId, Contract contract, Order order, OrderState orderState) {
    try {
      if (logger.isDebugEnabled())
        logger.debug(
            "openOrder: {} {} {} {}",
            new Object[] {
              orderId, Util.toString(contract), Util.toString(order), Util.toString(orderState)
            });

      OpenOrder openOrder = openOrdersById.get(orderId);
      if (openOrder != null) {
        if ((openOrder.isFilled() || (!openOrder.isOpen() && openOrder.getQuantityFilled() > 0))
            && orderState.m_commission != Double.MAX_VALUE) {
          closeOpenOrder(openOrder, orderState.m_commission);
        }
      } else {
        if ("PendingSubmit".equals(orderState.m_status)
            || "PreSubmitted".equals(orderState.m_status)
            || "Submitted".equals(orderState.m_status)) {
          openOrder = toOpenOrder(contract, order);
          openOrdersById.put(orderId, openOrder);
          logger.info("Added {}", openOrder);
        }
      }
    } catch (Throwable t) {
      logger.error(t.getMessage(), t);
    }
  }
示例#2
0
文件: IBTrader.java 项目: klon/jtrade
  @Override
  public void orderStatus(
      int orderId,
      String status,
      int filled,
      int remaining,
      double avgFillPrice,
      int permId,
      int parentId,
      double lastFillPrice,
      int clientId,
      String whyHeld) {
    try {
      if (logger.isDebugEnabled())
        logger.debug(
            "orderStatus: {} {} {} {} {} {} {} {} {} {}",
            new Object[] {
              orderId,
              status,
              filled,
              remaining,
              avgFillPrice,
              permId,
              parentId,
              lastFillPrice,
              clientId,
              whyHeld
            });

      if ("Cancelled".equals(status)) {
        OpenOrder openOrder = openOrdersById.remove(orderId);
        if (openOrder != null) {
          openOrder.setCancelled();
          logger.info("Cancelled {}", openOrder);
          for (OrderListener listener : orderListeners) {
            try {
              listener.onOrderCancelled(openOrder);
            } catch (Throwable t) {
              logger.error(t.getMessage(), t);
            }
          }
          if ((openOrder.isFilled()
              || (!openOrder.isOpen() && openOrder.getQuantityFilled() > 0))) {
            closeOpenOrder(openOrder, 0);
          }
        } else {
          logger.warn("Cancelled order {}, no matching order found!", orderId);
        }
      }

    } catch (Throwable t) {
      // Do not allow exceptions come back to the socket -- it will cause
      // disconnects
      logger.error(t.getMessage(), t);
    }
  }