public void Init()
        {
            AutoMapperConfig.Configure();

            _yahooFinanceService         = new YahooFinanceService();
            _financialCalculationService = new FinancialCalculationService();
            _googleFinanceService        = new GoogleFinanceService(new WebRequestService());
            _portfolioController         = new PortfolioController(_yahooFinanceService, _googleFinanceService, _financialCalculationService);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DashboardService"/> class.
 /// </summary>
 /// <param name="configuration">The configuration.</param>
 /// <param name="dashboardLogHistoryRepository">The dashboard log history repository.</param>
 /// <param name="iIPStackService">The i ip stack service.</param>
 /// <param name="exchangeRatesService">The exchange rates service.</param>
 /// <param name="yahooFinanceService">The yahoo finance service.</param>
 public DashboardService(IConfiguration configuration, IDashboardLogHistoryRepository dashboardLogHistoryRepository,
                         IIPStackService iIPStackService, IExchangeRatesService exchangeRatesService, IYahooFinanceService yahooFinanceService, UserManager <ApplicationUser> userManager)
 {
     this.configuration = configuration;
     this.dashboardLogHistoryRepository = dashboardLogHistoryRepository;
     this.iIPStackService      = iIPStackService;
     this.exchangeRatesService = exchangeRatesService;
     this.yahooFinanceService  = yahooFinanceService;
     this.userManager          = userManager;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="PortfolioController"/> class.
        /// </summary>
        /// <param name="yahooFinanceService">
        /// The yahoo finance service.
        /// </param>
        /// <param name="googleFinanceService">
        /// </param>
        /// <param name="financialCalculationService">
        /// The financial Calculation Service.
        /// </param>
        public PortfolioController(IYahooFinanceService yahooFinanceService, IGoogleFinanceService googleFinanceService, IFinancialCalculationService financialCalculationService)
        {
            if (googleFinanceService == null)
            {
                throw new ArgumentNullException(nameof(googleFinanceService));
            }
            if (yahooFinanceService == null)
            {
                throw new ArgumentNullException(nameof(yahooFinanceService));
            }
            if (financialCalculationService == null)
            {
                throw new ArgumentNullException(nameof(financialCalculationService));
            }

            _yahooFinanceService         = yahooFinanceService;
            _googleFinanceService        = googleFinanceService;
            _financialCalculationService = financialCalculationService;
        }
        async public Task <IActionResult> GetFinanceAsync([FromRoute] string symbol, [FromServices] IYahooFinanceService service, [FromServices] IMemoryCache cache)
        {
            try
            {
                //FIXME: Create a abstraction to put value in memory cache
                var finance = await cache.GetOrCreateAsync(symbol.ToLowerInvariant(), entry =>
                {
                    entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(30);

                    //FIXME: Validates the symbol
                    return(service.GetStockFinanceAsync(symbol));
                });

                var result             = finance.Chart.Results.First();
                var quote              = result.Indicators.Quotes.First();
                var firstTradeDate     = result.Meta.FirstTradeDate;
                var regularMarketTime  = result.Meta.RegularMarketTime;
                var regularMarketPrice = result.Meta.RegularMarketPrice;

                //FIXME: Add application service
                var symbolFinance = new SymbolFinance
                {
                    FirstTradeDate     = firstTradeDate.ToDatetime(),
                    RegularMarketTime  = regularMarketTime.ToDatetime(),
                    RegularMarketPrice = regularMarketPrice
                };

                symbolFinance.Indicators = new ReadOnlyCollection <SymbolIndicatorValue>(
                    result
                    .Timestamps
                    .Select((t, i) => new SymbolIndicatorValue(t, quote.Opens[i], quote.Highs[i], quote.Lows[i], quote.Closes[i]))
                    .ToList());

                return(Ok(symbolFinance));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "An error occurred"));
            }
        }
Exemplo n.º 5
0
 public YahooFinanceDbProvider(IYahooFinanceService yahooFinanceService, IStocksRepository stocksRepository)
 {
     _yahooFinanceService = yahooFinanceService;
     _stocksRepository    = stocksRepository;
 }
 public void Init()
 {
     AutoMapperConfig.Configure();
     _yahooFinanceService         = new YahooFinanceService();
     _financialCalculationService = new FinancialCalculationService();
 }
Exemplo n.º 7
0
 public StockQuotesService(IHistoricalQuotesRepository historicalQuotesRepository, IYahooFinanceService yahooFinanceService)
 {
     _historicalQuotesRepository = historicalQuotesRepository;
     _yahooFinanceService        = yahooFinanceService;
 }