I am trying to connect to Binance api from my Rails application. But every time I am getting 401 unauthorized
error message from Binance. Below is my code.
class Binance
END_POINT = 'https://api.binance.com'.freeze
KEY = 'my-binance-key'
SECRET = 'my-binance-secret'
def self.account_info
url = "#{END_POINT}/api/v3/account"
query_string = "timestamp=#{DateTime.now.strftime('%Q')}"
digest = OpenSSL::Digest.new('sha256')
signature = OpenSSL::HMAC.hexdigest(digest, SECRET, query_string)
url = "#{END_POINT}/api/v3/account?#{query_string}&signature=#{signature}"
response = RestClient.get(url, headers: { 'X-MBX-APIKEY': KEY })
end
end
Here is a link from Binance api with example: