Esempio n. 1
0
        private void SetTimerRt(RtFreqParam p_freqParam)
        {
            // lock (m_rtTimerLock)
            var tradingHoursNow = Utils.UsaTradingHoursNow_withoutHolidays();

            p_freqParam.Timer !.Change(TimeSpan.FromSeconds((tradingHoursNow == TradingHours.RegularTrading) ? p_freqParam.FreqRthSec : p_freqParam.FreqOthSec), TimeSpan.FromMilliseconds(-1.0));
        }
Esempio n. 2
0
        private void UpdateRt(RtFreqParam p_freqParam)
        {
            p_freqParam.NTimerPassed++;
            Asset[] downloadAssets = p_freqParam.Assets;
            if (p_freqParam.RtFreq == RtFreq.HighFreq)                                                                                                                                                               // if it is highFreq timer, then add the recently asked assets.
            {
                var recentlyAskedNonNavAssets = m_lastRtPriceQueryTime.Where(r => r.Key.AssetId.AssetTypeID == AssetType.Stock && ((DateTime.UtcNow - r.Value) <= TimeSpan.FromSeconds(5 * 60))).Select(r => r.Key); //  if there was a function call in the last 5 minutes
                downloadAssets = p_freqParam.Assets.Concat(recentlyAskedNonNavAssets).ToArray();
            }
            if (downloadAssets.Length == 0)
            {
                return;
            }

            var tradingHoursNow = Utils.UsaTradingHoursNow_withoutHolidays();

            if (tradingHoursNow == TradingHours.RegularTrading)
            {
                DownloadLastPriceIex(downloadAssets);
            }
            else
            {
                DownloadLastPriceYF(downloadAssets, tradingHoursNow);
            }
        }
Esempio n. 3
0
        private void UpdateNavRt(RtFreqParam p_freqParam)
        {
            // NAV Tickers GA.IM.NAV, DC.IM.NAV, DC.ID.NAV, DC.NAV , but select only the Non-virtual non-Aggregate ones.
            // Most of the time, DC watches he "DC.NAV" real-time only. In that case, don't update Agy's "GA.IM.NAV" in every 60 seconds.
            p_freqParam.NTimerPassed++;
            BrokerNav[] downloadAssets = p_freqParam.Assets.Select(r => (r as BrokerNav) !).ToArray();
            if (p_freqParam.RtFreq == RtFreq.HighFreq)  // if it is highFreq timer, then add the recently asked assets.
            {
                List <BrokerNav> updatingNavAssets = new List <BrokerNav>();
                var recentlyAskedNavAssets         = m_lastRtPriceQueryTime.Where(r => r.Key.AssetId.AssetTypeID == AssetType.BrokerNAV && ((DateTime.UtcNow - r.Value) <= TimeSpan.FromSeconds(5 * 60))).Select(r => (r.Key as BrokerNav) !); //  if there was a function call in the last 5 minutes
                foreach (var nav in recentlyAskedNavAssets)
                {
                    // the virtual DC.NAV assets: replace them with the underlying sub-Navs
                    if (nav.IsAggregatedNav)    // add the underlying sub-Navs
                    {
                        updatingNavAssets.AddRange(AssetsCache.Assets.Where(r => r.AssetId.AssetTypeID == AssetType.BrokerNAV && !((r as BrokerNav) !.IsAggregatedNav) && (r as BrokerNav) !.User == nav.User).Select(r => (r as BrokerNav) !));
                    }
                    else
                    {
                        updatingNavAssets.Add(nav);
                    }
                }
                downloadAssets = downloadAssets.Concat(updatingNavAssets).ToArray();
            }
            if (downloadAssets.Length == 0)
            {
                return;
            }

            DownloadLastPriceNav(downloadAssets.ToList());
        }
Esempio n. 4
0
        public void RtNavTimer_Elapsed(object?p_state)     // Timer is coming on a ThreadPool thread
        {
            if (p_state == null)
            {
                throw new Exception("RtNavTimer_Elapsed() received null object.");
            }
            RtFreqParam freqParam = (RtFreqParam)p_state;

            Utils.Logger.Info($"MemDbRt.RtNavTimer_Elapsed({freqParam.RtFreq}). BEGIN.");
            try
            {
                UpdateNavRt(freqParam);
            }
            catch (System.Exception e)  // Exceptions in timers crash the app.
            {
                Utils.Logger.Error(e, $"MemDbRt.RtNavTimer_Elapsed({freqParam.RtFreq}) exception.");
            }
            SetTimerRt(freqParam);
            Utils.Logger.Info($"MemDbRt.RtNavTimer_Elapsed({freqParam.RtFreq}). END");
        }
Esempio n. 5
0
 private static void ServerDiagnosticRealtime(StringBuilder p_sb, RtFreqParam p_rtFreqParam)
 {
     p_sb.Append($"Realtime ({p_rtFreqParam.Name}): FreqRthSec: {p_rtFreqParam.FreqRthSec}, FreqOthSec: {p_rtFreqParam.FreqOthSec}, NTimerPassed: {p_rtFreqParam.NTimerPassed}, assets: '");
     p_sb.AppendLongListByLine(p_rtFreqParam.Assets.Where(r => r.AssetId.AssetTypeID == AssetType.Stock).Select(r => ((Stock)r).YfTicker), ",", 10, "<br>");
     p_sb.Append($"'<br>");
 }