Class: ApiController::Peatio

Inherits:
Object
  • Object
show all
Defined in:
lib/ApiController/peatio.rb

Overview

General peatio api functionality

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, barong_base_url, app_id, email, password) ⇒ Peatio

Returns a new instance of Peatio.



9
10
11
12
13
14
15
16
# 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

Instance Method Details

#cancel_order(id) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ApiController/peatio.rb', line 18

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

#refresh_jwtObject



51
52
53
# File 'lib/ApiController/peatio.rb', line 51

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