Ejemplo n.º 1
0
void Application::rejectOrder
( const FIX::SenderCompID& sender, const FIX::TargetCompID& target,
  const FIX::ClOrdID& clOrdID, const FIX::Symbol& symbol,
  const FIX::Side& side, const std::string& message )
{
  FIX::TargetCompID targetCompID( sender.getValue() );
  FIX::SenderCompID senderCompID( target.getValue() );

  FIX42::ExecutionReport fixOrder
  ( FIX::OrderID ( clOrdID.getValue() ),
    FIX::ExecID ( m_generator.genExecutionID() ),
    FIX::ExecTransType ( FIX::ExecTransType_NEW ),
    FIX::ExecType ( FIX::ExecType_REJECTED ),
    FIX::OrdStatus ( FIX::ExecType_REJECTED ),
    symbol, side, FIX::LeavesQty( 0 ), FIX::CumQty( 0 ), FIX::AvgPx( 0 ) );

  fixOrder.set( clOrdID );
  fixOrder.set( FIX::Text( message ) );

  try
  {
    FIX::Session::sendToTarget( fixOrder, senderCompID, targetCompID );
  }
  catch ( FIX::SessionNotFound& ) {}}
void NewOrderRequestMessage::process(OrderBook& orderBook) const {

  LOG4CXX_INFO(logger_, "Handing new order request");

  FIX::SenderCompID senderCompId;
  fixMsg_.getHeader().get(senderCompId);

  FIX::TargetCompID targetCompId;
  fixMsg_.getHeader().get(targetCompId);

  FIX::ClOrdID clOrdId;
  fixMsg_.get(clOrdId);

  FIX::Symbol symbol;
  fixMsg_.get(symbol);

  FIX::Side side;
  fixMsg_.get(side);

  FIX::OrdType orderType;
  fixMsg_.get(orderType);

  FIX::Price price;
  if (orderType == FIX::OrdType_LIMIT)
    fixMsg_.get(price);

  FIX::OrderQty orderQty;
  fixMsg_.get(orderQty);

  FIX::TimeInForce timeInForce(FIX::TimeInForce_DAY);
  if(fixMsg_.isSetField(timeInForce))
    fixMsg_.get(timeInForce);

  // let's do our validations here
  if(!exchange_->getOrderBookManager()->symbolExists(symbol.getString())) {
    LOG4CXX_INFO(logger_, "Symbol " << symbol.getString() << " not found. Rejecting this order.");
    reject("Security not found");
    return;
  }


  shared_ptr<Order> order(new Order(
      exchange_->getIdGenerator()->nextOrderId(),
      clOrdId.getValue(),
      senderCompId.getValue(),
      symbol.getValue(),
      FixTypeConverter::convert(side),
      (long)orderQty,
      price.getValue(),
      FixTypeConverter::convert(orderType),
      FixTypeConverter::convert(timeInForce)));

  // order is accepted, send order confirmation
  LOG4CXX_INFO(logger_, "New order accepted");
  exchange_->getFixEngine()->getFixMessageHandler()->sendOrderResponse(order, Order::ORDER_STATUS_NEW);

  // now match the order
  orderBook.match(order);
  if(order->isOpen()) {
    // order is not completely filled. let's add it to the order book
    orderBook.add(order);
  }
}
std::string NewOrderRequestMessage::getSenderCompId() const {
  FIX::SenderCompID senderCompId;
  fixMsg_.getHeader().get(senderCompId);
  return senderCompId.getValue();
}