BTCMarkets / API

API
120 stars 30 forks source link

Authentication example #39

Open bugrem opened 6 years ago

bugrem commented 6 years ago

I'm having issues getting the API authentication to work on my IDE. Could someone please provide an example of the values of a given call for each step of the process.

For example, if we use the values from the Authentication example page:

URI: /order/history timestamp: 1378818710123 request body: {"currency":"AUD", "instrument":"BTC", "limit":"10"}

Let's say a user authenticates with the following private key (this is just a random string i banged out):

6dhAuK/bHWU2mA4kL3B8s34HnjSHu8nuBUIb7sNJKI3buh7dsBNUIcb7ghnjrE+Edm6Vf3CGYImk9s7bsay5gv==

what would the generated signature be in this case? I really just want to check that I am generating the correct key and that my authentication failure is from this or if I need to be looking elsewhere.

martin-nginio commented 6 years ago

Hi @bugrem

The following request body should work:

{"currency":"AUD","instrument":"BTC","limit":10,"since":null}

(assuming you do not need to specify "since" value.

Please let me know if you come across issues.

Thank you.

Note: Our engineering team is in the process of introducing order/trade history with http GET and improved pagination (and easier authentication) soon.

Regards, Martin

bugrem commented 6 years ago

Hi Martin,

I was actually hoping for some concrete examples of the values generated with the HmacSHA512 authentication algorithm to be sent in the 'signature' parameter of the API GET/POST call. As in, what is the actual string generated from the algorithm using the above variables? I haven't had any experience with hashing algorithms before so am wondering where exactly I am tripping up.

That body string was just what I copied from the Authentication help page (https://github.com/BTCMarkets/API/wiki/Authentication) which gives en example of the generated signature string but not how it is calculated (no example private key).

martin-nginio commented 6 years ago

if you are using Java, Python or Javascript language you can refer to the sample codes listed below: here:"https://github.com/BTCMarkets/API

It' d be easier to run and debug them and check out the values.

Alternatively, you can also share your the section in your code that does authentication and one of our engineers can help with debugging depending on the programming language you use.

Whalanator commented 6 years ago

Hi bugrem I get

GfF/XpGONnUsp5TTUEeA172CzKgkHrwHqGR48Qz0ttXaXojnu02IwyGYM4DQPpueRI+QZiLqscdM5erFnQriZw==

using your key.

To get the same result make sure the string you sign is identical to mine. In C++ I write mine as:

"/order/history" + "\n" + "1378818710123" + "\n" + "{\"currency\":\"AUD\", \"instrument\":\"BTC\", \"limit\":\"10\"}"

so the string doesn't doesn't end with a newline character.

I am also trying to figure out how to use the api. I am getting an internal server error so hopefully my authentication is not the problem. But I'm interested to hear if you get the same value.

martin-nginio commented 6 years ago

Hi

please note. The string to sign needs to have "since" variable in it. Also there should be no space between variables in the body of the json: (..."BTC","limit"...) is correct but (..."BTC", "limit"...) will produce an authentication error.

/order/history
1506409549714
{"currency":"AUD","instrument":"BTC","limit":10,"since":null}

I'm not sure why you receive internal server error with C++. I checked with our dev team and it I can confirm sample codes works for other languages.