Example #1
0
        private static async Task ShowOrderBookLatenciesDistribution(string connectionString)
        {
            using var file = File.CreateText("Analysis(orderbook).txt");
            var orderBooks = await MartenTypes.LoadOrderBook(connectionString, file);

            var groups = orderBooks.GroupBy(x => x.ExchangeDateTime == null).ToDictionary(x => x.Key);

            file.WriteLine($"{groups[true].Count()} orderbooks with ExchangeDateTime == null");


            file.WriteLine("Distribution of latencies:");

            var latencyGroupsByExchangeName = groups[false]
                                              .Select(x => (x.ExchangeName, Latency: (int)(x.DateTime - x.ExchangeDateTime.Value).TotalMilliseconds))
                                              .GroupBy(x => x.ExchangeName)
                                              .ToDictionary(x => x.Key,
                                                            x => x.GroupBy(y => y.Latency)
                                                            .OrderBy(y => y.Key));

            foreach (var latencyGroups in latencyGroupsByExchangeName)
            {
                file.WriteLine(latencyGroups.Key);
                file.WriteLine();

                foreach (var latencyGroup in latencyGroups.Value)
                {
                    file.WriteLine($"{latencyGroup.Key:D6} ms, count {latencyGroup.Count()}");
                }

                file.WriteLine();
            }
        }
Example #2
0
        private static async Task ShowTradesLatenciesDistribution(string connectionString)
        {
            using var file = File.CreateText("Analysis(trades).txt");
            var trades = await MartenTypes.LoadTrades(connectionString, file);

            file.WriteLine("Distribution of trades latencies:");

            var latencyGroupsByExchangeName = trades
                                              .SelectMany(x => x.TradeItems, (x, y) => (x.ExchangeName, Latency: (int)(x.DateTime - y.TransactionTime).TotalMilliseconds))
                                              .GroupBy(x => x.ExchangeName)
                                              .ToDictionary(x => x.Key,
                                                            x => x.GroupBy(y => y.Latency)
                                                            .OrderBy(y => y.Key));

            foreach (var latencyGroups in latencyGroupsByExchangeName)
            {
                file.WriteLine(latencyGroups.Key);
                file.WriteLine();

                foreach (var latencyGroup in latencyGroups.Value)
                {
                    file.WriteLine($"{latencyGroup.Key:D6} ms, count {latencyGroup.Count()}");
                }

                file.WriteLine();
            }
        }