public static void LoadDataRow(ref DataRow destinationRow, List <KeyValuePair <FixTag, string> > fieldMap, QuickFix.Message fixMessage)
        {
            foreach (KeyValuePair <FixTag, string> fixTagToDbField in fieldMap)
            {
                FixTag currentTag  = fixTagToDbField.Key;
                string valueColumn = fixTagToDbField.Value;
                string value;

                if (fixMessage.isSetField((int)currentTag))
                {
                    value = fixMessage.getField((int)currentTag);
                    if (string.IsNullOrEmpty(destinationRow[valueColumn] as string))
                    {
                        if ((int)currentTag == (int)FixTag.MaturityMonthYear)
                        {
                            destinationRow[valueColumn] =
                                FixFieldValueConverter.FormatMaturityDate(value, FixFieldValueConverter.TryGetFixValue(FixTag.MaturityDay, fixMessage));
                        }
                        else
                        {
                            destinationRow[valueColumn] =
                                FixFieldValueConverter.Instance[currentTag, value, valueColumn.Contains("DATE")];
                        }
                    }
                }
                else if (fixMessage.getHeader().isSetField((int)currentTag))
                {
                    value = fixMessage.getHeader().getField((int)currentTag);
                    if (string.IsNullOrEmpty(destinationRow[valueColumn] as string))
                    {
                        destinationRow[valueColumn] = FixFieldValueConverter.Instance[currentTag, value, valueColumn.Contains("DATE")];
                    }
                }
            }
        }
Exemple #2
0
        public void crack(QuickFix.Message message, QuickFix.SessionID sessionID, BeginString beginString)
        {
            String value = beginString.getValue();

            if (value.Equals("FIX.4.0"))
            {
                ((QuickFix40.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.1"))
            {
                ((QuickFix41.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.2"))
            {
                ((QuickFix42.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.3"))
            {
                ((QuickFix43.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.4"))
            {
                ((QuickFix44.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.5.0"))
            {
                ((QuickFix50.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIXT.1.1"))
            {
                if (message.isAdmin())
                {
                    ((QuickFixT11.MessageCracker) this).crack(message, sessionID);
                }
                else
                {
                    ApplVerID applVerID = new ApplVerID();
                    if (!message.getHeader().isSetField(applVerID))
                    {
                        Session session = Session.lookupSession(sessionID);
                        applVerID.setValue(session.getSenderDefaultApplVerID());
                    }
                    else
                    {
                        message.getHeader().getField(applVerID);
                    }

                    crack(message, sessionID, Message.toBeginString(applVerID));
                }
            }
            else
            {
                onMessage(message, sessionID);
            }
        }
Exemple #3
0
 internal static void ReplicateFixMessage(QuickFix.Message msg)
 {
     try
     {
         lock (m_LockedObj)
         {
             string msgTypeString   = msg.getHeader().getField(m_msgTypeTag);
             Guid[] subscribersKeys = GetFixMsgSubscribers(msgTypeString);
             if (subscribersKeys != null && subscribersKeys.Length > 0)
             {
                 foreach (Guid key in subscribersKeys)
                 {
                     PushUpdates(new IReplicationResponse[] { new ReplicatedFixMsg()
                                                              {
                                                                  ClientKey = key, FixMessage = msg.ToString(), ResponseDateTime = DateTime.Now, FixVersion = msg.getHeader().getField(m_fixMsgVersionTag)
                                                              } });
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Counters.IncrementCounter(CountersConstants.ExceptionMessages);
         SystemLogger.WriteOnConsoleAsync(true, string.Format("ReplicateFixMessage, Error: {0} ", ex.Message), ConsoleColor.Red, ConsoleColor.Black, true);
     }
 }
Exemple #4
0
        public new void crack(QuickFix.Message message, QuickFix.SessionID sessionID)
        {
            BeginString beginString = new BeginString();

            message.getHeader().getField(beginString);
            crack(message, sessionID, beginString);
        }
Exemple #5
0
        public new void crack(QuickFix.Message message, QuickFix.SessionID sessionID)
        {
            BeginString beginString = new BeginString();

            message.getHeader().getField(beginString);
            String value = beginString.getValue();

            if (value.Equals("FIX.4.0"))
            {
                ((QuickFix40.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.1"))
            {
                ((QuickFix41.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.2"))
            {
                ((QuickFix42.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.3"))
            {
                ((QuickFix43.MessageCracker) this).crack(message, sessionID);
            }
            else if (value.Equals("FIX.4.4"))
            {
                ((QuickFix44.MessageCracker) this).crack(message, sessionID);
            }
            else
            {
                onMessage(message, sessionID);
            }
        }
        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());
            }
        }
        //See onGatewayStatusMessage or MarketDataSnapshotFullRefresh for example of parsing a group
        public void parseMessage(QuickFix.Message message, QuickFix.SessionID sessionID)
        {
            try
            {
                updateDisplay(message.GetType().FullName);

                QuickFix.SenderSubID     senderID = new SenderSubID();
                QuickFix.TargetSubID     targetID = new TargetSubID();
                QuickFix.OnBehalfOfSubID oboID    = new OnBehalfOfSubID();

                if (message.getHeader().isSetField(senderID))
                {
                    updateDisplay(string.Format("SenderSubID: {0}", message.getHeader().getField(senderID)));
                }

                if (message.getHeader().isSetField(targetID))
                {
                    updateDisplay(string.Format("TargetSubID: {0}", message.getHeader().getField(targetID)));
                }

                if (message.getHeader().isSetField(oboID))
                {
                    updateDisplay(string.Format("OnBehalfOfSubID: {0}", message.getHeader().getField(oboID)));
                }

                foreach (QuickFix.Field f in message)
                {
                    updateDisplay(string.Format("TAG: {0} = {1}", f.getField(), f));
                }
            }
            catch (Exception ex)
            {
                updateDisplay(ex.ToString());
            }
        }
        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 #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);
            }
        }
        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);
            }
        }
        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 #12
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 #13
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 #14
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);
            }
        }
Exemple #15
0
 /**
  * Add the missing tags to the message header, in this case the TargetSubID
  */
 private void setHeader(QuickFix.Message message, QuickFix.SessionID session)
 {
     message.getHeader().setField(new QuickFix.TargetSubID(settings.get(session).getString("TargetSubID")));
 }