JKorf / Bitfinex.Net

A C# .netstandard client library for the Bitfinex REST and Websocket API focusing on clear usage and models
https://jkorf.github.io/Bitfinex.Net/
MIT License
88 stars 49 forks source link

Error: 10100 - apikey: invalid #7

Closed henningms closed 6 years ago

henningms commented 6 years ago

Hi there,

I've been trying your library to see if I could retrieve orders history etc because I've been struggling to do so myself but I get APIKey Invalid error.

static async Task Main(string[] args)
    {
            var options = new BitfinexClientOptions()
            {
                ApiCredentials = new ApiCredentials("something", "something")
            };

            using (var client = new BitfinexClient(options))
            {
                var result = await client.GetOrderHistoryAsync("tBTCUSD");
            }
        }

Do you know why this occurs? Tried generating new api keys and testing them as well to no luck.

JKorf commented 6 years ago

Hi, I'm not sure why that would happen. It's working for me.

Could you maybe provide me with an ApiKey/secret that is no longer active and wasn't working? Make sure it is no longer active. I can then check if there are some differences when encoding them compared to my own.

henningms commented 6 years ago

Hmm, weird.

Revoked API key: Key: gXJWyEY53IwPk425jytbAGRsyw7NPvLkM5LCdA2o4eM Secret: TtXWNOzAyC3tUTlkYhW8UgqZkF857Eyej9JYKvKU2si

JKorf commented 6 years ago

I don't really see anything wrong. Can you put log verbosity on debug and share the logging you get?

henningms commented 6 years ago
2018.04.16 12:05:13:597 | Info | Loglevel set to Debug
2018.04.16 12:05:16:163 | Debug | Sending signed request to https://api.bitfinex.com/v2/auth/r/orders/tBTCUSD/hist
2018.04.16 12:05:16:806 | Warning | Server returned an error: ["error",10100,"apikey: invalid"]

That's what I get when logging debug, so not a lot more. So you can retrieve order history with your api key(s)? Weird.

(This is with an active key)

henningms commented 6 years ago

I'm sorry, I actually get nonce: small error when using the checked out code. I modified the nonce a bit when I first started testing.

Although changing the nonce to become higher result in the apikey invalid error so yeah. No luck there hmm.

JKorf commented 6 years ago

I can retrieve it with my keys yes. Maybe it has something to do with localization. What culture and timezone is your computer in?

Nonce: small indicates a nonce that is smaller than a previously provided one. Nonce should always be higher than the ones before, so if you sent a high nonce earlier you'll need to wait till that time is passed or you'll have to use a higher nonce from now on.

henningms commented 6 years ago

I'm in Norway which is UTC+2 right now.

henningms commented 6 years ago

Not sure what's happening, but I figured out why my own POST attempt failed. I forgot the / before API in the signature string.

JKorf commented 6 years ago

Your own post attempt?

henningms commented 6 years ago

I've tried to write my own little snippet for retrieving orders history. Unable to get it to work I tried your library, but I seemed to get the same error. I'll try to debug using your library now that I got my own code working.

JKorf commented 6 years ago

I see. Please let me know if you find anything. Hard to debug on this side if nothing is breaking ;)

JKorf commented 6 years ago

Have you managed to find out why your own snippet is working but the lib doesn't? Would be great if I could fix it.

henningms commented 6 years ago

Hi, no, I will do a diff of the two requests later today!

henningms commented 6 years ago

Figured out. It has to do with the nonce apparently.

Could you test for me on your end if you replace the nonce generation from

private string nonce => Math.Round((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds * 10).ToString(CultureInfo.InvariantCulture);

to this one:

private string nonce => ((long)((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds * 1000)).ToString();

and see if it works fine on your end? Using the original code I either get a nonce too small or a nonce invalid due to the string becoming "1.543435663+E9".

JKorf commented 6 years ago

Seems to work fine for me, I've changed it to in the latest version being pushed now. Thanks for your help on this!

tree1891 commented 5 years ago

I have same issue when call GetWalletsAsync().

tree1891 commented 5 years ago

Because of postParametersPosition = PostParameters.InUri, WriteParamBody can not be called.

JKorf commented 5 years ago

This has been fixed in the latest version again.