Ejemplo n.º 1
0
        public async Task DeleteAsync(string assetPairId)
        {
            Instrument instrument = await GetByAssetPairIdAsync(assetPairId);

            if (instrument.Mode == InstrumentMode.Active)
            {
                throw new InvalidOperationException("Can not remove active instrument");
            }

            IReadOnlyCollection <RemainingVolume> remainingVolumes = await _remainingVolumeService.GetAllAsync();

            RemainingVolume remainingVolume =
                remainingVolumes.SingleOrDefault(o => o.AssetPairId == instrument.AssetPairId);

            if (remainingVolume != null && remainingVolume.Volume != 0)
            {
                throw new InvalidOperationException("Can not remove instrument while remaining volume exist");
            }

            await _instrumentRepository.DeleteAsync(assetPairId);

            await _crossInstrumentRepository.DeleteAsync(assetPairId);

            await _remainingVolumeService.DeleteAsync(assetPairId);

            _cache.Remove(assetPairId);

            _log.InfoWithDetails("Instrument was deleted", instrument);
        }