tryString() public method

Try to get a string field.
public tryString ( Wombat.MamaFieldDescriptor descriptor, string &result ) : bool
descriptor Wombat.MamaFieldDescriptor
result string
return bool
Ejemplo n.º 1
0
        private MamdaOptionContract findContract(
            MamdaSubscription  subscription,
            MamaMsg            msg)
        {
            /*
            * NOTE: fields which are enums can be pubished as integers if feedhandler
            * uses mama-publish-enums-as-ints.  It may also be possible for a feed to
            * publish the numerical value as a string. All enumerated fields must be handled
            * by getting the value based on the field type.
            */

            // Look up the strike price and expiration date
            string contractSymbol = null;
            if (!msg.tryString(MamdaOptionFields.CONTRACT_SYMBOL, ref contractSymbol))
            {
                throw new MamdaDataException ("cannot find contract symbol");
            }

            string fullSymbol = contractSymbol;
            MamdaOptionContract contract = mChain.getContract(fullSymbol);
            if (contract == null)
            {
                string expireDateStr = String.Empty;
                double strikePrice = 0.0;
                string putCall = String.Empty;
                uint openInterest = 0;
                
                msg.tryString(MamdaOptionFields.EXPIRATION_DATE, ref expireDateStr);
                msg.tryF64(MamdaOptionFields.STRIKE_PRICE, ref strikePrice);

                if (msg.tryField (MamdaOptionFields.PUT_CALL, ref tmpfield_))
                {
                    putCall = getFieldAsString(tmpfield_);
                }

                int symbolLen = fullSymbol.Length;
                string symbol   = null;
                string exchange = null;
                int dotIndex = fullSymbol.LastIndexOf('.');
                if (dotIndex > 0)
                {
                    // Have exchange in symbol.
                    exchange = fullSymbol.Substring(dotIndex + 1);
                    symbol   = fullSymbol.Substring(0, dotIndex);
                }
                else
                {
                    exchange = "";
                    symbol = fullSymbol;
                }

                DateTime expireDate = DateTime.MinValue;
                try
                {
                    expireDate = mDateFormat.Parse(expireDateStr);
                }
                catch (FormatException e)
                {
                    throw new MamdaDataException (
                        String.Format("cannot parse expiration date: {0}", expireDateStr));
                }

                MamdaOptionContract.PutOrCall putCallchar = extractPutCall(msg,fullSymbol);
                contract = new MamdaOptionContract(
                    symbol,
                    exchange,
                    expireDate,
                    strikePrice,
                    putCallchar);

               MamdaOptionContract.ExerciseStyle exerciseStyleChar = extractExerciseStyle(msg,fullSymbol);
               contract.setExerciseStyle(exerciseStyleChar);

               
                if (msg.tryU32 (MamdaOptionFields.OPEN_INTEREST, ref openInterest))
                {
                    contract.setOpenInterest( (long)openInterest );
                }

                mChain.addContract(fullSymbol, contract);

                mLastActionContract = contract;
                mLastActionContractFieldState = MamdaFieldState.MODIFIED;
                mLastAction = MamdaOptionAction.Add;
                mLastActionFieldState = MamdaFieldState.MODIFIED;
                foreach (MamdaOptionChainHandler handler in mHandlers)
                {
                    handler.onOptionContractCreate(subscription, this, msg, contract, mChain);
                }
            }
            return contract;
        }
Ejemplo n.º 2
0
		/// <summary>
		/// Get the participant Id from the message.
		/// </summary>
		/// <param name="msg">The MamaMsg instance</param>
		/// <returns>The participant id if it exists or null if this is a
		/// consolidated symbol</returns>
		/// <exception cref="MamdaDataException">If the symbol contains a dot but the part id
		/// cannot be extracted.</exception>
		private string getPartId(MamaMsg msg)
		{
			string partId = null;
			string symbol = null;
            
            if (msg.tryString(MamdaCommonFields.PART_ID, ref partId))
            {
                if (partId != String.Empty)
                    return partId;
            }
            
            if (!msg.tryString(MamdaCommonFields.ISSUE_SYMBOL, ref symbol))
            {
                if (!msg.tryString(MamdaCommonFields.INDEX_SYMBOL, ref symbol))
                {
                    if (!msg.tryString(MamdaCommonFields.SYMBOL, ref symbol))
                    {
                        return null;
                    }
                }
            }
            
       
			int lastDotIndex = symbol.LastIndexOf('.');           
            if (lastDotIndex != -1)
            {
                lastDotIndex++;
                if (lastDotIndex != symbol.Length)
                {
                    return symbol.Substring(lastDotIndex);
                }
            }

			return null;
		}
Ejemplo n.º 3
0
        private void updateFundamentalFields(MamaMsg msg)
        {
            /*
            * NOTE: fields which are enums can be pubished as integers if feedhandler
            * uses mama-publish-enums-as-ints.  It may also be possible for a feed to
            * publish the numerical value as a string. All enumerated fields must be handled
            * by getting the value based on the field type.
            */

            if (msg.tryDateTime(MamdaFundamentalFields.SRC_TIME, ref mSrcTimeStr))
              mSrcTimeStrFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryDateTime(MamdaFundamentalFields.ACTIVITY_TIME, ref mActTimeStr))
              mActTimeStrFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryString(MamdaFundamentalFields.CORP_ACT_TYPE, ref mCorpActType))
              mCorpActTypeFieldState = MamdaFieldState.MODIFIED;
            
            if(msg.tryField (MamdaFundamentalFields.DIVIDEND_FREQ, ref mTmpfield))
            {
                mDivFreq = getFieldAsString(mTmpfield);
                mDivFreqFieldState = MamdaFieldState.MODIFIED;
            }

            if (msg.tryString(MamdaFundamentalFields.DIVIDEND_EX_DATE, ref mDivExDate))
              mDivExDateFieldState = MamdaFieldState.MODIFIED;
            
            if(msg.tryString(MamdaFundamentalFields.DIVIDEND_PAY_DATE, ref mDivPayDate))
              mDivPayDateFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryString(MamdaFundamentalFields.DIVIDEND_REC_DATE, ref mDivRecordDate))
              mDivRecordDateFieldState = MamdaFieldState.MODIFIED;
            
            if(msg.tryString(MamdaFundamentalFields.DIVIDEND_CURRENCY, ref mDivCurrency))
              mDivCurrencyFieldState = MamdaFieldState.MODIFIED;

            if (msg.tryString(MamdaFundamentalFields.MRKT_SEGM_NATIVE, ref mMrktSegmNative))
              mMrktSegmNativeFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryString(MamdaFundamentalFields.MRKT_SECT_NATIVE, ref mMrktSectNative))
              mMrktSectNativeFieldState = MamdaFieldState.MODIFIED;

            if(msg.tryField (MamdaFundamentalFields.MRKT_SEGMENT, ref mTmpfield))
            {
                mMarketSegment = getFieldAsString(mTmpfield);
                mMarketSegmentFieldState = MamdaFieldState.MODIFIED;
            }

            if(msg.tryField (MamdaFundamentalFields.MRKT_SECTOR, ref mTmpfield))
            {
                mMarketSector = getFieldAsString(mTmpfield);
                mMarketSectorFieldState = MamdaFieldState.MODIFIED;
            }

            if (msg.tryI64  (MamdaFundamentalFields.SHARES_OUT, ref mSharesOut))
              mSharesOutFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryI64  (MamdaFundamentalFields.SHARES_FLOAT, ref mSharesFloat))
              mSharesFloatFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryI64  (MamdaFundamentalFields.SHARES_AUTH, ref mSharesAuth))
              mSharesAuthFieldState = MamdaFieldState.MODIFIED;

            if (msg.tryF64(MamdaFundamentalFields.DIVIDEND_PRICE, ref mDividendPrice))
              mDividendPriceFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryF64(MamdaFundamentalFields.EARN_PER_SHARE, ref mEarnPerShare))
              mEarnPerShareFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryF64(MamdaFundamentalFields.VOLATILITY, ref mVolatility))
              mVolatilityFieldState = MamdaFieldState.MODIFIED;

            if (msg.tryF64(MamdaFundamentalFields.PRICE_EARN_RATIO, ref mPeRatio))
              mPeRatioFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryF64(MamdaFundamentalFields.YIELD, ref mYield))
              mYieldFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryF64(MamdaFundamentalFields.HIST_VOLATILITY, ref mHistVolatility))
              mHistVolatilityFieldState = MamdaFieldState.MODIFIED;
            
            if (msg.tryF64(MamdaFundamentalFields.RISK_FREE_RATE, ref mRiskFreeRate))
              mRiskFreeRateFieldState = MamdaFieldState.MODIFIED;
        }
Ejemplo n.º 4
0
        private void getEntries(
            MamdaOrderBookPriceLevel level,
            MamaMsg plMsg)
        {
            /* Entries may or may not exist in the message.  If they do exist,
             * they exist as a vector of submessages, separate submessages, or
             * (if there is only one entry in the message) in the price level
             * message itself. */

            /* Optional order book fields: */
            MamaMsg[] msgEntries = null;
            /*We won't have PL_ENTRIES if FieldAttrsOrderBookWombatMsg
             is not specified in the data dictionary*/
            if (MamdaOrderBookFields.PL_ENTRIES != null)
            {
                /* null is passed as default value otherwise
                    getVectorMsg throws an exception if not found*/
                msgEntries = plMsg.getVectorMsg(MamdaOrderBookFields.PL_ENTRIES, null);
            }
            if (msgEntries != null)
            {
                MamdaOrderBookEntry[] entries = new MamdaOrderBookEntry[msgEntries.Length];
                for (int j = 0; j < msgEntries.Length; j++)
                {
                    MamaMsg entMsg = msgEntries[j];
                    if (entMsg != null)
                    {
                        MamdaOrderBookEntry entry = new MamdaOrderBookEntry();
                        getEntryInfo(entry, entMsg, level);
                        level.addEntry(entry);
                    }
                }
                return;
            }

            /* Second, try the list of entries. */
            int maxEntryFields = MamdaOrderBookFields.PL_ENTRY.Length;

            // Get the number of attached sub messages
            int numEntryAttached = plMsg.getI32(MamdaOrderBookFields.PL_NUM_ATTACH, 0);

            // If there are no sub messages attempt to get the entry Id from this price level message
            if (0 == numEntryAttached)
            {
                string entID = null;
                // Check for the entry Id
                if (plMsg.tryString(MamdaOrderBookFields.ENTRY_ID, ref entID))
                {
                    // Add a new entry to the level
                    MamdaOrderBookEntry entry = new MamdaOrderBookEntry();
                    getEntryInfo(entry, plMsg, level);
                    level.addEntry(entry);
                }
            }

            else
            {
                // Ensure we dont' enumerate beyond the maximum number of entries
                if (numEntryAttached < maxEntryFields)
                {
                    maxEntryFields = numEntryAttached;
                }

                // Enumerate all the entries
                for (int j = 1; j <= maxEntryFields; j++)
                {
                    // Get the sub message
                    MamaMsg entMsg = plMsg.getMsg(MamdaOrderBookFields.PL_ENTRY[j], null);
                    if (entMsg != null)
                    {
                        // Add an entry for this level
                        MamdaOrderBookEntry entry = new MamdaOrderBookEntry();
                        getEntryInfo(entry, entMsg, level);
                        level.addEntry(entry);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void handleStandardFields(MamdaSubscription subscription,
                                           MamaMsg msg,
                                           bool checkSeqNum)
        {
            if (mSymbol == null)
                msg.tryString (MamdaCommonFields.SYMBOL, ref mSymbol);

            if (mPartId == null)
            {
                if ((!msg.tryString (MamdaOrderBookFields.PART_ID, ref mPartId)) && (mSymbol != null))
                {
                    // No explicit part ID in message, but maybe in symbol.
                    int lastDot = mSymbol.IndexOf (".");
                    if (lastDot != -1)
                    {
                        lastDot++;
                        int lastChar = mSymbol.Length;
                        if (lastDot != lastChar)
                        {
                            mPartId = mSymbol.Substring (lastDot, (lastChar-lastDot));
                        }
                    }
                }
            }

            msg.tryDateTime (MamdaOrderBookFields.SRC_TIME, ref mSrcTime);
            msg.tryDateTime (MamdaOrderBookFields.ACTIVITY_TIME, ref mActivityTime);
            msg.tryDateTime (MamdaOrderBookFields.LINE_TIME, ref mLineTime);
            msg.tryDateTime (MamaReservedFields.SendTime, ref mSendTime);

            mEventTime = msg.getDateTime (MamdaOrderBookFields.BOOK_TIME, mSrcTime);

            long seqNum = msg.getI64(MamaReservedFields.SeqNum);
            if (checkSeqNum && (seqNum != (mEventSeqNum + 1)))
            {
                mGapBegin    = mEventSeqNum + 1;
                mGapEnd      = seqNum - 1;
                mEventSeqNum = seqNum;
                invokeGapHandlers (subscription, msg);
            }
            else
            {
                mEventSeqNum = seqNum;
            }
        }