class Peatio::MemberAPIv2::Client

Public Class Methods

new(root_url, jwt) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 6
def initialize(root_url, jwt)
  @root_api_url = root_url
  @jwt = jwt
end

Public Instance Methods

clear_orders(side) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 34
def clear_orders(side)
  request(:post, "orders/clear?side=#{side}")
end
delete_order(id) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 42
def delete_order(id)
  body = {
    id: id
  }
  request(:post, 'order/delete', body)
end
get_currency(currency) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 11
def get_currency(currency)
  request(:get, "currencies/#{currency}")
end
get_ticker(ticker) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 15
def get_ticker(ticker)
  request(:get, "tickers/#{ticker}")
end
new_order(market, side, volume, price, ord_type) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 23
def new_order(market, side, volume, price, ord_type)
  body = {
    market: market,
    side: side,
    volume: volume,
    price: price,
    ord_type: ord_type
  }
  request(:post, 'orders', body)
end
orders(market) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 38
def orders(market)
  request(:get, "orders?market=#{market}")
end
profile() click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 19
def profile
  request(:get, 'members/me')
end

Private Instance Methods

build_path(path) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 76
def build_path(path)
  "api/v2/#{path}"
end
http_client() click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 67
def http_client
  Faraday.new(url: @root_api_url) do |conn|
    conn.request :json
    conn.response :json
    conn.adapter Faraday.default_adapter
    conn.authorization :Bearer, @jwt
  end
end
request(request_method, request_path, params = nil) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 51
def request(request_method, request_path, params = nil)
  unless request_method.in?(%i[get post])
    raise ArgumentError, "Request method is not supported: #{request_method.inspect}."
  end

  begin
    http_client
      .public_send(request_method, build_path(request_path), params)
      .tap { |response| puts response unless response.success? }
      .assert_success!
      .body
  rescue Faraday::Error => e
    puts e.backtrace
  end
end
response_err_msg(response) click to toggle source
# File lib/peatio/member_api_v2/client.rb, line 80
def response_err_msg(response)
  "PEATIO ERROR:  #{response.body} >>>>>>>> header >>>>> #{response.headers}"
end