Exemplo n.º 1
0
        public void OnMessage(QuickFix.FIX42.OrderCancelReplaceRequest msg, QuickFix.SessionID session)
        {
            try
            {
                // qty set ?
                int qty = -1;
                if (msg.IsSetOrderQty()) qty = Convert.ToInt32(msg.OrderQty.getValue());
                else if (msg.IsSetCashOrderQty()) qty = Convert.ToInt32(msg.CashOrderQty.getValue());
                if (qty < 0)
                {
                    RejectCancelRequest(session, msg.ClOrdID, msg.OrigClOrdID, null, "Qty nor CashOrderQty field is not set", QuickFix.Fields.CxlRejReason.BROKER_OPTION, true);
                    return;
                }

                double price = (msg.IsSetPrice() ? Convert.ToDouble(msg.Price.getValue()) : 0);
                double stopPx = (msg.IsSetStopPx() ? Convert.ToDouble(msg.StopPx.getValue()) : 0);

                ProcessOrderCancelRequest(session, msg.ClOrdID, msg.OrigClOrdID, true, qty, price, stopPx);

            }
            catch (Exception e)
            {
                RejectCancelRequest(session, msg.ClOrdID, msg.OrigClOrdID, null, "OnMessage(QuickFix.FIX42.OrderCancelReplaceRequest msg, QuickFix.SessionID session) : internal error : " + e.ToString()
                , QuickFix.Fields.CxlRejReason.OTHER, true);

            }
        }
Exemplo n.º 2
0
        public void OnMessage(QuickFix.FIX42.NewOrderSingle msg, QuickFix.SessionID session)
        {
            try
            {
                OrderFixBridge r ;
                lock(locker_)
                    r = m_orders.AddOrGet(null, msg.ClOrdID.getValue(), session);

                if (r.Order!=null)
                {
                    RejectNew(session, msg.Symbol.getValue(), msg.ClOrdID.getValue(), Convert.ToInt32(msg.OrderQty.getValue()), Converter.c(msg.Side), "ClOrdID '" + msg.ClOrdID + "'already exists !");
                    return;
                }

                QuickFixStaticAcceptor.FromFIX_SendOrder(
                    r,
                    msg.Symbol.getValue(),
                    Converter.c(msg.Side),
                    Converter.c(msg.OrdType),
                    msg.IsSetOrderQty() ? Convert.ToInt32(msg.OrderQty.getValue()) : 0,
                    msg.IsSetPrice() ? Convert.ToDouble(msg.Price.getValue()) : 0,
                    msg.IsSetStopPx() ? Convert.ToDouble(msg.StopPx.getValue()) : 0,
                    msg.IsSetText() ? msg.Text.getValue() : string.Empty
                );

                if (r.Order == null)
                {
                    RejectNew(session, msg.Symbol.getValue(), msg.ClOrdID.getValue(), Convert.ToInt32(msg.OrderQty.getValue()), Converter.c(msg.Side), "NinjaTrader7 returned null on creating order (internal error)");
                    return;
                }
            }
            catch (Exception e)
            {
                RejectNew(session, msg.Symbol.getValue(), msg.ClOrdID.getValue(), Convert.ToInt32(msg.OrderQty.getValue()), Converter.c(msg.Side), e.Message);
            }
        }