Skip to content

Instantly share code, notes, and snippets.

@kelby
Last active January 24, 2019 13:22
Show Gist options
  • Save kelby/b38ecda2c16948a16e80d1b994e38a29 to your computer and use it in GitHub Desktop.
Save kelby/b38ecda2c16948a16e80d1b994e38a29 to your computer and use it in GitHub Desktop.
StocksExchange API Integration
require 'openssl'
require 'httparty'
url = "https://stocks.exchange/api2"
api_key = "your_api_key"
api_secret = "your_api_secret"
nonce = Time.now.to_i
method = "GetInfo"
data = {"method": method, "nonce": nonce}
signdata = "method=#{method}&nonce=#{nonce}"
sign = OpenSSL::HMAC.hexdigest("SHA512", api_secret, signdata)
response = HTTParty.post(url,
:body => data.to_json,
:headers => { 'Sign' => sign, 'Key' => api_key })
@Drengel1990
Copy link

Drengel1990 commented Apr 10, 2018

require 'openssl'
require 'httparty'

api_key = "your_api_key"
api_secret = "your_api_secret"

nonce = Time.now.to_i
method = "GetInfo"

url = "https://stocks.exchange/api2?method=#{method}&nonce=#{nonce}"
data = {method: method, nonce: nonce}
sign = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), api_secret, data.to_s)

response = HTTParty.post(url, body: data.to_s, headers: {
    'Sign' => sign,
    'Key' => api_key
})

Your code not correct working.
Please checked this code

@kelby
Copy link
Author

kelby commented Jan 24, 2019

# base url is changed. use this:
url = "https://app.stex.com/api2?method=#{method}&nonce=#{nonce}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment