public async Task Send(BitmexWebsocketChannel toChannel, MultiplexingMessageBase multiplexingMessage) { var message = new List <object> { (int)multiplexingMessage.MessageType, toChannel.ChannelId, toChannel.ChannelName }; if (multiplexingMessage.Payload != null) { message.Add(multiplexingMessage.Payload); } var serialized = BitmexJsonSerializer.Serialize(message); try { await _communicator.Send(serialized).ConfigureAwait(false); } catch (Exception e) { Log.Error(e, L($"Exception while sending message '{serialized}'. Error: {e.Message}")); throw; } }
/// <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 async Task Send <T>(T request) where T : RequestBase { try { BmxValidations.ValidateInput(request, nameof(request)); var serialized = request.IsRaw ? request.OperationString : BitmexJsonSerializer.Serialize(request); await _communicator.Send(serialized).ConfigureAwait(false); } catch (Exception e) { Log.Error(e, L($"Exception while sending message '{request}'. Error: {e.Message}")); throw; } }