Esempio n. 1
0
        private async Task RemoveExpiredKeysAsync(IEnumerable <TrustKeyDto> expiredKeys, List <TrustKeyDto> keyCache)
        {
            foreach (var expiredKey in expiredKeys)
            {
                await _nexusDb.AddAsync(new TrustKey
                {
                    GenesisBlock = await _nexusDb.Blocks.FirstOrDefaultAsync(x => x.Height == expiredKey.GenesisBlockHeight),
                    Address      = await _nexusDb.Addresses.FirstOrDefaultAsync(x => x.AddressId == expiredKey.AddressId),
                    Transaction  = await _nexusDb.Transactions.FirstOrDefaultAsync(x => x.TransactionId == expiredKey.TransactionId),
                    Hash         = expiredKey.TrustHash,
                    Key          = expiredKey.TrustKey,
                    CreatedOn    = DateTime.Now
                });

                keyCache.RemoveAll(x => x.TrustKey == expiredKey.TrustKey);
            }

            await _nexusDb.SaveChangesAsync();
        }
Esempio n. 2
0
        protected override async Task ExecuteAsync()
        {
            var nxsSummary = await _bittrexClient.GetMarketSummaryAsync(Market);

            var btcTicket = await _bittrexClient.GetTickerAsync(UsdMarket);

            if (btcTicket != null)
            {
                await _redis.SetAsync(Settings.Redis.BittrexLastUsdBtcPrice, btcTicket.Last);
            }

            if (nxsSummary == null)
            {
                Logger.LogInformation("Bittrex data not availible");
                return;
            }

            await _redis.SetAsync(Settings.Redis.BittrexLastBtcNxsPrice, nxsSummary.Last);

            var summary = nxsSummary.ToBittrexSummary();

            Interlocked.Increment(ref _runCount);

            if (_runCount == DbSaveRunInterval)
            {
                await _nexusDb.BittrexSummaries.AddAsync(summary);

                await _nexusDb.SaveChangesAsync();

                Interlocked.Exchange(ref _runCount, 0);

                Logger.LogInformation("Latest Bittrex data saved to DB");
            }

            var summaryDto = new BittrexSummaryDto(summary);

            await _redis.PublishAsync(Settings.Redis.BittrexSummaryPubSub, summaryDto);

            await _redis.SetAsync(Settings.Redis.BittrexSummaryPubSub, summaryDto);
        }