JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.03k stars 425 forks source link

System.Exception: Failed to authenticate request, make sure your API credentials are correct #1393

Closed stephanie-rimel closed 1 month ago

stephanie-rimel commented 1 month ago

I am randomly getting this error all of a sudden despite never changing my api credentials. Nothing changed about my setup and now I get this error, I checked on binance and my api credentials are still valid, I even attempted swapping the credentials out for new ones and I still get the error. Can you think of a reason why this would happen?


       ---> System.ObjectDisposedException: Cannot access a disposed object.
      Object name: 'System.Security.SecureString'.
         at System.Security.SecureString.get_Length()
         at CryptoExchange.Net.ExtensionMethods.GetString(SecureString source)
         at Binance.Net.BinanceAuthenticationProvider.AuthenticateRequest(RestApiClient apiClient, Uri uri, HttpMethod method, IDictionary`2 uriParamete
rs, IDictionary`2 bodyParameters, Dictionary`2 headers, Boolean auth, ArrayParametersSerialization arraySerialization, HttpMethodParameterPosition parameterPosition, RequestBodyFormat requestBodyFormat)
         at CryptoExchange.Net.Clients.RestApiClient.CreateRequest(String baseAddress, RequestDefinition definition, ParameterCollection uriParameters, ParameterCollection bodyParameters, Dictionary`2 additionalHeaders)
         --- End of inner exception stack trace ---
         at CryptoExchange.Net.Clients.RestApiClient.CreateRequest(String baseAddress, RequestDefinition definition, ParameterCollection uriParameters, ParameterCollection bodyParameters, Dictionary`2 additionalHeaders)
         at CryptoExchange.Net.Clients.RestApiClient.SendAsync[T](String baseAddress, RequestDefinition definition, ParameterCollection uriParameters, ParameterCollection bodyParameters, CancellationToken cancellationToken, Dictionary`2 additionalHeaders, Nullable`1 weight)
         at Binance.Net.Clients.SpotApi.BinanceRestClientSpotApi.SendToAddressAsync[T](String baseAddress, RequestDefinition definition, ParameterCollection parameters, CancellationToken cancellationToken, Nullable`1 weight)
         at Binance.Net.Clients.SpotApi.BinanceRestClientSpotApiAccount.GetAccountInfoAsync(Nullable`1 omitZeroBalances, Nullable`1 receiveWindow, CancellationToken ct)
         at BotTrading.Shared.TradingProfiles.UpdateCurrentBalances(List`1 profiles)
         at BotTrading.Shared.TradingProfiles.OnInitializedAsync()
         at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync()
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)```
stephanie-rimel commented 1 month ago

It worked for like a few seconds, and now I am getting the error: Request Timed Out. Are you fixing it by chance or is this a problem on the binance end? This is the line of code that is throwing the error: var result = await BinanceClient.SpotApi.Account.GetAccountInfoAsync(); // .Balances

JKorf commented 1 month ago

It looks like your credentials are disposed. Can it be your client is disposed / out of scope?