示例#1
0
        private void DoUpdateMarketPrices(object aState)
        {
            try
            {
                var lChanged = new ConcurrentBag <string>();
                using (var lClient = new PoloniexClient())
                {
                    var lMarketsData = lClient.GetTickerMarkets();
                    if (!lMarketsData.Success)
                    {
                        throw new Exception("Unable to get updated market prices info");
                    }
                    Parallel.ForEach(lMarketsData.Data, (lMarketData) =>
                    {
                        string lMarketPairID = lMarketData.Key;
                        MarketPriceInfo lRemoteMarketPrice = new MarketPriceInfo
                        {
                            Last = lMarketData.Value.last,
                            Bid  = lMarketData.Value.highestBid,
                            Ask  = lMarketData.Value.lowestAsk
                        };

                        if ((FMarketPrices.TryGetValue(lMarketPairID, out MarketPriceInfo lPrice) && lPrice != lRemoteMarketPrice) || lPrice == null)
                        {
                            FMarketPrices.AddOrUpdate(lMarketPairID, lRemoteMarketPrice, (key, oldValue) => lRemoteMarketPrice);
                            lChanged.Add(lMarketPairID);
                        }
                    });
                }