public async Task HandleIndexAsync(Index index) { MarketMakerState marketMakerState = await _marketMakerStateService.GetAsync(); IndexSettings indexSettings = await _indexSettingsService.GetByIndexAsync(index.Name); if (marketMakerState.Status != MarketMakerStatus.Active) { if (indexSettings != null) { foreach (AssetWeight assetWeight in index.Weights) { await _assetHedgeSettingsService.EnsureAsync(assetWeight.AssetId); } } return; } foreach (var assetWeight in index.Weights) { Quote quote = new Quote($"{assetWeight.AssetId}USD", index.Timestamp, assetWeight.Price, assetWeight.Price, ExchangeNames.Virtual); await _quoteService.UpdateAsync(quote); } if (indexSettings == null) { return; } await _semaphore.WaitAsync(); try { await _indexPriceService.UpdateAsync(index); await _hedgeService.UpdateLimitOrdersAsync(); await _marketMakerService.UpdateLimitOrdersAsync(index.Name); } catch (InvalidOperationException exception) { _log.WarningWithDetails("An error occurred while processing index", exception, index); } catch (Exception exception) { _log.ErrorWithDetails(exception, "An error occurred while processing index", index); throw; } finally { _semaphore.Release(); } }
public async Task HandleIndexAsync(Index index, Index shortIndex) { MarketMakerState marketMakerState = await _marketMakerStateService.GetAsync(); IndexSettings indexSettings = await _indexSettingsService.GetByIndexAsync(index.Name); IndexSettings shortIndexSettings = null; if (shortIndex != null) { shortIndexSettings = await _indexSettingsService.GetByIndexAsync(shortIndex.Name); } if (marketMakerState.Status != MarketMakerStatus.Active) { // TODO: Shouldn't they be updated if Market Maker status is Active? await UpdateAssets(indexSettings, index); return; } await UpdateVirtualExchangePrices(index); if (indexSettings == null) { return; } await _semaphore.WaitAsync(); try { await RecalculateIndicesPrices(index, shortIndex, shortIndexSettings); await _hedgeService.UpdateLimitOrdersAsync(); await UpdateMarketMakerOrders(index, shortIndex, shortIndexSettings); } catch (InvalidOperationException exception) { _log.WarningWithDetails("An error occurred while processing index", exception, index); } catch (Exception exception) { _log.ErrorWithDetails(exception, "An error occurred while processing index", index); throw; } finally { _semaphore.Release(); } }
public async Task <MarketMakerStateModel> GetStateAsync() { MarketMakerState marketMakerState = await _marketMakerStateService.GetAsync(); return(Mapper.Map <MarketMakerStateModel>(marketMakerState)); }