Пример #1
0
        /// <summary>
        /// To get an option for the underlying futures.
        /// </summary>
        /// <param name="future">Underlying futures.</param>
        /// <param name="provider">The provider of information about instruments.</param>
        /// <param name="strike">Strike.</param>
        /// <param name="expirationDate">The options expiration date.</param>
        /// <param name="optionType">Option type.</param>
        /// <returns>Options contract.</returns>
        public static Security GetOption(this Security future, ISecurityProvider provider, decimal strike, DateTimeOffset expirationDate, OptionTypes optionType)
        {
            if (future == null)
            {
                throw new ArgumentNullException(nameof(future));
            }

            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            var option = provider
                         .Lookup(new Security
            {
                Strike               = strike,
                OptionType           = optionType,
                ExpiryDate           = expirationDate,
                UnderlyingSecurityId = future.Id
            })
                         .FirstOrDefault();

            if (option == null)
            {
                throw new ArgumentException(LocalizedStrings.Str707Params.Put(future.Id), nameof(future));
            }

            return(option);
        }
Пример #2
0
        /// <summary>
        /// To get opposite option (for Call to get Put, for Put to get Call).
        /// </summary>
        /// <param name="option">Options contract.</param>
        /// <param name="provider">The provider of information about instruments.</param>
        /// <returns>The opposite option.</returns>
        public static Security GetOppositeOption(this Security option, ISecurityProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            option.CheckOption();

            var oppositeOption = provider
                                 .Lookup(new Security
            {
                OptionType           = option.OptionType == OptionTypes.Call ? OptionTypes.Put : OptionTypes.Call,
                Strike               = option.Strike,
                ExpiryDate           = option.ExpiryDate,
                UnderlyingSecurityId = option.UnderlyingSecurityId,
            })
                                 .FirstOrDefault();

            if (oppositeOption == null)
            {
                throw new ArgumentException(LocalizedStrings.Str706Params.Put(option.Id), nameof(option));
            }

            return(oppositeOption);
        }
Пример #3
0
 /// <summary>
 /// To get derivatives by the underlying asset.
 /// </summary>
 /// <param name="asset">Underlying asset.</param>
 /// <param name="provider">The provider of information about instruments.</param>
 /// <param name="expirationDate">The expiration date.</param>
 /// <returns>The list of derivatives.</returns>
 /// <remarks>
 /// It returns an empty list if derivatives are not found.
 /// </remarks>
 public static IEnumerable <Security> GetDerivatives(this Security asset, ISecurityProvider provider, DateTimeOffset?expirationDate = null)
 {
     return(provider.Lookup(new Security
     {
         UnderlyingSecurityId = asset.Id,
         ExpiryDate = expirationDate,
     }));
 }
Пример #4
0
        /// <inheritdoc />
        protected override void OnSendInMessage(Message message)
        {
            switch (message.Type)
            {
            case MessageTypes.Reset:
            {
                _subscriptions.Clear();
                break;
            }

            case MessageTypes.SecurityLookup:
            {
                if (_securityProvider != null)
                {
                    var lookupMsg = (SecurityLookupMessage)message;

                    var securities = lookupMsg.SecurityId == default
                                                        ? _securityProvider.LookupAll()
                                                        : _securityProvider.Lookup(lookupMsg);

                    foreach (var security in securities)
                    {
                        SendOutMessage(security.Board.ToMessage());
                        SendOutMessage(security.ToMessage(originalTransactionId: lookupMsg.TransactionId));
                    }

                    SendOutMessage(new SecurityLookupResultMessage {
                            OriginalTransactionId = lookupMsg.TransactionId
                        });
                    return;
                }

                break;
            }

            case MessageTypes.MarketData:
            {
                var mdMsg = (MarketDataMessage)message;

                if (mdMsg.IsSubscribe)
                {
                    _subscriptions.Add(mdMsg.TransactionId);
                }

                break;
            }

            case ExtendedMessageTypes.EmulationState:
                SendOutMessage(message);
                return;
            }

            base.OnSendInMessage(message);
        }
Пример #5
0
 /// <inheritdoc />
 public IEnumerable <Security> Lookup(SecurityLookupMessage criteria)
 {
     return(_inner.SyncGet(d => d.Values.Filter(criteria).ToArray()).Concat(_underlying.Lookup(criteria)).Distinct());
 }
Пример #6
0
		/// <summary>
		/// To get an option for the underlying futures.
		/// </summary>
		/// <param name="future">Underlying futures.</param>
		/// <param name="provider">The provider of information about instruments.</param>
		/// <param name="strike">Strike.</param>
		/// <param name="expirationDate">The options expiration date.</param>
		/// <param name="optionType">Option type.</param>
		/// <returns>Options contract.</returns>
		public static Security GetOption(this Security future, ISecurityProvider provider, decimal strike, DateTimeOffset expirationDate, OptionTypes optionType)
		{
			if (future == null)
				throw new ArgumentNullException("future");

			if (provider == null)
				throw new ArgumentNullException("provider");

			var option = provider
				.Lookup(new Security
				{
					Strike = strike,
					OptionType = optionType,
					ExpiryDate = expirationDate,
					UnderlyingSecurityId = future.Id
				})
				.FirstOrDefault();

			if (option == null)
				throw new ArgumentException(LocalizedStrings.Str707Params.Put(future.Id), "future");

			return option;
		}
Пример #7
0
		/// <summary>
		/// To get opposite option (for Call to get Put, for Put to get Call).
		/// </summary>
		/// <param name="option">Options contract.</param>
		/// <param name="provider">The provider of information about instruments.</param>
		/// <returns>The opposite option.</returns>
		public static Security GetOppositeOption(this Security option, ISecurityProvider provider)
		{
			if (provider == null)
				throw new ArgumentNullException("provider");

			option.CheckOption();

			var oppositeOption = provider
				.Lookup(new Security
				{
					OptionType = option.OptionType == OptionTypes.Call ? OptionTypes.Put : OptionTypes.Call,
					Strike = option.Strike,
					ExpiryDate = option.ExpiryDate,
					UnderlyingSecurityId = option.UnderlyingSecurityId,
				})
				.FirstOrDefault();

			if (oppositeOption == null)
				throw new ArgumentException(LocalizedStrings.Str706Params.Put(option.Id), "option");

			return oppositeOption;
		}
Пример #8
0
		/// <summary>
		/// To get derivatives by the underlying asset.
		/// </summary>
		/// <param name="asset">Underlying asset.</param>
		/// <param name="provider">The provider of information about instruments.</param>
		/// <param name="expirationDate">The expiration date.</param>
		/// <returns>The list of derivatives.</returns>
		/// <remarks>
		/// It returns an empty list if derivatives are not found.
		/// </remarks>
		public static IEnumerable<Security> GetDerivatives(this Security asset, ISecurityProvider provider, DateTimeOffset? expirationDate = null)
		{
			return provider.Lookup(new Security
			{
				UnderlyingSecurityId = asset.Id,
				ExpiryDate = expirationDate,
			});
		}
Пример #9
0
 public override IEnumerable <Security> Lookup(Security criteria)
 {
     return(_securityProvider.Lookup(criteria));
 }