Exemple #1
0
        public override async Task UpdateHistoricalQuote(int stockID, DateTime from, DateTime to)
        {
            try
            {
                string     EODapiToken = ConfigService.GetConfigs().Where(c => c.ConfigName == "EOD_APIToken").Select(c => c.ConfigValue).FirstOrDefault();
                string     quotesURL   = ConfigService.GetConfigs().Where(c => c.ConfigName == "EOD_HistoricalQuotes_URL").Select(c => c.ConfigValue).FirstOrDefault();
                StockModel stock       = StockService.GetStocks().Where(s => s.Id == stockID).FirstOrDefault();

                using (WebClient web = new WebClient())
                {
                    string jsonHistoricalData = await web.DownloadStringTaskAsync(String.Format(quotesURL, stock.symbol, from.ToString("yyyy-MM-dd"), to.ToString("yyyy-MM-dd"), EODapiToken));

                    List <jsonmdlEODHistorical> data             = JsonConvert.DeserializeObject <List <jsonmdlEODHistorical> >(jsonHistoricalData);
                    List <HistoricalQuoteEOD>   historicalQuotes = data.Select(h => new HistoricalQuoteEOD()
                    {
                        adj_close  = h.AdjustedClose,
                        closing    = h.Close,
                        date_round = h.Date,
                        maximun    = h.High,
                        minimun    = h.Low,
                        opening    = h.Open,
                        stock_id   = stockID,
                        volume     = h.Volume
                    }).ToList <HistoricalQuoteEOD>();
                    QuotesService.SaveHistoricalQuote(historicalQuotes.ToList <IHistoricalQuote>());
                }
            }
            catch (Exception ex)
            {
                //TODO - Log error
                TaskManagerService.LogTaskError("EODQuotesProvider - UpdateHistoricalQuote", ex.Message);
            }
        }
Exemple #2
0
        protected override void ExecuteTask(VcssTaskModel vcssTask)
        {
            string[] jsonData = vcssTask.data.Split('#');
            int      stockId  = int.Parse(jsonData[1]);
            List <jsonmdlEODHistorical> data = JsonConvert.DeserializeObject <List <jsonmdlEODHistorical> >(jsonData[0]);

            List <IHistoricalQuote> historicalQuotes = data.Select(h => new HistoricalQuoteEOD()
            {
                adj_close  = h.AdjustedClose,
                closing    = h.Close,
                date_round = h.Date,
                maximun    = h.High,
                minimun    = h.Low,
                opening    = h.Open,
                stock_id   = stockId,
                volume     = h.Volume
            }).ToList <IHistoricalQuote>();

            QuotesService.SaveHistoricalQuote(historicalQuotes);
        }
        protected override void ExecuteTask(VcssTaskModel vcssTask)
        {
            DateTime marketDate = DateTime.UtcNow.AddHours(vcssTask.VcssTaskInfo.Market.utc_offset).Date;
            Dictionary <string, int>  symbols = StockService.GetStocks().Where(s => s.market_id == 1 && s.type_id == 4 && s.active).ToDictionary(s => s.symbol, s => s.Id);
            List <jsonmdlBOLSARIndex> data    = JsonConvert.DeserializeObject <List <jsonmdlBOLSARIndex> >(vcssTask.data).Where(x => symbols.ContainsKey(x.Symbol)).ToList();

            //INTRADIARY DATA
            List <IRealTimeQuote> realTimeQuotes = data.Select(rt => new RealTimeQuoteBOLSAR()
            {
                ask              = 0,
                ask_size         = 0,
                bid              = 0,
                bid_size         = 0,
                change           = rt.Tendencia,
                change_percent   = rt.Variacion,
                datetime         = this.GetIntradiaryDateTime(marketDate, rt.strHora),
                last_trade_date  = DateTime.Now,
                last_trade_price = rt.Ultimo,
                last_trade_size  = 0,
                last_trade_time  = "",
                opening          = rt.Ultimo,
                prev_closing     = rt.Apertura,
                stock_id         = symbols[rt.Symbol]
            }).ToList <IRealTimeQuote>();

            //HISTORICAL DATA
            List <IHistoricalQuote> historicalQuotes = data.Select(h => new HistoricalQuoteBOLSAR()
            {
                adj_close  = 0,
                closing    = h.Ultimo,
                date_round = marketDate,
                maximun    = h.Maximo_Valor,
                minimun    = h.Minimo_Valor,
                opening    = h.Apertura,
                stock_id   = symbols[h.Symbol],
                volume     = 0
            }).ToList <IHistoricalQuote>();

            QuotesService.SaveRealTimeQuote(realTimeQuotes);
            QuotesService.SaveHistoricalQuote(historicalQuotes);
        }
        protected override void ExecuteTask(VcssTaskModel vcssTask)
        {
            DateTime marketDate = DateTime.UtcNow.AddHours(vcssTask.VcssTaskInfo.Market.utc_offset).Date;
            Dictionary <string, int>         symbols = StockService.GetStocks().Where(s => s.market_id == 2 && s.active).ToDictionary(s => s.symbol + ".US", s => s.Id);
            IEnumerable <jsonmdlEODRealTime> data    = JsonConvert.DeserializeObject <List <jsonmdlEODRealTime> >(vcssTask.data).Where(rt => symbols.ContainsKey(rt.Code));

            //INTRADIARY DATA
            List <IRealTimeQuote> realTimeQuotes = data.Select(rt => new RealTimeQuoteEOD()
            {
                ask              = 0,
                ask_size         = 0,
                bid              = 0,
                bid_size         = 0,
                change           = 0,
                change_percent   = rt.Change,
                datetime         = this.GetIntradiaryDateTime(vcssTask.VcssTaskInfo.Market.utc_offset, rt.Timestamp),
                last_trade_date  = DateTime.Now,
                last_trade_price = rt.Close,
                last_trade_size  = 0,
                last_trade_time  = "",
                opening          = rt.Close,
                prev_closing     = rt.PreviousClose,
                stock_id         = symbols[rt.Code]
            }).ToList <IRealTimeQuote>();

            //HISTORICAL DATA
            List <IHistoricalQuote> historicalQuotes = data.Select(h => new HistoricalQuoteEOD()
            {
                adj_close  = 0,
                closing    = h.Close,
                date_round = marketDate,
                maximun    = h.High,
                minimun    = h.Low,
                opening    = h.Open,
                stock_id   = symbols[h.Code],
                volume     = h.Volume
            }).ToList <IHistoricalQuote>();

            QuotesService.SaveRealTimeQuote(realTimeQuotes);
            QuotesService.SaveHistoricalQuote(historicalQuotes);
        }