public async Task UpdateAsync(Instrument instrument, string userId)
        {
            Instrument currentInstrument = await GetByAssetPairIdAsync(instrument.AssetPairId);

            InstrumentMode currentInstrumentMode = currentInstrument.Mode;

            currentInstrument.Update(instrument);
            currentInstrument.Approve();

            await _instrumentRepository.UpdateAsync(currentInstrument);

            _cache.Set(currentInstrument);

            if (instrument.Mode == InstrumentMode.Disabled && currentInstrumentMode != InstrumentMode.Disabled)
            {
                try
                {
                    await _lykkeExchangeService.CancelAsync(instrument.AssetPairId);
                }
                catch (Exception exception)
                {
                    _log.WarningWithDetails("An error occurred while cancelling limit orders", exception,
                                            new { currentInstrument, userId });
                }

                await _orderBookService.RemoveAsync(instrument.AssetPairId);
            }

            _log.InfoWithDetails("Instrument was updated", new { currentInstrument, userId });
        }
        public async Task CancelLimitOrderAsync(string assetId)
        {
            if (_hedgeLimitOrders.TryGetValue(assetId, out HedgeLimitOrder hedgeLimitOrder))
            {
                await _lykkeExchangeService.CancelAsync(hedgeLimitOrder.AssetPairId);

                _hedgeLimitOrderService.Close(hedgeLimitOrder);

                _hedgeLimitOrders.Remove(assetId);
            }
        }
Exemple #3
0
        public async Task CancelLimitOrdersAsync(string indexName)
        {
            IndexSettings indexSettings = await _indexSettingsService.GetByIndexAsync(indexName);

            if (indexSettings == null)
            {
                throw new InvalidOperationException("Index settings not found");
            }

            await _lykkeExchangeService.CancelAsync(indexSettings.AssetPairId);

            _log.InfoWithDetails("Limit orders canceled", new { IndexName = indexName, indexSettings.AssetPairId });
        }