private async Task DoProcess() { try { while (!_token.IsCancellationRequested) { try { foreach (var pair in _brokers.ToList()) { var brokerId = pair.Key; var symbol = pair.Value; var writerBidAsk = new MyNoSqlServer.DataWriter.MyNoSqlServerDataWriter <CandleBidAskNoSql>( Program.ReloadedSettings(model => model.MyNoSqlWriterUrl), CandleBidAskNoSql.TableNameMinute(brokerId), true); await writerBidAsk.CleanAndKeepMaxRecords(CandleBidAskNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 1).Date), 0); await writerBidAsk.CleanAndKeepMaxRecords(CandleBidAskNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 2).Date), 0); await writerBidAsk.CleanAndKeepMaxRecords(CandleBidAskNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 3).Date), 0); await writerBidAsk.CleanAndKeepMaxRecords(CandleBidAskNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 4).Date), 0); await writerBidAsk.CleanAndKeepMaxRecords(CandleBidAskNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 5).Date), 0); await writerBidAsk.CleanAndKeepMaxRecords(CandleBidAskNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 6).Date), 0); await writerBidAsk.CleanAndKeepMaxRecords(CandleBidAskNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 7).Date), 0); var writerTrade = new MyNoSqlServer.DataWriter.MyNoSqlServerDataWriter <CandleTradeNoSql>( Program.ReloadedSettings(model => model.MyNoSqlWriterUrl), CandleTradeNoSql.TableNameMinute(brokerId), true); await writerTrade.CleanAndKeepMaxRecords(CandleTradeNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 1).Date), 0); await writerTrade.CleanAndKeepMaxRecords(CandleTradeNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 2).Date), 0); await writerTrade.CleanAndKeepMaxRecords(CandleTradeNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 3).Date), 0); await writerTrade.CleanAndKeepMaxRecords(CandleTradeNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 4).Date), 0); await writerTrade.CleanAndKeepMaxRecords(CandleTradeNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 5).Date), 0); await writerTrade.CleanAndKeepMaxRecords(CandleTradeNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 6).Date), 0); await writerTrade.CleanAndKeepMaxRecords(CandleTradeNoSql.GeneratePartitionKey(symbol, DateTime.UtcNow.AddDays(-Program.Settings.DaysToKeepMinutes - 7).Date), 0); _logger.LogInformation("Cleanup minutes for broker: {brokerId} and symbol: {symbol}", brokerId, symbol); } } catch (Exception ex) { _logger.LogError(ex, "Cannot cleanup minutes"); } await Task.Delay(TimeSpan.FromHours(1), _token.Token); } } catch (Exception) { } }
public IMyNoSqlServerDataWriter <CandleBidAskNoSql> GetWriter(string brokerId, CandleType type) { if (type == CandleType.Minute) { if (_minuteWriterByBroker.TryGetValue(brokerId, out var writer)) { return(writer); } writer = new MyNoSqlServer.DataWriter.MyNoSqlServerDataWriter <CandleBidAskNoSql>( Program.ReloadedSettings(model => model.MyNoSqlWriterUrl), CandleBidAskNoSql.TableNameMinute(brokerId), true); _minuteWriterByBroker[brokerId] = writer; return(writer); } if (type == CandleType.Hour) { if (_hourWriterByBroker.TryGetValue(brokerId, out var writer)) { return(writer); } writer = new MyNoSqlServer.DataWriter.MyNoSqlServerDataWriter <CandleBidAskNoSql>( Program.ReloadedSettings(model => model.MyNoSqlWriterUrl), CandleBidAskNoSql.TableNameHour(brokerId), true); _hourWriterByBroker[brokerId] = writer; return(writer); } if (type == CandleType.Day) { if (_dayWriterByBroker.TryGetValue(brokerId, out var writer)) { return(writer); } writer = new MyNoSqlServer.DataWriter.MyNoSqlServerDataWriter <CandleBidAskNoSql>( Program.ReloadedSettings(model => model.MyNoSqlWriterUrl), CandleBidAskNoSql.TableNameDay(brokerId), true); _dayWriterByBroker[brokerId] = writer; return(writer); } if (type == CandleType.Month) { if (_monthWriterByBroker.TryGetValue(brokerId, out var writer)) { return(writer); } writer = new MyNoSqlServer.DataWriter.MyNoSqlServerDataWriter <CandleBidAskNoSql>( Program.ReloadedSettings(model => model.MyNoSqlWriterUrl), CandleBidAskNoSql.TableNameMonth(brokerId), true); _monthWriterByBroker[brokerId] = writer; return(writer); } throw new Exception($"Unknown candle type {type}"); }
private void RegisterNoSqlClient(string brokerId) { MyNoSqlTcpClient client; lock (_gate) { if (_myNoSqlSubscriberByBroker.TryGetValue(brokerId, out client)) { return; } client = new MyNoSqlTcpClient(_getMyNoSqlHostPort, $"{_appName}-{brokerId}"); _minuteBidAskReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleBidAskNoSql>(client, CandleBidAskNoSql.TableNameMinute(brokerId)); _hourBidAskReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleBidAskNoSql>(client, CandleBidAskNoSql.TableNameHour(brokerId)); _dayBidAskReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleBidAskNoSql>(client, CandleBidAskNoSql.TableNameDay(brokerId)); _monthBidAskReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleBidAskNoSql>(client, CandleBidAskNoSql.TableNameMonth(brokerId)); _minuteTradeReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleTradeNoSql>(client, CandleTradeNoSql.TableNameMinute(brokerId)); _hourTradeReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleTradeNoSql>(client, CandleTradeNoSql.TableNameHour(brokerId)); _dayTradeReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleTradeNoSql>(client, CandleTradeNoSql.TableNameDay(brokerId)); _monthTradeReaderByBroker[brokerId] = new MyNoSqlReadRepository <CandleTradeNoSql>(client, CandleTradeNoSql.TableNameMonth(brokerId)); _myNoSqlSubscriberByBroker[brokerId] = client; } client.Start(); //todo: use wait initialization var index = 0; while (index < 50) { if (_minuteBidAskReaderByBroker[brokerId].Count() > 0 && _hourBidAskReaderByBroker[brokerId].Count() > 0 && _dayBidAskReaderByBroker[brokerId].Count() > 0 && _monthBidAskReaderByBroker[brokerId].Count() > 0 && _minuteTradeReaderByBroker[brokerId].Count() > 0 && _hourTradeReaderByBroker[brokerId].Count() > 0 && _dayTradeReaderByBroker[brokerId].Count() > 0 && _monthTradeReaderByBroker[brokerId].Count() > 0) { break; } Thread.Sleep(100); index++; } }