class ApiController::Peatio

General peatio api functionality

Public Class Methods

new(endpoint, barong_base_url, app_id, email, password) click to toggle source
# File lib/ApiController/peatio.rb, line 9
def initialize(endpoint, barong_base_url, app_id, email, password)
  @endpoint = endpoint
  @barong_base_url = barong_base_url
  @app_id = app_id
  @email = email
  @password = password
  refresh_jwt
end

Public Instance Methods

cancel_order(id) click to toggle source
# File lib/ApiController/peatio.rb, line 35
def cancel_order(id)
  response = RestClient.post("#{@endpoint}/order/delete",
                             {
                                 'id': id
                             },
                             {'Authorization': "Bearer #{@auth_token}",
                              'content_type': 'application/x-www-form-urlencoded'})

rescue RestClient::Unauthorized => e
  refresh_jwt
  puts e
  puts 'Getting new JWT'
rescue ::StandardError => e
  puts e
end
post_order(market, price, volume, type) click to toggle source
# File lib/ApiController/peatio.rb, line 18
def post_order(market, price, volume, type)
  response = RestClient.post("#{@endpoint}/orders",
                             {
                                 'market': market,
                                 'side': type,
                                 'volume': volume.to_s,
                                 'price': price.to_s,
                                 'ord_type': 'limit'
                             },
                             {'Authorization': "Bearer #{@auth_token}",
                              'content_type': 'application/x-www-form-urlencoded'})
rescue RestClient::Unauthorized => e
  refresh_jwt
  puts e
  puts 'Getting new JWT'
end
refresh_jwt() click to toggle source
# File lib/ApiController/peatio.rb, line 51
def refresh_jwt
  @auth_token = ApiController::Barong.new(@barong_base_url, @app_id).log_in(@email, @password)
end