Пример #1
0
        private async Task Simulator_Start(string symbol)
        {
            simulatorStarted = true;
            StateHasChanged();

            ////TEMP
            //FilesManager.MoveQFilesToDatedFolders();
            //return;

            /// Get all the feed file names for the TDAStreamerData.simulatorSettings

            TDAStreamerData.runDate = TDAStreamerData.simulatorSettings.runDate;

            TDAStreamerData.simulatorSettings.currentSimulatedTime = TDAStreamerData.simulatorSettings.runDateDate.Add(TDAStreamerData.simulatorSettings.startTime.TimeOfDay);
            if (TDAStreamerData.simulatorSettings.isSimulated != null && TDAStreamerData.simulatorSettings.isSimulated == false)
            /// means the simulator was stopped so need to reset counts
            {
                DictTopicCounts_Initialize();
            }
            TDAStreamerData.simulatorSettings.isSimulated = true;

            Dictionary <DateTime, string> feedFilesList = FilesManager.GetFeedFileNames(symbol, TDAStreamerData.simulatorSettings);

            /// Process each file
            foreach (var feedFile in feedFilesList)
            {
                /// Get the next feed file and make it a json Array
                //await Task.Yield();

                var fileJson = FilesManager.GetFeedFile(feedFile.Value);
                var feedJson = $"{{ \"data\":[{fileJson}] }}";

                //await Task.Yield();
                /// Process file
                await TDAStreamerOnMessage(feedJson);

                //await Task.Yield();
                /// Wait for next file
                int delayMilliSecs = TDAStreamerData.simulatorSettings.clockDelay;
                await Task.Delay(delayMilliSecs);

                //await Task.Yield();

                /// Pause the simulator
                while (simulatorPaused)
                {
                    await Task.Yield();

                    await Task.Delay(1000);
                }
                /// Stop the simulator
                if (simulatorStarted == false)
                {
                    break;
                }
            }
        }
Пример #2
0
        private async Task TDA_Process_Data(string jsonResponse)
        {
            var dataJsonSvcArray = JObject.Parse(jsonResponse)["data"];

            foreach (var svcJsonObject in dataJsonSvcArray)
            {
                var svcName = svcJsonObject["service"].ToString();
                //if (simulatorSettings!=null && simulatorSettings.isSimulated)
                svcDateTime = GetServiceTime(svcJsonObject);

                var svcJson        = svcJsonObject.ToString();
                var svcFieldedJson = svcJson;

                /// Decode
                /// Get field names corresponding to field numbers
                List <string> svcFields = TDAConstants.TDAResponseFields[svcName];
                /// Replace field numbers with field names
                for (int i = 1; i < svcFields.Count; i++)
                {
                    string sIndex = $"\"{i}\":";
                    svcFieldedJson = svcFieldedJson.Replace(sIndex, $" \"{svcFields[i]}\":");
                }

                if (TDAStreamerData.simulatorSettings != null && !TDAStreamerData.simulatorSettings.buildDatabaseDuringSimulate)
                {
                    LogText("DECODED: " + svcFieldedJson);
                }

                var svcJsonObjectDecoded = JObject.Parse(svcFieldedJson);
                //var contents = svcJsonObjectDecoded["content"].ToString();

                /// Send to connected hub
                ///
                await TDAStreamerData.captureTdaServiceData(svcFieldedJson);

                clock = TDAChart.svcDateTime.ToString(clockFormat);

                /// Send to message queue
                /// We can replay these messages later from simulator
                /// Need to NOT reswnd
                dictTopicCounts[svcName] += 1;
                if (!simulate)
                {
                    await FilesManager.SendToMessageQueue(symbol, svcName, svcDateTime, svcFieldedJson);
                }
                //await Send(svcName, svcFieldedJson);
                StateHasChanged();
            }
        }
Пример #3
0
        public static void SaveToCsvFile(string svcName, string symbol, TimeSales_Content timeAndSales)
        {
            List <string> timeAndSalesFields = FilesManager.GetCSVHeader(new TimeSales_Content()).Split(',').ToList();

            var lstValues = new List <string>();

            foreach (string name in timeAndSalesFields)
            {
                lstValues.Add($"{timeAndSales[name]}");
            }
            string record = string.Join(',', lstValues) + "\n";

            string fileName = $"{svcName} {symbol} {DateTime.Now.ToString("MMM dd yyyy")}.csv";

            if (!System.IO.File.Exists(fileName))
            {
                System.IO.File.AppendAllText(fileName, string.Join(",", timeAndSalesFields) + "\n");
            }
            System.IO.File.AppendAllText(fileName, record);
        }
Пример #4
0
        private void sendTimeSalesData()
        {
            if (TDAStreamerData.simulatorSettings != null && TDAStreamerData.simulatorSettings.buildDatabaseDuringSimulate)
            {
                return;
            }
            console.warn(System.Reflection.MethodBase.GetCurrentMethod().Name);
            console.warn($"TDAChart.svcDateTime: {TDAChart.svcDateTime}  lastSvcTime:  {lastSvcTime}");
            if (TDAChart.svcDateTime != lastSvcTime)
            {
                //JsConsole.JsConsole.Warn(TDAStreamerJs, TDAChart.svcDateTime.Subtract(lastSvcTime).Milliseconds);
                i++;
                //if (lastSvcTime == null)
                //    lastSvcTime = TDAChart.svcDateTime;
                //else if (TDAChart.svcDateTime.Subtract(lastSvcTime).Milliseconds >= 500)
                //{


                //JsConsole.JsConsole.Warn(TDAStreamerJs, TDAChart.svcDateTime.Subtract(lastSvcTime).Milliseconds);
                //var msg = TDAChart.svcDateTime.ToOADate().ToString();


                sendData();
                lastSvcTime = TDAChart.svcDateTime;
                //Send("TimeAndSales", JsonSerializer.Serialize<Data.TimeSales_Content>(TDAStreamerData.timeAndSales));
                // Send("TimeAndSales", msg);
                StateHasChanged();
                //}
                async Task sendData()
                {
                    console.warn("sendData");


                    /// 3 needs to be set from client
                    var ratioFrames = await TDABookManager.getIncrementalRatioFrames(TDABook.seconds);

                    /// So we don't send the same frame more than once
                    if (ratioFrames[0].dateTime != prevRatioFrameDateTime)
                    {
                        // System.Diagnostics.Debug.Print(ratioFrames[0].dateTime.ToLongTimeString());
                        prevRatioFrameDateTime = ratioFrames[0].dateTime;
                        try
                        {
                            console.warn($"ratioFrames[0].dateTime: {ratioFrames[0].dateTime}  prevRatioFrameDateTime: {prevRatioFrameDateTime}");
                            var msg = JsonSerializer.Serialize <RatioFrame[]>(ratioFrames);
                            await Send("getIncrementalRatioFrames", msg);

                            //console.warn("sendData:" + msg, true);

                            /// TODO: Remove this to rebuild old AllRatioFrames files! !!!!!!!!!!!!!!!!!!!!!!!!!
                            ///
                            var buildAllRatioFrames =
                                TDAStreamerData.simulatorSettings.isSimulated == null ||
                                !(bool)TDAStreamerData.simulatorSettings.isSimulated ||
                                TDAStreamerData.simulatorSettings.rebuildAllRatioFrames
                            ;

                            if (buildAllRatioFrames)
                            {
                                await FilesManager.AppendToMessageQueue(symbol, "AllRatioFrames", svcDateTime, msg);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            //Send("TimeAndSales", JsonSerializer.Serialize<TimeSales_Content>(TDAStreamerData.timeAndSales));
            //sendPrintsData();
            //Send("TimeAndSales", JsonSerializer.Serialize<TimeSales_Content>(TDAStreamerData.timeAndSales));


            //dictTopicCounts["TimeAndSales"] += 1;
        }