class Excoin::Account

Attributes

active_wallet_count[R]
active_wallets[R]
deposit_count[R]
inactive_wallet_count[R]
inactive_wallets[R]
name[R]
orders[R]
trades[R]
withdrawal_count[R]

Public Class Methods

new() click to toggle source
# File lib/account/account.rb, line 6
def initialize
  self.populate_account_summary
  self.orders
  self.trades
end

Public Instance Methods

deposits(currency = nil) click to toggle source
# File lib/account/account.rb, line 78
def deposits(currency = nil)
  if currency
    return self.wallet(currency).deposits
  else
    deposits = Hash.new
    @active_wallets.each_pair do |wallet_currency, wallet|
      deposits.merge!(wallet.deposits)
    end
    return deposits
  end
end
order(order_id) click to toggle source
# File lib/account/account.rb, line 16
def order(order_id)
  self.orders.all.select{|order| order.id == order_id}[0]
end
populate_account_summary() click to toggle source
# File lib/account/account.rb, line 30
def populate_account_summary
  begin
    account_data = self.get_summary
    @name = account_data['username']

    @active_wallet_count = account_data['active_wallet_count']

    @active_wallets = Hash.new
    account_data['active_wallets'].each do |w|
      @active_wallets.merge!({w['currency'] => Wallet.new(true, w)})
    end

    @inactive_wallet_count = account_data['inactive_wallet_count']

    @inactive_wallets = Hash.new
    account_data['inactive_wallets'].each do |w|
      @inactive_wallets.merge!({w['currency'] => Wallet.new(false, w)})
    end

    @deposit_count = account_data['deposit_count']

    account_data['deposits'].each do |deposit_data|
      self.wallet(deposit_data['currency']).add_deposit(deposit_data)
    end

    @withdrawal_count = account_data['withdrawal_count']

    account_data['withdrawals'].each do |withdrawal_data|
      self.wallet(withdrawal_data['currency']).add_withdrawal(withdrawal_data)
    end
  rescue
    puts "Error in Excoin::Account.populate_account_summary"
    puts account_data
  end
end
unconfirmed_deposits() click to toggle source
# File lib/account/account.rb, line 102
def unconfirmed_deposits
  return self.deposits.select{|id, deposit_object| deposit_object.confirmed == false}
end
unconfirmed_withdrawals() click to toggle source
# File lib/account/account.rb, line 106
def unconfirmed_withdrawals
  return self.withdrawals.select{|id, withdrawal_object| withdrawal_object.confirmed == false}
end
update() click to toggle source
# File lib/account/account.rb, line 24
def update
  self.populate_account_summary
  @orders.update
  @trades.update
end
wallet(currency) click to toggle source
# File lib/account/account.rb, line 74
def wallet(currency)
  self.wallets[currency]
end
wallets() click to toggle source
# File lib/account/account.rb, line 66
def wallets
  if @inactive_wallets.size > 0
    return @active_wallets.merge(@inactive_wallets)
  else
    return @active_wallets
  end
end
withdrawals(currency = nil) click to toggle source
# File lib/account/account.rb, line 90
def withdrawals(currency = nil)
  if currency
    return self.wallet(currency).withdrawals
  else
    withdrawals = Hash.new
    @active_wallets.each_pair do |wallet_currency, wallet|
      withdrawals.merge!(wallet.withdrawals)
    end
    return withdrawals
  end
end

Protected Instance Methods

get_summary() click to toggle source
# File lib/account/account.rb, line 112
def get_summary
  Excoin.api.account_summary
end