/// <summary> /// Perform extraction of trading data, write results in csv /// </summary> internal async Task Extract() { if (_paused) { return; } var now = DateTime.Now; IEnumerable <Trade> trades = null; try { trades = await _tradingService.GetTradesAsync(now); } catch (Exception ex) { Log(ex.Message); //cant miss extract Log($"Repeating extract in {_serviceErrorDelay} ms"); var worker = new BackgroundWorker(); worker.DoWork += async delegate { Thread.Sleep(_serviceErrorDelay); await Extract(); worker.Dispose(); }; worker.RunWorkerAsync(); } if (trades == null) { return; } try { var aggregations = AggregateTrades(trades); if (aggregations.Count != 24) { Log("Amount of periods is not 24"); } var lines = PrepareOutput(aggregations); //write to csv _csvWriter.Dump($"{now.ToString("yyyyMMdd_HHmm")}.csv", lines); } catch (Exception ex) { Log(ex.Message); } }