Example #1
0
        /// <summary>
        /// When simulating, this method will load all of the needed nodes for simulating a live feed/stream.
        /// </summary>
        private void PrepareSimDayNodes()
        {
            if (AlgoTraderState.IsSim)
            {
                // load up today's nodes for StreamManager to pretend to add nodes by using today's nodes

                int       amount = 100;
                Stopwatch sw     = new Stopwatch();
                sw.Start();

                object lockObj = new object();

                for (int m = 0; m < Global.State.AllSymbols.Count; m += amount)
                {
                    Parallel.For(0, amount, new ParallelOptions {
                        MaxDegreeOfParallelism = 30
                    }, n =>
                    {
                        if (m + n < Global.State.AllSymbols.Count)
                        {
                            // NodesData nodes = null;
                            NodesData nodes = DataMethods.GetCachedDayNodesData(Global.State.AllSymbols[m + n], AlgoTraderState.CurrentDay, Interval.HalfSecond, justCache: false);

                            // NodesData nodesData = DataMethods.GetCachedDayNodesData(Global.State.AllSymbols[m + n], CurrentDay, Interval.HalfSecond, computeNodes: true, justCache: false);

                            // no need to ComputeGaps because it's 1 day... trusting well formatted data
                            lock (lockObj)
                            {
                                AlgoTraderShared.SimDayNodes.Add(Global.State.AllSymbols[m + n], nodes);

                                //nodes.Add(Global.State.AllSymbols[m + n], DataMethods.GetCachedDayNodesData(Global.State.AllSymbols[m + n], CurrentDay, Interval.HalfSecond, computeNodes: true, justCache: false));
                            }
                            TC.Log.AddLine("Loaded " + Global.State.AllSymbols[m + n] + " stock nodes for stream manager");
                        }
                    });

                    if (!TC.CheckNotStopped())
                    {
                        break;
                    }
                }

                sw.Stop();

                TC.Log.AddLine("Finished loading sim nodes for stream manager in " + UC.MillisecondsToSeconds(sw.ElapsedMilliseconds, 3) + " sec(s). That's " + ((decimal)Global.State.AllSymbols.Count / UC.MillisecondsToSeconds(sw.ElapsedMilliseconds, 3)) + " per sec.");
            }
        }
Example #2
0
        public static void BuildMinuteDayNodes(ThreadControl tc)
        {
            // this should be called AFTER updated yesterday's ticks AND data tracker no data days updated


            List <string> symbols = new List <string>(Global.State.AllSymbols);

            symbols.Shuffle();

            symbols.Remove("spy");
            symbols.Remove("aapl");
            symbols.Add("spy");
            symbols.Add("aapl");
            symbols.Reverse();



            ZonedDateTime ie = SystemClock.Instance.GetCurrentInstant().InZone(UCDT.TimeZones.Eastern);

            // set the current date to yesterday via eastern timezone just to be safe
            DateTime dt = new DateTime(ie.Year, ie.Month, ie.Day, 0, 0, 0, DateTimeKind.Unspecified).AddDays(-20);


            DateTime firstDataDay = Global.State.DataTracker.DataDays[0].DT;

            while (dt > firstDataDay && tc.CheckNotStopped())
            {
                FD fd = new FD(dt);

                Parallel.For(0, symbols.Count, new ParallelOptions {
                    MaxDegreeOfParallelism = 20
                }, n =>
                {
                    if (DataMethods.DayNodesDataCacheable(symbols[n], fd))
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();
                        NodesData nodes = DataMethods.GetCachedDayNodesData(symbols[n], fd, Interval.HalfSecond, computeNodes: false, justCache: true);
                        sw.Stop();
                        tc.Log.AddLine("[" + symbols[n] + "] " + fd.ToString() + " Done. Took " + UC.MillisecondsToSeconds(sw.ElapsedMilliseconds, 2) + " sec(s)");
                    }
                    else
                    {
                        tc.Log.AddLine("[" + symbols[n] + "] " + fd.ToString() + ". Not cacheable.");
                    }
                });

                dt = dt.AddDays(-1);
            }
        }