Sha256: 2f05c0d500eb819551299edd0347c3885fdc14ff4523f80d00203bafb4e2774f

Contents?: true

Size: 1.77 KB

Versions: 7

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

module ApiController
  # General peatio api functionality
  class Peatio
    require 'json'
    require 'rest-client'
    require_relative 'barong'
    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

    def post_order(market, price, volume, type)
      response = RestClient.post("#{@endpoint}/orders",
                                 {
                                     'market': market,
                                     'side': type.to_s,
                                     '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

    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

    def refresh_jwt
      @auth_token = ApiController::Barong.new(@barong_base_url, @app_id).log_in(@email, @password)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
SimBot-0.1.27 lib/ApiController/peatio.rb
SimBot-0.1.26 lib/ApiController/peatio.rb
SimBot-0.1.25 lib/ApiController/peatio.rb
SimBot-0.1.24 lib/ApiController/peatio.rb
SimBot-0.1.23 lib/ApiController/peatio.rb
SimBot-0.1.22 lib/ApiController/peatio.rb
SimBot-0.1.21 lib/ApiController/peatio.rb