public async Task DeleteBacktestCandles(BacktestOptions backtestOptions) { LiteCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <CandleAdapter>("Candle_" + backtestOptions.CandlePeriod); candleCollection.EnsureIndex("Timestamp"); candleCollection.Delete(Query.Between("Timestamp", backtestOptions.StartDate, backtestOptions.EndDate, true, true)); }
public async Task SaveBacktestCandlesBulk(List <Candle> candles, BacktestOptions backtestOptions) { var items = Mapping.Mapper.Map <List <CandleAdapter> >(candles); LiteCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <CandleAdapter>("Candle_" + backtestOptions.CandlePeriod); candleCollection.EnsureIndex("Timestamp"); candleCollection.InsertBulk(items); }
public async Task <Candle> GetBacktestLastCandle(BacktestOptions backtestOptions) { IMongoCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <CandleAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); CandleAdapter lastCandle = await candleCollection.Find(_ => true).SortByDescending(e => e.Timestamp).Limit(1).FirstOrDefaultAsync(); var items = Mapping.Mapper.Map <Candle>(lastCandle); return(items); }
public async Task <Candle> GetBacktestFirstCandle(BacktestOptions backtestOptions) { LiteCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <CandleAdapter>("Candle_" + backtestOptions.CandlePeriod); candleCollection.EnsureIndex("Timestamp"); CandleAdapter lastCandle = candleCollection.Find(Query.All("Timestamp"), limit: 1).FirstOrDefault(); var items = Mapping.Mapper.Map <Candle>(lastCandle); return(items); }
public async Task <List <TradeSignal> > GetBacktestSignalsByStrategy(BacktestOptions backtestOptions, string strategy) { var itemCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <TradeSignalAdapter>("Signals_" + backtestOptions.CandlePeriod); itemCollection.EnsureIndex("StrategyName"); var items = itemCollection.Find(Query.Where("StrategyName", s => s.AsString == strategy), Query.Descending).ToList(); var result = Mapping.Mapper.Map <List <TradeSignal> >(items); return(result); }
public async Task <List <TradeSignal> > GetBacktestSignalsByStrategy(BacktestOptions backtestOptions, string strategy) { IMongoCollection <TradeSignalAdapter> itemCollection = DataStoreBacktest.GetInstance("Signals_" + MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <TradeSignalAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); var items = await itemCollection.Find(entry => entry.StrategyName == strategy).ToListAsync(); #warning TODO: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit=> temporarly order by LINQ var result = Mapping.Mapper.Map <List <TradeSignal> >(items).OrderBy(c => c.Timestamp).ToList(); return(result); }
public async Task SaveBacktestCandlesBulkCheckExisting(List <Candle> candles, BacktestOptions backtestOptions) { var items = Mapping.Mapper.Map <List <CandleAdapter> >(candles); LiteCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <CandleAdapter>("Candle_" + backtestOptions.CandlePeriod); foreach (var item in items) { var checkData = candleCollection.FindOne(x => x.Timestamp == item.Timestamp); if (checkData == null) { candleCollection.Insert(item); } } }
public async Task SaveBacktestCandle(Candle candle, BacktestOptions backtestOptions) { var item = Mapping.Mapper.Map <CandleAdapter>(candle); LiteCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <CandleAdapter>("Candle_" + backtestOptions.CandlePeriod); candleCollection.EnsureIndex("Timestamp"); var newCandle = candleCollection.FindOne(x => x.Timestamp == item.Timestamp); if (newCandle == null) { candleCollection.Insert(item); } }
public async Task <List <Candle> > GetBacktestCandlesBetweenTime(BacktestOptions backtestOptions) { var results = new List <Candle>(); IMongoCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <CandleAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); List <CandleAdapter> candles = await candleCollection.Find(entry => entry.Timestamp >= backtestOptions.StartDate && entry.Timestamp <= backtestOptions.EndDate).ToListAsync(); #warning TODO: Sort operation used more than the maximum 33554432 bytes of RAM. Add an index, or specify a smaller limit=> temporarly order by LINQ results = Mapping.Mapper.Map <List <Candle> >(candles).OrderBy(c => c.Timestamp).ToList(); return(results); }
public async Task SaveBacktestTradeSignalsBulk(List <TradeSignal> signals, BacktestOptions backtestOptions) { var items = Mapping.Mapper.Map <List <TradeSignalAdapter> >(signals); IMongoCollection <TradeSignalAdapter> itemCollection = DataStoreBacktest.GetInstance("Signals_" + MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <TradeSignalAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); foreach (var item in items) { await itemCollection.DeleteManyAsync(i => i.StrategyName == item.StrategyName); } await itemCollection.InsertManyAsync(items); }
public async Task SaveBacktestCandle(Candle candle, BacktestOptions backtestOptions) { var item = Mapping.Mapper.Map <CandleAdapter>(candle); IMongoCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <CandleAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); FindOptions <CandleAdapter> marketCandleFindOptions = new FindOptions <CandleAdapter> { Limit = 1 }; IAsyncCursor <CandleAdapter> checkData = await candleCollection.FindAsync(x => x.Timestamp == item.Timestamp, marketCandleFindOptions); if (await checkData.FirstOrDefaultAsync() == null) { await candleCollection.InsertOneAsync(item); } }
public async Task <List <Candle> > GetBacktestCandlesBetweenTime(BacktestOptions backtestOptions) { try { LiteCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <CandleAdapter>("Candle_" + backtestOptions.CandlePeriod); candleCollection.EnsureIndex("Timestamp"); List <CandleAdapter> candles = candleCollection.Find(Query.Between("Timestamp", backtestOptions.StartDate, backtestOptions.EndDate), Query.Ascending).ToList(); var items = Mapping.Mapper.Map <List <Candle> >(candles); return(items); } catch (Exception ex) { Global.Logger.Error(ex.ToString()); throw; } }
public async Task SaveBacktestTradeSignalsBulk(List <TradeSignal> signals, BacktestOptions backtestOptions) { var items = Mapping.Mapper.Map <List <TradeSignalAdapter> >(signals); LiteCollection <TradeSignalAdapter> itemCollection = DataStoreBacktest.GetInstance(GetDatabase(backtestOptions)).GetTable <TradeSignalAdapter>("Signals_" + backtestOptions.CandlePeriod); foreach (var item in items) { itemCollection.Delete(i => i.StrategyName == item.StrategyName); } // TradeSignalAdapter lastCandle = itemCollection.Find(Query.All("Timestamp", Query.Descending), limit: 1).FirstOrDefault(); itemCollection.EnsureIndex("Timestamp"); itemCollection.InsertBulk(items); }
public async Task SaveBacktestCandlesBulkCheckExisting(List <Candle> candles, BacktestOptions backtestOptions) { var items = Mapping.Mapper.Map <List <CandleAdapter> >(candles); IMongoCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <CandleAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); FindOptions <CandleAdapter> marketCandleFindOptions = new FindOptions <CandleAdapter> { Limit = 1 }; foreach (var item in items) { IAsyncCursor <CandleAdapter> checkData = await candleCollection.FindAsync(x => x.Timestamp.Equals(item.Timestamp), marketCandleFindOptions); if (await checkData.FirstOrDefaultAsync() == null) { await candleCollection.InsertOneAsync(item); } } }
public async Task DeleteBacktestCandles(BacktestOptions backtestOptions) { IMongoCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <CandleAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); await candleCollection.DeleteManyAsync(entry => entry.Timestamp >= backtestOptions.StartDate && entry.Timestamp <= backtestOptions.EndDate); }
public async Task SaveBacktestCandlesBulk(List <Candle> candles, BacktestOptions backtestOptions) { var items = Mapping.Mapper.Map <List <CandleAdapter> >(candles); IMongoCollection <CandleAdapter> candleCollection = DataStoreBacktest.GetInstance(MongoDbBaseName + backtestOptions.CandlePeriod).GetTable <CandleAdapter>(backtestOptions.Exchange + "_" + backtestOptions.Coin); await candleCollection.InsertManyAsync(items); }