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

Error message: INVALID_SIGNATURE #12

Closed gazzer2k closed 6 years ago

gazzer2k commented 6 years ago

Hi,

This is my code to just get order history on a BTC-GRS pair. But, the same error also appears when I try and buy or sell.

        BittrexDefaults.SetDefaultApiCredentials("xxxx", "yyyy");
        BittrexDefaults.SetDefaultLogOutput(Console.Out);
        BittrexDefaults.SetDefaultLogVerbosity(LogVerbosity.Debug);

        using (var client = new BittrexClient())
        {
            client.MaxRetries = 3;

            var markets = client.GetMarkets();

            var orderHistory = client.GetOrderHistory("BTC-GRS");

        }

        Console.ReadKey();

The error is (Error Code 6000): 05:13:53:093 | Debug | Call failed to https://www.bittrex.com/api/v1.1/account /getorderhistory?market=BTC-GRS, Error message: INVALID_SIGNATURE

Please note I've taken out my api key and secret key but I believe they're both valid.

Any ideas?

Thanks Gary

JKorf commented 6 years ago

Hello, I tried locally with my own key and secret and I don't have any problems. Can I ask if you're running DotNetCore or .Net framework? The error suggests that the message signing is invalid, but apparently not for all keys. I assume your key/secret don't have any weird symbols in them? (Please don't paste either of those)

gazzer2k commented 6 years ago

Thanks. I'm running .NET standard 4.6.2 in VS 2015.It is in debug mode if that makes a difference? I can run the getcurrencies and other methods fine. Unless i have to force the app to be 32 bit?

Gary

On Tuesday, 21 November 2017, 18:57:38 GMT, JKorf <notifications@github.com> wrote:  

Hello, I tried locally with my own key and secret and I don't have any problems. Can I ask if you're running DotNetCore or .Net framework? The error suggests that the message signing is invalid, but apparently not for all keys. I assume your key/secret don't have any weird symbols in them? (Please don't paste either of those)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

JKorf commented 6 years ago

I've been trying to reproduce your issue but I haven't been able to when running in the same setup you have. The error you get indicates that the API secret doesn't correspond to the API key. Please make sure your API secret is correct (No extra spaces, '0' instead of 'o' or something).

JKorf commented 6 years ago

Are you still having troubles with this?

gazzer2k commented 6 years ago

Sorry for not replying. I haven't had time to try again. Thanks very much for looking into the problem though! On Friday, 24 November 2017, 08:17:37 GMT, JKorf notifications@github.com wrote:

Are you still having troubles with this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

inventti-glaicon commented 6 years ago

I guess that its invalid-signature, in BittrexAbstractClient.cs.SetApiSecret should be ASCII. Right?

JKorf commented 6 years ago

I haven't been able to reproduce the issue. I figured it could be something to do with encodings since it is input specific. However since the API keys/secrets are all ASCII characters as far as I know, the result will be the same whether you use ASCII or UTF8 encoding since the byte representation is the same.

inventti-glaicon commented 6 years ago

In my situation the api key and api secret are equals... I've not seen it before.

gazzer2k commented 6 years ago

Thanks! That worked for me. I changed the encoding to ASCII in BittrexAbstractClient.cs.SetApiSecret, recompiled and now my small app works perfectly. Gary On Wednesday, 29 November 2017, 16:29:34 GMT, inventti-glaicon notifications@github.com wrote:

In my situation the api key and api secret are equals... I've not seen it before.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

JKorf commented 6 years ago

Glad you managed to get it working. I'm just trying to figure you what the problem is. Is there any character in your key/secret other than a-Z 0-9?

           var secret = "1234567890QWERTYUIOPLKJHFGDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm";
           var key = "1234567890QWERTYUIOPLKJHFGDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm";

            var hmac = new HMACSHA512(Encoding.ASCII.GetBytes(secret));
            var hmac2 = new HMACSHA512(Encoding.ASCII.GetBytes(secret));
            var hmac3 = new HMACSHA512(Encoding.UTF8.GetBytes(secret));
            var hmac4 = new HMACSHA512(Encoding.UTF8.GetBytes(secret));

            var result = hmac.ComputeHash(Encoding.ASCII.GetBytes(key));
            var result2 = hmac2.ComputeHash(Encoding.UTF8.GetBytes(key));
            var result3 = hmac3.ComputeHash(Encoding.ASCII.GetBytes(key));
            var result4 = hmac4.ComputeHash(Encoding.UTF8.GetBytes(key));

            Console.WriteLine(ByteToString(result));
            Console.WriteLine(ByteToString(result2));
            Console.WriteLine(ByteToString(result3));
            Console.WriteLine(ByteToString(result4));

These combinations all produce the same outcome.

gazzer2k commented 6 years ago

No,  actually the keys are just a-Z or 0-9 Can't see any strange characters in there. It's very mysterious. I know when I have to anything remotely web related that I always use UTF8 encoding.But, this should really be necesary if the input has extended characters. Otherwise, ASCII should work fine.

On Wednesday, 29 November 2017, 19:32:09 GMT, JKorf <notifications@github.com> wrote:  

Glad you managed to get it working. I'm just trying to figure you what the problem is. Is there any character in your key/secret other than a-Z 0-9? var secret = "1234567890QWERTYUIOPLKJHFGDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm"; var key = "1234567890QWERTYUIOPLKJHFGDSAZXCVBNMqwertyuioplkjhgfdsazxcvbnm";

        var hmac = new HMACSHA512(Encoding.ASCII.GetBytes(secret));
        var hmac2 = new HMACSHA512(Encoding.ASCII.GetBytes(secret));
        var hmac3 = new HMACSHA512(Encoding.UTF8.GetBytes(secret));
        var hmac4 = new HMACSHA512(Encoding.UTF8.GetBytes(secret));

        var result = hmac.ComputeHash(Encoding.ASCII.GetBytes(key));
        var result2 = hmac2.ComputeHash(Encoding.UTF8.GetBytes(key));
        var result3 = hmac3.ComputeHash(Encoding.ASCII.GetBytes(key));
        var result4 = hmac4.ComputeHash(Encoding.UTF8.GetBytes(key));

        Console.WriteLine(ByteToString(result));
        Console.WriteLine(ByteToString(result2));
        Console.WriteLine(ByteToString(result3));
        Console.WriteLine(ByteToString(result4));

These combinations all produce the same outcome.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

JKorf commented 6 years ago

Weird. Could you maybe help me out and disable your current ApiKey/Secret in Bittrex, try to use them after to verify they are disabled and post them? You can just create a new pair in your account. I understand if you're hesitant of this, but it would help me in solving this.

fcallejon commented 6 years ago

Sorry to comment in a closed issue. I'm getting the same problem in a Xamarin project (netstandard2.0) but only on the device (one+ 3T with Oreo), both debug and release.

I haven't got the time to test it further. I'll update later.

fcallejon commented 6 years ago

After I changed SetApiSecret (and deleted obj and bin ... crazy xamarin) everything worked as expected.

Seems there is a difference on how NetStandard handles the hash and/or encoding.