示例#1
0
        public async Task <List <Deposit> > AddDeposits(List <Deposit> deposits, string exchange)
        {
            _log.LogInformation($"Adding new deposits to database");

            var context = _context.Deposits;
            var list    = new List <Deposit>();

            foreach (var deposit in deposits)
            {
                deposit.Exchange = exchange;
                var singleOrDefault = context.SingleOrDefault(x => x.Currency == deposit.Currency &&
                                                              x.Time == deposit.Time &&
                                                              x.Exchange == deposit.Exchange &&
                                                              x.Address == deposit.Address &&
                                                              x.Amount == deposit.Amount &&
                                                              x.TransactionId == deposit.TransactionId);

                if (singleOrDefault == null)
                {
                    context.Add(deposit);
                    list.Add(deposit);
                }
            }

            await _context.SaveChangesAsync();

            return(list);
        }
示例#2
0
        public async Task AddLastChecked(string exchange, DateTime timestamp)
        {
            var lastCheckeds = _context.LastCheckeds;
            var lastChecked  = lastCheckeds.SingleOrDefault(x => x.Exchange == exchange);

            if (lastChecked == null)
            {
                lastCheckeds.Add(new LastChecked
                {
                    Exchange  = exchange,
                    Timestamp = timestamp
                });
            }
            else
            {
                lastChecked.Timestamp = timestamp;
            }

            await _context.SaveChangesAsync();
        }
示例#3
0
        public async Task MigrateToSqlLite()
        {
            var allSettings = _context.Settings;

            if (!File.Exists(Directory.GetCurrentDirectory() + "/database/cryptogrambot.db"))
            {
                return;
            }

            var hasMigratedBefore = allSettings.SingleOrDefault(x => x.Name == "SQLite.Migration.Complete");

            if (hasMigratedBefore != null && hasMigratedBefore.Value != "true")
            {
                var balanceHistories = _liteDbDatabaseService.GetAllBalances();

                foreach (var balanceHistory in balanceHistories)
                {
                    _context.Set <BalanceHistory>().Add(balanceHistory);
                }

                var allTrades = _liteDbDatabaseService.GetAllTrades();
                foreach (var allTrade in allTrades)
                {
                    _context.Set <Trade>().Add(allTrade);
                }

                var allLastChecked = _liteDbDatabaseService.GetAllLastChecked();
                foreach (var lastChecked in allLastChecked)
                {
                    _context.Set <LastChecked>().Add(lastChecked);
                }

                var allProfitAndLoss = _liteDbDatabaseService.GetAllProfitAndLoss();
                foreach (var pnl in allProfitAndLoss)
                {
                    _context.Set <ProfitAndLoss>().Add(pnl);
                }

                _liteDbDatabaseService.Close();

                var setting = new Setting
                {
                    Name  = "SQLite.Migration.Complete",
                    Value = "true"
                };

                _context.Settings.Add(setting);

                await _context.SaveChangesAsync();
            }
        }