Class: Itbit::Wallet

Inherits:
Object
  • Object
show all
Defined in:
lib/itbit/wallet.rb

Overview

Your ItBit wallets, translated from itbit api to a more suitable ruby style. Field names are underscored. Values for balance and trading_balance are converted to BigDecimal

Class Method Summary collapse

Class Method Details

.allObject

Lists all wallets.



8
9
10
11
# File 'lib/itbit/wallet.rb', line 8

def self.all
  Api.request(:get, "/wallets", userId: Itbit.user_id)
    .collect { |wallet| translate_wallet(wallet) }
end

.create!(name) ⇒ Object

Creates a new order

Parameters:

  • name (String)

    The name for the new wallet.



15
16
17
# File 'lib/itbit/wallet.rb', line 15

def self.create!(name)
  translate_wallet(Api.request(:post, "/wallets", name: name, userId: Itbit.user_id))
end

.translate_wallet(raw_wallet) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/itbit/wallet.rb', line 19

def self.translate_wallet(raw_wallet)
  wallet = raw_wallet.reduce({}) do |w, pair|
    w[pair[0].underscore.to_sym] = pair[1]
    w
  end
  wallet[:balances] = wallet[:balances].dup.collect do |b|
    { total_balance: b['totalBalance'].to_d,
      currency: b['currency'].downcase.to_sym,
      available_balance: b['availableBalance'].to_d,
    }
  end
  wallet
end