/// <summary> /// Method for subscribing to the feeds of a given symbol. /// </summary> /// <param name="symbolId">Symbol Id to subscribe to</param> /// <param name="handler">Delegate for handling feed updates</param> public void SubscribeFeed(int symbolId, OnFeedReceived handler) { lock(_lockSubscription) { if (notifyList.ContainsKey(symbolId)) { notifyList[symbolId].Add(handler); } else { notifyList.Add(symbolId, new List<OnFeedReceived>() { handler }); } } }
/// <summary> /// Method for unsubscribing to stop receiving updates for a given symbol /// </summary> /// <param name="symbolId">Symbol id to unsubscribe from</param> /// <param name="handler">handler to remove - multiple handlers may be attached to the same symbol</param> public void UnsubscribeFeed(int symbolId, OnFeedReceived handler) { lock (_lockSubscription) { if (notifyList.ContainsKey(symbolId) && notifyList[symbolId].Contains(handler)) { notifyList[symbolId].Remove(handler); } else { throw new Exception("Subscription required for unsubscribing!"); } } }
/// <summary> /// Method for subscribing to the feeds of a given symbol. /// </summary> /// <param name="symbolId">Symbol Id to subscribe to</param> /// <param name="handler">Delegate for handling feed updates</param> public void SubscribeFeed(int symbolId, OnFeedReceived handler) { lock (_lockSubscription) { if (notifyList.ContainsKey(symbolId)) { notifyList[symbolId].Add(handler); } else { notifyList.Add(symbolId, new List <OnFeedReceived>() { handler }); } } }
/// <summary> /// Method for subscribing to the feeds of a given symbol. /// </summary> /// <param name="sym">Symbol Id to subscribe to</param> /// <param name="handler">Delegate for handling feed updates</param> public void SubscribeFeed(int sym, OnFeedReceived handler) { lock (_lockSubscription) { if (notifyList.ContainsKey(sym)) { //assuming that if symbol exists, handler list would already be initialized notifyList[sym].Add(handler); } else { notifyList.Add(sym, new List <OnFeedReceived>() { handler }); } } }
private static void FeedReceived(string msg) { var feed = JsonConvert.DeserializeObject <Feed>(msg); OnFeedReceived?.Invoke(feed); }
/// <summary> /// Method for unsubscribing to stop receiving updates for a given symbol /// </summary> /// <param name="symbolId">Symbol id to unsubscribe from</param> /// <param name="handler">handler to remove - multiple handlers may be attached to the same symbol</param> public void UnsubscribeFeed(int symbolId, OnFeedReceived handler) { lock(_lockSubscription) { if (notifyList.ContainsKey(symbolId) && notifyList[symbolId].Contains(handler)) { notifyList[symbolId].Remove(handler); } else { throw new Exception("Subscription required for unsubscribing!"); } } }
/// <summary> /// Method for subscribing to the feeds of a given symbol. /// </summary> /// <param name="sym">Symbol Id to subscribe to</param> /// <param name="handler">Delegate for handling feed updates</param> public void SubscribeFeed(int sym, OnFeedReceived handler) { lock(_lockSubscription) { if (notifyList.ContainsKey(sym)) { //assuming that if symbol exists, handler list would already be initialized notifyList[sym].Add(handler); } else { notifyList.Add(sym, new List<OnFeedReceived>() { handler }); } } }