Class: Trader::AccountOrder
- Inherits:
-
Object
- Object
- Trader::AccountOrder
- Defined in:
- lib/trade-o-matic/core/account_order.rb
Constant Summary collapse
- PENDING =
:pending
- OPEN =
:open
- CLOSED =
:closed
- CANCELED =
:canceled
Instance Method Summary collapse
- #cancel! ⇒ Object
- #convert_to(_pair, _quote = nil) ⇒ Object
- #executed_volume ⇒ Object
- #finished? ⇒ Boolean
- #id ⇒ Object
-
#initialize(_backend, _session, _raw, _forced_pair = nil) ⇒ AccountOrder
constructor
A new instance of AccountOrder.
- #instruction ⇒ Object
- #limit? ⇒ Boolean
- #original_pair ⇒ Object
- #pair ⇒ Object
- #pending_volume ⇒ Object
- #price ⇒ Object
- #refresh! ⇒ Object
- #status ⇒ Object
-
#volume ⇒ Object
TODO: executed_price.
Constructor Details
#initialize(_backend, _session, _raw, _forced_pair = nil) ⇒ AccountOrder
Returns a new instance of AccountOrder.
8 9 10 11 12 13 |
# File 'lib/trade-o-matic/core/account_order.rb', line 8 def initialize(_backend, _session, _raw, _forced_pair=nil) @backend = _backend @session = _session @raw = _raw @forced_pair = _forced_pair end |
Instance Method Details
#cancel! ⇒ Object
74 75 76 77 |
# File 'lib/trade-o-matic/core/account_order.rb', line 74 def cancel! @raw = backend.cancel_order(session, id) self end |
#convert_to(_pair, _quote = nil) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/trade-o-matic/core/account_order.rb', line 15 def convert_to(_pair, _quote=nil) forced_pair = CurrencyPair.for_code _pair, _quote return self if forced_pair == pair self.class.new backend, session, @raw, forced_pair end |
#executed_volume ⇒ Object
61 62 63 |
# File 'lib/trade-o-matic/core/account_order.rb', line 61 def executed_volume convert_base original_pair.base.pack @raw.executed_volume end |
#finished? ⇒ Boolean
79 80 81 |
# File 'lib/trade-o-matic/core/account_order.rb', line 79 def finished? status == CLOSED or status == CANCELED end |
#id ⇒ Object
23 24 25 |
# File 'lib/trade-o-matic/core/account_order.rb', line 23 def id @raw.id end |
#instruction ⇒ Object
43 44 45 |
# File 'lib/trade-o-matic/core/account_order.rb', line 43 def instruction @raw.instruction end |
#limit? ⇒ Boolean
39 40 41 |
# File 'lib/trade-o-matic/core/account_order.rb', line 39 def limit? @raw.limit? end |
#original_pair ⇒ Object
31 32 33 |
# File 'lib/trade-o-matic/core/account_order.rb', line 31 def original_pair @raw.pair end |
#pair ⇒ Object
27 28 29 |
# File 'lib/trade-o-matic/core/account_order.rb', line 27 def pair forced_pair || original_pair end |
#pending_volume ⇒ Object
65 66 67 |
# File 'lib/trade-o-matic/core/account_order.rb', line 65 def pending_volume convert_base(volume - executed_volume) end |
#price ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/trade-o-matic/core/account_order.rb', line 47 def price if limit? convert_quote original_pair.quote.pack @raw.price else nil end end |
#refresh! ⇒ Object
69 70 71 72 |
# File 'lib/trade-o-matic/core/account_order.rb', line 69 def refresh! @raw = backend.fetch_order(session, id) self end |
#status ⇒ Object
35 36 37 |
# File 'lib/trade-o-matic/core/account_order.rb', line 35 def status @raw.status end |
#volume ⇒ Object
TODO: executed_price
57 58 59 |
# File 'lib/trade-o-matic/core/account_order.rb', line 57 def volume convert_base original_pair.base.pack @raw.volume end |