Esempio n. 1
0
        public AggregatedAssetPairData GetAggAssetPairData(AssetPair pair)
        {
            var data = _assetPairs.GetOrAdd(pair, k =>
            {
                var id  = AggregatedAssetPairData.GetHash(k);
                var apd = PublicContext.I.GetCollection <AggregatedAssetPairData>().FindById(id);
                if (apd != null)
                {
                    return(apd);
                }

                var prov = Networks.I.AssetPairAggregationProviders.FirstProvider();
                var r    = ApiCoordinator.GetCoinSnapshot(prov, new AssetPairDataContext(new AggregatedAssetPairData(k, prov)));

                apd = r.IsNull ? new AggregatedAssetPairData(k, prov)
                {
                    UtcUpdated = DateTime.UtcNow, IsMissing = true
                } : r.Response;
                apd.Save(PublicContext.I);

                return(apd);
            });

            data.Refresh(PublicContext.I);
            return(data);
        }
Esempio n. 2
0
        private static void RemoveFaulting(Dictionary <Network, IReadOnlyList <AssetPair> > pbn)
        {
            var hasFault = false;

            var networks = pbn.Keys.ToList();

            foreach (var n in networks)
            {
                var prov = n.Providers.FirstOf <IDepositProvider>();
                if (prov == null)
                {
                    continue;
                }

                var r = ApiCoordinator.GetTransferSuspensions(prov);
                if (r.IsNull)
                {
                    continue;
                }

                var pairs = pbn[n].AsList();
                var c     = pairs.Count;
                pairs.RemoveAll(x => r.Response.DepositSuspended.Any(x.Has));
                pairs.RemoveAll(x => r.Response.WithdrawalSuspended.Any(x.Has));
                hasFault = hasFault || c != pairs.Count;

                pbn[n] = pairs;
            }

            if (hasFault)
            {
                pbn.RemoveAll(x => !x.Value.Any());
            }
        }
Esempio n. 3
0
        public void Refresh(IDataContext context)
        {
            if (IsFresh)
            {
                return;
            }

            lock (RefreshLock)
            {
                if (IsFresh)
                {
                    return;
                }

                if (AggregationProvider == null)
                {
                    return;
                }

                var r = ApiCoordinator.GetCoinSnapshot(AggregationProvider, new AssetPairDataContext(this));
                if (r.Success)
                {
                    this.Save(context);
                }
            }
        }
Esempio n. 4
0
        public Network NetworkConfirmedPricing(AssetPair pair)
        {
            var     provs = Providers.OfList <IPublicPricingProvider>().OrderByVolume(pair).Where(x => x.IsDirect);
            var     ctx   = new PublicPriceContext(pair);
            Network net   = null;

            foreach (var i in provs)
            {
                lock (_confirmedLock)
                    if (_confirmed.Any(x => x.Item1 == i && Equals(x.Item2, pair)))
                    {
                        net = i.Network;
                        break;
                    }

                if (ApiCoordinator.GetPricing(i, ctx).IsNull)
                {
                    continue;
                }

                net = i.Network;

                lock (_confirmedLock)
                    _confirmed.Add(new Tuple <IPublicPricingProvider, AssetPair>(i, pair));
                break;
            }

            return(net);
        }
Esempio n. 5
0
        public async Task <AssetPairs> GetPairsAsync(Network network, bool onlyDirect = true)
        {
            var q    = onlyDirect ? network?.Providers.OfType <IAssetPairsProvider>().Where(x => x.IsDirect) : network?.Providers.OfType <IAssetPairsProvider>();
            var prov = q.FirstProvider();

            if (prov == null)
            {
                Logging.I.DefaultLogger.Error($"An instance of {nameof(IAssetPairsProvider)} cannot be located for {network.Name}");
                return(null);
            }

            var r = await ApiCoordinator.GetAssetPairsAsync(prov).ConfigureAwait(false);

            return(r.IsNull ? null : r.Response);
        }
Esempio n. 6
0
        public async void RefreshAsync()
        {
            var prov = Network.Providers.FirstProviderOf <IAssetPairsProvider>();

            if (prov == null)
            {
                throw new Exception($"Cannot 'refresh' {nameof(AssetPairData)} for {Network.Name} as a {nameof(IAssetPairsProvider)} cannot be located.");
            }

            var pairs = await ApiCoordinator.GetAssetPairsAsync(prov).ConfigureAwait(false);

            if (pairs.IsFailed)
            {
                return;
            }

            Pairs = pairs.Response;
        }
Esempio n. 7
0
        private void DoRefresh()
        {
            var cc = Networks.I.CoinListProviders.FirstProvider();
            var r  = ApiCoordinator.GetCoinInformation(cc);

            if (r.IsNull)
            {
                return;
            }

            Items.Clear();
            Items.AddRange(r.Response);
            Items.Add(new AssetInfo()
            {
                Asset = Assets.I.GetRaw("EUR"), FullName = "Euro", SortOrder = 1
            });
            Items.Add(new AssetInfo()
            {
                Asset = Assets.I.GetRaw("USD"), FullName = "U.S. dollar", SortOrder = 1
            });
        }
Esempio n. 8
0
        public void KeepFresh(UserContext context, IDepositProvider provider, Asset asset, bool forceStale = false)
        {
            var stale = forceStale || _ws.Any(x => x.Asset == asset && (!x.IsFresh() || x.IsExpired()));

            if (!stale)
            {
                return;
            }

            lock (Lock)
            {
                var r = ApiCoordinator.FetchAllDepositAddresses(provider, new WalletAddressAssetContext(asset, context));
                if (r.IsNull)
                {
                    return;
                }

                AddRange(r.Response);
                this.Save(context);
            }
        }
Esempio n. 9
0
        private static MarketPricesData GrabPriceDataAndSave(KeyValuePair <Network, IReadOnlyList <AssetPair> > kv)
        {
            Console.WriteLine($"Getting price data for {kv.Key.Name} from {kv.Value.Count} pairs.");

            var prov = kv.Key.PublicPriceProviders.FirstDirectProvider <IPublicPricingProvider>();

            if (prov == null)
            {
                Console.WriteLine($"No provider found for {kv.Key.Name}");
                return(null);
            }
            var r = ApiCoordinator.GetPricing(prov, new PublicPricesContext(kv.Value.ToList()));

            if (r.IsNull)
            {
                Console.WriteLine($"No prices found for {kv.Key.Name}");
                return(null);
            }

            var data = new MarketPricesData(kv.Key, r.Response.MarketPrices);

            data.SavePublic();
            return(data);
        }
Esempio n. 10
0
        private PublicVolumeResponse GetVolumeDataAgg(IAggVolumeDataProvider prov, AssetPair pair)
        {
            var apir = ApiCoordinator.GetAggVolumeData(prov, new AggVolumeDataContext(pair));

            return(apir.IsNull ? null : apir.Response);
        }