Class: Excoin::Account
- Inherits:
-
Object
- Object
- Excoin::Account
- Defined in:
- lib/account/account.rb
Defined Under Namespace
Classes: Order, Orders, Trade, Trades, Wallet
Instance Attribute Summary collapse
-
#active_wallet_count ⇒ Object
readonly
Returns the value of attribute active_wallet_count.
-
#active_wallets ⇒ Object
readonly
Returns the value of attribute active_wallets.
-
#deposit_count ⇒ Object
readonly
Returns the value of attribute deposit_count.
-
#inactive_wallet_count ⇒ Object
readonly
Returns the value of attribute inactive_wallet_count.
-
#inactive_wallets ⇒ Object
readonly
Returns the value of attribute inactive_wallets.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#orders ⇒ Object
readonly
Returns the value of attribute orders.
-
#trades ⇒ Object
readonly
Returns the value of attribute trades.
-
#withdrawal_count ⇒ Object
readonly
Returns the value of attribute withdrawal_count.
Instance Method Summary collapse
- #deposits(currency = nil) ⇒ Object
-
#initialize ⇒ Account
constructor
A new instance of Account.
- #order(order_id) ⇒ Object
- #populate_account_summary ⇒ Object
- #unconfirmed_deposits ⇒ Object
- #unconfirmed_withdrawals ⇒ Object
- #update ⇒ Object
- #wallet(currency) ⇒ Object
- #wallets ⇒ Object
- #withdrawals(currency = nil) ⇒ Object
Constructor Details
#initialize ⇒ Account
Returns a new instance of Account.
6 7 8 9 10 |
# File 'lib/account/account.rb', line 6 def initialize self.populate_account_summary self.orders self.trades end |
Instance Attribute Details
#active_wallet_count ⇒ Object (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_wallets ⇒ Object (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_count ⇒ Object (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_count ⇒ Object (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_wallets ⇒ Object (readonly)
Returns the value of attribute inactive_wallets.
2 3 4 |
# File 'lib/account/account.rb', line 2 def inactive_wallets @inactive_wallets end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/account/account.rb', line 2 def name @name end |
#orders ⇒ Object (readonly)
Returns the value of attribute orders.
2 3 4 |
# File 'lib/account/account.rb', line 2 def orders @orders end |
#trades ⇒ Object (readonly)
Returns the value of attribute trades.
2 3 4 |
# File 'lib/account/account.rb', line 2 def trades @trades end |
#withdrawal_count ⇒ Object (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_summary ⇒ Object
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 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 ⇒ Object
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_withdrawals ⇒ Object
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 |
#update ⇒ Object
24 25 26 27 28 |
# File 'lib/account/account.rb', line 24 def update self.populate_account_summary @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 |
#wallets ⇒ Object
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 |