Esempio n. 1
0
  @Override
  public void execDetails(int reqId, Contract contract, Execution execution) {
    try {
      if (logger.isDebugEnabled())
        logger.debug(
            "execDetails: {} {} {}",
            new Object[] {reqId, Util.toString(contract), Util.toString(execution)});

      OpenOrder openOrder = openOrdersById.get(execution.m_orderId);
      DateTime dt = DateTimeFormat.forPattern("yyyyMMdd  HH:mm:ss").parseDateTime(execution.m_time);
      if (openOrder != null) {
        int quantityChange = openOrder.isBuy() ? execution.m_shares : -execution.m_shares;
        openOrder.update(quantityChange, execution.m_price, dt);
        logExecution(openOrder, quantityChange);
      } else {
        logger.info(
            "Execution does not match any open order {} {}",
            Util.toString(contract),
            Util.toString(execution));
      }
    } catch (Throwable t) {
      // Do not allow exceptions come back to the socket -- it will cause
      // disconnects
      logger.error(t.getMessage(), t);
    }
  }
Esempio n. 2
0
 protected Order makeOrder(OpenOrder openOrder) {
   Order order = new Order();
   order.m_orderRef = openOrder.getReference() != null ? openOrder.getReference() : "";
   order.m_overridePercentageConstraints = true;
   order.m_totalQuantity = Math.abs(openOrder.getQuantity());
   if (openOrder.isBuy()) {
     order.m_action = "BUY";
   } else if (openOrder.isSell()) {
     order.m_action = "SELL";
   }
   if (openOrder.isMarket()) {
     order.m_orderType = "MKT";
   } else if (openOrder.isLimit()) {
     order.m_orderType = "LMT";
     order.m_lmtPrice = openOrder.getPrice();
   } else if (openOrder.isStopMarket()) {
     order.m_orderType = "STP";
     order.m_triggerMethod = 8; // midpoint
     order.m_auxPrice = openOrder.getStopPrice();
   } else if (openOrder.isStopLimit()) {
     order.m_orderType = "STPLMT";
     order.m_triggerMethod = 8; // midpoint
     order.m_lmtPrice = openOrder.getPrice();
     order.m_auxPrice = openOrder.getStopPrice();
   } else if (openOrder.isTrailMarket()) {
     order.m_orderType = "TRAIL";
     order.m_triggerMethod = 8; // midpoint
     order.m_auxPrice = openOrder.getTrailStopOffset();
   } else if (openOrder.isTrailLimit()) {
     order.m_orderType = "TRAILLMT";
     order.m_triggerMethod = 8; // midpoint
     order.m_lmtPrice = openOrder.getPrice();
     order.m_trailStopPrice = openOrder.getStopPrice();
     order.m_auxPrice = openOrder.getTrailStopOffset();
   }
   return order;
 }