/// <summary> /// Bitstamp websocket client. /// Use method `Send()` to subscribe to channels. /// And `Streams` to handle messages. /// </summary> /// <param name="communicator">Live or backtest communicator</param> public BitstampWebsocketClient(IBitstampCommunicator communicator) { BitstampValidations.ValidateInput(communicator, nameof(communicator)); _communicator = communicator; _messageReceivedSubscription = _communicator.MessageReceived.Subscribe(HandleMessage); }
/// <summary> /// Serializes request and sends message via websocket communicator. /// It logs and re-throws every exception. /// </summary> /// <param name="request">Request/message to be sent</param> public void Send <T>(T request) where T : RequestBase { try { BitstampValidations.ValidateInput(request, nameof(request)); var serialized = BitstampJsonSerializer.Serialize(request); _communicator.Send(serialized); } catch (Exception e) { Log.Error(e, L($"Exception while sending message '{request}'. Error: {e.Message}")); throw; } }