JKorf / Bittrex.Net

A C# .Net wrapper for the Bittrex web API including all features easily accessible and usable
MIT License
141 stars 62 forks source link

Bittrex auth issue #175

Open aph5nt opened 4 years ago

aph5nt commented 4 years ago

Hi, I often get this type of error for private API operations. To solve this I have to generate a new set of auth tokens. But for some reason, after some time I get this error once again... I suspect it has something to Bittrex security policy.

Is it possible to get a more descriptive error message?

How to reproduce:


System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.
   at Internal.Cryptography.HashProviderDispenser.HmacHashProvider.TryFinalizeHashAndReset(Span`1 destination, Int32& bytesWritten)
   at Internal.Cryptography.HashProviderDispenser.HmacHashProvider.FinalizeHashAndReset()
   at System.Security.Cryptography.HashAlgorithm.CaptureHashCodeAndReinitialize()
   at Bittrex.Net.BittrexAuthenticationProviderV3.AddAuthenticationToHeaders(String uri, HttpMethod method, Dictionary`2 parameters, Boolean signed, PostParameters postParameterPosition, ArrayParametersSerialization arraySerialization)
   at CryptoExchange.Net.RestClient.ConstructRequest(Uri uri, HttpMethod method, Dictionary`2 parameters, Boolean signed, PostParameters postPosition, ArrayParametersSerialization arraySerialization)
   at CryptoExchange.Net.RestClient.SendRequest[T](Uri uri, HttpMethod method, CancellationToken cancellationToken, Dictionary`2 parameters, Boolean signed, Boolean checkResult, Nullable`1 postPosition, Nullable`1 arraySerialization)
   at Bittrex.Net.BittrexClientV3.GetClosedWithdrawalsAsync(String currency, Nullable`1 status, Nullable`1 startDate, Nullable`1 endDate, Nullable`1 pageSize, String nextPageToken, String previousPageToken, CancellationToken ct)```
pwnzya commented 4 years ago

I have never had this issue, so I am not sure, but you could try getting debugging info by setting BittrexClientOptions.LogVerbosity to Debug. Also, you could try to get the error info in the response message sent by Bittrex. If you have already tried this, then I don't know.

The code would look something like this:

private async void TestGetClosedWithdrawls()
{
    string key = "yourkey";
    string secret = "yourSecret";

    BittrexClientV3.SetDefaultOptions(new BittrexClientOptions
    {
        LogWriters = new List<TextWriter>() { Console.Out },
        LogVerbosity = LogVerbosity.Debug,
        ApiCredentials = new ApiCredentials(key, secret)
    });

    using (var client = new BittrexClientV3())
    {
        try
        {
            var result = await client.GetClosedWithdrawalsAsync();
            if (result.Success)
            {
                // do something with the data
            }
            else
            {   // print error info
                Console.WriteLine($"Failed to receive withdrawl records.");
                Console.WriteLine($"ResponseStatusCode = {result.ResponseStatusCode}");
                Console.WriteLine($"Error code = {result.Error.Code}");
                Console.WriteLine($"Error message = {result.Error.Message}");
                Console.WriteLine($"Error data = {result.Error.Data}");
            }
        }
        catch(Exception exception)
        {
            Console.WriteLine($"Caught an exception in TestGetClosedWithdrawls:");
            Console.WriteLine($"{exception}");
        }
    }
}