Class: Buda::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/buda/client.rb,
lib/buda/resources/currency.rb

Overview

Client component to make the requests and get data

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, amount) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
24
25
26
27
28
# File 'lib/buda/client.rb', line 19

def initialize(api_key, api_secret)
  @api_key = api_key
  @api_secret = api_secret
  @user_agent = "buda-ruby/#{Buda::VERSION}"
  @headers = {
    'Content-Type': 'application/json', 'X-SBTC-APIKEY': @api_key,
    'User-Agent': @user_agent
  }
  @default_params = {}
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



6
7
8
# File 'lib/buda/resources/currency.rb', line 6

def amount
  @amount
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/buda/resources/currency.rb', line 6

def id
  @id
end

Instance Method Details

#balancesObject



50
51
52
53
54
55
56
57
# File 'lib/buda/client.rb', line 50

def balances
  result = get.call('balances', true)[:balances]
  balances = []
  result&.each do |balance|
    balances << Balance.new(**balance)
  end
  balances
end

#deleteObject



34
35
36
# File 'lib/buda/client.rb', line 34

def delete
  request('delete')
end

#deposits(currency) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/buda/client.rb', line 72

def deposits(currency)
  result = get.call("currencies/#{currency}/deposits", true)[:deposits]
  deposits = []
  result&.each do |deposit|
    deposits << Deposit.new(**deposit)
  end
  deposits
end

#getObject



30
31
32
# File 'lib/buda/client.rb', line 30

def get
  request('get')
end

#get_balance(balance_id) ⇒ Object



59
60
61
62
# File 'lib/buda/client.rb', line 59

def get_balance(balance_id)
  result = get.call("balances/#{balance_id}", true)[:balance]
  Balance.new(**result)
end

#get_market(market_id) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/buda/client.rb', line 64

def get_market(market_id)
  market = get.call("markets/#{market_id.upcase}")[:market]
  ticker = get.call("markets/#{market_id.upcase}/ticker")[:ticker]
  new_market = Market.new(**market)
  new_market.set_ticker(**ticker)
  new_market
end

#inspectObject



17
18
19
# File 'lib/buda/resources/currency.rb', line 17

def inspect
  "<Currency #{@amount} (#{@id})>"
end

#request(method) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/buda/client.rb', line 38

def request(method)
  proc do |resource, is_private, **kwargs|
    parameters = params(method, **kwargs)
    response = make_request(method, resource, parameters, is_private)
    content = JSON.parse(response.body, symbolize_names: true)

    # raise_custom_error(content[:error]) if response.status.client_error? || response.status.server_error?

    content
  end
end

#to_sObject



90
91
92
93
94
95
# File 'lib/buda/client.rb', line 90

def to_s
  visible_chars = 4
  hidden_part = '*' * (@api_key.size - visible_chars)
  visible_key = @api_key.slice(0, visible_chars)
  "Client(🔑=#{hidden_part + visible_key}"
end

#withdrawals(currency) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/buda/client.rb', line 81

def withdrawals(currency)
  result = get.call("currencies/#{currency}/withdrawals", true)[:withdrawals]
  withdrawals = []
  result&.each do |withdrawal|
    withdrawals << Withdrawal.new(**withdrawal)
  end
  withdrawals
end