Wombat.MamaMsg.tryField C# (CSharp) Method

tryField() public method

Try to get a MAMA msg field. The result contains the reusable field object of the nativeHandle object. Applications calling this method will receive the same reusable object for repeated calls on same nativeHandle object.
public tryField ( Wombat.MamaFieldDescriptor descriptor, Wombat.MamaMsgField &result ) : bool
descriptor Wombat.MamaFieldDescriptor
result Wombat.MamaMsgField
return bool
        public bool tryField(
			MamaFieldDescriptor descriptor,
			ref MamaMsgField result)
        {
            return tryField (null, (ushort)descriptor.getFid(), ref result);
        }

Same methods

MamaMsg::tryField ( string name, ushort fid, Wombat.MamaMsgField &result ) : bool

Usage Example

        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;
        }
All Usage Examples Of Wombat.MamaMsg::tryField
MamaMsg