public async Task SendMessageAsync(IWsIqOptionMessageCreator messageCreator) { if (await OpenWebSocketAsync()) { _logger.Information($"send message => :\t{messageCreator.CreateIqOptionMessage()}"); Client.Send(messageCreator.CreateIqOptionMessage()); } }
/// <summary> /// Commit the message to the IqOption Server, and wait for result back /// </summary> /// <param name="messageCreator">The message creator builder.</param> /// <param name="observableResult">The target observable that will trigger after message was incomming</param> /// <typeparam name="TResult">The expected result</typeparam> /// <returns></returns> public Task <TResult> SendMessageAsync <TResult>( IWsIqOptionMessageCreator messageCreator, IObservable <TResult> observableResult) { var tcs = new TaskCompletionSource <TResult>(); var token = new CancellationTokenSource(5000).Token; try { token.ThrowIfCancellationRequested(); token.Register(() => { if (tcs.TrySetCanceled()) { _logger.ForContext("Topic", "Wait Result Cancelled") .Debug("Wait result for type '{0}', took long times {1} seconds. The result will send back with default {0}\n{2}", typeof(TResult), 5000, messageCreator.CreateIqOptionMessage()); } }); observableResult .FirstAsync() .Subscribe(x => { tcs.TrySetResult(x); }, token); // send message SendMessageAsync(messageCreator); } catch (Exception ex) { tcs.TrySetException(ex); } return(tcs.Task); }
/// <summary> /// Commit the message with Fire-And-Forgot style /// </summary> /// <param name="messageCreator"></param> /// <returns></returns> public async Task SendMessageAsync(IWsIqOptionMessageCreator messageCreator, string requestPrefix = "") { using (await _asyncLock.WaitAsync(CancellationToken.None).ConfigureAwait(false)) { _requestCounter = _requestCounter + 1; var payload = messageCreator.CreateIqOptionMessage($"{requestPrefix}{_requestCounter}"); WebSocketClient.Send(payload); _logger.LogDebug("⬆ {payload}", payload); } }
public Task SendMessageAsync(IWsIqOptionMessageCreator messageCreator) { var payload = messageCreator.CreateIqOptionMessage(); _logger.ForContext("Topic", "request >>").Debug("{payload}", payload); _client.Send(payload); return(Task.CompletedTask); }
/// <summary> /// Commit the message with Fire-And-Forgot style /// </summary> /// <param name="messageCreator"></param> /// <returns></returns> public Task SendMessageAsync(IWsIqOptionMessageCreator messageCreator) { using (LogContext.Push(new ProfileEnricher(Profile))) { var payload = messageCreator.CreateIqOptionMessage(); _client.Send(payload); _logger .ForContext("Topic", "request >>") .Debug("{payload}", payload); } return(Task.CompletedTask); }
public Task SendMessageAsync(IWsIqOptionMessageCreator messageCreator) { _client.Send(messageCreator.CreateIqOptionMessage()); return(Task.CompletedTask); }