Sha256: 0ad3438a3928c3e7581afdca36eb1131046dfa927341425db2790f259579702f

Contents?: true

Size: 1.76 KB

Versions: 16

Compression:

Stored size: 1.76 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,
                                     '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

16 entries across 16 versions & 1 rubygems

Version Path
SimBot-0.1.43 lib/ApiController/peatio.rb
SimBot-0.1.42 lib/ApiController/peatio.rb
SimBot-0.1.41 lib/ApiController/peatio.rb
SimBot-0.1.40 lib/ApiController/peatio.rb
SimBot-0.1.39 lib/ApiController/peatio.rb
SimBot-0.1.38 lib/ApiController/peatio.rb
SimBot-0.1.37 lib/ApiController/peatio.rb
SimBot-0.1.36 lib/ApiController/peatio.rb
SimBot-0.1.35 lib/ApiController/peatio.rb
SimBot-0.1.34 lib/ApiController/peatio.rb
SimBot-0.1.33 lib/ApiController/peatio.rb
SimBot-0.1.32 lib/ApiController/peatio.rb
SimBot-0.1.31 lib/ApiController/peatio.rb
SimBot-0.1.30 lib/ApiController/peatio.rb
SimBot-0.1.29 lib/ApiController/peatio.rb
SimBot-0.1.28 lib/ApiController/peatio.rb