/// <summary>
        /// Print the contents of the chain to standard out.
        /// </summary>
        public void dump()
        {
            Console.WriteLine("Dump chain: {0}", mSymbol);

            int      i        = 0;
            Iterator callIter = mCallOptions.iterator();
            Iterator putIter  = mPutOptions.iterator();

            while (callIter.hasNext() || putIter.hasNext())
            {
                Console.WriteLine("{0} | ", i);
                if (callIter.hasNext())
                {
                    MamdaOptionContract callContract = (MamdaOptionContract)callIter.next();
                    dump(callContract);
                }
                else
                {
                    Console.Write("          ");
                }

                Console.Write(" | ");

                if (putIter.hasNext())
                {
                    MamdaOptionContract putContract = (MamdaOptionContract)putIter.next();
                    dump(putContract);
                }
                else
                {
                }
                Console.WriteLine();
                ++i;
            }
        }
            /* Ascending expiration month, strike price, and exchange. */
            public int compare(object o1, object o2)
            {
                MamdaOptionContract contract1 = (MamdaOptionContract)o1;
                MamdaOptionContract contract2 = (MamdaOptionContract)o2;

                // Expiration month
                DateTime expiration1 = contract1.getExpireDate();
                DateTime expiration2 = contract2.getExpireDate();
                int      comp        = expiration1.CompareTo(expiration2);

                if (comp == 0)
                {
                    // Strike price
                    double strike1 = contract1.getStrikePrice();
                    double strike2 = contract2.getStrikePrice();
                    comp = strike1.CompareTo(strike2);
                }
                if (comp == 0)
                {
                    // Exchange
                    string exchange1 = contract1.getExchange();
                    string exchange2 = contract2.getExchange();
                    comp = exchange1.CompareTo(exchange2);
                }
                return(comp);
            }
 private void dump(MamdaOptionContract contract)
 {
     Console.Write("{0} {1}   {2}   {3}",
                   contract.getSymbol(),
                   contract.getExchange(),
                   contract.getExpireDate(),
                   contract.getStrikePrice());
 }
Example #4
0
 /// <summary>
 /// Handler for option chain structural updates.
 /// </summary>
 /// <param name="subscription"></param>
 /// <param name="listener"></param>
 /// <param name="msg"></param>
 /// <param name="contract"></param>
 /// <param name="chain"></param>
 public void onOptionContractCreate(
     MamdaSubscription subscription,
     MamdaOptionChainListener listener,
     MamaMsg msg,
     MamdaOptionContract contract,
     MamdaOptionChain chain)
 {
     resetRange();
 }
Example #5
0
        /// <summary>
        /// Return whether an option contract falls within this view's
        /// parameters.
        /// </summary>
        /// <param name="contract"></param>
        /// <returns></returns>
        public bool isVisible(MamdaOptionContract contract)
        {
            double   strikePrice = contract.getStrikePrice();
            DateTime expireDate  = contract.getExpireDate();

            return((mLowExpireDate <= expireDate) &&
                   (mHighExpireDate >= expireDate) &&
                   (mLowStrike <= strikePrice) &&
                   (strikePrice <= mHighStrike));
        }
        /// <summary>
        /// Add an option contract.  This method would not normally be
        /// invoked by a user application.  Rather,
        /// MamdaOptionChainListener would be most likely to call this
        /// method.
        /// </summary>
        /// <param name="contractSymbol">The option instrument symbol.</param>
        /// <param name="contract">The Mamda option contract representation.</param>
        public void addContract(
            string contractSymbol,
            MamdaOptionContract contract)
        {
            DateTime expireDate  = contract.getExpireDate();
            double   strikePrice = contract.getStrikePrice();
            string   exchange    = contract.getExchange();

            MamdaOptionContract.PutOrCall putCall = contract.getPutCall();

            mOptions.put(contractSymbol, contract);
            if (putCall == MamdaOptionContract.PutOrCall.Call)
            {
                mCallOptions.add(contract);
            }
            else
            {
                mPutOptions.add(contract);
            }

            // Add the contract to the expiration-by-strike set.
            MamdaOptionExpirationStrikes expireStrikes = (MamdaOptionExpirationStrikes)mExpirationSet.valueOf(expireDate);

            if (expireStrikes == null)
            {
                expireStrikes = new MamdaOptionExpirationStrikes();
                mExpirationSet.put(expireDate, expireStrikes);
            }
            MamdaOptionStrikeSet strikeSet = (MamdaOptionStrikeSet)expireStrikes.valueOf(strikePrice);

            if (strikeSet == null)
            {
                strikeSet = new MamdaOptionStrikeSet(expireDate, strikePrice);
                expireStrikes.put(strikePrice, strikeSet);
            }
            MamdaOptionContractSet contractSet = (putCall == MamdaOptionContract.PutOrCall.Call) ?
                                                 strikeSet.getCallSet() : strikeSet.getPutSet();

            if (MamdaOptionExchangeUtils.isBbo(exchange))
            {
                contractSet.setBboContract(contract);
            }
            else if (MamdaOptionExchangeUtils.isWombatBbo(exchange))
            {
                contractSet.setWombatBboContract(contract);
            }
            else
            {
                contractSet.setExchangeContract(exchange, contract);
                mExchanges.add(exchange);
            }
            mStrikePrices.add(strikePrice);
        }
        private void handleTradeMsg(
            MamdaOptionContract contract,
            MamdaSubscription subscription,
            MamaMsg msg,
            mamaMsgType msgType)
        {
            MamdaTradeListener tradeListener = contract.getTradeListener();

            if (tradeListener != null)
            {
                tradeListener.onMsg(subscription, msg, msgType);
            }
        }
        /*      End Field State Accessors   */

        private void handleQuoteMsg(
            MamdaOptionContract contract,
            MamdaSubscription subscription,
            MamaMsg msg,
            mamaMsgType msgType)
        {
            MamdaQuoteListener quoteListener = contract.getQuoteListener();

            if (quoteListener != null)
            {
                quoteListener.onMsg(subscription, msg, msgType);
            }
        }
        /// <summary>
        /// Implementation of MamdaListener interface.
        /// </summary>
        /// <param name="subscription"></param>
        /// <param name="msg"></param>
        /// <param name="msgType"></param>
        public void onMsg(
            MamdaSubscription subscription,
            MamaMsg msg,
            mamaMsgType msgType)
        {
            if (!MamdaOptionFields.isSet())
            {
                return;
            }

            if (msgType == mamaMsgType.MAMA_MSG_TYPE_END_OF_INITIALS)
            {
                foreach (MamdaOptionChainHandler handler in mHandlers)
                {
                    handler.onOptionChainRecap(subscription, this, msg, mChain);
                }
                return;
            }

            MamdaOptionContract contract = findContract(subscription, msg);

            switch (msgType)
            {
            case mamaMsgType.MAMA_MSG_TYPE_INITIAL:
            case mamaMsgType.MAMA_MSG_TYPE_RECAP:
                handleQuoteMsg(contract, subscription, msg, msgType);
                handleTradeMsg(contract, subscription, msg, msgType);
                break;

            case mamaMsgType.MAMA_MSG_TYPE_QUOTE:
                handleQuoteMsg(contract, subscription, msg, msgType);
                break;

            case mamaMsgType.MAMA_MSG_TYPE_TRADE:
            case mamaMsgType.MAMA_MSG_TYPE_CANCEL:
            case mamaMsgType.MAMA_MSG_TYPE_ERROR:
            case mamaMsgType.MAMA_MSG_TYPE_CORRECTION:
                handleTradeMsg(contract, subscription, msg, msgType);
                break;
            }
        }
        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);
        }
 /// <summary>
 /// Set the contract for the best bid and offer, as calculated
 /// by Wombat.
 /// </summary>
 /// <param name="contract"></param>
 public void setWombatBboContract(MamdaOptionContract contract)
 {
     mWombatmBboContract = contract;
 }
Example #12
0
		private void handleTradeMsg(
			MamdaOptionContract  contract,
			MamdaSubscription    subscription,
			MamaMsg              msg,
			mamaMsgType          msgType)
		{
			MamdaTradeListener tradeListener = contract.getTradeListener();
			if (tradeListener != null)
			{
				tradeListener.onMsg(subscription, msg, msgType);
			}
		}	
Example #13
0
        /// <summary>
        /// Handler for option chain structural updates.
        /// </summary>
        /// <param name="subscription"></param>
        /// <param name="listener"></param>
        /// <param name="msg"></param>
        /// <param name="contract"></param>
        /// <param name="chain"></param>
        public void onOptionContractCreate(
			MamdaSubscription         subscription,
			MamdaOptionChainListener  listener,
			MamaMsg                   msg,
			MamdaOptionContract       contract,
			MamdaOptionChain          chain)
        {
            resetRange();
        }
 /// <summary>
 /// Set the contract for the particular exchange.
 /// </summary>
 /// <param name="exchange"></param>
 /// <param name="contract"></param>
 public void setExchangeContract(
     string exchange,
     MamdaOptionContract contract)
 {
     mExchangeContracts.put(exchange, contract);
 }
Example #15
0
 /// <summary>
 /// Set the contract for the best bid and offer, as calculated
 /// by Wombat.
 /// </summary>
 /// <param name="contract"></param>
 public void setWombatBboContract(MamdaOptionContract contract)
 {
     mWombatmBboContract = contract;
 }
Example #16
0
        /// <summary>
        /// Set the contract for the particular exchange.
        /// </summary>
        /// <param name="exchange"></param>
        /// <param name="contract"></param>
        public void setExchangeContract(
			string               exchange,
			MamdaOptionContract  contract)
        {
            mExchangeContracts.put(exchange, contract);
        }
Example #17
0
 /// <summary>
 /// Set the contract for the best bid and offer.
 /// </summary>
 /// <param name="contract"></param>
 public void setBboContract(MamdaOptionContract contract)
 {
     mBboContract = contract;
 }
Example #18
0
 /// <summary>
 /// Return whether an option contract falls within this view's
 /// parameters.
 /// </summary>
 /// <param name="contract"></param>
 /// <returns></returns>
 public bool isVisible(MamdaOptionContract contract)
 {
     double strikePrice = contract.getStrikePrice();
     DateTime expireDate  = contract.getExpireDate();
     return ((mLowExpireDate <= expireDate) &&
             (mHighExpireDate >= expireDate) &&
             (mLowStrike <= strikePrice) &&
             (strikePrice <= mHighStrike));
 }
Example #19
0
		/// <summary>
		/// Add an option contract.  This method would not normally be
		/// invoked by a user application.  Rather,
		/// MamdaOptionChainListener would be most likely to call this
		/// method.
		/// </summary>
		/// <param name="contractSymbol">The option instrument symbol.</param>
		/// <param name="contract">The Mamda option contract representation.</param>
		public void addContract(
			string               contractSymbol,
			MamdaOptionContract  contract)
		{
			DateTime expireDate = contract.getExpireDate();
			double strikePrice  = contract.getStrikePrice();
			string exchange     = contract.getExchange();
			MamdaOptionContract.PutOrCall putCall = contract.getPutCall();

			mOptions.put(contractSymbol, contract);
			if (putCall == MamdaOptionContract.PutOrCall.Call)
			{
				mCallOptions.add(contract);
			}
			else
			{
				mPutOptions.add(contract);
			}

			// Add the contract to the expiration-by-strike set.
			MamdaOptionExpirationStrikes expireStrikes = (MamdaOptionExpirationStrikes)mExpirationSet.valueOf(expireDate);
			if (expireStrikes == null)
			{
				expireStrikes = new MamdaOptionExpirationStrikes();
				mExpirationSet.put(expireDate, expireStrikes);
			}
			MamdaOptionStrikeSet strikeSet = (MamdaOptionStrikeSet)expireStrikes.valueOf(strikePrice);
			if (strikeSet == null)
			{
				strikeSet = new MamdaOptionStrikeSet(expireDate, strikePrice);
				expireStrikes.put(strikePrice, strikeSet);
			}
			MamdaOptionContractSet contractSet = (putCall == MamdaOptionContract.PutOrCall.Call) ?
				strikeSet.getCallSet() : strikeSet.getPutSet();
			if (MamdaOptionExchangeUtils.isBbo(exchange))
			{
				contractSet.setBboContract(contract);
			}
			else if (MamdaOptionExchangeUtils.isWombatBbo(exchange))
			{
				contractSet.setWombatBboContract(contract);
			}
			else
			{
				contractSet.setExchangeContract(exchange, contract);
				mExchanges.add(exchange);
			}
			mStrikePrices.add(strikePrice);
		}
Example #20
0
        /*      End Field State Accessors   */

        private void handleQuoteMsg(
			MamdaOptionContract  contract,
			MamdaSubscription    subscription,
			MamaMsg              msg,
			mamaMsgType          msgType)
		{
			MamdaQuoteListener quoteListener = contract.getQuoteListener();
			if (quoteListener != null)
			{
				quoteListener.onMsg(subscription, msg, msgType);
			}
		}
Example #21
0
		private void dump(MamdaOptionContract contract)
		{
			Console.Write("{0} {1}   {2}   {3}",
				contract.getSymbol(),
				contract.getExchange(),
				contract.getExpireDate(),
				contract.getStrikePrice());
		}
Example #22
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;
        }
 /// <summary>
 /// Set the contract for the best bid and offer.
 /// </summary>
 /// <param name="contract"></param>
 public void setBboContract(MamdaOptionContract contract)
 {
     mBboContract = contract;
 }