private ICachedCalculation <Dictionary <string, AssetPairInfo> > GetAssetPairsCache()
 {
     return(Calculate.Cached(() => _system.UtcNow,
                             (prev, now) => now.Subtract(prev) < TimeSpan.FromMinutes(5),
                             now => _assetsService.GetAssetPairs().ToDictionary(p => p.Id,
                                                                                p => _convertService.Convert <AssetPairResponseModel, AssetPairInfo>(p,
                                                                                                                                                     o => o.ConfigureMap(MemberList.Destination)))));
 }
Beispiel #2
0
        public void Remove(string assetPairId)
        {
            _readerWriterLockSlim.EnterWriteLock();

            try
            {
                if (_assetPairs.ContainsKey(assetPairId))
                {
                    _assetPairs.Remove(assetPairId);
                    _assetPairsByAssets = GetAssetPairsByAssetsCache();
                    _assetPairsIds      = Calculate.Cached(() => _assetPairs, CacheChangedCondition, p => p.Keys.ToImmutableHashSet());
                }
            }
            finally
            {
                _readerWriterLockSlim.ExitWriteLock();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds new item item if does not exist, otherwise updates
        /// </summary>
        /// <param name="assetPair"></param>
        /// <returns>true if added, false if updated</returns>
        public bool AddOrUpdate(IAssetPair assetPair)
        {
            _readerWriterLockSlim.EnterWriteLock();
            var itemExists = _assetPairs.ContainsKey(assetPair.Id);

            try
            {
                if (itemExists)
                {
                    _assetPairs.Remove(assetPair.Id);
                }

                _assetPairs.Add(assetPair.Id, assetPair);

                _assetPairsByAssets = GetAssetPairsByAssetsCache();
                _assetPairsIds      = Calculate.Cached(() => _assetPairs, CacheChangedCondition, p => p.Keys.ToImmutableHashSet());

                return(!itemExists);
            }
            finally
            {
                _readerWriterLockSlim.ExitWriteLock();
            }
        }
Beispiel #4
0
 private ICachedCalculation <IReadOnlyDictionary <AssetPairKey, IAssetPair> > GetAssetPairsByAssetsCache()
 {
     return(Calculate.Cached(() => _assetPairs, ReferenceEquals,
                             pairs => pairs.Values.SelectMany(p => new []
Beispiel #5
0
 public AssetPairsCache()
 {
     _assetPairsByAssets = GetAssetPairsByAssetsCache();
     _assetPairsIds      = Calculate.Cached(() => _assetPairs, ReferenceEquals, p => p.Keys.ToImmutableHashSet());
 }
Beispiel #6
0
 public AssetPairsCache()
 {
     _assetPairsByAssets = GetAssetPairsByAssetsCache();
     _assetPairsIds      = Calculate.Cached(() => _assetPairs, CacheChangedCondition, p => p.Keys.ToImmutableHashSet());
 }
Beispiel #7
0
 private ICachedCalculation <IReadOnlyDictionary <AssetPairKey, IAssetPair> > GetAssetPairsByAssetsCache()
 {
     return(Calculate.Cached(() => _assetPairs, CacheChangedCondition,
                             pairs => pairs.Values.SelectMany(p => new []
 private ICachedCalculation <ILookup <string, CrossRateCalcInfo> > DependentAssetPairsCache()
 {
     return(Calculate.Cached(Get, ReferenceEquals,
                             src => src.SelectMany(i => new[] { (i.Value.Source1.Id, i.Value), (i.Value.Source2.Id, i.Value) })
Beispiel #9
0
 private ICachedCalculation <IReadOnlyDictionary <AssetPairKey, IAssetPair> > GetAssetPairsByAssetsCache()
 {
     // TODO: (anokhin) FX and trading pairs should be separated and we should use only FX here. For now, knowing that we receive Trading + FX, we are hacking that by reverting the order of the items to use FX rates first
     return(Calculate.Cached(() => _assetPairs, CacheChangedCondition,
                             pairs => pairs.Values.Reverse().SelectMany(p => new []