Exemple #1
0
        public void Handle(QuickFix.Message msg)
        {
            // check message type tag, if execution report then push execution report update
            QuickFix.MsgType msgType       = new QuickFix.MsgType();
            string           msgTypeString = msg.getHeader().getField(m_msgTypeTag);

            if (msgTypeString == m_MsgTypeTagValueToHandle)
            {
                Counters.IncrementCounter(CountersConstants.RejectionMsgs);
                string txt = string.Empty;
                if (msg.isSetField(58))
                {
                    txt = msg.getField(58);
                }

                try
                {
                    if (msg.isSetField(373))
                    {
                        string rejectReasonValue = string.Empty;
                        rejectReasonValue = msg.getField(373);
                        txt += ", " + Lookups.GetSessionRejectReason(rejectReasonValue).MessageEn;
                    }
                }
                catch (Exception ex)
                {
                    Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                    SystemLogger.WriteOnConsoleAsync(true, string.Format("Error getting reason of rejected message: {0}", ex.Message), ConsoleColor.Red, ConsoleColor.Black, false);
                }
                // create IResponseMessage
                SystemLogger.WriteOnConsoleAsync(true, string.Format("Order Rejected, Details {0} ,  Reason: {1} ", msg.ToXML(), txt), ConsoleColor.Red, ConsoleColor.White, false);
            }
        }
        public virtual void fromApp(QuickFix.Message message, QuickFix.SessionID sessionID)
        {
            try
            {
                QuickFix.MsgType msgType = new QuickFix.MsgType();
                message.getHeader().getField(msgType);
                string msgTypeValue = msgType.getValue();

                log.WriteLog(string.Format("fromApp: {0}", msgTypeValue));

                switch (msgTypeValue)
                {
                case "UAT":
                    onGatewayStatusMessage((QuickFix42.Message)message, sessionID);
                    break;

                case "UAP":
                    onPositionReportMessage((QuickFix42.Message)message, sessionID);
                    break;

                default:
                    crack(message, sessionID);
                    break;
                }
            }
            catch (QuickFix.UnsupportedMessageType umt)
            {
                log.WriteLog("UnsupportedMessageType: " + umt.Message);
                parseMessage(message, sessionID);
            }
            catch (Exception ex)
            {
                log.WriteLog(ex.ToString());
            }
        }
        public void Handle(QuickFix.Message msg)
        {
            // check message type tag, if execution report then push execution report update
            QuickFix.MsgType msgType       = new QuickFix.MsgType();
            string           msgTypeString = msg.getHeader().getField(m_msgTypeTag);

            if (msgTypeString == m_MsgTypeTagValueToHandle)
            {
                //SystemLogger.WriteOnConsole(true, string.Format("new message recieved, Type: {0}, Message: '{1}'", msgTypeString, msg.ToXML()), ConsoleColor.Cyan, ConsoleColor.Black, false);

                //string reason = string.Empty;
                //if (msg.isSetField(58))
                //{
                //    reason = msg.getField(58);
                //}
                //int sequence = int.Parse(msg.getHeader().getField(34));
                //if (reason.ToLower().Contains("expected sequence") && reason.ToLower().Contains("upper"))
                //{
                //}
                //else if (reason.ToLower().Contains("expected sequence") && reason.ToLower().Contains("lower"))
                //{
                //}

                ////{8=FIX.4.29=10735=534=1149=CRDTEST52=20110127-08:07:04.64856=BELTONE58=MsgSeqNum too low, expecting 9 but received 110=251}
                //// create IResponseMessage
            }
        }
Exemple #4
0
 public void Handle(QuickFix.Message msg)
 {
     // check message type tag, if execution report then push execution report update
     QuickFix.MsgType msgType = new QuickFix.MsgType();
     string msgTypeString = msg.getHeader().getField(m_msgTypeTag);
     if (msgTypeString == m_MsgTypeTagValueToHandle)
     {
         //SystemLogger.WriteOnConsole(true, string.Format("new message recieved, Type: {0}, Message: '{1}'", msgTypeString, msg.ToXML()), ConsoleColor.Cyan, ConsoleColor.Black, false);
         // create IResponseMessage
     }
 }
        public virtual void toAdmin(QuickFix.Message message, QuickFix.SessionID sessionID)
        {
            Console.WriteLine("toAdmin: " + message);

            QuickFix.MsgType mt = new QuickFix.MsgType();
            message.getHeader().getField(mt);

            if (mt.getValue() == QuickFix.MsgType.Logon)
            {
                if (!_password.Equals(""))
                {
                    message.setField(new QuickFix.RawData(_password));
                }

                if (_resetSession)
                {
                    message.setField(new QuickFix.ResetSeqNumFlag(true));
                }
            }
            else
            {
                updateDisplay("toAdmin: " + DateTime.Now.ToString("hh:mm:ss.fff"));
            }
        }
Exemple #6
0
 public void set(QuickFix.MsgType value)
 {
     setField(value);
 }
Exemple #7
0
 public Message(QuickFix.MsgType msgType) : base(new QuickFix.BeginString("FIXT.1.1"), msgType)
 {
     m_header  = new Header(this);
     m_trailer = new Trailer(this);
     getHeader().setField(new QuickFix.ApplVerID("9"));
 }
        public new void crack(QuickFix.Message message,
                              QuickFix.SessionID sessionID)
        {
            QuickFix.MsgType msgType = new QuickFix.MsgType();
            message.getHeader().getField(msgType);
            String msgTypeValue = msgType.getValue();

            if (msgTypeValue == "0")
            {
                onMessage((Heartbeat)(message), sessionID);
            }
            else
            if (msgTypeValue == "A")
            {
                onMessage((Logon)(message), sessionID);
            }
            else
            if (msgTypeValue == "1")
            {
                onMessage((TestRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "2")
            {
                onMessage((ResendRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "3")
            {
                onMessage((Reject)(message), sessionID);
            }
            else
            if (msgTypeValue == "4")
            {
                onMessage((SequenceReset)(message), sessionID);
            }
            else
            if (msgTypeValue == "5")
            {
                onMessage((Logout)(message), sessionID);
            }
            else
            if (msgTypeValue == "j")
            {
                onMessage((BusinessMessageReject)(message), sessionID);
            }
            else
            if (msgTypeValue == "BE")
            {
                onMessage((UserRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "BF")
            {
                onMessage((UserResponse)(message), sessionID);
            }
            else
            if (msgTypeValue == "7")
            {
                onMessage((Advertisement)(message), sessionID);
            }
            else
            if (msgTypeValue == "6")
            {
                onMessage((IndicationOfInterest)(message), sessionID);
            }
            else
            if (msgTypeValue == "B")
            {
                onMessage((News)(message), sessionID);
            }
            else
            if (msgTypeValue == "C")
            {
                onMessage((Email)(message), sessionID);
            }
            else
            if (msgTypeValue == "R")
            {
                onMessage((QuoteRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AJ")
            {
                onMessage((QuoteResponse)(message), sessionID);
            }
            else
            if (msgTypeValue == "AG")
            {
                onMessage((QuoteRequestReject)(message), sessionID);
            }
            else
            if (msgTypeValue == "AH")
            {
                onMessage((RFQRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "S")
            {
                onMessage((Quote)(message), sessionID);
            }
            else
            if (msgTypeValue == "Z")
            {
                onMessage((QuoteCancel)(message), sessionID);
            }
            else
            if (msgTypeValue == "a")
            {
                onMessage((QuoteStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AI")
            {
                onMessage((QuoteStatusReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "i")
            {
                onMessage((MassQuote)(message), sessionID);
            }
            else
            if (msgTypeValue == "b")
            {
                onMessage((MassQuoteAcknowledgement)(message), sessionID);
            }
            else
            if (msgTypeValue == "V")
            {
                onMessage((MarketDataRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "W")
            {
                onMessage((MarketDataSnapshotFullRefresh)(message), sessionID);
            }
            else
            if (msgTypeValue == "X")
            {
                onMessage((MarketDataIncrementalRefresh)(message), sessionID);
            }
            else
            if (msgTypeValue == "Y")
            {
                onMessage((MarketDataRequestReject)(message), sessionID);
            }
            else
            if (msgTypeValue == "c")
            {
                onMessage((SecurityDefinitionRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "d")
            {
                onMessage((SecurityDefinition)(message), sessionID);
            }
            else
            if (msgTypeValue == "v")
            {
                onMessage((SecurityTypeRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "w")
            {
                onMessage((SecurityTypes)(message), sessionID);
            }
            else
            if (msgTypeValue == "x")
            {
                onMessage((SecurityListRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "y")
            {
                onMessage((SecurityList)(message), sessionID);
            }
            else
            if (msgTypeValue == "z")
            {
                onMessage((DerivativeSecurityListRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AA")
            {
                onMessage((DerivativeSecurityList)(message), sessionID);
            }
            else
            if (msgTypeValue == "e")
            {
                onMessage((SecurityStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "f")
            {
                onMessage((SecurityStatus)(message), sessionID);
            }
            else
            if (msgTypeValue == "g")
            {
                onMessage((TradingSessionStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "h")
            {
                onMessage((TradingSessionStatus)(message), sessionID);
            }
            else
            if (msgTypeValue == "D")
            {
                onMessage((NewOrderSingle)(message), sessionID);
            }
            else
            if (msgTypeValue == "8")
            {
                onMessage((ExecutionReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "Q")
            {
                onMessage((DontKnowTrade)(message), sessionID);
            }
            else
            if (msgTypeValue == "G")
            {
                onMessage((OrderCancelReplaceRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "F")
            {
                onMessage((OrderCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "9")
            {
                onMessage((OrderCancelReject)(message), sessionID);
            }
            else
            if (msgTypeValue == "H")
            {
                onMessage((OrderStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "q")
            {
                onMessage((OrderMassCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "r")
            {
                onMessage((OrderMassCancelReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "AF")
            {
                onMessage((OrderMassStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "s")
            {
                onMessage((NewOrderCross)(message), sessionID);
            }
            else
            if (msgTypeValue == "t")
            {
                onMessage((CrossOrderCancelReplaceRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "u")
            {
                onMessage((CrossOrderCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AB")
            {
                onMessage((NewOrderMultileg)(message), sessionID);
            }
            else
            if (msgTypeValue == "AC")
            {
                onMessage((MultilegOrderCancelReplaceRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "k")
            {
                onMessage((BidRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "l")
            {
                onMessage((BidResponse)(message), sessionID);
            }
            else
            if (msgTypeValue == "E")
            {
                onMessage((NewOrderList)(message), sessionID);
            }
            else
            if (msgTypeValue == "m")
            {
                onMessage((ListStrikePrice)(message), sessionID);
            }
            else
            if (msgTypeValue == "N")
            {
                onMessage((ListStatus)(message), sessionID);
            }
            else
            if (msgTypeValue == "L")
            {
                onMessage((ListExecute)(message), sessionID);
            }
            else
            if (msgTypeValue == "K")
            {
                onMessage((ListCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "M")
            {
                onMessage((ListStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "J")
            {
                onMessage((AllocationInstruction)(message), sessionID);
            }
            else
            if (msgTypeValue == "P")
            {
                onMessage((AllocationInstructionAck)(message), sessionID);
            }
            else
            if (msgTypeValue == "AS")
            {
                onMessage((AllocationReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "AT")
            {
                onMessage((AllocationReportAck)(message), sessionID);
            }
            else
            if (msgTypeValue == "AK")
            {
                onMessage((Confirmation)(message), sessionID);
            }
            else
            if (msgTypeValue == "AU")
            {
                onMessage((ConfirmationAck)(message), sessionID);
            }
            else
            if (msgTypeValue == "BH")
            {
                onMessage((ConfirmationRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "T")
            {
                onMessage((SettlementInstructions)(message), sessionID);
            }
            else
            if (msgTypeValue == "AV")
            {
                onMessage((SettlementInstructionRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AD")
            {
                onMessage((TradeCaptureReportRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AQ")
            {
                onMessage((TradeCaptureReportRequestAck)(message), sessionID);
            }
            else
            if (msgTypeValue == "AE")
            {
                onMessage((TradeCaptureReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "AR")
            {
                onMessage((TradeCaptureReportAck)(message), sessionID);
            }
            else
            if (msgTypeValue == "o")
            {
                onMessage((RegistrationInstructions)(message), sessionID);
            }
            else
            if (msgTypeValue == "p")
            {
                onMessage((RegistrationInstructionsResponse)(message), sessionID);
            }
            else
            if (msgTypeValue == "AL")
            {
                onMessage((PositionMaintenanceRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AM")
            {
                onMessage((PositionMaintenanceReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "AN")
            {
                onMessage((RequestForPositions)(message), sessionID);
            }
            else
            if (msgTypeValue == "AO")
            {
                onMessage((RequestForPositionsAck)(message), sessionID);
            }
            else
            if (msgTypeValue == "AP")
            {
                onMessage((PositionReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "AW")
            {
                onMessage((AssignmentReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "AX")
            {
                onMessage((CollateralRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "AY")
            {
                onMessage((CollateralAssignment)(message), sessionID);
            }
            else
            if (msgTypeValue == "AZ")
            {
                onMessage((CollateralResponse)(message), sessionID);
            }
            else
            if (msgTypeValue == "BA")
            {
                onMessage((CollateralReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "BB")
            {
                onMessage((CollateralInquiry)(message), sessionID);
            }
            else
            if (msgTypeValue == "BC")
            {
                onMessage((NetworkStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "BD")
            {
                onMessage((NetworkStatusResponse)(message), sessionID);
            }
            else
            if (msgTypeValue == "BG")
            {
                onMessage((CollateralInquiryAck)(message), sessionID);
            }
            else
            {
                onMessage(message, sessionID);
            }
        }
Exemple #9
0
        public void crack(QuickFix.Message message,
                          QuickFix.SessionID sessionID)
        {
            QuickFix.MsgType msgType = new QuickFix.MsgType();
            message.getHeader().getField(msgType);
            String msgTypeValue = msgType.getValue();

            if (msgTypeValue == "0")
            {
                onMessage((Heartbeat)(message), sessionID);
            }
            else
            if (msgTypeValue == "A")
            {
                onMessage((Logon)(message), sessionID);
            }
            else
            if (msgTypeValue == "1")
            {
                onMessage((TestRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "2")
            {
                onMessage((ResendRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "3")
            {
                onMessage((Reject)(message), sessionID);
            }
            else
            if (msgTypeValue == "4")
            {
                onMessage((SequenceReset)(message), sessionID);
            }
            else
            if (msgTypeValue == "5")
            {
                onMessage((Logout)(message), sessionID);
            }
            else
            if (msgTypeValue == "7")
            {
                onMessage((Advertisement)(message), sessionID);
            }
            else
            if (msgTypeValue == "6")
            {
                onMessage((IndicationofInterest)(message), sessionID);
            }
            else
            if (msgTypeValue == "B")
            {
                onMessage((News)(message), sessionID);
            }
            else
            if (msgTypeValue == "C")
            {
                onMessage((Email)(message), sessionID);
            }
            else
            if (msgTypeValue == "R")
            {
                onMessage((QuoteRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "S")
            {
                onMessage((Quote)(message), sessionID);
            }
            else
            if (msgTypeValue == "D")
            {
                onMessage((NewOrderSingle)(message), sessionID);
            }
            else
            if (msgTypeValue == "8")
            {
                onMessage((ExecutionReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "Q")
            {
                onMessage((DontKnowTrade)(message), sessionID);
            }
            else
            if (msgTypeValue == "G")
            {
                onMessage((OrderCancelReplaceRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "F")
            {
                onMessage((OrderCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "9")
            {
                onMessage((OrderCancelReject)(message), sessionID);
            }
            else
            if (msgTypeValue == "H")
            {
                onMessage((OrderStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "J")
            {
                onMessage((Allocation)(message), sessionID);
            }
            else
            if (msgTypeValue == "P")
            {
                onMessage((AllocationACK)(message), sessionID);
            }
            else
            if (msgTypeValue == "E")
            {
                onMessage((NewOrderList)(message), sessionID);
            }
            else
            if (msgTypeValue == "N")
            {
                onMessage((ListStatus)(message), sessionID);
            }
            else
            if (msgTypeValue == "L")
            {
                onMessage((ListExecute)(message), sessionID);
            }
            else
            if (msgTypeValue == "K")
            {
                onMessage((ListCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "M")
            {
                onMessage((ListStatusRequest)(message), sessionID);
            }
            else
            {
                onMessage(message, sessionID);
            }
        }
Exemple #10
0
 public bool isSet(QuickFix.MsgType field)
 {
     return(isSetField(field));
 }
Exemple #11
0
        public void RenderOrderAsFix(out QuickFix.Message myNOS, out KaiTrade.Interfaces.Message myMsg, out string myDriverCode, KaiTrade.Interfaces.Order myOrder)
        {
            try
            {
                lock (this)
                {
                    // do not actually submit triggered orders

                    // register the order as a publisher
                    KaiTrade.Interfaces.Publisher myPub = null;
                    myPub = AppFactory.Instance().GetPublisherManager().GetPublisher(myOrder.Identity);
                    if (myPub == null)
                    {
                        myPub = myOrder as KaiTrade.Interfaces.Publisher;
                        AppFactory.Instance().GetPublisherManager().Add(myPub);
                    }

                    // Check the limits for the order
                    string myTextErr;
                    if (LimitChecker.Instance().BreaksLimits(out myTextErr, myOrder))
                    {
                        myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED);
                        myOrder.Text = "order failed order qty limit test";
                        Exception myE = new Exception("process order failed order qty limit test");
                        throw myE;
                    }

                    // Create the FIX order message
                    myNOS = new QuickFix.Message();

                    // pending new at this stage
                    myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.PENDING_NEW);

                    myOrder.TransactTime = new QuickFix.TransactTime(DateTime.Now.ToUniversalTime());
                    myNOS.setField(myOrder.TransactTime);

                    //myOrder.ClOrdID = new QuickFix.ClOrdID(KaiUtil.Identities.Instance.genReqID());

                    // Associate the CLOrdID with this order
                    AppFactory.Instance().GetOrderManager().AssociateClOrdID(myOrder.ClOrdID.getValue(), myOrder);

                    // Set fix version
                    QuickFix.BeginString myBeginString = new QuickFix.BeginString("FIX.4.4");
                    myNOS.getHeader().setField(myBeginString);

                    // Set order message type
                    QuickFix.MsgType msgType = new QuickFix.MsgType();
                    msgType.setValue("D");
                    myNOS.getHeader().setField(msgType);

                    myNOS.setField(myOrder.ClOrdID);

                    // set up the product details in the message
                    myOrder.Product.Set(myNOS);

                    // Qty
                    myNOS.setField(myOrder.OrderQty);

                    // MaxFloor
                    if (myOrder.MaxFloor != null)
                    {
                        myNOS.setField(myOrder.MaxFloor);
                    }

                    // set the side
                    myNOS.setField(myOrder.Side);

                    // set the order type
                    myNOS.setField(myOrder.OrdType);

                    // Time in force
                    if (myOrder.TimeInForce != null)
                    {
                        myNOS.setField(myOrder.TimeInForce);
                    }
                    else
                    {
                        myOrder.TimeInForce = new QuickFix.TimeInForce(QuickFix.TimeInForce.DAY);
                        myNOS.setField(myOrder.TimeInForce);
                    }

                    // Validation - check they entered a date/time if needed
                    switch (myOrder.TimeInForce.getValue())
                    {
                        case QuickFix.TimeInForce.GOOD_TILL_DATE:
                            break;

                        default:
                            break;
                    }

                    // do not add the price to the fix message on Market orders
                    if (myOrder.OrdType.getValue() != QuickFix.OrdType.MARKET)
                    {
                        if (myOrder.Price.getValue() > 0)
                        {
                            myNOS.setField(myOrder.Price);
                        }
                        else
                        {
                            throw new Exception("Must specify price > 0 on Limit and other non Market orders");
                        }
                    }

                    if (myOrder.StopPx != null)
                    {
                        myNOS.setField(myOrder.StopPx);
                    }

                    // default the handlInst to automated
                    if (myOrder.HandlInst != null)
                    {
                        myNOS.setField(myOrder.HandlInst);
                    }
                    else
                    {
                        myOrder.HandlInst = new QuickFix.HandlInst(QuickFix.HandlInst.AUTOEXECPUB);
                        myNOS.setField(myOrder.HandlInst);
                    }

                    // Create the message wrapper used to send the order to the driver
                    myMsg = new KaiTCPComm.KaiMessageWrap();

                    myMsg.Label = "D";

                    myDriverCode = "";
                    // A trade venue must be specified on the order
                    KaiTrade.Interfaces.Venue myVenue = null;
                    if (myOrder.Product.TradeVenue.Length > 0)
                    {
                        // get the driver code and session details from the venue manager
                        myVenue = AppFactory.Instance().GetVenueManager().GetVenue(myOrder.Product.TradeVenue);
                        if (myVenue != null)
                        {
                            myDriverCode = myVenue.DriverCode;
                            if (myVenue.TargetVenue.Length > 0)
                            {
                                myMsg.VenueCode = myVenue.TargetVenue;
                            }
                            if (myVenue.BeginString.Length > 0)
                            {
                                // this is the FIX version the server wants, we convert between
                                // versions in the FIX client
                                myMsg.Format = myVenue.BeginString;
                            }

                            if (myVenue.SID.Length > 0)
                            {
                                QuickFix.SenderCompID mySID = new QuickFix.SenderCompID(myVenue.SID);
                                myNOS.getHeader().setField(mySID);
                                myMsg.ClientID = myVenue.SID;
                            }
                            if (myVenue.TID.Length > 0)
                            {
                                QuickFix.TargetCompID myTID = new QuickFix.TargetCompID(myVenue.TID);
                                myNOS.getHeader().setField(myTID);
                                myMsg.TargetID = myVenue.TID;
                            }
                        }
                        else
                        {
                            string myErr = "Invalid Venue Code:" + myOrder.Product.TradeVenue;
                            m_Log.Error(myErr);
                            Exception myE = new Exception(myErr);
                            throw myE;
                        }
                    }
                    else
                    {
                        string myErr = "No Venue Code specified on product:";
                        m_Log.Error(myErr);
                        Exception myE = new Exception(myErr);
                        throw myE;
                    }

                    // process any venue field bags - do this prior to the order bags
                    // to allow the order setting to override the venues
                    List<KaiTrade.Interfaces.Field> myFieldBag;
                    KTAFacade.Instance().SetBag(out myFieldBag, myVenue.NOSBag, ",");
                    foreach (KaiTrade.Interfaces.Field myField in myFieldBag)
                    {
                        try
                        {
                            myNOS.setString(int.Parse(myField.ID), myField.Value);
                        }
                        catch (Exception myE)
                        {
                            m_Log.Error("NOS Extra tags from venue error:", myE);
                        }
                    }

                    // process any additional tags for the order
                    foreach (KaiTrade.Interfaces.Field myField in myOrder.NOSBag)
                    {
                        try
                        {
                            myNOS.setString(int.Parse(myField.ID), myField.Value);
                        }
                        catch (Exception myE)
                        {
                            m_Log.Error("NOS Extra tags error:", myE);
                        }
                    }

                    // additional setting placed here will override the
                    // fields in the bags

                    if (myOrder.Account != null)
                    {
                        if (myOrder.Account.getValue().Length > 0)
                        {
                            myNOS.setField(myOrder.Account);
                        }
                    }

                    QuickFix.TargetStrategyParameters targetStrategyParameters = new QuickFix.TargetStrategyParameters(myOrder.StrategyName);
                    myNOS.setField(targetStrategyParameters);

                    // Process any strategy parameters
                    if (myOrder.K2Parameters.Count > 0)
                    {
                        QuickFix.NoStrategyParameters noStratParms = new QuickFix.NoStrategyParameters(myOrder.K2Parameters.Count);
                        myNOS.setField(noStratParms);
                        QuickFix50Sp2.NewOrderSingle.NoStrategyParameters group = new QuickFix50Sp2.NewOrderSingle.NoStrategyParameters();
                        QuickFix.StrategyParameterName strategyParameterName;
                        QuickFix.StrategyParameterType strategyParameterType;
                        QuickFix.StrategyParameterValue strategyParameterValue;

                        foreach (KaiTrade.Interfaces.K2Parameter param in myOrder.K2Parameters)
                        {
                            strategyParameterName = new QuickFix.StrategyParameterName(param.ParameterName);
                            group.setField(strategyParameterName);
                            strategyParameterType = new QuickFix.StrategyParameterType((int)param.ParameterType);
                            group.setField(strategyParameterType);
                            strategyParameterValue = new QuickFix.StrategyParameterValue(param.ParameterValue);
                            group.setField(strategyParameterValue);
                            myNOS.addGroup(group);
                        }
                    }

                    // Set the FIX string as message data
                    myMsg.Data = myNOS.ToString();

                    // inform order manager clients that the order has changed
                    AppFactory.Instance().GetOrderManager().SetChanged(myOrder.Identity);
                }
            }
            catch (Exception myE)
            {
                m_Log.Error("RenderOrderAsFix:", myE);
                myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED);
                myOrder.Text = myE.Message;
                // inform order manager clients that the order has changed
                AppFactory.Instance().GetOrderManager().SetChanged(myOrder.Identity);
                throw (myE);
            }
        }
Exemple #12
0
        /// <summary>
        /// Cancel the order specified
        /// </summary>
        /// <param name="myID">ID of order to cancel</param>
        public void CancelOrder(string myID)
        {
            try
            {
                // Get Order
                KaiTrade.Interfaces.OrderManager myOM = AppFactory.Instance().GetOrderManager();
                KaiTrade.Interfaces.Order myOrder = myOM.GetOrder(myID);

                if (myOrder == null)
                {
                    string myError = "Order not found cannot cancel:" + myID;
                    Exception myE = new Exception(myError);
                }

                if (m_ORLog.IsInfoEnabled)
                {
                    m_ORLog.Info("CancelOrder:" + myOrder.ToString());
                }

                if (order.LastOrderCommand == KaiTrade.Interfaces.LastOrderCommand.cancel)
                {
                    string myError = "Order has already had a cancel processed - cannot recancel:" + myID;
                    Exception myE = new Exception(myError);
                }

                // Is this a triggered order
                if (myOrder.TriggerOrderID.Length > 0)
                {
                    KaiTrade.Interfaces.TriggeredOrder triggeredOrder = KTAFacade.Instance().Factory.GetTriggeredOrderManager().Get(myOrder.TriggerOrderID);
                    triggeredOrder.Cancel();
                    return;
                }
                // store the clordID's
                //NOT USED? QuickFix.OrigClOrdID myOrigClOrdID;
                QuickFix.ClOrdID myClOrdID;

                if ((myOrder.OrdStatus.getValue() == QuickFix.OrdStatus.FILLED) || (myOrder.OrdStatus.getValue() == QuickFix.OrdStatus.CANCELED))
                {
                    // cannot cancel the order - so return
                    return;
                }

                // Create a FIX cancel messsage

                QuickFix.Message myFixMsg = new QuickFix.Message();
                QuickFix.MsgType msgType = new QuickFix.MsgType("F");
                myFixMsg.getHeader().setField(msgType);
                QuickFix.BeginString myBeginString = new QuickFix.BeginString("FIX.4.4");
                myFixMsg.getHeader().setField(myBeginString);

                // set the original to the existing clordid
                myOrder.OrigClOrdID = new QuickFix.OrigClOrdID(myOrder.ClOrdID.getValue());
                myFixMsg.setField(myOrder.OrigClOrdID);

                // save the existing clordid and set the new clordid
                myClOrdID = myOrder.ClOrdID;
                myOrder.ClOrdID = new QuickFix.ClOrdID(KaiUtil.Identities.Instance.genReqID());
                myFixMsg.setField(myOrder.ClOrdID);
                // Associate the CLOrdID with this order
                AppFactory.Instance().GetOrderManager().AssociateClOrdID(myOrder.ClOrdID.getValue(), myOrder);

                // OrderID
                if (myOrder.OrderID != null)
                {
                    myFixMsg.setField(myOrder.OrderID);
                }

                ////Side
                myFixMsg.setField(myOrder.Side);

                // set up the product details in the message
                myOrder.Product.Set(myFixMsg);

                //// Transact Time
                myOrder.TransactTime = new QuickFix.TransactTime(DateTime.Now.ToUniversalTime());
                myFixMsg.setField(myOrder.TransactTime);

                // Create the message wrapper used to send the order cancel to the driver
                KaiTrade.Interfaces.Message myMsg = new KaiTCPComm.KaiMessageWrap();

                myMsg.Label = "F";

                string myDriverCode = "";
                // A trade venue must be specified on the order
                KaiTrade.Interfaces.Venue myVenue = null;
                if (myOrder.Product.TradeVenue.Length > 0)
                {
                    // get the driver code and session details from the venue manager
                    myVenue = AppFactory.Instance().GetVenueManager().GetVenue(myOrder.Product.TradeVenue);
                    if (myVenue != null)
                    {
                        myDriverCode = myVenue.DriverCode;
                        if (myVenue.TargetVenue.Length > 0)
                        {
                            myMsg.VenueCode = myVenue.TargetVenue;
                        }
                        if (myVenue.BeginString.Length > 0)
                        {
                            // this is the FIX version the server wants, we convert between
                            // versions in the FIX client
                            myMsg.Format = myVenue.BeginString;
                        }

                        if (myVenue.SID.Length > 0)
                        {
                            QuickFix.SenderCompID mySID = new QuickFix.SenderCompID(myVenue.SID);
                            myFixMsg.getHeader().setField(mySID);
                            myMsg.ClientID = myVenue.SID;
                        }
                        if (myVenue.TID.Length > 0)
                        {
                            QuickFix.TargetCompID myTID = new QuickFix.TargetCompID(myVenue.TID);
                            myFixMsg.getHeader().setField(myTID);
                            myMsg.TargetID = myVenue.TID;
                        }
                    }
                    else
                    {
                        string myErr = "Invalid Venue Code:" + myOrder.Product.TradeVenue;
                        m_Log.Error(myErr);
                        Exception myE = new Exception(myErr);
                        throw myE;
                    }
                }
                else
                {
                    string myErr = "No Venue Code specified on product:";
                    m_Log.Error(myErr);
                    Exception myE = new Exception(myErr);
                    throw myE;
                }

                // process any venue field bags - do this prior to the order bags
                // to allow the order setting to override the venues
                List<KaiTrade.Interfaces.Field> myFieldBag;
                KTAFacade.Instance().SetBag(out myFieldBag, myVenue.CancelBag, ",");

                foreach (KaiTrade.Interfaces.Field myField in myFieldBag)
                {
                    try
                    {
                        myFixMsg.setString(int.Parse(myField.ID), myField.Value);
                    }
                    catch (Exception myE)
                    {
                        m_Log.Error("cancel Extra tags from venue error:", myE);
                    }
                }

                // process any additional tags for the order
                foreach (KaiTrade.Interfaces.Field myField in myOrder.CancelBag)
                {
                    try
                    {
                        myFixMsg.setString(int.Parse(myField.ID), myField.Value);
                    }
                    catch (Exception myE)
                    {
                        m_Log.Error("cancel Extra tags error:", myE);
                    }
                }
                if (myOrder.Account != null)
                {
                    if (myOrder.Account.getValue().Length > 0)
                    {
                        myFixMsg.setField(myOrder.Account);
                    }
                }
                // Set the FIX string as message data
                myMsg.Data = myFixMsg.ToString();

                // inform order manager clients that the order has changed
                myOM.SetChanged(myOrder.Identity);

                try
                {
                    //Send the message
                    KaiTrade.Interfaces.Driver myDrv = AppFactory.Instance().GetDriverManager().GetDriver(myDriverCode);
                    if (myDrv != null)
                    {
                        // send the message for processing
                        order.LastOrderCommand = KaiTrade.Interfaces.LastOrderCommand.cancel;

                        //SendDelegate mySend = new SendDelegate(myDrv.Send);
                        //IAsyncResult ar = mySend.BeginInvoke(myMsg, SRCallback, "123456789");
                        // send the message for processing
                        myDrv.Send(myMsg);
                    }
                    else
                    {
                        string myError = "Driver not found for code:" + myDriverCode;
                        m_Log.Error(myError);
                        Exception myE = new Exception(myError);
                        throw myE;
                    }
                }
                catch (Exception myE)
                {
                    m_Log.Error("CanceltOrder:" + myOrder.Identity, myE);
                    myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED);
                    order.LastOrderCommand = KaiTrade.Interfaces.LastOrderCommand.none;
                    throw (myE);
                }
            }
            catch (Exception myE)
            {
                m_Log.Error("CancelOrder:", myE);
                throw (myE);
            }
        }
        public void Handle(QuickFix.Message msg)
        {
            long orderID = -1;

            // check message type tag, if execution report then push execution report update
            QuickFix.MsgType msgType       = new QuickFix.MsgType();
            string           msgTypeString = msg.getHeader().getField(m_msgTypeTag);

            if (msgTypeString == m_MsgTypeTagValueToHandle)
            {
                Counters.IncrementCounter(CountersConstants.OrderCancelRejectRspMsgs);

                //SystemLogger.WriteOnConsole(true, string.Format("new message recieved, Type: {0}, Message: '{1}'", msgTypeString, msg.ToXML()), ConsoleColor.Cyan, ConsoleColor.Black, false);
                SingleOrder order = null;
                // get order id
                if (msg.isSetField(11))
                {
                    orderID = long.Parse(msg.getField(11).Split(new char[] { '-' })[0]);
                    try
                    {
                        order = OrdersManager.GetOrder(orderID);
                    }
                    catch (Exception ex) // order not found
                    {
                        // get borse order  id
                        string bourseOrderID = msg.getField(37);
                        order = OrdersManager.GetOrder(bourseOrderID);
                        if (order == null)
                        {
                            SystemLogger.WriteOnConsoleAsync(true, string.Format("order BourseOrderID {0} not found !", bourseOrderID), ConsoleColor.Red, ConsoleColor.Black, true);
                            return;
                        }
                    }
                } // then search by borse order  id
                else if (msg.isSetField(37))
                {
                    string bourseOrderID = msg.getField(37);
                    order = OrdersManager.GetOrder(bourseOrderID);
                    if (order == null)
                    {
                        SystemLogger.WriteOnConsoleAsync(true, string.Format("order BourseOrderID {0} not found !", bourseOrderID), ConsoleColor.Red, ConsoleColor.Black, true);
                        return;
                    }
                }


                lock (order)
                {
                    string reason = string.Empty;
                    if (msg.isSetField(102))
                    {
                        try
                        {
                            reason = Lookups.GetOrderCancelRejectReasonsLookup(msg.getField(102)).MessageEn + " ,";
                        }
                        catch (Exception ex)
                        {
                            Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                            SystemLogger.WriteOnConsoleAsync(true, string.Format("Error getting order cancel reject reason: {0}", ex.Message), ConsoleColor.Red, ConsoleColor.Black, false);
                        }
                    }
                    if (msg.isSetField(58))
                    {
                        reason += msg.getField(58) + " ";
                    }
                    Nullable <DateTime> transactionDateTime = null;
                    if (msg.isSetField(60))
                    {
                        transactionDateTime = msg.getUtcTimeStamp(60);
                    }
                    LookupItem statusLookup = Lookups.GetOrderStatusLookup(msg.getField(39));
                    string     status       = statusLookup.CodeValue;

                    Guid requesterOrderID = (Guid)order[SingleOrderProperties.RequesterOrderID];
                    // find subscribed callbacks
                    //order[SingleOrderProperties.OrderStatus] = status;

                    bool   isPendingCancel  = false;
                    bool   isPendingReplace = false;
                    string orderNote        = string.Empty;
                    if (order[SingleOrderProperties.OrderStatus].ToString() == ORD_STATUS.PendingCancel)
                    {
                        isPendingCancel = true;
                        orderNote       = "Order cancel has been refused by bourse: " + reason;
                    }
                    else if (order[SingleOrderProperties.OrderStatus].ToString() == ORD_STATUS.PendingReplace)
                    {
                        // handle diff allocation cancellation

                        isPendingReplace = true;
                        orderNote        = "Order replace has been refused by bourse: " + reason;


                        #region Handle Mcsd Reset Allocation


                        try
                        {
                            if (order[SingleOrderProperties.IsMcsdAllocRequired] != null)
                            {
                                if (Convert.ToBoolean(order[SingleOrderProperties.IsMcsdAllocRequired]) == true)
                                {
                                    order[SingleOrderProperties.ActionOnAllocResponse] = ActionOnAllocResponse.DoNothing;
                                    int mcsdQty = Convert.ToInt32(order[SingleOrderProperties.McsdrAllocQty]);

                                    //  orderid = Convert.ToInt64(order[SingleOrderProperties.OrderID]);
                                    OrdersManager.HandleRejectedOrderAllocation(orderID, mcsdQty);
                                }
                            }
                        }
                        catch (Exception exp)
                        {
                            Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                            SystemLogger.LogErrorAsync(string.Format("Error, Reset MCSD allocation of Order {0}, Error : {1}", orderID, exp.ToString()));
                        }
                        #endregion
                    }
                    else
                    {
                        orderNote = "Order cancel/replace has been refused by bourse: " + reason;
                    }


                    // create IResponseMessage
                    string username = OrdersManager.GetOrdSessionIfAvailable((long)order[SingleOrderProperties.OrderID]);
                    if (username != null)
                    {
                        try
                        {
                            if (isPendingCancel)
                            {
                                Sessions.Push(username, new IResponseMessage[] { new Fix_OrderCancelRejected()
                                                                                 {
                                                                                     Message = reason, RequesterOrderID = requesterOrderID, OrderStatus = order[SingleOrderProperties.OriginalOrderStatus].ToString()
                                                                                 } });
                            }
                            else if (isPendingReplace)
                            {
                                Sessions.Push(username, new IResponseMessage[] { new Fix_OrderReplaceRejected()
                                                                                 {
                                                                                     Message = reason, RequesterOrderID = requesterOrderID, OrderStatus = order[SingleOrderProperties.OriginalOrderStatus].ToString()
                                                                                 } });
                            }
                            else
                            {
                                Sessions.Push(username, new IResponseMessage[] { new Fix_OrderReplaceCancelReject()
                                                                                 {
                                                                                     Message = reason, RequesterOrderID = requesterOrderID, OrderStatus = order[SingleOrderProperties.OriginalOrderStatus].ToString()
                                                                                 } });
                            }
                        }
                        catch (Exception ex)
                        {
                            Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                            SystemLogger.WriteOnConsoleAsync(true, string.Format("error sending order cancel reject to clients: {0}", ex.Message), ConsoleColor.Red, ConsoleColor.Black, true);
                        }
                    }
                    // update databse
                    try
                    {
                        DatabaseMethods db = new DatabaseMethods();

                        order[SingleOrderProperties.OrderStatus]      = order[SingleOrderProperties.OriginalOrderStatus];
                        order[SingleOrderProperties.IsPending]        = false;
                        order[SingleOrderProperties.Note]             =
                            order[SingleOrderProperties.Note2]        = "Action Status: " + status;
                        order[SingleOrderProperties.ModifiedDateTime] = transactionDateTime == null ? DateTime.Now : transactionDateTime;


                        Dictionary <string, object> orders_Columns = new Dictionary <string, object>();


                        orders_Columns.Add(SingleOrderProperties.OrderStatus, order[SingleOrderProperties.OriginalOrderStatus]);
                        orders_Columns.Add(SingleOrderProperties.Note, order[SingleOrderProperties.Note]);
                        orders_Columns.Add(SingleOrderProperties.Note2, order[SingleOrderProperties.Note2]);
                        orders_Columns.Add(SingleOrderProperties.ActionOnAllocResponse, ActionOnAllocResponse.DoNothing);
                        orders_Columns.Add(SingleOrderProperties.ModifiedDateTime, transactionDateTime == null ? DateTime.Now : transactionDateTime);
                        orders_Columns.Add(SingleOrderProperties.IsPending, false);


                        Dictionary <string, object> orders_Filters = new Dictionary <string, object>();
                        orders_Filters.Add(SingleOrderProperties.OrderID, order[SingleOrderProperties.OrderID]);

                        Dictionary <string, object> ordersDetails_Columns = new Dictionary <string, object>();
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.OrderID, order[SingleOrderProperties.OrderID]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.ClOrderID, order[SingleOrderProperties.ClOrderID]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.OrigClOrdID, order[SingleOrderProperties.OrigClOrdID]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.ExecutionMsgType, msgTypeString);

                        ordersDetails_Columns.Add(SingleOrdDetailsProps.AvgPrice, order[SingleOrderProperties.AvgPrice]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.CurrentPrice, order[SingleOrderProperties.CurrentPrice]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.ExecPrice, order[SingleOrderProperties.LastExecPrice]);

                        ordersDetails_Columns.Add(SingleOrdDetailsProps.CurrentQuantity, order[SingleOrderProperties.CurrentQuantity]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.ExecutedQuantity, order[SingleOrderProperties.ExecutedQuantity]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.LastExecQuantity, order[SingleOrderProperties.LastExecQuantity]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.RemainingQuantity, order[SingleOrderProperties.RemainingQuantity]);

                        ordersDetails_Columns.Add(SingleOrdDetailsProps.ExecType, order[SingleOrderProperties.ExecType]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.OrderStatus, order[SingleOrderProperties.OrderStatus]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.Note, order[SingleOrderProperties.Note]);

                        ordersDetails_Columns.Add(SingleOrdDetailsProps.OrderType, order[SingleOrderProperties.OrderType]);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.TimeInForce, order[SingleOrderProperties.TimeInForce]);

                        ordersDetails_Columns.Add(SingleOrdDetailsProps.IsResponse, true);


                        if (order[SingleOrderProperties.OrderStatus].ToString() == ORD_STATUS.PendingCancel)
                        {
                            ordersDetails_Columns.Add(SingleOrdDetailsProps.IsCancelResponse, true);
                        }
                        else if (order[SingleOrderProperties.OrderStatus].ToString() == ORD_STATUS.PendingReplace)
                        {
                            ordersDetails_Columns.Add(SingleOrdDetailsProps.IsModifyResponse, true);
                        }
                        else
                        {
                            ordersDetails_Columns.Add(SingleOrdDetailsProps.IsModifyResponse, true);
                            ordersDetails_Columns.Add(SingleOrdDetailsProps.IsCancelResponse, true);
                        }


                        ordersDetails_Columns.Add(SingleOrdDetailsProps.DateTime, DateTime.Now);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.ExecutionDate, transactionDateTime == null ? DateTime.Now : transactionDateTime);
                        ordersDetails_Columns.Add(SingleOrdDetailsProps.ExecutionRecievedDateTime, DateTime.Now);


                        db.UpdateOrderDetails(orders_Columns, orders_Filters, ordersDetails_Columns);



                        db = null;
                    }
                    catch (Exception ex)
                    {
                        Counters.IncrementCounter(CountersConstants.ExceptionMessages);
                        SystemLogger.WriteOnConsoleAsync(true, string.Format("error updating order cancel reject into the db error: {0}", ex.Message), ConsoleColor.Red, ConsoleColor.Black, true);
                    }
                }
            }
        }
        public new void crack( QuickFix.Message message,
                     QuickFix.SessionID sessionID )
        {
            QuickFix.MsgType msgType = new QuickFix.MsgType();
            message.getHeader().getField(msgType);
            String msgTypeValue = msgType.getValue();

            if( msgTypeValue == "0" )
              onMessage( (Heartbeat)(message), sessionID );
            else
            if( msgTypeValue == "A" )
              onMessage( (Logon)(message), sessionID );
            else
            if( msgTypeValue == "1" )
              onMessage( (TestRequest)(message), sessionID );
            else
            if( msgTypeValue == "2" )
              onMessage( (ResendRequest)(message), sessionID );
            else
            if( msgTypeValue == "3" )
              onMessage( (Reject)(message), sessionID );
            else
            if( msgTypeValue == "4" )
              onMessage( (SequenceReset)(message), sessionID );
            else
            if( msgTypeValue == "5" )
              onMessage( (Logout)(message), sessionID );
            else
            if( msgTypeValue == "7" )
              onMessage( (Advertisement)(message), sessionID );
            else
            if( msgTypeValue == "6" )
              onMessage( (IndicationofInterest)(message), sessionID );
            else
            if( msgTypeValue == "B" )
              onMessage( (News)(message), sessionID );
            else
            if( msgTypeValue == "C" )
              onMessage( (Email)(message), sessionID );
            else
            if( msgTypeValue == "R" )
              onMessage( (QuoteRequest)(message), sessionID );
            else
            if( msgTypeValue == "S" )
              onMessage( (Quote)(message), sessionID );
            else
            if( msgTypeValue == "i" )
              onMessage( (MassQuote)(message), sessionID );
            else
            if( msgTypeValue == "Z" )
              onMessage( (QuoteCancel)(message), sessionID );
            else
            if( msgTypeValue == "a" )
              onMessage( (QuoteStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "b" )
              onMessage( (QuoteAcknowledgement)(message), sessionID );
            else
            if( msgTypeValue == "V" )
              onMessage( (MarketDataRequest)(message), sessionID );
            else
            if( msgTypeValue == "W" )
              onMessage( (MarketDataSnapshotFullRefresh)(message), sessionID );
            else
            if( msgTypeValue == "X" )
              onMessage( (MarketDataIncrementalRefresh)(message), sessionID );
            else
            if( msgTypeValue == "Y" )
              onMessage( (MarketDataRequestReject)(message), sessionID );
            else
            if( msgTypeValue == "c" )
              onMessage( (SecurityDefinitionRequest)(message), sessionID );
            else
            if( msgTypeValue == "d" )
              onMessage( (SecurityDefinition)(message), sessionID );
            else
            if( msgTypeValue == "e" )
              onMessage( (SecurityStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "f" )
              onMessage( (SecurityStatus)(message), sessionID );
            else
            if( msgTypeValue == "g" )
              onMessage( (TradingSessionStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "h" )
              onMessage( (TradingSessionStatus)(message), sessionID );
            else
            if( msgTypeValue == "D" )
              onMessage( (NewOrderSingle)(message), sessionID );
            else
            if( msgTypeValue == "8" )
              onMessage( (ExecutionReport)(message), sessionID );
            else
            if( msgTypeValue == "Q" )
              onMessage( (DontKnowTrade)(message), sessionID );
            else
            if( msgTypeValue == "G" )
              onMessage( (OrderCancelReplaceRequest)(message), sessionID );
            else
            if( msgTypeValue == "F" )
              onMessage( (OrderCancelRequest)(message), sessionID );
            else
            if( msgTypeValue == "9" )
              onMessage( (OrderCancelReject)(message), sessionID );
            else
            if( msgTypeValue == "H" )
              onMessage( (OrderStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "J" )
              onMessage( (Allocation)(message), sessionID );
            else
            if( msgTypeValue == "P" )
              onMessage( (AllocationACK)(message), sessionID );
            else
            if( msgTypeValue == "T" )
              onMessage( (SettlementInstructions)(message), sessionID );
            else
            if( msgTypeValue == "k" )
              onMessage( (BidRequest)(message), sessionID );
            else
            if( msgTypeValue == "l" )
              onMessage( (BidResponse)(message), sessionID );
            else
            if( msgTypeValue == "E" )
              onMessage( (NewOrderList)(message), sessionID );
            else
            if( msgTypeValue == "m" )
              onMessage( (ListStrikePrice)(message), sessionID );
            else
            if( msgTypeValue == "N" )
              onMessage( (ListStatus)(message), sessionID );
            else
            if( msgTypeValue == "L" )
              onMessage( (ListExecute)(message), sessionID );
            else
            if( msgTypeValue == "K" )
              onMessage( (ListCancelRequest)(message), sessionID );
            else
            if( msgTypeValue == "M" )
              onMessage( (ListStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "j" )
              onMessage( (BusinessMessageReject)(message), sessionID );
            else onMessage( message, sessionID );
        }
Exemple #15
0
 public QuickFix.MsgType get(QuickFix.MsgType value)
 {
     getField(value); return(value);
 }
Exemple #16
0
 public QuickFix.MsgType getMsgType()
 {
     QuickFix.MsgType value = new QuickFix.MsgType();
     getField(value); return(value);
 }
Exemple #17
0
        /// <summary>
        /// Edit the order for the ID specified - throws an exception if the order isnt working
        /// </summary>
        /// <param name="myID"></param>
        /// <param name="newQty">new qty if specified</param>
        /// <param name="newPrice">new price if specified</param>
        public void ReplaceOrder(string myID, double? newQty, double? newPrice, double? newStopPx)
        {
            KaiTrade.Interfaces.Order myOrder = null;
            try
            {
                // Get Order
                KaiTrade.Interfaces.OrderManager myOM = AppFactory.Instance().GetOrderManager();
                myOrder = myOM.GetOrder(myID);
                if (myOrder == null)
                {
                    string myError = "Order not found cannot edit:" + myID;
                    Exception myE = new Exception(myError);
                    throw myE;
                }
                if (m_ORLog.IsInfoEnabled)
                {
                    m_ORLog.Info("ReplaceOrder:"+ myOrder.ToString());
                }
                // are these changes?
                if (!newValueDifferentFromOld(myOrder, newQty, newPrice, newStopPx))
                {
                    string myError = "The new fields in the Replace request are the same as the existing fields" + myID;
                    Exception myE = new Exception(myError);
                    throw myE;
                }
                // Is this a triggered order
                if (myOrder.TriggerOrderID.Length > 0)
                {
                    if (newQty.HasValue)
                    {
                        myOrder.OrderQty = new QuickFix.OrderQty((double)newQty);
                    }

                    if (newPrice.HasValue)
                    {
                        myOrder.Price = new QuickFix.Price((double)newPrice);
                    }
                    if (newStopPx.HasValue)
                    {
                        myOrder.StopPx = new QuickFix.StopPx((double)newStopPx);
                    }
                    return;
                }
                // store the clordID's
                //NOT USED? QuickFix.OrigClOrdID myOrigClOrdID;
                QuickFix.ClOrdID myClOrdID;

                // check if we are pending cancel or pending mod
                if (order.LastOrderCommand == KaiTrade.Interfaces.LastOrderCommand.replace)
                {
                    // we are currently doing a replace - cannot do another
                    string myError = "Order is already processing a replace cannot modify at this time:" + myID;
                    Exception myE = new Exception(myError);
                    throw myE;
                }

                if (order.LastOrderCommand == KaiTrade.Interfaces.LastOrderCommand.cancel)
                {
                    // we are currently doing a cancel - cannot do a mod
                    string myError = "Order is already processing a cancel cannot modify" + myID;
                    Exception myE = new Exception(myError);
                    throw myE;
                }

                // check that the order is working
                if (!myOrder.IsWorking())
                {
                    if ((myOrder.OrdType.getValue() == QuickFix.OrdType.STOP) || (myOrder.OrdType.getValue() == QuickFix.OrdType.STOP_LIMIT))
                    {
                        // no action
                    }
                    else
                    {
                        string myError = "Order is not in a working state cannot replace:" + myID;
                        Exception myE = new Exception(myError);
                        throw myE;
                    }
                }
                // Check the limits for the order
                string myTextErr;
                double qty;
                if (newQty.HasValue)
                {
                    qty = newQty.Value;
                }
                else
                {
                    qty = myOrder.OrderQty.getValue();
                }
                double px;
                if (newPrice.HasValue)
                {
                    px = newPrice.Value;
                }
                else
                {
                    px = myOrder.Price.getValue();
                }
                if (LimitChecker.Instance().BreaksLimits(out myTextErr, myOrder, qty, px))
                {
                    myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED);
                    myOrder.Text = "You have exceeded the order qty limit - please re-enter";
                    Exception myE = new Exception("You have exceeded the order qty limit - please re-enter");
                    throw myE;
                }

                // Create a FIX cancel replace messsage

                QuickFix.Message myFixMsg = new QuickFix.Message();
                QuickFix.MsgType msgType = new QuickFix.MsgType("G");
                myFixMsg.getHeader().setField(msgType);
                QuickFix.BeginString myBeginString = new QuickFix.BeginString("FIX.4.4");
                myFixMsg.getHeader().setField(myBeginString);

                // OrderID
                if (myOrder.OrderID == null)
                {
                    myOrder.Text = "No order ID found cannot modify order";
                    Exception myE = new Exception("No order ID found cannot modify order");
                    throw myE;
                }

                // set the original to the existing clordid
                myOrder.OrigClOrdID = new QuickFix.OrigClOrdID(myOrder.ClOrdID.getValue());
                myFixMsg.setField(myOrder.OrigClOrdID);

                myFixMsg.setField(myOrder.OrderID);

                ////Side
                myFixMsg.setField(myOrder.Side);

                // set up the product details in the message
                myOrder.Product.Set(myFixMsg);

                //// Transact Time
                myOrder.TransactTime = new QuickFix.TransactTime(DateTime.Now.ToUniversalTime());
                myFixMsg.setField(myOrder.TransactTime);

                myFixMsg.setField(myOrder.OrdType);

                // Create the message wrapper used to send the order cancel to the driver
                KaiTrade.Interfaces.Message myMsg = new KaiTCPComm.KaiMessageWrap();

                myMsg.Label = "G";

                string myDriverCode = "";
                // A trade venue must be specified on the order
                KaiTrade.Interfaces.Venue myVenue = null;
                if (myOrder.Product.TradeVenue.Length > 0)
                {
                    // get the driver code and session details from the venue manager
                    myVenue = AppFactory.Instance().GetVenueManager().GetVenue(myOrder.Product.TradeVenue);
                    if (myVenue != null)
                    {
                        myDriverCode = myVenue.DriverCode;
                        if (myVenue.TargetVenue.Length > 0)
                        {
                            myMsg.VenueCode = myVenue.TargetVenue;
                        }
                        if (myVenue.BeginString.Length > 0)
                        {
                            // this is the FIX version the server wants, we convert between
                            // versions in the FIX client
                            myMsg.Format = myVenue.BeginString;
                        }

                        if (myVenue.SID.Length > 0)
                        {
                            QuickFix.SenderCompID mySID = new QuickFix.SenderCompID(myVenue.SID);
                            myFixMsg.getHeader().setField(mySID);
                            myMsg.ClientID = myVenue.SID;
                        }
                        if (myVenue.TID.Length > 0)
                        {
                            QuickFix.TargetCompID myTID = new QuickFix.TargetCompID(myVenue.TID);
                            myFixMsg.getHeader().setField(myTID);
                            myMsg.TargetID = myVenue.TID;
                        }
                    }
                    else
                    {
                        string myErr = "Invalid Venue Code:" + myOrder.Product.TradeVenue;
                        m_Log.Error(myErr);
                        Exception myE = new Exception(myErr);
                        throw myE;
                    }
                }
                else
                {
                    string myErr = "No Venue Code specified on product:";
                    m_Log.Error(myErr);
                    Exception myE = new Exception(myErr);
                    throw myE;
                }

                // process any venue field bags - do this prior to the order bags
                // to allow the order setting to override the venues
                List<KaiTrade.Interfaces.Field> myFieldBag;
                KTAFacade.Instance().SetBag(out myFieldBag, myVenue.ReplaceBag, ",");

                foreach (KaiTrade.Interfaces.Field myField in myFieldBag)
                {
                    try
                    {
                        myFixMsg.setString(int.Parse(myField.ID), myField.Value);
                    }
                    catch (Exception myE)
                    {
                        m_Log.Error("replace Extra tags from venue error:", myE);
                    }
                }

                // process any additional tags for the order
                foreach (KaiTrade.Interfaces.Field myField in myOrder.ReplaceBag)
                {
                    try
                    {
                        myFixMsg.setString(int.Parse(myField.ID), myField.Value);
                    }
                    catch (Exception myE)
                    {
                        m_Log.Error("replace Extra tags error:", myE);
                    }
                }
                if (myOrder.Account != null)
                {
                    if (myOrder.Account.getValue().Length > 0)
                    {
                        myFixMsg.setField(myOrder.Account);
                    }
                }

                try
                {
                    //Send the message
                    KaiTrade.Interfaces.Driver myDrv = AppFactory.Instance().GetDriverManager().GetDriver(myDriverCode);
                    if (myDrv != null)
                    {
                        // save the existing clordid and set the new clordid
                        myClOrdID = myOrder.ClOrdID;
                        myOrder.ClOrdID = new QuickFix.ClOrdID(KaiUtil.Identities.Instance.genReqID());
                        myFixMsg.setField(myOrder.ClOrdID);
                        // Associate the CLOrdID with this order
                        AppFactory.Instance().GetOrderManager().AssociateClOrdID(myOrder.ClOrdID.getValue(), myOrder);

                        if (newQty.HasValue)
                        {
                            myOrder.OrderQty = new QuickFix.OrderQty((double)newQty);
                            myFixMsg.setField(myOrder.OrderQty);
                        }

                        if (newPrice.HasValue)
                        {
                            myOrder.Price = new QuickFix.Price((double)newPrice);
                            myFixMsg.setField(myOrder.Price);
                        }
                        if (newStopPx.HasValue)
                        {
                            myOrder.StopPx = new QuickFix.StopPx((double)newStopPx);
                            myFixMsg.setField(myOrder.StopPx);
                        }

                        // Set the FIX string as message data
                        myMsg.Data = myFixMsg.ToString();

                        // inform order manager clients that the order has changed
                        myOM.SetChanged(myOrder.Identity);
                        // send the message for processing
                        //myDrv.Send(myMsg);
                        // send the message for processing
                        order.LastOrderCommand = KaiTrade.Interfaces.LastOrderCommand.replace;
                        //SendDelegate mySend = new SendDelegate(myDrv.Send);
                        //IAsyncResult ar = mySend.BeginInvoke(myMsg, SRCallback, "123456789");
                        myDrv.Send(myMsg);
                    }
                    else
                    {
                        string myError = "Driver not found for code:" + myDriverCode;
                        m_Log.Error(myError);
                        Exception myE = new Exception(myError);
                        throw myE;
                    }
                }
                catch (Exception myE)
                {
                    m_Log.Error("EditOrder:Sendnessage part" + myOrder.Identity, myE);
                    myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED);
                    throw (myE);
                }
            }
            catch (Exception myE)
            {
                m_Log.Error("ReplaceOrder:", myE);
                if (myOrder != null)
                {
                    myOrder.OrdStatus = new QuickFix.OrdStatus(QuickFix.OrdStatus.REJECTED);
                    myOrder.Text = myE.Message;
                }
                throw (myE);
            }
        }
Exemple #18
0
 public QuickFix.MsgType getMsgType()
 { QuickFix.MsgType value = new QuickFix.MsgType();
   getField(value); return value; }
        public new void crack(QuickFix.Message message,
                              QuickFix.SessionID sessionID)
        {
            QuickFix.MsgType msgType = new QuickFix.MsgType();
            message.getHeader().getField(msgType);
            String msgTypeValue = msgType.getValue();

            if (msgTypeValue == "0")
            {
                onMessage((Heartbeat)(message), sessionID);
            }
            else
            if (msgTypeValue == "A")
            {
                onMessage((Logon)(message), sessionID);
            }
            else
            if (msgTypeValue == "1")
            {
                onMessage((TestRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "2")
            {
                onMessage((ResendRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "3")
            {
                onMessage((Reject)(message), sessionID);
            }
            else
            if (msgTypeValue == "4")
            {
                onMessage((SequenceReset)(message), sessionID);
            }
            else
            if (msgTypeValue == "5")
            {
                onMessage((Logout)(message), sessionID);
            }
            else
            if (msgTypeValue == "7")
            {
                onMessage((Advertisement)(message), sessionID);
            }
            else
            if (msgTypeValue == "6")
            {
                onMessage((IndicationofInterest)(message), sessionID);
            }
            else
            if (msgTypeValue == "B")
            {
                onMessage((News)(message), sessionID);
            }
            else
            if (msgTypeValue == "C")
            {
                onMessage((Email)(message), sessionID);
            }
            else
            if (msgTypeValue == "R")
            {
                onMessage((QuoteRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "S")
            {
                onMessage((Quote)(message), sessionID);
            }
            else
            if (msgTypeValue == "i")
            {
                onMessage((MassQuote)(message), sessionID);
            }
            else
            if (msgTypeValue == "Z")
            {
                onMessage((QuoteCancel)(message), sessionID);
            }
            else
            if (msgTypeValue == "a")
            {
                onMessage((QuoteStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "b")
            {
                onMessage((QuoteAcknowledgement)(message), sessionID);
            }
            else
            if (msgTypeValue == "V")
            {
                onMessage((MarketDataRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "W")
            {
                onMessage((MarketDataSnapshotFullRefresh)(message), sessionID);
            }
            else
            if (msgTypeValue == "X")
            {
                onMessage((MarketDataIncrementalRefresh)(message), sessionID);
            }
            else
            if (msgTypeValue == "Y")
            {
                onMessage((MarketDataRequestReject)(message), sessionID);
            }
            else
            if (msgTypeValue == "c")
            {
                onMessage((SecurityDefinitionRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "d")
            {
                onMessage((SecurityDefinition)(message), sessionID);
            }
            else
            if (msgTypeValue == "e")
            {
                onMessage((SecurityStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "f")
            {
                onMessage((SecurityStatus)(message), sessionID);
            }
            else
            if (msgTypeValue == "g")
            {
                onMessage((TradingSessionStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "h")
            {
                onMessage((TradingSessionStatus)(message), sessionID);
            }
            else
            if (msgTypeValue == "D")
            {
                onMessage((NewOrderSingle)(message), sessionID);
            }
            else
            if (msgTypeValue == "8")
            {
                onMessage((ExecutionReport)(message), sessionID);
            }
            else
            if (msgTypeValue == "Q")
            {
                onMessage((DontKnowTrade)(message), sessionID);
            }
            else
            if (msgTypeValue == "G")
            {
                onMessage((OrderCancelReplaceRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "F")
            {
                onMessage((OrderCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "9")
            {
                onMessage((OrderCancelReject)(message), sessionID);
            }
            else
            if (msgTypeValue == "H")
            {
                onMessage((OrderStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "J")
            {
                onMessage((Allocation)(message), sessionID);
            }
            else
            if (msgTypeValue == "P")
            {
                onMessage((AllocationACK)(message), sessionID);
            }
            else
            if (msgTypeValue == "T")
            {
                onMessage((SettlementInstructions)(message), sessionID);
            }
            else
            if (msgTypeValue == "k")
            {
                onMessage((BidRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "l")
            {
                onMessage((BidResponse)(message), sessionID);
            }
            else
            if (msgTypeValue == "E")
            {
                onMessage((NewOrderList)(message), sessionID);
            }
            else
            if (msgTypeValue == "m")
            {
                onMessage((ListStrikePrice)(message), sessionID);
            }
            else
            if (msgTypeValue == "N")
            {
                onMessage((ListStatus)(message), sessionID);
            }
            else
            if (msgTypeValue == "L")
            {
                onMessage((ListExecute)(message), sessionID);
            }
            else
            if (msgTypeValue == "K")
            {
                onMessage((ListCancelRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "M")
            {
                onMessage((ListStatusRequest)(message), sessionID);
            }
            else
            if (msgTypeValue == "j")
            {
                onMessage((BusinessMessageReject)(message), sessionID);
            }
            else
            {
                onMessage(message, sessionID);
            }
        }
Exemple #20
0
 public Message(QuickFix.MsgType msgType) : base(new QuickFix.BeginString("FIXT.1.1"), msgType)
 {
     m_header  = new Header(this);
     m_trailer = new Trailer(this);
 }
        public new void crack( QuickFix.Message message,
                     QuickFix.SessionID sessionID )
        {
            QuickFix.MsgType msgType = new QuickFix.MsgType();
            message.getHeader().getField(msgType);
            String msgTypeValue = msgType.getValue();

            if( msgTypeValue == "0" )
              onMessage( (Heartbeat)(message), sessionID );
            else
            if( msgTypeValue == "A" )
              onMessage( (Logon)(message), sessionID );
            else
            if( msgTypeValue == "1" )
              onMessage( (TestRequest)(message), sessionID );
            else
            if( msgTypeValue == "2" )
              onMessage( (ResendRequest)(message), sessionID );
            else
            if( msgTypeValue == "3" )
              onMessage( (Reject)(message), sessionID );
            else
            if( msgTypeValue == "4" )
              onMessage( (SequenceReset)(message), sessionID );
            else
            if( msgTypeValue == "5" )
              onMessage( (Logout)(message), sessionID );
            else
            if( msgTypeValue == "j" )
              onMessage( (BusinessMessageReject)(message), sessionID );
            else
            if( msgTypeValue == "BE" )
              onMessage( (UserRequest)(message), sessionID );
            else
            if( msgTypeValue == "BF" )
              onMessage( (UserResponse)(message), sessionID );
            else
            if( msgTypeValue == "7" )
              onMessage( (Advertisement)(message), sessionID );
            else
            if( msgTypeValue == "6" )
              onMessage( (IndicationOfInterest)(message), sessionID );
            else
            if( msgTypeValue == "B" )
              onMessage( (News)(message), sessionID );
            else
            if( msgTypeValue == "C" )
              onMessage( (Email)(message), sessionID );
            else
            if( msgTypeValue == "R" )
              onMessage( (QuoteRequest)(message), sessionID );
            else
            if( msgTypeValue == "AJ" )
              onMessage( (QuoteResponse)(message), sessionID );
            else
            if( msgTypeValue == "AG" )
              onMessage( (QuoteRequestReject)(message), sessionID );
            else
            if( msgTypeValue == "AH" )
              onMessage( (RFQRequest)(message), sessionID );
            else
            if( msgTypeValue == "S" )
              onMessage( (Quote)(message), sessionID );
            else
            if( msgTypeValue == "Z" )
              onMessage( (QuoteCancel)(message), sessionID );
            else
            if( msgTypeValue == "a" )
              onMessage( (QuoteStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "AI" )
              onMessage( (QuoteStatusReport)(message), sessionID );
            else
            if( msgTypeValue == "i" )
              onMessage( (MassQuote)(message), sessionID );
            else
            if( msgTypeValue == "b" )
              onMessage( (MassQuoteAcknowledgement)(message), sessionID );
            else
            if( msgTypeValue == "V" )
              onMessage( (MarketDataRequest)(message), sessionID );
            else
            if( msgTypeValue == "W" )
              onMessage( (MarketDataSnapshotFullRefresh)(message), sessionID );
            else
            if( msgTypeValue == "X" )
              onMessage( (MarketDataIncrementalRefresh)(message), sessionID );
            else
            if( msgTypeValue == "Y" )
              onMessage( (MarketDataRequestReject)(message), sessionID );
            else
            if( msgTypeValue == "c" )
              onMessage( (SecurityDefinitionRequest)(message), sessionID );
            else
            if( msgTypeValue == "d" )
              onMessage( (SecurityDefinition)(message), sessionID );
            else
            if( msgTypeValue == "v" )
              onMessage( (SecurityTypeRequest)(message), sessionID );
            else
            if( msgTypeValue == "w" )
              onMessage( (SecurityTypes)(message), sessionID );
            else
            if( msgTypeValue == "x" )
              onMessage( (SecurityListRequest)(message), sessionID );
            else
            if( msgTypeValue == "y" )
              onMessage( (SecurityList)(message), sessionID );
            else
            if( msgTypeValue == "z" )
              onMessage( (DerivativeSecurityListRequest)(message), sessionID );
            else
            if( msgTypeValue == "AA" )
              onMessage( (DerivativeSecurityList)(message), sessionID );
            else
            if( msgTypeValue == "e" )
              onMessage( (SecurityStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "f" )
              onMessage( (SecurityStatus)(message), sessionID );
            else
            if( msgTypeValue == "g" )
              onMessage( (TradingSessionStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "h" )
              onMessage( (TradingSessionStatus)(message), sessionID );
            else
            if( msgTypeValue == "D" )
              onMessage( (NewOrderSingle)(message), sessionID );
            else
            if( msgTypeValue == "8" )
              onMessage( (ExecutionReport)(message), sessionID );
            else
            if( msgTypeValue == "Q" )
              onMessage( (DontKnowTrade)(message), sessionID );
            else
            if( msgTypeValue == "G" )
              onMessage( (OrderCancelReplaceRequest)(message), sessionID );
            else
            if( msgTypeValue == "F" )
              onMessage( (OrderCancelRequest)(message), sessionID );
            else
            if( msgTypeValue == "9" )
              onMessage( (OrderCancelReject)(message), sessionID );
            else
            if( msgTypeValue == "H" )
              onMessage( (OrderStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "q" )
              onMessage( (OrderMassCancelRequest)(message), sessionID );
            else
            if( msgTypeValue == "r" )
              onMessage( (OrderMassCancelReport)(message), sessionID );
            else
            if( msgTypeValue == "AF" )
              onMessage( (OrderMassStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "s" )
              onMessage( (NewOrderCross)(message), sessionID );
            else
            if( msgTypeValue == "t" )
              onMessage( (CrossOrderCancelReplaceRequest)(message), sessionID );
            else
            if( msgTypeValue == "u" )
              onMessage( (CrossOrderCancelRequest)(message), sessionID );
            else
            if( msgTypeValue == "AB" )
              onMessage( (NewOrderMultileg)(message), sessionID );
            else
            if( msgTypeValue == "AC" )
              onMessage( (MultilegOrderCancelReplaceRequest)(message), sessionID );
            else
            if( msgTypeValue == "k" )
              onMessage( (BidRequest)(message), sessionID );
            else
            if( msgTypeValue == "l" )
              onMessage( (BidResponse)(message), sessionID );
            else
            if( msgTypeValue == "E" )
              onMessage( (NewOrderList)(message), sessionID );
            else
            if( msgTypeValue == "m" )
              onMessage( (ListStrikePrice)(message), sessionID );
            else
            if( msgTypeValue == "N" )
              onMessage( (ListStatus)(message), sessionID );
            else
            if( msgTypeValue == "L" )
              onMessage( (ListExecute)(message), sessionID );
            else
            if( msgTypeValue == "K" )
              onMessage( (ListCancelRequest)(message), sessionID );
            else
            if( msgTypeValue == "M" )
              onMessage( (ListStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "J" )
              onMessage( (AllocationInstruction)(message), sessionID );
            else
            if( msgTypeValue == "P" )
              onMessage( (AllocationInstructionAck)(message), sessionID );
            else
            if( msgTypeValue == "AS" )
              onMessage( (AllocationReport)(message), sessionID );
            else
            if( msgTypeValue == "AT" )
              onMessage( (AllocationReportAck)(message), sessionID );
            else
            if( msgTypeValue == "AK" )
              onMessage( (Confirmation)(message), sessionID );
            else
            if( msgTypeValue == "AU" )
              onMessage( (ConfirmationAck)(message), sessionID );
            else
            if( msgTypeValue == "BH" )
              onMessage( (ConfirmationRequest)(message), sessionID );
            else
            if( msgTypeValue == "T" )
              onMessage( (SettlementInstructions)(message), sessionID );
            else
            if( msgTypeValue == "AV" )
              onMessage( (SettlementInstructionRequest)(message), sessionID );
            else
            if( msgTypeValue == "AD" )
              onMessage( (TradeCaptureReportRequest)(message), sessionID );
            else
            if( msgTypeValue == "AQ" )
              onMessage( (TradeCaptureReportRequestAck)(message), sessionID );
            else
            if( msgTypeValue == "AE" )
              onMessage( (TradeCaptureReport)(message), sessionID );
            else
            if( msgTypeValue == "AR" )
              onMessage( (TradeCaptureReportAck)(message), sessionID );
            else
            if( msgTypeValue == "o" )
              onMessage( (RegistrationInstructions)(message), sessionID );
            else
            if( msgTypeValue == "p" )
              onMessage( (RegistrationInstructionsResponse)(message), sessionID );
            else
            if( msgTypeValue == "AL" )
              onMessage( (PositionMaintenanceRequest)(message), sessionID );
            else
            if( msgTypeValue == "AM" )
              onMessage( (PositionMaintenanceReport)(message), sessionID );
            else
            if( msgTypeValue == "AN" )
              onMessage( (RequestForPositions)(message), sessionID );
            else
            if( msgTypeValue == "AO" )
              onMessage( (RequestForPositionsAck)(message), sessionID );
            else
            if( msgTypeValue == "AP" )
              onMessage( (PositionReport)(message), sessionID );
            else
            if( msgTypeValue == "AW" )
              onMessage( (AssignmentReport)(message), sessionID );
            else
            if( msgTypeValue == "AX" )
              onMessage( (CollateralRequest)(message), sessionID );
            else
            if( msgTypeValue == "AY" )
              onMessage( (CollateralAssignment)(message), sessionID );
            else
            if( msgTypeValue == "AZ" )
              onMessage( (CollateralResponse)(message), sessionID );
            else
            if( msgTypeValue == "BA" )
              onMessage( (CollateralReport)(message), sessionID );
            else
            if( msgTypeValue == "BB" )
              onMessage( (CollateralInquiry)(message), sessionID );
            else
            if( msgTypeValue == "BC" )
              onMessage( (NetworkStatusRequest)(message), sessionID );
            else
            if( msgTypeValue == "BD" )
              onMessage( (NetworkStatusResponse)(message), sessionID );
            else
            if( msgTypeValue == "BG" )
              onMessage( (CollateralInquiryAck)(message), sessionID );
            else onMessage( message, sessionID );
        }