Пример #1
0
        public async Task <List <Order> > UpdateOrders(List <Watcher> watchers)
        {
            // Start watch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Grab watchers willing to buy or sell
            watchers = watchers.Where(WatcherExpression.WatcherWillingToBuyOrSell().Compile()).ToList();

            // Get all orders
            var orders = await _mainDbContext.Orders.ToListAsync();

            // Build new orders
            var newOrders = OrderBuilder.BuildNewOrders(watchers, orders);

            // Add
            _mainDbContext.Orders.AddRange(newOrders);

            // Save
            await _mainDbContext.SaveChangesAsync();

            // Stop watch
            stopwatch.Stop();

            // Log into Splunk
            _logger.LogSplunkInformation("UpdateOrders", new
            {
                newOrders.Count,
                ExecutionTime = stopwatch.Elapsed.TotalSeconds
            });

            // Return
            return(newOrders);
        }
Пример #2
0
        public async Task <List <Line> > UpdateLines(List <Currency> currencies, List <Indicator> indicators)
        {
            // Start watch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Get watchers willing to buy or sell
            var watchers = await _mainDbContext.Watchers.Where(WatcherExpression.WatcherWillingToBuyOrSell()).ToListAsync();

            // Build new lines
            var lines = LineBuilder.BuildLines(currencies, indicators, watchers);

            // Set new lines
            _mainDbContext.Lines.AddRange(lines);

            // Save
            await _mainDbContext.SaveChangesAsync();

            // Stop watch
            stopwatch.Stop();

            // Log into Splunk
            _logger.LogSplunkInformation("UpdateLines", new
            {
                lines.Count,
                ExecutionTime = stopwatch.Elapsed.TotalSeconds
            });

            // Return
            return(lines);
        }
Пример #3
0
        public async Task Run()
        {
            try
            {
                // Start watch

                var stopwatch = new Stopwatch();
                stopwatch.Start();

                // Get all currencies
                var currencies = await _currencyRepository.GetAll();

                // Get all indicators
                var indicators = await _indicatorRepository.GetAll();

                // Set all indicators dependencies
                await SetIndicatorDependencies(indicators);

                // Get non-default watchers with buy or sell
                var watchers = await _watcherRepository.GetAll(WatcherExpression.WatcherWillingToBuyOrSell());

                // Set current lines as no longer current
                await SetCurrentLinesAsNoLongerCurrent();

                // Build new lines
                var lines = LineBuilder.BuildLines(currencies, indicators, watchers);

                // Set new lines
                _lineRepository.AddRange(lines);

                // Save
                await _mainDbContext.SaveChangesAsync();

                // Stop watch
                stopwatch.Stop();

                // Log into Splunk
                _logger.LogSplunkJob(new
                {
                    lines.Count,
                    ExecutionTime = stopwatch.Elapsed.TotalSeconds
                });

                // Return
                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                // Log into Splunk
                _logger.LogSplunkJob(new
                {
                    JobFailed = ex.Message
                });

                // Log error into Splunk
                _logger.LogSplunkError(ex);
            }
        }
Пример #4
0
        public async Task Run()
        {
            try
            {
                // Start watch
                var stopwatch = new Stopwatch();
                stopwatch.Start();

                // Get all watchers with buy or sells
                var watchers = await _watcherRepository.GetAll(WatcherExpression.WatcherWillingToBuyOrSell());

                // Get all orders
                var orders = await _orderRepository.GetAll();

                // Build new orders
                var newOrders = OrderBuilder.BuildNewOrders(watchers, orders);

                // Add
                _orderRepository.AddRange(newOrders);

                // Save
                await _mainDbContext.SaveChangesAsync();

                // Stop watch
                stopwatch.Stop();

                // Log into Splunk
                _logger.LogSplunkJob(new
                {
                    newOrders.Count,
                    ExecutionTime = stopwatch.Elapsed.TotalSeconds
                });

                // Return
                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                // Log into Splunk
                _logger.LogSplunkJob(new
                {
                    JobFailed = ex.Message
                });

                // Log error into Splunk
                _logger.LogSplunkError(ex);
            }
        }