Ejemplo n.º 1
0
        public void ResetTests(SecurityCache cache, SecuritySeedData seedType)
        {
            switch (seedType)
            {
            case SecuritySeedData.None:
            case SecuritySeedData.OpenInterest:
            case SecuritySeedData.OpenInterestTick:
                break;

            case SecuritySeedData.QuoteTick:
                Assert.IsNotNull(cache.GetData());
                Assert.Greater(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Quote), 0);
                cache.Reset();
                Assert.IsFalse(cache.HasData(typeof(Tick)));
                Assert.AreEqual(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Quote), 0);
                break;

            case SecuritySeedData.TradeTick:
                Assert.IsNotNull(cache.GetData());
                Assert.Greater(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Trade), 0);
                cache.Reset();
                Assert.IsFalse(cache.HasData(typeof(Tick)));
                Assert.AreEqual(cache.GetAll <Tick>().Count(x => x.TickType == TickType.Trade), 0);
                break;

            default:
                Assert.IsNotNull(cache.GetData());
                cache.Reset();
                break;
            }
        }
        public string[] GetPropertiesBy(SecuritySeedData type)
        {
            switch (type)
            {
            case SecuritySeedData.None:
                return(new string[0]);

            case SecuritySeedData.OpenInterest:
                return(new[] { "OpenInterest" });

            case SecuritySeedData.OpenInterestTick:
                return(new[] { "OpenInterest" });

            case SecuritySeedData.TradeTick:
                return(new[] { "Price", "Volume" });

            case SecuritySeedData.QuoteTick:
                return(new[] { "AskPrice", "AskSize", "BidPrice", "BidSize" });

            case SecuritySeedData.TradeBar:
                return(new[] { "Price", "Volume", "Open", "High", "Low", "Close" });

            case SecuritySeedData.QuoteBar:
                return(new[] { "Price", "Open", "High", "Low", "Close", "AskPrice", "AskSize", "BidPrice", "BidSize" });

            case SecuritySeedData.Fundamentals:
                // fundamentals data does not modify security cache properties
                return(new string[0]);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
 public void AddDataWithSameEndTime_SetsQuoteTickValues(SecurityCache cache, SecuritySeedData seedType)
 {
     AddDataAndAssertChanges(cache, seedType, SecuritySeedData.QuoteTick, new Tick
     {
         AskPrice = 101,
         AskSize  = 102,
         BidPrice = 103,
         BidSize  = 104,
         TickType = TickType.Quote,
         EndTime  = ReferenceTime
     });
 }
Ejemplo n.º 4
0
 public void AddDataWithSameEndTime_SetsTradeBarValues(SecurityCache cache, SecuritySeedData seedType)
 {
     AddDataAndAssertChanges(cache, seedType, SecuritySeedData.TradeBar, new TradeBar
     {
         Open    = 101,
         High    = 102,
         Low     = 103,
         Close   = 104,
         Volume  = 105,
         EndTime = ReferenceTime
     });
 }
        public void AddDataWithSameEndTime_SetsTradeTickValues(SecurityCache cache, SecuritySeedData seedType)
        {
            var map = new Dictionary <string, string> {
                { "Volume", "Quantity" }
            };

            AddDataAndAssertChanges(cache, seedType, SecuritySeedData.TradeTick, new Tick
            {
                Value    = 101,
                Quantity = 102,
                TickType = TickType.Trade,
                EndTime  = ReferenceTime
            }, map);
        }
        private void AddDataAndAssertChanges(SecurityCache cache, SecuritySeedData seedType, SecuritySeedData dataType, BaseData data, Dictionary <string, string> cacheToBaseDataPropertyMap = null)
        {
            var before       = JObject.FromObject(cache);
            var dataSnapshot = JObject.FromObject(data);

            cache.AddData(data);
            var after = JObject.FromObject(cache);

            var updatedCacheProperties = GetPropertiesBy(dataType);

            if (seedType == SecuritySeedData.QuoteBar && (dataType == SecuritySeedData.QuoteBar || dataType == SecuritySeedData.TradeBar))
            {
                // these properties aren't updated when previous data is quote bar at same time as a new IBar
                updatedCacheProperties = updatedCacheProperties.Where(p =>
                                                                      p != "Open" &&
                                                                      p != "High" &&
                                                                      p != "Low" &&
                                                                      p != "Close" &&
                                                                      p != "Price"
                                                                      ).ToArray();
            }

            foreach (var property in before.Properties())
            {
                string dataPropertyName = null;
                if (updatedCacheProperties.Contains(property.Name))
                {
                    if (cacheToBaseDataPropertyMap?.TryGetValue(property.Name, out dataPropertyName) == true)
                    {
                        // avoiding failures due to decimal <> long in JToken.DeepEquals
                        var e = dataSnapshot.SelectToken(dataPropertyName).ToString();
                        var a = after.SelectToken(property.Name).ToString();
                        Assert.AreEqual(e, a, $"{property.Name}: Expected {e}. Actual {a}");
                    }
                    else
                    {
                        dataSnapshot.IsEqualTo(after, property.Name);
                    }
                }
                else
                {
                    before.IsEqualTo(after, property.Name);
                }
            }
        }
        public void AddDataWithSameEndTime_SetsQuoteBarValues(SecurityCache cache, SecuritySeedData seedType)
        {
            var map = new Dictionary <string, string>
            {
                { "Price", "Close" },
                { "BidPrice", "Bid.Close" },
                { "BidSize", "LastBidSize" },
                { "AskPrice", "Ask.Close" },
                { "AskSize", "LastAskSize" }
            };

            AddDataAndAssertChanges(cache, seedType, SecuritySeedData.QuoteBar, new QuoteBar
            {
                Bid         = new Bar(101, 102, 103, 104),
                Ask         = new Bar(105, 106, 107, 108),
                LastAskSize = 109,
                LastBidSize = 110,
                EndTime     = ReferenceTime
            }, map);
        }
Ejemplo n.º 8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                //app.UseDeveloperExceptionPage();
                app.UseExceptionHandlerMiddleware();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            var scopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>();
            var scope        = scopeFactory.CreateScope();

            SecuritySeedData.Initialize(scope.ServiceProvider);

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapAreaControllerRoute(
                    name: "Identity",
                    areaName: "Identity",
                    pattern: "Identity/{controller=Account}/{action=Login}/{id?}");

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");

                endpoints.MapRazorPages();
            });
        }
Ejemplo n.º 9
0
        public void Configure(IApplicationBuilder app)
        {
            if (Environment.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }

            var scopeFactory = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>();
            var scope        = scopeFactory.CreateScope();

            SecuritySeedData.Initialize(scope.ServiceProvider);

            app.UseStaticFiles();

            app.UseRouting();
            app.UseIdentityServer();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapDefaultControllerRoute();
            });
        }
        public void AddDataFundamentals_DoesNotChangeCacheValues(SecurityCache cache, SecuritySeedData seedType)
        {
            var map = new Dictionary <string, string>();

            AddDataAndAssertChanges(cache, seedType, SecuritySeedData.Fundamentals, new Fundamentals
            {
                Value   = 111,
                EndTime = ReferenceTime
            }, map);
        }
        public void AddDataWithSameEndTime_SetsOpenInterestTickValues(SecurityCache cache, SecuritySeedData seedType)
        {
            var map = new Dictionary <string, string> {
                { "OpenInterest", "Value" }
            };

            AddDataAndAssertChanges(cache, seedType, SecuritySeedData.OpenInterestTick, new Tick
            {
                Value    = 101,
                TickType = TickType.OpenInterest,
                EndTime  = ReferenceTime
            }, map);
        }