private void DoUpdateMarketPrices(object aState) { try { var lChanged = new ConcurrentBag <string>(); using (var lClient = new BitfinexClient()) { var lMarketsData = lClient.GetTickerAsync(symbols: "ALL").Result; if (!lMarketsData.Success) { throw new Exception("Unable to get updated market prices info"); } Parallel.ForEach(lMarketsData.Data, (lMarketData) => { string lMarketPairID = lMarketData.Symbol.Remove(0, 1).ToLowerInvariant(); MarketPriceInfo lRemoteMarketPrice = new MarketPriceInfo { Last = lMarketData.LastPrice, Bid = lMarketData.Bid, Ask = lMarketData.Ask }; if ((FMarketPrices.TryGetValue(lMarketPairID, out MarketPriceInfo lPrice) && lPrice != lRemoteMarketPrice) || lPrice == null) { FMarketPrices.AddOrUpdate(lMarketPairID, lRemoteMarketPrice, (key, oldValue) => lRemoteMarketPrice); lChanged.Add(lMarketPairID); } }); }
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); } }); }
public IMarketPriceInfo GetMarketPrice(IExchangeMarket aMarket) { MarketPriceInfo lResult = new MarketPriceInfo(); if (!aMarket.TryCastToLocalMarket(out ExchangeMarket lExchangeMarket)) { throw new ArgumentException(nameof(aMarket), "Invalid Market"); } if (FMarketPrices.TryGetValue(lExchangeMarket.MarketPairID, out MarketPriceInfo lValue)) { lResult = lValue; } return(lResult); }
private void ProcessMarketSummaries(IEnumerable <BittrexTick> aMarketPrices) { Parallel.ForEach(aMarketPrices, (lMarketPrice) => { var lMarketPairID = lMarketPrice.Symbol; MarketPriceInfo lRemoteMarketPrice = new MarketPriceInfo { Last = lMarketPrice.LastTradeRate, Bid = lMarketPrice.BidRate, Ask = lMarketPrice.AskRate }; if ((FMarketPrices.TryGetValue(lMarketPairID, out MarketPriceInfo lPrice) && lPrice != lRemoteMarketPrice) || lPrice == null) { FMarketPrices.AddOrUpdate(lMarketPairID, lRemoteMarketPrice, (key, oldValue) => lRemoteMarketPrice); if (!FMarketsIDsWithPriceChanged.Contains(lMarketPairID)) { FMarketsIDsWithPriceChanged.Add(lMarketPairID); } } });