Class: Excoin::Account

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

Defined Under Namespace

Classes: Order, Orders, Trade, Trades, Wallet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAccount

Returns a new instance of Account.



6
7
8
9
10
# File 'lib/account/account.rb', line 6

def initialize
  self.
  self.orders
  self.trades
end

Instance Attribute Details

#active_wallet_countObject (readonly)

Returns the value of attribute active_wallet_count.



2
3
4
# File 'lib/account/account.rb', line 2

def active_wallet_count
  @active_wallet_count
end

#active_walletsObject (readonly)

Returns the value of attribute active_wallets.



2
3
4
# File 'lib/account/account.rb', line 2

def active_wallets
  @active_wallets
end

#deposit_countObject (readonly)

Returns the value of attribute deposit_count.



2
3
4
# File 'lib/account/account.rb', line 2

def deposit_count
  @deposit_count
end

#inactive_wallet_countObject (readonly)

Returns the value of attribute inactive_wallet_count.



2
3
4
# File 'lib/account/account.rb', line 2

def inactive_wallet_count
  @inactive_wallet_count
end

#inactive_walletsObject (readonly)

Returns the value of attribute inactive_wallets.



2
3
4
# File 'lib/account/account.rb', line 2

def inactive_wallets
  @inactive_wallets
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/account/account.rb', line 2

def name
  @name
end

#ordersObject (readonly)

Returns the value of attribute orders.



2
3
4
# File 'lib/account/account.rb', line 2

def orders
  @orders
end

#tradesObject (readonly)

Returns the value of attribute trades.



2
3
4
# File 'lib/account/account.rb', line 2

def trades
  @trades
end

#withdrawal_countObject (readonly)

Returns the value of attribute withdrawal_count.



2
3
4
# File 'lib/account/account.rb', line 2

def withdrawal_count
  @withdrawal_count
end

Instance Method Details

#deposits(currency = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# 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) ⇒ Object



16
17
18
# File 'lib/account/account.rb', line 16

def order(order_id)
  self.orders.all.select{|order| order.id == order_id}[0]
end

#populate_account_summaryObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/account/account.rb', line 30

def 
  begin
     = self.get_summary
    @name = ['username']

    @active_wallet_count = ['active_wallet_count']

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

    @inactive_wallet_count = ['inactive_wallet_count']

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

    @deposit_count = ['deposit_count']

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

    @withdrawal_count = ['withdrawal_count']

    ['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 
  end
end

#unconfirmed_depositsObject



102
103
104
# File 'lib/account/account.rb', line 102

def unconfirmed_deposits
  return self.deposits.select{|id, deposit_object| deposit_object.confirmed == false}
end

#unconfirmed_withdrawalsObject



106
107
108
# File 'lib/account/account.rb', line 106

def unconfirmed_withdrawals
  return self.withdrawals.select{|id, withdrawal_object| withdrawal_object.confirmed == false}
end

#updateObject



24
25
26
27
28
# File 'lib/account/account.rb', line 24

def update
  self.
  @orders.update
  @trades.update
end

#wallet(currency) ⇒ Object



74
75
76
# File 'lib/account/account.rb', line 74

def wallet(currency)
  self.wallets[currency]
end

#walletsObject



66
67
68
69
70
71
72
# 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) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
# 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