0

This is what I am having trouble understanding and doing.

I need to add a header called sign with the query's POST data signed by my key's "secret" according to the HMAC-SHA512 method. What is my query's post data? And how can I find it so that I can encrypt it and send it as a header.

These are my parameters: "command" => "returnBalances", "nonce" => Time.now.to_i

Please let me know:

  • How do I find my post request data.
  • How do I use the HMAC-SHA512 method to encrypt this data so that I can send it in a header. (using Ruby)

Thank you people let me know.

Pabi
  • 946
  • 3
  • 16
  • 47

1 Answers1

1

I answered your question more completely here, in the context of the Poloniex exchange:

Ruby Http Post Parameters

To answer your specific questions from this post:

  1. How do I find my post request data?

POST data simply means the body of your request. This could be JSON, plain text, form data, etc. In cases where a specific format (i.e. JSON) isn't mentioned, POST data probably refers to POST form data (Content-Type: application/x-www-form-urlencoded). This is how data submitted from a web form is formatted and indeed that appears to be what Poloniex is looking for.

x-www-form-urlencoded data can be produced like this in Ruby:

form_data = URI.encode_www_form({:command => 'returnBalances', :nonce => Time.now.to_i * 1000 })
puts form_data

command=returnBalances&nonce=1447537613000

Mozilla Developer's Network link on POST form data.

  1. How do I use the HMAC-SHA512 method to encrypt this data so that I can send it in a header? (using Ruby)

HMAC digest produces a unique string based on a secret key and the data provided. In Ruby, you can produce an HMAC digest like so:

OpenSSL::HMAC.hexdigest( 'sha512', secret, form_data)
Community
  • 1
  • 1