public async Task <HedgeSettings> GetAsync()
        {
            HedgeSettings hedgeSettings = _cache.Get(CacheKey);

            if (hedgeSettings == null)
            {
                hedgeSettings = await _hedgeSettingsRepository.GetAsync();

                if (hedgeSettings == null)
                {
                    hedgeSettings = new HedgeSettings
                    {
                        MarketOrderMarkup = .02m,
                        ThresholdDown     = 1000,
                        ThresholdUp       = 5000,
                        ThresholdDownBuy  = 1000,
                        ThresholdDownSell = 1000,
                        ThresholdUpBuy    = 5000,
                        ThresholdUpSell   = 5000,
                        ThresholdCritical = 10000
                    };
                }

                _cache.Initialize(new[] { hedgeSettings });

                bool isDirty = false;

                if (hedgeSettings.ThresholdDownBuy == default(decimal))
                {
                    hedgeSettings.ThresholdDownBuy = hedgeSettings.ThresholdDown;
                    isDirty = true;
                }

                if (hedgeSettings.ThresholdDownSell == default(decimal))
                {
                    hedgeSettings.ThresholdDownSell = hedgeSettings.ThresholdDown;
                    isDirty = true;
                }

                if (hedgeSettings.ThresholdUpBuy == default(decimal))
                {
                    hedgeSettings.ThresholdUpBuy = hedgeSettings.ThresholdUp;
                    isDirty = true;
                }

                if (hedgeSettings.ThresholdUpSell == default(decimal))
                {
                    hedgeSettings.ThresholdUpSell = hedgeSettings.ThresholdUp;
                    isDirty = true;
                }

                if (isDirty)
                {
                    await UpdateAsync(hedgeSettings);
                }
            }

            return(hedgeSettings);
        }
        private async Task <IReadOnlyCollection <Domain.PnLStopLossSettings> > Initialize()
        {
            IReadOnlyCollection <Domain.PnLStopLossSettings> pnLStopLossSettings = await _pnLStopLossSettingsRepository.GetAllAsync();

            _cache.Initialize(pnLStopLossSettings);

            return(pnLStopLossSettings);
        }
예제 #3
0
        private async Task <IReadOnlyCollection <PnLStopLossEngine> > Initialize()
        {
            IReadOnlyCollection <PnLStopLossEngine> pnLStopLossEngines = await _pnLStopLossEngineRepository.GetAllAsync();

            _cache.Initialize(pnLStopLossEngines);

            return(pnLStopLossEngines);
        }
예제 #4
0
        public AssetLinkService(IReadOnlyCollection <AssetMapping> mappingSettings, ILogFactory logFactory)
        {
            _cache = new InMemoryCache <AssetLink>(assetLink => assetLink.AssetId, false);
            _log   = logFactory.CreateLog(this);

            IReadOnlyCollection <AssetLink> assetLinks = mappingSettings.Select(o => new AssetLink
            {
                AssetId         = o.AssetId,
                ExternalAssetId = o.ExternalAssetId
            }).ToArray();

            _cache.Initialize(assetLinks);
        }
        public async Task <IReadOnlyCollection <Credit> > GetAllAsync()
        {
            IReadOnlyCollection <Credit> credits = _cache.GetAll();

            if (credits == null)
            {
                credits = await _creditRepository.GetAllAsync();

                _cache.Initialize(credits);
            }

            return(credits);
        }
        public async Task <IReadOnlyCollection <AssetHedgeSettings> > GetAllAsync()
        {
            IReadOnlyCollection <AssetHedgeSettings> assetHedgeSettings = _cache.GetAll();

            if (assetHedgeSettings == null)
            {
                assetHedgeSettings = await _assetHedgeSettingsRepository.GetAllAsync();

                _cache.Initialize(assetHedgeSettings);
            }

            return(assetHedgeSettings);
        }
        public async Task <IReadOnlyCollection <Position> > GetAllAsync()
        {
            IReadOnlyCollection <Position> positions = _cache.GetAll();

            if (positions == null)
            {
                positions = await _positionRepository.GetAllAsync();

                _cache.Initialize(positions);
            }

            return(positions);
        }
        public async Task <IReadOnlyCollection <Instrument> > GetAllAsync()
        {
            IReadOnlyCollection <Instrument> instruments = _cache.GetAll();

            if (instruments == null)
            {
                instruments = await _instrumentRepository.GetAllAsync();

                _cache.Initialize(instruments);
            }

            return(instruments);
        }
예제 #9
0
        public async Task <IReadOnlyCollection <AssetPairLink> > GetAllAsync()
        {
            IReadOnlyCollection <AssetPairLink> assetPairLinks = _cache.GetAll();

            if (assetPairLinks == null)
            {
                assetPairLinks = await _assetPairLinkRepository.GetAllAsync();

                _cache.Initialize(assetPairLinks);
            }

            return(assetPairLinks);
        }
예제 #10
0
        public async Task <IReadOnlyCollection <IndexSettings> > GetAllAsync()
        {
            IReadOnlyCollection <IndexSettings> indexSettings = _cache.GetAll();

            if (indexSettings == null)
            {
                indexSettings = await _indexSettingsRepository.GetAllAsync();

                _cache.Initialize(indexSettings);
            }

            return(indexSettings);
        }
예제 #11
0
        public async Task <IReadOnlyCollection <Token> > GetAllAsync()
        {
            IReadOnlyCollection <Token> tokens = _cache.GetAll();

            if (tokens == null)
            {
                tokens = await _tokenRepository.GetAllAsync();

                _cache.Initialize(tokens);
            }

            return(tokens);
        }
예제 #12
0
        public async Task <IReadOnlyCollection <SummaryReport> > GetAllAsync()
        {
            IReadOnlyCollection <SummaryReport> summaryReports = _cache.GetAll();

            if (summaryReports == null)
            {
                summaryReports = await _summaryReportRepository.GetAllAsync();

                _cache.Initialize(summaryReports);
            }

            return(summaryReports);
        }
예제 #13
0
        public async Task <IReadOnlyCollection <RemainingVolume> > GetAllAsync()
        {
            IReadOnlyCollection <RemainingVolume> remainingVolumes = _cache.GetAll();

            if (remainingVolumes == null)
            {
                remainingVolumes = await _remainingVolumeRepository.GetAllAsync();

                _cache.Initialize(remainingVolumes);
            }

            return(remainingVolumes);
        }
예제 #14
0
        public async Task <IReadOnlyCollection <AssetPairSettings> > GetAssetPairsAsync()
        {
            IReadOnlyCollection <AssetPairSettings> assetPairsSettings = _assetPairsCache.GetAll();

            if (assetPairsSettings == null)
            {
                assetPairsSettings = await _assetPairSettingsRepository.GetAllAsync();

                _assetPairsCache.Initialize(assetPairsSettings);

                InitializeAssetPairs();
            }

            return(assetPairsSettings);
        }
예제 #15
0
        public async Task <IReadOnlyCollection <Domain.AssetSettings> > GetAllAsync()
        {
            IReadOnlyCollection <Domain.AssetSettings> assets = _cache.GetAll();

            if (assets == null)
            {
                assets = (await _assetSettingsRepository.GetAllAsync())
                         .Append(UsdAssetSettings)
                         .ToArray();

                _cache.Initialize(assets);
            }

            return(assets);
        }
        public async Task <TimersSettings> GetAsync()
        {
            TimersSettings timersSettings = _cache.Get(CacheKey);

            if (timersSettings == null)
            {
                timersSettings = await _timersSettingsRepository.GetAsync() ?? new TimersSettings();

                if (timersSettings.MarketMaker == TimeSpan.Zero)
                {
                    timersSettings.MarketMaker = TimeSpan.FromSeconds(5);
                }

                if (timersSettings.Hedging == TimeSpan.Zero)
                {
                    timersSettings.Hedging = TimeSpan.FromSeconds(1);
                }

                if (timersSettings.LykkeBalances == TimeSpan.Zero)
                {
                    timersSettings.LykkeBalances = TimeSpan.FromSeconds(1);
                }

                if (timersSettings.ExternalBalances == TimeSpan.Zero)
                {
                    timersSettings.ExternalBalances = TimeSpan.FromSeconds(1);
                }

                if (timersSettings.Settlements == TimeSpan.Zero)
                {
                    timersSettings.Settlements = TimeSpan.FromSeconds(5);
                }

                if (timersSettings.InternalTrader == TimeSpan.Zero)
                {
                    timersSettings.InternalTrader = TimeSpan.FromSeconds(5);
                }

                if (timersSettings.PnLStopLoss == TimeSpan.Zero)
                {
                    timersSettings.PnLStopLoss = TimeSpan.FromSeconds(1);
                }

                _cache.Initialize(new[] { timersSettings });
            }

            return(timersSettings);
        }
예제 #17
0
        public async Task <Funding> GetAsync()
        {
            Funding funding = _cache.Get(CacheKey);

            if (funding == null)
            {
                funding = await _fundingRepository.GetAsync();

                if (funding == null)
                {
                    funding = new Funding();
                }

                _cache.Initialize(new[] { funding });
            }

            return(funding);
        }
예제 #18
0
        public async Task <IReadOnlyCollection <Instrument> > GetAllAsync()
        {
            IReadOnlyCollection <Instrument> instruments = _cache.GetAll();

            if (instruments == null)
            {
                instruments = await _instrumentRepository.GetAllAsync();

                foreach (Instrument instrument in instruments)
                {
                    instrument.CrossInstruments = await _crossInstrumentRepository.GetAsync(instrument.AssetPairId);
                }

                _cache.Initialize(instruments);
            }

            return(instruments);
        }
예제 #19
0
        public async Task <IReadOnlyList <ExchangeSettings> > GetAllAsync()
        {
            IReadOnlyList <ExchangeSettings> settings = _cache.GetAll();

            if (settings == null)
            {
                settings = await _exchangeSettingsRepository.GetAllAsync();

                settings = settings.Union(_exchanges
                                          .Where(o => settings.All(p => p.Name != o))
                                          .Select(o => new ExchangeSettings(o)))
                           .Where(o => _exchanges.Contains(o.Name))
                           .ToList();

                _cache.Initialize(settings);
            }

            return(settings);
        }
        public async Task <TimersSettings> GetAsync()
        {
            TimersSettings timersSettings = _cache.Get(CacheKey);

            if (timersSettings == null)
            {
                timersSettings = await _timersSettingsRepository.GetAsync();

                if (timersSettings == null)
                {
                    timersSettings = new TimersSettings
                    {
                        MarketMaker = TimeSpan.FromSeconds(5),
                        Balances    = TimeSpan.FromSeconds(1)
                    };
                }

                _cache.Initialize(new[] { timersSettings });
            }

            return(timersSettings);
        }
예제 #21
0
        public async Task <QuoteThresholdSettings> GetAsync()
        {
            QuoteThresholdSettings quoteThresholdSettings = _cache.Get(CacheKey);

            if (quoteThresholdSettings == null)
            {
                quoteThresholdSettings = await _quoteThresholdSettingsRepository.GetAsync();

                if (quoteThresholdSettings == null)
                {
                    quoteThresholdSettings = new QuoteThresholdSettings
                    {
                        Enabled = true,
                        Value   = .2m
                    };
                }

                _cache.Initialize(new[] { quoteThresholdSettings });
            }

            return(quoteThresholdSettings);
        }
        public async Task <QuoteTimeoutSettings> GetAsync()
        {
            QuoteTimeoutSettings quoteTimeoutSettings = _cache.Get(CacheKey);

            if (quoteTimeoutSettings == null)
            {
                quoteTimeoutSettings = await _quoteTimeoutSettingsRepository.GetAsync();

                if (quoteTimeoutSettings == null)
                {
                    quoteTimeoutSettings = new QuoteTimeoutSettings
                    {
                        Enabled = true,
                        Value   = TimeSpan.FromSeconds(5)
                    };
                }

                _cache.Initialize(new[] { quoteTimeoutSettings });
            }

            return(quoteTimeoutSettings);
        }
예제 #23
0
        public async Task <MarketMakerState> GetAsync()
        {
            MarketMakerState marketMakerState = _cache.Get(CacheKey);

            if (marketMakerState == null)
            {
                marketMakerState = await _marketMakerStateRepository.GetAsync();

                if (marketMakerState == null)
                {
                    marketMakerState = new MarketMakerState
                    {
                        Status    = MarketMakerStatus.Stopped,
                        Timestamp = DateTime.UtcNow
                    };
                }

                _cache.Initialize(new[] { marketMakerState });
            }

            return(marketMakerState);
        }
        public async Task <MarketMakerState> GetStateAsync()
        {
            MarketMakerState state = _cache.Get(CacheKey);

            if (state == null)
            {
                state = await _marketMakerStateRepository.GetAsync();

                if (state == null)
                {
                    state = new MarketMakerState
                    {
                        Status = MarketMakerStatus.Disabled,
                        Time   = DateTime.UtcNow
                    };
                }

                _cache.Initialize(new[] { state });
            }

            return(state);
        }
예제 #25
0
        public async Task <TimersSettings> GetAsync()
        {
            TimersSettings timersSettings = _cache.Get(CacheKey);

            if (timersSettings == null)
            {
                timersSettings = await _timersSettingsRepository.GetAsync();

                if (timersSettings == null)
                {
                    timersSettings = new TimersSettings
                    {
                        LykkeBalances    = TimeSpan.FromSeconds(10),
                        ExternalBalances = TimeSpan.FromSeconds(10),
                        Settlements      = TimeSpan.FromMinutes(5)
                    };
                }

                _cache.Initialize(new[] { timersSettings });
            }

            return(timersSettings);
        }
예제 #26
0
        public async Task <HedgeSettings> GetAsync()
        {
            HedgeSettings hedgeSettings = _cache.Get(CacheKey);

            if (hedgeSettings == null)
            {
                hedgeSettings = await _hedgeSettingsRepository.GetAsync();

                if (hedgeSettings == null)
                {
                    hedgeSettings = new HedgeSettings
                    {
                        MarketOrderMarkup = .02m,
                        ThresholdDown     = 1000,
                        ThresholdUp       = 5000,
                        ThresholdCritical = 10000
                    };
                }

                _cache.Initialize(new[] { hedgeSettings });
            }

            return(hedgeSettings);
        }