Sha256: fb29435b75c677145614f0aa85d474daa58ff129f970d55a051f7f519e9f2373
Contents?: true
Size: 1.94 KB
Versions: 1
Compression:
Stored size: 1.94 KB
Contents
# frozen_string_literal: true module Peatio module MemberAPIv2 class Client def initialize(root_url, jwt) @root_api_url = root_url @jwt = jwt end def get_currency(currency) request(:get, "currencies/#{currency}") end def get_ticker(ticker) request(:get, "tickers/#{ticker}") end def profile request(:get, 'members/me') end 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 def clear_orders(side) request(:post, "orders/clear?side=#{side}") end def orders(market) request(:get, "orders?market=#{market}") end def delete_order(id) body = { id: id } request(:post, 'order/delete', body) end private 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 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 def build_path(path) "api/v2/#{path}" end def response_err_msg(response) "PEATIO ERROR: #{response.body} >>>>>>>> header >>>>> #{response.headers}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
SimBot-0.1.43 | lib/peatio/member_api_v2/client.rb |