public void Subscribe(string symbol) { //...failsafe... if (webSocket == null) { return; } symbol = symbol.ToUpper(); if (_symbols.Contains(symbol)) { return; } lock (_symbols) { _symbols.Add(symbol); } FireConnectionStatus("Listening to " + symbol); //...send out the message to listen for data var message = new BitmexSocketMessage { op = "subscribe", args = new List <string> { $"trade:{symbol}" } }; var _webSocketMessage = JsonConvert.SerializeObject(message); webSocket.Send(_webSocketMessage); }
public void UnSubscribe(string symbol) { //failsafe... if (webSocket == null) { return; } if (!_symbols.Contains(symbol)) { return; } lock (_subscribers) { if (_subscribers.Any(s => s.IsSymbolWatching(symbol))) { return; } } lock (_symbols) { _symbols.Remove(symbol); } FireConnectionStatus("De-Listening to " + symbol); //...send out the message to de-listen for data var message = new BitmexSocketMessage { op = "unsubscribe", args = new List <string> { $"trade:{symbol}" } }; var _webSocketMessage = JsonConvert.SerializeObject(message); webSocket.Send(_webSocketMessage); }