Sha256: cc1e12ada9c49007f51cd91966f52fca6c0ff8f54afb0ae12d897e29d2eeab6c

Contents?: true

Size: 960 Bytes

Versions: 5

Compression:

Stored size: 960 Bytes

Contents

=begin
#SnapTrade

#Connect brokerage accounts to your app for live positions and trading

The version of the OpenAPI document: 1.0.0
Contact: api@snaptrade.com

=end

require 'base64'
require 'openssl'

module SnapTrade
  class ApiClientCustom
    def self.request_hook(request, configuration)
      request.params[:timestamp] = Time.now.to_i
      path = request.path[request.path.index('/api/v1/')..-1]
      query = Faraday::Utils.build_query(request.params)
      sig_object = {
        "content" => request.body.nil? || request.body.empty? ? nil : JSON.parse(request.body),
        "path" => path,
        "query" => query
      }
      sig_content = JSON.generate(sig_object, sort_by: :to_s)
      sig_digest = OpenSSL::HMAC.digest(OpenSSL::Digest::SHA256.new, configuration.consumer_key, sig_content)
      signature = Base64.encode64(sig_digest).strip()
      request.headers[:Signature] = signature
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
snaptrade-1.16.2 lib/snaptrade/api_client_custom.rb
snaptrade-1.16.1 lib/snaptrade/api_client_custom.rb
snaptrade-1.15.1 lib/snaptrade/api_client_custom.rb
snaptrade-1.13.0 lib/snaptrade/api_client_custom.rb
snaptrade-1.8.0 lib/snaptrade/api_client_custom.rb