private void OnMarketUpdate(object sender, UpdateArgs <L1LsPriceData> e) { try { var wlmUpdate = e.UpdateData; var epic = e.ItemName.Replace("L1:", ""); foreach (var watchlistItem in WatchlistMarkets.Where(watchlistItem => watchlistItem.Model.Epic == epic)) { watchlistItem.Model.Epic = epic; watchlistItem.Model.Bid = wlmUpdate.Bid; watchlistItem.Model.Offer = wlmUpdate.Offer; watchlistItem.Model.NetChange = wlmUpdate.Change; watchlistItem.Model.PctChange = wlmUpdate.ChangePct; watchlistItem.Model.Low = wlmUpdate.Low; watchlistItem.Model.High = wlmUpdate.High; watchlistItem.Model.Open = wlmUpdate.MidOpen; watchlistItem.UpdateTime = wlmUpdate.UpdateTime; watchlistItem.Model.MarketStatus = wlmUpdate.MarketState; } } catch (Exception ex) { WatchlistL1PriceUpdates = ex.Message; } }
private void ClearWatchlistMarkets() { if (WatchlistMarkets != null) { UnsubscribeFromWatchlistInstruments(); WatchlistMarkets.Clear(); } }
// <Summary> // GetRestWatchlistMarkets // </Summary> public async void GetRestWatchlistMarkets() { try { if ((Watchlists != null) && (WatchlistIndex < Watchlists.Count)) { AddStatusMessage(String.Format("Retrieving watchlist markets for watchlist called {0}", Watchlists[WatchlistIndex].WatchlistName)); var response = await igRestApiClient.instrumentsForWatchlist(Watchlists[WatchlistIndex].WatchlistId); if (response != null) { if (response && (response.Response.markets != null) && (response.Response.markets.Count > 0)) { WatchlistMarkets.Clear(); foreach (var wim in response.Response.markets.Select(LoadMarket)) { WatchlistMarkets.Add(wim); } // Get unique epics for these orders ( we don't want to subscribe to the same epic twice ) var uniqueEpics = (from dbo in WatchlistMarkets where dbo.Model.StreamingPricesAvailable == true select dbo.Model.Epic).Distinct().ToArray(); if (uniqueEpics.Length != 0) { SubscribeL1WatchlistPrices(uniqueEpics); SubscribeToCharts(uniqueEpics); } else { AddStatusMessage("There are no watchlist instruments with streaming prices enabled"); } } else { AddStatusMessage("HttpStatusCode error: " + response.StatusCode); } } else { AddStatusMessage("GetRestWatchlistMarkets : null response from server"); } } } catch (Exception ex) { AddStatusMessage(ex.Message); } }
// <Summary> // GetRestWatchlistMarkets // </Summary> public async void GetRestWatchlistMarkets() { try { if ((Watchlists != null) && (WatchlistIndex < Watchlists.Count)) { UpdateWatchlistsMessage(String.Format("Retrieving watchlist markets for watchlist called {0}", Watchlists[WatchlistIndex].WatchlistName)); var response = await igRestApiClient.instrumentsForWatchlist(Watchlists[WatchlistIndex].WatchlistId); if (response != null) { if (response && (response.Response.markets != null) && (response.Response.markets.Count > 0)) { WatchlistMarkets.Clear(); foreach (var wl in response.Response.markets) { var wim = new IgPublicApiData.WatchlistMarketModel(); wim.Model = new IgPublicApiData.InstrumentModel(); wim.Model.High = wl.high; wim.Model.Low = wl.low; wim.Model.Epic = wl.epic; wim.Model.Bid = wl.bid; wim.Model.Offer = wl.offer; wim.Model.PctChange = wl.percentageChange; wim.Model.NetChange = wl.netChange; wim.Model.InstrumentName = wl.instrumentName; wim.Model.StreamingPricesAvailable = wl.streamingPricesAvailable; wim.Model.MarketStatus = wl.marketStatus; WatchlistMarkets.Add(wim); } // Get unique epics for these orders ( we don't want to subscribe to the same epic twice ) var uniqueEpics = (from dbo in WatchlistMarkets where dbo.Model.StreamingPricesAvailable == true select dbo.Model.Epic).Distinct().ToArray(); if (uniqueEpics.Length != 0) { SubscribeL1WatchlistPrices(uniqueEpics); } else { UpdateWatchlistsMessage("There are no watchlist instruments with streaming prices enabled"); } } else { UpdateWatchlistsMessage("HttpStatusCode error: " + response.StatusCode); } } else { UpdateWatchlistsMessage("GetRestWatchlistMarkets : null response from server"); } } } catch (Exception ex) { UpdateWatchlistsMessage(ex.Message); } }