Esempio n. 1
0
        /// <summary>
        /// Decode price FIX message
        /// </summary>
        /// <param name="FIXMsg"></param>
        /// <returns></returns>
        public bool DecodeFIXMessage(IFIXMessage FIXMsg)
        {
            try
            {
                IFIXGroup fixCountGroup = FIXMsg.GetGroupByTag(FIXTagConstants.esFIXTagESNoSecurityPositions, null);
                if (fixCountGroup != null)
                {
                    for (int i = 0; i < fixCountGroup.get_NumberOfGroups(null); i++)
                    {
                        IFIXGroup fixRptGroup = fixCountGroup.GetGroupByIndex(i);

                        string strMnemonic = fixRptGroup.get_AsString(FIXTagConstants.esFIXTagESTickerMnemonic);
                        string strSecExchange = fixRptGroup.get_AsString(FIXTagConstants.esFIXTagSecurityExchange);
                        string strContractGroup = fixRptGroup.get_AsString(FIXTagConstants.esFIXTagESContractGroup);
                        string strContractGroupOffset = fixRptGroup.get_AsString(FIXTagConstants.esFIXTagESMarginGroupOffset);
                        Position thePosition;
                        if (m_Positions.ContainsKey(strMnemonic))
                            thePosition = m_Positions[strMnemonic];
                        else
                        {
                            thePosition = new Position(m_iAccountID);
                            thePosition.Symbol = strMnemonic;
                            m_Positions.Add(strMnemonic, thePosition);
                        }
                        thePosition.DecodeFIXGroup(fixRptGroup);
                    }
                }
                IFIXGroup group = FIXMsg.GetGroupByTag(FIXTagConstants.esFIXTagESNoSecurityExchanges, null);

                if (group != null)
                {
                    int nCount = group.get_NumberOfGroups(null);

                    for (int i = 0; i < nCount; i++)
                    {
                        IFIXGroup singleGroup = group.GetGroupByIndex(i);

                        string sExchange = singleGroup.get_AsString(FIXTagConstants.esFIXTagSecurityExchange);

                        AddTicker(sExchange, singleGroup);
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        /// <summary>
        /// Decode price FIX message
        /// </summary>
        /// <param name="FIXMsg"></param>
        /// <param name="bSnapFull"></param>
        /// <returns></returns>
        public bool DecodeFIX(IFIXMessage FIXMsg,bool bSnapFull)
        {
            bool bReturn = false;
            m_sSymbol = FIXMsg.get_AsString(FIXTagConstants.esFIXTagESTickerMnemonic);

            int nTotal = 0;
            if (FIXMsg.GetNumber(out nTotal, FIXTagConstants.esFIXTagTotalVolumeTraded))
                m_nTotalTradeVolume = nTotal;

            IFIXGroup group = FIXMsg.GetGroupByTag(FIXTagConstants.esFIXTagNoMDEntries, null);

            if (group != null)
            {
                int nCount = group.get_NumberOfGroups(null);

                for (int i = 0; i < nCount; i++)
                {
                    IFIXGroup singleGroup = group.GetGroupByIndex(i);

                    string sType = singleGroup.get_AsString(FIXTagConstants.esFIXTagMDEntryType);

                    int nImplied = singleGroup.get_AsNumber(FIXTagConstants.esFIXTagESMDEntryIsImplied);
                    string sTime = singleGroup.get_AsString(FIXTagConstants.esFIXTagMDEntryTime);

                    bReturn = true;

                    switch (sType)
                    {
                        case MESSAGEFIX3Lib.FIXMarketDataTypeConstants.esFIXMarketDataTypeBestAsk:
                            {
                                switch (nImplied)
                                {
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestFromActual:
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestFromActualAndImplied:
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestFromImplied:
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestImpliedNoActual:
                                        m_eAskOrderType = (Implied)nImplied;
                                        SetPrice(out m_Ask, singleGroup);
                                        break;
                                }
                                break;
                            }
                        case MESSAGEFIX3Lib.FIXMarketDataTypeConstants.esFIXMarketDataTypeBestBid:
                            {
                                switch (nImplied)
                                {
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestFromActual:
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestFromActualAndImplied:
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestFromImplied:
                                    case (int)MESSAGEFIX3Lib.FIXESIsImpliedConstants.esFIXESIsImpliedBestImpliedNoActual:
                                        m_eBidOrderType = (Implied)nImplied;
                                        SetPrice(out m_Bid, singleGroup);
                                        break;
                                }
                                break;
                                break;
                            }

                        case MESSAGEFIX3Lib.FIXMarketDataTypeConstants.esFIXMarketDataTypeSettlementPrice:
                            {
                                int nType = singleGroup.get_AsNumber(FIXTagConstants.esFIXTagOpenCloseSettlementFlag);

                                MESSAGEFIX3Lib.FIXSettlementFlagConstants type = (MESSAGEFIX3Lib.FIXSettlementFlagConstants)nType;

                                double dPrice = singleGroup.get_AsDouble(FIXTagConstants.esFIXTagMDEntryPx);
                                if (type == MESSAGEFIX3Lib.FIXSettlementFlagConstants.esFIXSettlementOpenCloseYesterday)
                                {
                                    m_dSettlement = dPrice;
                                    m_sSettlementTime = singleGroup.get_AsString(FIXTagConstants.esFIXTagMDEntryTime);
                                    m_sSettlementDate = singleGroup.get_AsString(FIXTagConstants.esFIXTagMDEntryDate);
                                }
                                else
                                {
                                    m_dPrevSettlement = dPrice;
                                    m_sPrevSettlementTime = singleGroup.get_AsString(FIXTagConstants.esFIXTagMDEntryTime);
                                    m_sPrevSettlementDate = singleGroup.get_AsString(FIXTagConstants.esFIXTagMDEntryDate);
                                }
                                break;
                            }
                        case MESSAGEFIX3Lib.FIXMarketDataTypeConstants.esFIXMarketDataTypeClosingPrice:
                            {
                                m_dClose = singleGroup.get_AsDouble(FIXTagConstants.esFIXTagMDEntryPx);
                                break;
                            }
                        case MESSAGEFIX3Lib.FIXMarketDataTypeConstants.esFIXMarketDataTypeTrade:
                            {
                                SetPrice(out m_Trade, singleGroup);
                                break;
                            }
                        case MESSAGEFIX3Lib.FIXMarketDataTypeConstants.esFIXMarketDataTypeSessionHighPrice:
                            {
                                m_SessionHigh = singleGroup.get_AsDouble(FIXTagConstants.esFIXTagMDEntryPx);
                                break;
                            }
                        case MESSAGEFIX3Lib.FIXMarketDataTypeConstants.esFIXMarketDataTypeSessionLowPrice:
                            {
                                m_SessionLow = singleGroup.get_AsDouble(FIXTagConstants.esFIXTagMDEntryPx);
                                break;
                            }
                    }
                }
            }
            m_bSnapshot = bSnapFull;
            return bReturn;
        }