private async Task StartMonitoringInner(CancellationToken cancellationToken)
        {
            _stockSocketConnector.Connect();

            var tradingSettings      = _configurationService.GetTradingSettings();
            var tradingCurrencyPairs = await GetActiveCurrencyPairs();

            var periodsForAnalysis = new[]
            {
                tradingSettings.Period.GetLowerFramePeriod(),
                tradingSettings.Period,
                tradingSettings.Period.GetHigherFramePeriod()
            };

            foreach (var currencyPair in tradingCurrencyPairs)
            {
                await _candleLoadingService.InitSubscription(currencyPair.Id, periodsForAnalysis);

                _candleLoadingService.CandlesUpdated += (o, e) =>
                {
                    if (e.Period != tradingSettings.Period)
                    {
                        return;
                    }

                    CheckOutForNewPosition(currencyPair);
                };
            }

            WaitHandle.WaitAny(new[] { cancellationToken.WaitHandle });

            await _stockSocketConnector.Disconnect();
        }
Ejemplo n.º 2
0
        private async Task StartTradingInner(CancellationToken cancellationToken)
        {
            await _stockSocketConnector.ConnectAsync();

            await _tradingPositionService.SyncExistingPositionsWithStock(positionChangedEventArgs => _tradingEventsObserver.RaisePositionChanged(positionChangedEventArgs));

            await LoadExistingPositions();

            await CheckOutNewTickersForRequiredVolume();

            WaitHandle.WaitAny(new[] { cancellationToken.WaitHandle });

            await _stockSocketConnector.Disconnect();
        }