/********************************************************
        * CONSTRUCTOR/DELEGATE DEFINITIONS
        *********************************************************/
        /// <summary>
        /// Construct the Market Vehicle
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours, bool useQuantConnectData = false)
        {
            //Set Basics:
            this._symbol = symbol;
            this._type = type;
            this._resolution = resolution;
            this._isFillDataForward = fillDataForward;
            this._leverage = leverage;
            this._isExtendedMarketHours = extendedMarketHours;
            this._isQuantConnectData = useQuantConnectData;

            //Setup Transaction Model for this Asset
            switch (type)
            {
                case SecurityType.Equity:
                    Model = new EquityTransactionModel();
                    break;
                case SecurityType.Forex:
                    Model = new ForexTransactionModel();
                    break;
                case SecurityType.Base:
                    Model = new SecurityTransactionModel();
                    break;
            }

            //Holdings for new Vehicle:
            Cache = new SecurityCache();
            Holdings = new SecurityHolding(symbol, Model);
            Exchange = new SecurityExchange();
        }
Exemple #2
0
        /********************************************************
        * CONSTRUCTOR/DELEGATE DEFINITIONS
        *********************************************************/
        /// <summary>
        /// Construct the Market Vehicle
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours)
        {
            //Set Basics:
            this._symbol = symbol;
            this._type = type;
            this._resolution = resolution;
            this._isFillDataForward = fillDataForward;
            this._leverage = leverage;
            this._isExtendedMarketHours = extendedMarketHours;

            //Holdings for new Vehicle:
            Cache = new SecurityCache();
            Holdings = new SecurityHolding(symbol, Model);
            Exchange = new SecurityExchange();

            //Cannot initalise a default model.
            Model = null;

            //Set data type:
            if (resolution == Resolution.Minute || resolution == Resolution.Second) {
                _dataType = typeof(TradeBar);
            } else {
                _dataType = typeof(Tick);
            }
        }
Exemple #3
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(SecurityExchangeHours exchangeHours, SubscriptionDataConfig config, decimal leverage)
        {
            _config = config;

            Cache = new SecurityCache();
            Exchange = new SecurityExchange(exchangeHours);
            DataFilter = new SecurityDataFilter();
            PortfolioModel = new SecurityPortfolioModel();
            TransactionModel = new SecurityTransactionModel();
            MarginModel = new SecurityMarginModel(leverage);
            Holdings = new SecurityHolding(this);
        }
Exemple #4
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(SubscriptionDataConfig config, decimal leverage, bool isDynamicallyLoadedData = false)
        {
            _config = config;
            _symbol = config.Symbol;
            _isDynamicallyLoadedData = isDynamicallyLoadedData;

            Cache = new SecurityCache();
            Exchange = new SecurityExchange();
            DataFilter = new SecurityDataFilter();
            PortfolioModel = new SecurityPortfolioModel();
            TransactionModel = new SecurityTransactionModel();
            MarginModel = new SecurityMarginModel(leverage);
            Holdings = new SecurityHolding(this);
        }
Exemple #5
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           IBuyingPowerModel buyingPowerModel,
                           ISecurityDataFilter dataFilter,
                           IPriceVariationModel priceVariationModel,
                           ICurrencyConverter currencyConverter,
                           IRegisteredSecurityDataTypesProvider registeredTypesProvider
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException(nameof(symbolProperties), "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            Symbol              = symbol;
            SubscriptionsBag    = new ConcurrentBag <SubscriptionDataConfig>();
            QuoteCurrency       = quoteCurrency;
            SymbolProperties    = symbolProperties;
            IsTradable          = true;
            Cache               = cache;
            Exchange            = exchange;
            DataFilter          = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel      = portfolioModel;
            BuyingPowerModel    = buyingPowerModel;
            FillModel           = fillModel;
            FeeModel            = feeModel;
            SlippageModel       = slippageModel;
            SettlementModel     = settlementModel;
            VolatilityModel     = volatilityModel;
            Holdings            = new SecurityHolding(this, currencyConverter);
            Data = new DynamicSecurityData(registeredTypesProvider, Cache);

            UpdateSubscriptionProperties();
        }
        /// <summary>
        /// Will return the <see cref="SecurityCache"/> instance to use for a give Symbol.
        /// If the provided Symbol is a custom type which has an underlying we will try to use the
        /// underlying SecurityCache type cache, if the underlying is not present we will keep track
        /// of the custom Symbol in case it is added later.
        /// </summary>
        /// <returns>The cache instance to use</returns>
        public SecurityCache GetSecurityCache(Symbol symbol)
        {
            var securityCache = new SecurityCache();

            if (symbol.SecurityType == SecurityType.Base && symbol.HasUnderlying)
            {
                var underlyingSecurity = _securityProvider.GetSecurity(symbol.Underlying);
                if (underlyingSecurity != null)
                {
                    // we found the underlying, lets use its data type cache
                    SecurityCache.ShareTypeCacheInstance(underlyingSecurity.Cache, securityCache);
                }
                else
                {
                    // we didn't find the underlying, lets keep track of the underlying symbol which might get added in the future.
                    // else when it is added, we would have to go through existing Securities and find any which use it as underlying
                    _relatedSymbols.AddOrUpdate(symbol.Underlying,
                                                id => new ConcurrentBag <Symbol> {
                        symbol
                    },
                                                (id, bag) => { bag.Add(symbol); return(bag); }
                                                );
                }
            }
            else
            {
                ConcurrentBag <Symbol> customSymbols;
                if (_relatedSymbols.TryRemove(symbol, out customSymbols))
                {
                    // if we are here it means we added a symbol which is an underlying of some existing custom symbols
                    foreach (var customSymbol in customSymbols)
                    {
                        var customSecurity = _securityProvider.GetSecurity(customSymbol);
                        if (customSecurity != null)
                        {
                            // we make each existing custom security cache, use the new instance data type cache
                            // note that if any data already existed in the custom cache it will be passed
                            SecurityCache.ShareTypeCacheInstance(securityCache, customSecurity.Cache);
                        }
                    }
                }
            }

            return(securityCache);
        }
Exemple #7
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           IVolatilityModel volatilityModel,
                           ISecurityMarginModel marginModel,
                           ISecurityDataFilter dataFilter,
                           IPriceVariationModel priceVariationModel
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _symbol             = symbol;
            SubscriptionsBag    = new ConcurrentBag <SubscriptionDataConfig>();
            QuoteCurrency       = quoteCurrency;
            SymbolProperties    = symbolProperties;
            IsTradable          = true;
            Cache               = cache;
            Exchange            = exchange;
            DataFilter          = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel      = portfolioModel;
            MarginModel         = marginModel;
            FillModel           = fillModel;
            FeeModel            = feeModel;
            SlippageModel       = slippageModel;
            SettlementModel     = settlementModel;
            VolatilityModel     = volatilityModel;
            Holdings            = new SecurityHolding(this);
        }
Exemple #8
0
 /// <summary>
 /// Temporary convenience constructor
 /// </summary>
 protected Security(SubscriptionDataConfig config,
                    Cash quoteCurrency,
                    SymbolProperties symbolProperties,
                    SecurityExchange exchange,
                    SecurityCache cache,
                    ISecurityPortfolioModel portfolioModel,
                    IFillModel fillModel,
                    IFeeModel feeModel,
                    ISlippageModel slippageModel,
                    ISettlementModel settlementModel,
                    IVolatilityModel volatilityModel,
                    IBuyingPowerModel buyingPowerModel,
                    ISecurityDataFilter dataFilter,
                    IPriceVariationModel priceVariationModel,
                    ICurrencyConverter currencyConverter,
                    IRegisteredSecurityDataTypesProvider registeredTypesProvider
                    )
     : this(config.Symbol,
            quoteCurrency,
            symbolProperties,
            exchange,
            cache,
            portfolioModel,
            fillModel,
            feeModel,
            slippageModel,
            settlementModel,
            volatilityModel,
            buyingPowerModel,
            dataFilter,
            priceVariationModel,
            currencyConverter,
            registeredTypesProvider
            )
 {
     SubscriptionsBag.Add(config);
     UpdateSubscriptionProperties();
 }
Exemple #9
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(SubscriptionDataConfig config,
                           Cash quoteCurrency,
                           SymbolProperties symbolProperties,
                           SecurityExchange exchange,
                           SecurityCache cache,
                           ISecurityPortfolioModel portfolioModel,
                           IFillModel fillModel,
                           IFeeModel feeModel,
                           ISlippageModel slippageModel,
                           ISettlementModel settlementModel,
                           ISecurityMarginModel marginModel,
                           ISecurityDataFilter dataFilter
                           )
        {
            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _config          = config;
            QuoteCurrency    = quoteCurrency;
            SymbolProperties = symbolProperties;
            Cache            = cache;
            Exchange         = exchange;
            DataFilter       = dataFilter;
            PortfolioModel   = portfolioModel;
            MarginModel      = marginModel;
            FillModel        = fillModel;
            FeeModel         = feeModel;
            SlippageModel    = slippageModel;
            SettlementModel  = settlementModel;
            Holdings         = new SecurityHolding(this);
        }
Exemple #10
0
 /// <summary>
 /// Construct a new security vehicle based on the user options.
 /// </summary>
 protected Security(SubscriptionDataConfig config,
                    SecurityExchange exchange,
                    SecurityCache cache,
                    ISecurityPortfolioModel portfolioModel,
                    IFillModel fillModel,
                    IFeeModel feeModel,
                    ISlippageModel slippageModel,
                    ISettlementModel settlementModel,
                    ISecurityMarginModel marginModel,
                    ISecurityDataFilter dataFilter
                    )
 {
     _config         = config;
     Cache           = cache;
     Exchange        = exchange;
     DataFilter      = dataFilter;
     PortfolioModel  = portfolioModel;
     MarginModel     = marginModel;
     FillModel       = fillModel;
     FeeModel        = feeModel;
     SlippageModel   = slippageModel;
     SettlementModel = settlementModel;
     Holdings        = new SecurityHolding(this);
 }
Exemple #11
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(SubscriptionDataConfig config,
            Cash quoteCurrency,
            SymbolProperties symbolProperties,
            SecurityExchange exchange,
            SecurityCache cache,
            ISecurityPortfolioModel portfolioModel,
            IFillModel fillModel,
            IFeeModel feeModel,
            ISlippageModel slippageModel,
            ISettlementModel settlementModel,
            ISecurityMarginModel marginModel,
            ISecurityDataFilter dataFilter
            )
        {

            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _config = config;
            QuoteCurrency = quoteCurrency;
            SymbolProperties = symbolProperties;
            Cache = cache;
            Exchange = exchange;
            DataFilter = dataFilter;
            PortfolioModel = portfolioModel;
            MarginModel = marginModel;
            FillModel = fillModel;
            FeeModel = feeModel;
            SlippageModel = slippageModel;
            SettlementModel = settlementModel;
            Holdings = new SecurityHolding(this);
        }
Exemple #12
0
 /// <summary>
 /// Temporary convenience constructor
 /// </summary>
 protected Security(SubscriptionDataConfig config,
     Cash quoteCurrency,
     SymbolProperties symbolProperties,
     SecurityExchange exchange,
     SecurityCache cache,
     ISecurityPortfolioModel portfolioModel,
     IFillModel fillModel,
     IFeeModel feeModel,
     ISlippageModel slippageModel,
     ISettlementModel settlementModel,
     IVolatilityModel volatilityModel,
     ISecurityMarginModel marginModel,
     ISecurityDataFilter dataFilter
     )
     : this(config.Symbol,
         quoteCurrency,
         symbolProperties,
         exchange,
         cache,
         portfolioModel,
         fillModel,
         feeModel,
         slippageModel,
         settlementModel,
         volatilityModel,
         marginModel,
         dataFilter
         )
 {
     SubscriptionsBag.Add(config);
 }
Exemple #13
0
        /********************************************************
        * CONSTRUCTOR/DELEGATE DEFINITIONS
        *********************************************************/
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        public Security(string symbol, SecurityType type, Resolution resolution, bool fillDataForward, decimal leverage, bool extendedMarketHours, bool isDynamicallyLoadedData = false)
        {
            //Set Basics:
            _symbol = symbol;
            _type = type;
            _resolution = resolution;
            _isFillDataForward = fillDataForward;
            _leverage = leverage;
            _isExtendedMarketHours = extendedMarketHours;
            _isDynamicallyLoadedData = isDynamicallyLoadedData;

            //Setup Transaction Model for this Asset
            switch (type)
            {
                case SecurityType.Equity:
                    Model = new EquityTransactionModel();
                    DataFilter = new EquityDataFilter();
                    break;
                case SecurityType.Forex:
                    Model = new ForexTransactionModel();
                    DataFilter = new ForexDataFilter();
                    break;
                case SecurityType.Base:
                    Model = new SecurityTransactionModel();
                    DataFilter = new SecurityDataFilter();
                    break;
            }

            //Holdings for new Vehicle:
            Cache = new SecurityCache();
            Holdings = new SecurityHolding(symbol, type, Model);
            Exchange = new SecurityExchange();
        }
Exemple #14
0
        /// <summary>
        /// Construct a new security vehicle based on the user options.
        /// </summary>
        protected Security(Symbol symbol,
            Cash quoteCurrency,
            SymbolProperties symbolProperties,
            SecurityExchange exchange,
            SecurityCache cache,
            ISecurityPortfolioModel portfolioModel,
            IFillModel fillModel,
            IFeeModel feeModel,
            ISlippageModel slippageModel,
            ISettlementModel settlementModel,
            IVolatilityModel volatilityModel,
            ISecurityMarginModel marginModel,
            ISecurityDataFilter dataFilter,
            IPriceVariationModel priceVariationModel
            )
        {

            if (symbolProperties == null)
            {
                throw new ArgumentNullException("symbolProperties", "Security requires a valid SymbolProperties instance.");
            }

            if (symbolProperties.QuoteCurrency != quoteCurrency.Symbol)
            {
                throw new ArgumentException("symbolProperties.QuoteCurrency must match the quoteCurrency.Symbol");
            }

            _symbol = symbol;
            SubscriptionsBag = new ConcurrentBag<SubscriptionDataConfig>();
            QuoteCurrency = quoteCurrency;
            SymbolProperties = symbolProperties;
            IsTradable = true;
            Cache = cache;
            Exchange = exchange;
            DataFilter = dataFilter;
            PriceVariationModel = priceVariationModel;
            PortfolioModel = portfolioModel;
            MarginModel = marginModel;
            FillModel = fillModel;
            FeeModel = feeModel;
            SlippageModel = slippageModel;
            SettlementModel = settlementModel;
            VolatilityModel = volatilityModel;
            Holdings = new SecurityHolding(this);
        }
Exemple #15
0
 /// <summary>
 /// Construct a new security vehicle based on the user options.
 /// </summary>
 protected Security(SubscriptionDataConfig config,
     SecurityExchange exchange,
     SecurityCache cache,
     ISecurityPortfolioModel portfolioModel,
     IFillModel fillModel,
     IFeeModel feeModel,
     ISlippageModel slippageModel,
     ISettlementModel settlementModel,
     ISecurityMarginModel marginModel,
     ISecurityDataFilter dataFilter
     )
 {
     _config = config;
     Cache = cache;
     Exchange = exchange;
     DataFilter = dataFilter;
     PortfolioModel = portfolioModel;
     MarginModel = marginModel;
     FillModel = fillModel;
     FeeModel = feeModel;
     SlippageModel = slippageModel;
     SettlementModel = settlementModel;
     Holdings = new SecurityHolding(this);
 }
Exemple #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DynamicSecurityData"/> class
 /// </summary>
 /// <param name="registeredTypes">Provides all the registered data types for the algorithm</param>
 /// <param name="cache">The security cache</param>
 public DynamicSecurityData(IRegisteredSecurityDataTypesProvider registeredTypes, SecurityCache cache)
 {
     _registeredTypes = registeredTypes;
     _cache           = cache;
 }