Class: PandoBot::Lake::API

Inherits:
Object
  • Object
show all
Defined in:
lib/pando_bot/lake/api.rb

Overview

HTTP API

Instance Method Summary collapse

Constructor Details

#initialize(endpoint = 'https://api.4swap.org') ⇒ API

Returns a new instance of API.



10
11
12
13
14
15
16
17
18
# File 'lib/pando_bot/lake/api.rb', line 10

def initialize(endpoint = 'https://api.4swap.org')
  @client = Faraday.new(url: endpoint) do |f|
    f.request :json
    f.request :retry
    f.response :raise_error
    f.response :logger
    f.response :json
  end
end

Instance Method Details

#actions(**options) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/pando_bot/lake/api.rb', line 45

def actions(**options)
  path = '/api/actions'
  payload = {
    action: [3, options[:user_id], options[:follow_id], options[:asset_id], options[:route_id],
             options[:minimum_fill]].join(',')
  }
  @client.post(path, payload.to_json).body
end

#order(order_id, authorization:) ⇒ Object



34
35
36
37
38
# File 'lib/pando_bot/lake/api.rb', line 34

def order(order_id, authorization:)
  path = "/api/orders/#{order_id}"
  r = @client.get path, nil, { Authorization: authorization }
  r.body
end

#pairsObject



40
41
42
43
# File 'lib/pando_bot/lake/api.rb', line 40

def pairs
  path = '/api/pairs'
  @client.get(path).body
end

#pre_order(**params) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pando_bot/lake/api.rb', line 20

def pre_order(**params)
  path = '/api/orders/pre'

  payload = {
    pay_asset_id: params[:pay_asset_id],
    fill_asset_id: params[:fill_asset_id],
    funds: params[:funds]&.to_s,
    amount: params[:amount]&.round(8)&.to_s
  }.compact

  r = @client.post path, payload.to_json
  r.body
end

#tradable_asset_idsObject



54
55
56
57
58
59
60
61
62
# File 'lib/pando_bot/lake/api.rb', line 54

def tradable_asset_ids
  _pairs = pairs['data']['pairs']
  _ids = []
  _pairs.each do |pair|
    _ids.push(pair['base_asset_id'])
    _ids.push(pair['quote_asset_id'])
  end
  _ids.uniq!
end