Esempio n. 1
0
        private void UpdateMarketRealTimeQuotes(string providerName, string marketName, string data)
        {
            Configs_Market marketConfigs = this.dbcontext.GetMarketConfig(marketName);

            LOG.Log($">>> MARKET Configs: {marketConfigs.Name}|{marketConfigs.LastSync}|{marketConfigs.NextSync}|{marketConfigs.UTCOffset}|{marketConfigs.QuotesUpdatesActive}|");

            DateTime date = DateTime.UtcNow.AddHours(marketConfigs.UTCOffset);

            if (Configs_Market.QuoteUpdateAvailabe(marketConfigs, this.dbcontext.IsHoliday, date))
            {
                QuotesProvider quotesProvider = QuotesProvider.GetQuotesProviderInstance(providerName);
                Tuple <List <IRealTimeQuote>, List <IHistoricalQuote> > quotes = quotesProvider.GetQuotesFromJson(data);
                this.dbcontext.SaveRealTimeQuoteV1(quotes.Item1);
                this.dbcontext.SaveHistoricalQuoteV1(quotes.Item2);
                this.dbcontext.UpdateConfig($"{marketName}_LastSync", date.ToString());
            }
            this.dbcontext.UpdateConfig($"{marketName}_NextSync", date.AddMinutes(15).ToString());
        }
Esempio n. 2
0
        public static bool QuoteUpdateAvailabe(Configs_Market marketConfig, Func <DateTime, string, bool> isHoliday, DateTime currentDate)
        {
            bool result = false;

            if (marketConfig.QuotesUpdatesActive)
            {
                if (currentDate.DayOfWeek == DayOfWeek.Saturday || currentDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    result = false;
                }
                else if (marketConfig.NextSync <= currentDate)
                {
                    if (!isHoliday(currentDate, marketConfig.Name))
                    {
                        int startHour    = int.Parse(marketConfig.WorkHours.Split(';')[0].Split(':')[0]);
                        int startMinutes = int.Parse(marketConfig.WorkHours.Split(';')[0].Split(':')[1]);
                        int closeHour    = int.Parse(marketConfig.WorkHours.Split(';')[1].Split(':')[0]);
                        int closeMinutes = int.Parse(marketConfig.WorkHours.Split(';')[1].Split(':')[1]);

                        if (currentDate.Hour < startHour)
                        {
                            result = false;
                        }
                        else if (currentDate.Hour == startHour && currentDate.Minute < startMinutes)
                        {
                            result = false;
                        }
                        else if (currentDate.Hour > closeHour)
                        {
                            result = false;
                        }
                        else if (currentDate.Hour == closeHour && currentDate.Minute > closeMinutes)
                        {
                            result = false;
                        }
                        else
                        {
                            result = true;
                        }
                    }
                }
            }
            return(result);
        }
Esempio n. 3
0
        public Configs_Market GetMarketConfig(string name)
        {
            Configs_Market market = new Configs_Market();

            market.Name = name;

            using (SqlConnection connection = new SqlConnection(this.configs.ConnectionString))
            {
                connection.Open();
                string        queryString = $"SELECT ConfigName, ConfigValue FROM Config WHERE ConfigName like '{name}_%'";
                SqlCommand    command     = new SqlCommand(queryString, connection);
                SqlDataReader reader      = command.ExecuteReader();
                while (reader.Read())
                {
                    if (reader["ConfigName"].ToString().EndsWith("_LastSync"))
                    {
                        market.LastSync = DateTime.Parse(reader["ConfigValue"].ToString());
                    }
                    else if (reader["ConfigName"].ToString().EndsWith("_NextSync"))
                    {
                        market.NextSync = DateTime.Parse(reader["ConfigValue"].ToString());
                    }
                    else if (reader["ConfigName"].ToString().EndsWith("_UTCOffset"))
                    {
                        market.UTCOffset = int.Parse(reader["ConfigValue"].ToString());
                    }
                    else if (reader["ConfigName"].ToString().EndsWith("_QuotesUpdateActive"))
                    {
                        market.QuotesUpdatesActive = bool.Parse(reader["ConfigValue"].ToString());
                    }
                    else if (reader["ConfigName"].ToString().EndsWith("_WorkHours"))
                    {
                        market.WorkHours = reader["ConfigValue"].ToString();
                    }
                    else if (reader["ConfigName"].ToString().EndsWith("_QuoteProviderName"))
                    {
                        market.QuoteProviderName = reader["ConfigValue"].ToString();
                    }
                }
                reader.Close();
                connection.Close();
            }
            return(market);
        }
Esempio n. 4
0
        private void UpdateMarketRealTimeQuotes(string marketName)
        {
            LOG.Log($"   >> {marketName} Starting - {DateTime.Now}");

            Configs_Market marketConfigs = this.dbcontext.GetMarketConfig(marketName);

            LOG.Log($"      MARKET: {marketConfigs.Name}|{marketConfigs.LastSync}|{marketConfigs.NextSync}|{marketConfigs.UTCOffset}|{marketConfigs.QuotesUpdatesActive}|");

            Configs_QuoteDataProvider dataproviderConfigs = this.dbcontext.GetQuoteDataProviderConfig(marketConfigs.QuoteProviderName);

            LOG.Log($"      QUOTES:{dataproviderConfigs.Name}|{dataproviderConfigs.APIToken}|{dataproviderConfigs.HistoricalURL}|{dataproviderConfigs.RealTimeURL}|");

            List <mdlStock> stocks = this.dbcontext.GetMarketActiveStocks(marketName);

            LOG.Log($"      STOCKS: Count={stocks.Count}|");

            DateTime date = DateTime.UtcNow.AddHours(marketConfigs.UTCOffset);

            if (Configs_Market.QuoteUpdateAvailabe(marketConfigs, this.dbcontext.IsHoliday, date))
            {
                QuotesDataProvider            quotesDataProvider = QuotesDataProvider.GetQuoteDataProvider(dataproviderConfigs, marketConfigs);
                List <HistoricalQuoteDBModel> historical;
                List <RealTimeQuoteDBModel>   realtime = quotesDataProvider.GetRealTimeQuotes(stocks, date, this.dbcontext, out historical);
                LOG.Log($"      REALTIME: Count={realtime.Count}|");
                LOG.Log($"      HISTORICAL: Count={historical.Count}|");
                this.dbcontext.SaveRealTimeQuote(realtime);
                this.dbcontext.SaveHistoricalQuote(historical);
                this.dbcontext.UpdateConfig($"{marketName}_LastSync", date.ToString());
            }
            this.dbcontext.UpdateConfig($"{marketName}_NextSync", date.AddMinutes(15).ToString());

            if (date.Hour == 5)
            {
                string result = this.dbcontext.DeleteIntradiaryQuotes();
                LOG.Log($"      {result}");
            }

            LOG.Log($"   << {marketName} End - {DateTime.Now}");
        }
 public static QuotesDataProvider GetQuoteDataProvider(Configs_QuoteDataProvider dataproviderConfigs, Configs_Market marketConfigs)
 {
     if (marketConfigs.QuoteProviderName == "EOD")
     {
         return(new QuotesDataProvider_EOD(dataproviderConfigs, marketConfigs));
     }
     if (marketConfigs.QuoteProviderName == "BOLSAR")
     {
         return(new QuotesDataProvider_BOLSAR(dataproviderConfigs, marketConfigs));
     }
     return(null);
 }
 protected QuotesDataProvider(Configs_QuoteDataProvider dataproviderConfigs, Configs_Market marketConfigs)
 {
     this.MarketConfigs            = marketConfigs;
     this.QuoteDataProviderConfigs = dataproviderConfigs;
 }
Esempio n. 7
0
 public QuotesDataProvider_BOLSAR(Configs_QuoteDataProvider dataproviderConfigs, Configs_Market marketConfigs) : base(dataproviderConfigs, marketConfigs)
 {
 }