Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext <ApplicationDbContext>(
                options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

            services.AddTransient <IRepository, Repository>();
            services.AddTransient <IAdminRepository, AdminRepository>();

            services.AddIdentity <User, IdentityRole>()
            .AddEntityFrameworkStores <ApplicationDbContext>()
            .AddDefaultTokenProviders();

            services.Configure <IdentityOptions>(options =>
            {
                // Password settings.
                options.Password.RequireDigit           = true;
                options.Password.RequiredLength         = 6;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireUppercase       = false;
                // Lockout settings.
                options.Lockout.DefaultLockoutTimeSpan  = TimeSpan.FromMinutes(5);
                options.Lockout.MaxFailedAccessAttempts = 5;
                options.Lockout.AllowedForNewUsers      = true;

                //User settings.
                options.User.AllowedUserNameCharacters =
                    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_+";
                options.User.RequireUniqueEmail = true;
            });

            services.Configure <DataProtectionTokenProviderOptions>(opt =>
                                                                    opt.TokenLifespan = TimeSpan.FromHours(24));

            services.AddControllersWithViews().AddRazorRuntimeCompilation();
            // Here I inject my AVConnection
            AlphaVantageConnection AVConn = new AlphaVantageConnection(Configuration);

            services.AddSingleton <AlphaVantageConnection>(AVConn);

            var emailConfig = Configuration
                              .GetSection("EmailConfiguration")
                              .Get <EmailConfiguration>();

            services.AddSingleton(emailConfig);
            services.AddScoped <IEmailMessenger, EmailMessenger>();
        }
Ejemplo n.º 2
0
        public async Task <int> AddDailyPrices(SecuritiesDIM security)
        {
            using (PortfolioAceDbContext context = _contextFactory.CreateDbContext())
            {
                string avKey = context.AppSettings.Where(ap => ap.SettingName == "AlphaVantageAPI").First().SettingValue;
                AlphaVantageConnection            avConn    = _dataFactory.CreateAlphaVantageClient(avKey);
                IEnumerable <AVSecurityPriceData> allPrices = await avConn.GetPricesAsync(security);

                HashSet <DateTime> existingDates = context.SecurityPriceData.Where(spd => spd.Security.Symbol == security.Symbol).Select(spd => spd.Date).ToHashSet();
                string             assetClass    = security.AssetClass.Name;
                int pricesSaved = 0;
                foreach (AVSecurityPriceData price in allPrices)
                {
                    if (!existingDates.Contains(price.TimeStamp))
                    {
                        // i should the indirect quote therefore i inverse the price here...
                        if (assetClass == "FX")
                        {
                            price.Close = 1 / price.Close;
                        }
                        if (security.Currency.Symbol == "GBP" && assetClass != "FX")
                        {
                            price.Close /= 100;
                        }
                        SecurityPriceStore newPrice = new SecurityPriceStore {
                            Date = price.TimeStamp, ClosePrice = price.Close, SecurityId = security.SecurityId, PriceSource = price.PriceSource
                        };
                        context.SecurityPriceData.Add(newPrice);
                        pricesSaved += 1;
                    }
                }
                await context.SaveChangesAsync();

                return(pricesSaved);
            }
        }
Ejemplo n.º 3
0
 public AlphaVantageTests()
 {
     this.avConnection = new AlphaVantageConnection(this.config);
 }
Ejemplo n.º 4
0
 public AdminController(IAdminRepository adminRepo, AlphaVantageConnection avConn)
 {
     this._adminRepo = adminRepo;
     this._avConn    = avConn;
 }
Ejemplo n.º 5
0
 public TradeController(IRepository repo, IHttpContextAccessor httpContextAccessor, AlphaVantageConnection avConn)
 {
     this._repo   = repo;
     this._userId = httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
     this._avConn = avConn;
 }