Class: OKEX::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/okex/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, passphrase) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
# File 'lib/okex/client.rb', line 8

def initialize(key, secret, passphrase)
  @api_key = key
  @api_secret = secret
  @passphrase = passphrase
end

Instance Method Details

#get(host, path) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/okex/client.rb', line 14

def get(host, path)
  url = host + path
  ts = timestamp
  sig = sign(ts, "GET", path)
  _h = headers(ts, sig)

  puts "---> GET: url=#{url}, headers=#{_h}" if ENV['OKEX_DEBUG'].to_i > 0

  _resp(Faraday.get(url, nil, _h))
end

#post(host, path, payload) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/okex/client.rb', line 25

def post(host, path, payload)
  if payload.is_a?(Array)
    _json = payload.map do |hx|
      gen_payload(hx)
    end
    payload_json = "[#{_json.join(",")}]"
  else
    payload_json = gen_payload(payload)
  end
  
  url = host + path
  ts = timestamp
  sig = sign(ts, "POST", path + payload_json)
  _h = headers(ts, sig)

  puts "---> POST: url=#{url}, payload=#{payload_json}, headers=#{_h}" if ENV['OKEX_DEBUG'].to_i > 0

  _resp(Faraday.post(url, payload_json, _h))
end