Class: Trader::Balance
- Inherits:
-
Object
- Object
- Trader::Balance
- Defined in:
- lib/trade-o-matic/core/balance.rb
Instance Method Summary collapse
- #amount ⇒ Object
- #available_amount ⇒ Object
- #convert_to(_currency) ⇒ Object
- #currency ⇒ Object
- #frozen_amount ⇒ Object
-
#initialize(_backend, _session, _currency, _forced_currency = nil) ⇒ Balance
constructor
A new instance of Balance.
- #new_deposit_endpoint ⇒ Object
- #original_currency ⇒ Object
- #refresh! ⇒ Object
- #transfer(_amount, to: nil) ⇒ Object
- #withdraw(_amount, to: nil) ⇒ Object
Constructor Details
#initialize(_backend, _session, _currency, _forced_currency = nil) ⇒ Balance
Returns a new instance of Balance.
3 4 5 6 7 8 9 |
# File 'lib/trade-o-matic/core/balance.rb', line 3 def initialize(_backend, _session, _currency, _forced_currency=nil) @backend = _backend @session = _session @currency = _currency @forced_currency = _forced_currency @raw = nil end |
Instance Method Details
#amount ⇒ Object
26 27 28 |
# File 'lib/trade-o-matic/core/balance.rb', line 26 def amount convert original_currency.pack raw.amount end |
#available_amount ⇒ Object
30 31 32 |
# File 'lib/trade-o-matic/core/balance.rb', line 30 def available_amount convert original_currency.pack raw.available_amount end |
#convert_to(_currency) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/trade-o-matic/core/balance.rb', line 19 def convert_to(_currency) return self if _currency == currency copy = self.class.new backend, session, original_currency, _currency copy.raw = raw unless raw.nil? copy end |
#currency ⇒ Object
11 12 13 |
# File 'lib/trade-o-matic/core/balance.rb', line 11 def currency forced_currency || @currency end |
#frozen_amount ⇒ Object
34 35 36 |
# File 'lib/trade-o-matic/core/balance.rb', line 34 def frozen_amount convert(amount - available_amount) end |
#new_deposit_endpoint ⇒ Object
43 44 45 |
# File 'lib/trade-o-matic/core/balance.rb', line 43 def new_deposit_endpoint backend.generate_endpoint session, original_currency end |
#original_currency ⇒ Object
15 16 17 |
# File 'lib/trade-o-matic/core/balance.rb', line 15 def original_currency @currency end |
#refresh! ⇒ Object
38 39 40 41 |
# File 'lib/trade-o-matic/core/balance.rb', line 38 def refresh! self.raw = backend.get_balance session, currency self end |
#transfer(_amount, to: nil) ⇒ Object
55 56 57 |
# File 'lib/trade-o-matic/core/balance.rb', line 55 def transfer(_amount, to: nil) withdraw _amount, to: to.new_deposit_endpoint end |
#withdraw(_amount, to: nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/trade-o-matic/core/balance.rb', line 47 def withdraw(_amount, to: nil) _amount = currency.pack _amount _amount = _amount.convert_to original_currency backend.withdraw_to_endpoint session, currency, _amount.amount, to self end |