Beispiel #1
0
        public MarketHours GetMarketHours(DateTime date)
        {
            if (date < DateTime.Now)
            {
                throw new InvalidDateException();
            }

            string      url        = string.Format("https://api.tdameritrade.com/v1/marketdata/EQUITY/hours");
            var         client     = new RestClient(url);
            RestRequest getRequest = new RestRequest(Method.GET);

            getRequest.AddHeader("cache-control", "no-cache");
            getRequest.AddHeader("content-type", "application/x-www-form-urlencoded");
            getRequest.AddParameter("apikey", ConfigurationManager.AppSettings.Get("apikey"));
            getRequest.AddParameter("date", date.ToString("yyyy-MM-dd"));
            var response = client.Get(getRequest);

            JObject     marketSearch = JObject.Parse(response.Content);
            MarketHours marketHours  = new MarketHours()
            {
                Description        = (string)marketSearch["equity"]["EQ"]["marketType"],
                IsOpen             = (bool)marketSearch["equity"]["EQ"]["isOpen"],
                PreMarketStart     = DateTime.Parse((string)marketSearch["equity"]["EQ"]["sessionHours"]["preMarket"][0]["start"]),
                PreMarketEnd       = DateTime.Parse((string)marketSearch["equity"]["EQ"]["sessionHours"]["preMarket"][0]["end"]),
                RegularMarketStart = DateTime.Parse((string)marketSearch["equity"]["EQ"]["sessionHours"]["regularMarket"][0]["start"]),
                RegularMarketEnd   = DateTime.Parse((string)marketSearch["equity"]["EQ"]["sessionHours"]["regularMarket"][0]["end"]),
                PostMarketStart    = DateTime.Parse((string)marketSearch["equity"]["EQ"]["sessionHours"]["postMarket"][0]["start"]),
                PostMarketEnd      = DateTime.Parse((string)marketSearch["equity"]["EQ"]["sessionHours"]["preMarket"][0]["end"])
            };

            return(marketHours);
        }
Beispiel #2
0
 public StockMonitorService(
     ILogger <StockMonitorService> logger,
     IAccountStorage accounts,
     IAlertsStorage alerts,
     IStocksService2 stocks,
     IEmailService emails,
     MarketHours marketHours,
     StockMonitorContainer container)
 {
     _accounts    = accounts;
     _alerts      = alerts;
     _emails      = emails;
     _logger      = logger;
     _stocks      = stocks;
     _marketHours = marketHours;
     _container   = container;
 }
Beispiel #3
0
        private bool UpdateRequired(SymbolDescription description, BarDataScale barDataScale)
        {
            if (!_dataStore.ContainsSymbol(description.FullCode, barDataScale.Scale, barDataScale.BarInterval))
            {
                return(true);
            }

            MarketHours mktHours = new MarketHours();

            mktHours.Market = GetMarketInfo(description.FullCode);
            DateTime updateTime = _dataStore.SymbolLastUpdated(description.FullCode, barDataScale.Scale, barDataScale.BarInterval);

            if (!barDataScale.IsIntraday)
            {
                if ((DateTime.Now.Date >= updateTime.Date.AddDays(1)) ||
                    (updateTime.Date < mktHours.LastTradingSessionEndedNative.Date))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (mktHours.IsMarketOpenNow || (updateTime < mktHours.LastTradingSessionEndedNative))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }