예제 #1
0
        public void GetAllShouldReturnAllCategories()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>()
                                 .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var dbContext = new ApplicationDbContext(optionsBuilder.Options);

            var quotesService = new QuotesService(dbContext);

            var firstQuote = new Quote
            {
                Id      = 1,
                Content = "testContent",
            };

            var secondQuote = new Quote
            {
                Id      = 2,
                Content = "testContent",
            };

            dbContext.Quotes.Add(firstQuote);
            dbContext.Quotes.Add(secondQuote);
            dbContext.SaveChangesAsync();

            var result = quotesService.GetRandomQuote();

            Assert.NotNull(result);
            Assert.Equal("testContent", result.Content);
        }
예제 #2
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);
            }
        }
예제 #3
0
 public Proto5Handler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger <Proto5Handler> logger)
     : base(node, db, cache, quotes, services, config, logger)
 {
     Rpc         = new Rpc(node);
     Diagnostics = new Diagnostics(this);
     Validator   = new Validator(this);
 }
        public async void Import()
        {
            IEnumerable <Quote> quotes = await this.GetQuotes();

            var context = new ApplicationDbContext();
            IDbRepository <SQL.Quote> repo = new DbRepository <SQL.Quote>(context);
            var quotesService = new QuotesService(repo);

            foreach (var quote in quotes)
            {
                if (repo.All().Any(q => q.Text.ToLower() == quote.Text.ToLower()))
                {
                    continue;
                }
                quotesService.Add(new SQL.Quote()
                {
                    Text       = quote.Text,
                    Author     = this.LoadOrCreateAuthor(context, quote.Author, quote.AuthorImageUrl),
                    CreatedOn  = DateTime.Now,
                    ModifiedOn = DateTime.Now,
                    IsDeleted  = false,
                    Tags       = quote.Tags.Select(tag => new SQL.Tag
                    {
                        Name = tag
                    }
                                                   ).ToList()
                });
                Console.Write(".");
            }
            Console.WriteLine("Done!");
        }
예제 #5
0
        private void DeleteIntradiaryData(string marketName)
        {
            DateTime marketTime = MarketService.GetMarketCurrentLocalTime(marketName);

            if (marketTime.Hour == 5)
            {
                QuotesService.ClearIntradiaryDataByMarketID(marketName);
            }
        }
예제 #6
0
 public ProtocolHandler(TezosNode node, TzktContext db, CacheService cache, QuotesService quotes, IServiceProvider services, IConfiguration config, ILogger logger)
 {
     Node     = node;
     Db       = db;
     Cache    = cache;
     Quotes   = quotes;
     Services = services;
     Config   = config.GetTezosProtocolsConfig();
     Logger   = logger;
 }
 public string ClearIntradiary(string market_name)
 {
     try
     {
         QuotesService.ClearIntradiaryDataByMarketID(market_name);
     }
     catch (Exception ex)
     {
         return("ERROR Deleting Intradiary:\n " + ex.Message);
     }
     return("Intradiary Deleted");
 }
예제 #8
0
 public QuotesController(QuotesService myService,
                         CategoryService categoryService,
                         UserService userService,
                         FollowService followService,
                         IEmailSender emailSender)
 {
     _myService       = myService;
     _categoryService = categoryService;
     _userService     = userService;
     _followService   = followService;
     _emailSender     = emailSender;
 }
        public void Init()
        {
            this.quoteTestObject = TestObjectFactory.CreateQuote();
            quoteTestObject.Id   = 1;

            var quoteTestData = new List <Quote>();

            quoteTestData.Add(this.quoteTestObject);

            this.quoteRepository = TestObjectFactory.CreateRepository(quoteTestData);

            this.service = new QuotesService(this.quoteRepository);
        }
예제 #10
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);
        }
        public string RunHistoricalUpdate(int stockid, string startdate, string enddate)
        {
            string result = "";

            if (startdate != "" && enddate != "" && stockid != 0)
            {
                try
                {
                    Symbol   symbol = QuotesService.GetSymbolInfo(stockid);
                    DateTime start  = DateTime.Parse(startdate);
                    DateTime end    = DateTime.Parse(enddate);
                    result += symbol.Symbol_Name.ToUpper() + "\nStartDate: " + startdate + "\nEndDate: " + enddate;
                    QuotesService.ReadHistoricalData(start, end, symbol.Symbol_Name, symbol.Symbol_ID);
                }
                catch (Exception ex)
                {
                    return(result += "\nError: " + ex.Message);
                }
            }
            return(result += "\nHistorical Updated");
        }
 public ActionResult ReadDataFromCSV(HttpPostedFileBase csvdatafile)
 {
     QuotesService.ReadHistoricalDataFromCSV(csvdatafile.InputStream, csvdatafile.FileName);
     return(RedirectToAction("Index"));
 }
예제 #15
0
 public QuotesController(QuotesService quotesService)
 {
     _quotesService = quotesService;
 }
 // GET: AdminStockQuotes
 public ActionResult Index(int stockid = 0)
 {
     ViewBag.stock_id       = new SelectList(db.GetStocks().Where(s => s.active && s.market_id != 1).OrderBy(s => s.symbol), "Id", "symbol_market");
     ViewBag.SyncMarketInfo = QuotesService.GetMarketsSyncTimeInfo();
     return(View(db.GetStockQuotes(stockid).OrderByDescending(s => s.date_round)));
 }
예제 #17
0
 public QuotesController(QuotesService qs)
 {
     _qs = qs;
 }
 public MessagesController(QuotesService svc)
 {
     _svc = svc;
 }
 public QuotesController(QuotesService service)
 {
     _svc = service;
 }
예제 #20
0
 public QuotesCommands(QuotesService quotesService, QuoteEmbedGenerator quoteEmbedGenerator)
 {
     _quotesService       = quotesService;
     _quoteEmbedGenerator = quoteEmbedGenerator;
 }
예제 #21
0
 public QuotesCarouselModel(int market_id)
 {
     //this.QuotesList = new List<SimplifiedSymbolQuotes>();
     this.QuotesList = QuotesService.GetQuotesByMarketID(market_id);
 }
예제 #22
0
        public ActionResult Quote(int symbol_id)
        {
            Symbol model = QuotesService.GetSymbolInfo(symbol_id);

            return(View(model));
        }
예제 #23
0
 public DetailModel(QuotesService quotesService, AddToCart addToCart)
 {
     this._quotesService = quotesService;
     this._addToCart     = addToCart;
 }
 protected override void ExecuteTask(VcssTaskModel vcssTask)
 {
     QuotesService.ClearIntradiaryDataByMarketID(vcssTask.VcssTaskInfo.market_id.Value);
 }
예제 #25
0
 public IndexModel(QuotesService quotesService)
 {
     this._quotesService = quotesService;
 }
예제 #26
0
 public PendingOrderService(ApplicationDbContext ctx, QuotesService quotesService)
 {
     _ctx           = ctx;
     _quotesService = quotesService;
 }