protected override void Update(dynamic data, string symbol) { symbol = CleanAndExtractSymbol(symbol); if (ExchangeData.TryGetValue(symbol, out var old)) { old = old.Clone( ); } else { ExchangeData[symbol] = new CryptoCoin(symbol); } DeserializeData(data, symbol); Markets.AddOrUpdate(ExchangeData[symbol]); LastUpdate = DateTime.UtcNow; OnNext(ExchangeData[symbol]); if (!ExchangeData[symbol].HasSameValues(old)) { OnChanged(ExchangeData[symbol]); } }
private void OnMarketDataReturn(object sender, RspEventArgs e) { switch (sender.ToString()) { case "ProgramTradeApi.XMduserSpi": MarketDetail market = MarketDetail.CreateMarketDetail((e as TypedRspEventArgs <CLRDFITCDepthMarketDataField, object>).Data); Markets.AddOrUpdate(market.InstrumentID, market, (k, v) => { market.InstrumentName = v.InstrumentName; return(market); }); //eventMarketChanged?.Invoke(this, null); break; } }
protected override async Task FetchInitialDataAsync(CancellationToken ct) { Assets = await TradingPairsEndpoint .GetJsonAsync <List <BitstampAsset> > (ct) .ConfigureAwait(false); foreach (var asset in Assets) { var datum = await $"{TickerEndpoint}{asset.UrlSymbol}/" .GetJsonAsync <TickerDatum> (ct) .ConfigureAwait(false); var symbol = CleanAndExtractSymbol(asset.Name.Replace("/", "")); ExchangeData[symbol] = new CryptoCoin(symbol, datum.Bid, datum.Ask, datum.Last, datum.Timestamp); Markets.AddOrUpdate(ExchangeData[symbol]); LastUpdate = DateTime.UtcNow; OnNext(ExchangeData[symbol]); OnChanged(ExchangeData[symbol]); await Task.Delay(PollingRate, ct).ConfigureAwait(false); } }