コード例 #1
0
        public IEnumerable <CandleTrade> GetLastCandlesTradeHistoryDesc(string brokerId, string symbol, int count, CandleType type)
        {
            var now = DateTime.UtcNow;
            var day = new DateTime(now.Year, now.Month, now.Day);

            var to = now.AddYears(-10);

            var index = 0;

            var reader = GetReaderTrade(brokerId, type);

            while (index < count && day > to)
            {
                var data = reader.Get(CandleTradeNoSql.GeneratePartitionKey(symbol, day));

                if (data != null)
                {
                    foreach (var item in data.Select(e => e.Candle).OrderByDescending(e => e.DateTime))
                    {
                        index++;
                        yield return(item);

                        if (index >= count)
                        {
                            break;
                        }
                    }
                }

                day = day.AddDays(-1);
            }
        }
コード例 #2
0
        public IEnumerable <CandleTrade> GetCandlesTradeHistoryDesc(string brokerId, string symbol, DateTime @from, DateTime to, CandleType type)
        {
            var reader = GetReaderTrade(brokerId, type);

            var day = new DateTime(to.Year, to.Month, to.Day);

            var end = from.AddDays(-1);

            while (day >= end)
            {
                var data = reader.Get(CandleTradeNoSql.GeneratePartitionKey(symbol, day),
                                      entity => entity.Candle.DateTime >= from && entity.Candle.DateTime <= to);

                if (data != null)
                {
                    foreach (var item in data.Select(e => e.Candle).OrderByDescending(e => e.DateTime))
                    {
                        yield return(item);
                    }
                }

                day = day.AddDays(-1);
            }
        }
コード例 #3
0
        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)
            { }
        }