0

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:

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#signed-endpoint-examples-for-post-apiv3order

r3b00t
  • 6,953
  • 6
  • 27
  • 37

0 Answers0