private async Task <CallResult <bool> > Authenticate(SocketSubscription subscription) { if (authProvider == null) { return(new CallResult <bool>(false, new NoApiCredentialsError())); } var authParams = authProvider.AddAuthenticationToParameters(baseAddressAuthenticated, Constants.GetMethod, new Dictionary <string, object>(), true); var authObjects = new HuobiAuthenticationRequest { AccessKeyId = authProvider.Credentials.Key.GetString(), Operation = "auth", SignatureMethod = (string)authParams["SignatureMethod"], SignatureVersion = authParams["SignatureVersion"].ToString(), Timestamp = (string)authParams["Timestamp"], Signature = (string)authParams["Signature"] }; Send(subscription.Socket, authObjects); var authResult = await subscription.WaitForEvent(AuthenticationEvent, socketResponseTimeout).ConfigureAwait(false); if (!authResult.Success) { await subscription.Close().ConfigureAwait(false); return(new CallResult <bool>(false, authResult.Error)); } return(new CallResult <bool>(true, null)); }
protected override async Task <CallResult <bool> > AuthenticateSocket(SocketConnection s) { if (authProvider == null) { return(new CallResult <bool>(false, new NoApiCredentialsError())); } var authParams = authProvider.AddAuthenticationToParameters(baseAddressAuthenticated, Constants.GetMethod, new Dictionary <string, object>(), true); var authObjects = new HuobiAuthenticationRequest { AccessKeyId = authProvider.Credentials.Key.GetString(), Operation = "auth", SignatureMethod = (string)authParams["SignatureMethod"], SignatureVersion = authParams["SignatureVersion"].ToString(), Timestamp = (string)authParams["Timestamp"], Signature = (string)authParams["Signature"] }; CallResult <bool> result = new CallResult <bool>(false, new ServerError("No response from server")); await s.SendAndWait(authObjects, ResponseTimeout, data => { if ((string)data["op"] != "auth") { return(false); } var authResponse = Deserialize <HuobiSocketAuthDataResponse <object> >(data, false); if (!authResponse.Success) { log.Write(LogVerbosity.Warning, "Authorization failed: " + authResponse.Error); result = new CallResult <bool>(false, authResponse.Error); return(true); } if (!authResponse.Data.IsSuccessful) { log.Write(LogVerbosity.Warning, "Authorization failed: " + authResponse.Data.ErrorMessage); result = new CallResult <bool>(false, new ServerError(authResponse.Data.ErrorCode, authResponse.Data.ErrorMessage)); return(true); } log.Write(LogVerbosity.Debug, "Authorization completed"); result = new CallResult <bool>(true, null); return(true); }); return(result); }