private async Task SendWithoutResponceAsync( string path, HttpMethod method, string query = null, IMessage command = null, CancellationToken cancellationToken = default) { var request = BuildRequestBase(path, method, query); var nonce = (new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds() * 1000000).ToString(); var authPayload = $"AUTH{nonce}"; var signature = XenaSignature.Sign(_options.ApiSecret, authPayload); request.Headers.Add("X-AUTH-API-KEY", _options.ApiKey); request.Headers.Add("X-AUTH-API-PAYLOAD", authPayload); request.Headers.Add("X-AUTH-API-SIGNATURE", signature); request.Headers.Add("X-AUTH-API-NONCE", nonce); if (command != null) { var payload = _serializer.Serialize(command); request.Content = new StringContent(payload, Encoding.UTF8, "application/json"); } await SendAsyncBaseWithoutResponse(request, cancellationToken).ConfigureAwait(false); return; }
private async Task <Logon> LogonAsync() { var nonce = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds() * 1000000; var authPayload = $"AUTH{nonce}"; var signature = XenaSignature.Sign(_tradingOptions.ApiSecret, authPayload); var logon = new Logon { MsgType = MsgTypes.Logon, Username = _tradingOptions.ApiKey, SendingTime = nonce, RawData = authPayload, Password = signature, }; logon.Account.AddRange(_tradingOptions.Accounts.Select(p => (ulong)p)); _logonChannel = new Channel <Logon>(); await SendCommandAsync(logon).ConfigureAwait(false); Logon logonResponse; try { logonResponse = await _logonChannel.ReceiveAsync(_tradingOptions.LogonResponseTimeout); } catch (TimeoutException ex) { const string msg = "Logon response timed out"; Logger.LogError(msg); throw new LogonResponseTimeoutException(msg, ex); } if (!string.IsNullOrWhiteSpace(logonResponse.RejectText)) { throw new LogonRejectedException(logonResponse.RejectText); } _logonChannel = null; Logger.LogInformation("Logon successful"); return(logonResponse); }