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.
9 10 11 12 13 14 |
# File 'lib/trade-o-matic/core/account_order.rb', line 9 def initialize(_backend, _session, _raw, _forced_pair=nil) @backend = _backend @session = _session @raw = _raw @forced_pair = _forced_pair end |
Instance Method Details
#cancel! ⇒ Object
75 76 77 78 |
# File 'lib/trade-o-matic/core/account_order.rb', line 75 def cancel! @raw = backend.cancel_order(session, id) self end |
#convert_to(_pair, _quote = nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/trade-o-matic/core/account_order.rb', line 16 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
62 63 64 |
# File 'lib/trade-o-matic/core/account_order.rb', line 62 def executed_volume convert_base original_pair.base.pack @raw.executed_volume end |
#finished? ⇒ Boolean
80 81 82 |
# File 'lib/trade-o-matic/core/account_order.rb', line 80 def finished? status == CLOSED or status == CANCELED end |
#id ⇒ Object
24 25 26 |
# File 'lib/trade-o-matic/core/account_order.rb', line 24 def id @raw.id end |
#instruction ⇒ Object
44 45 46 |
# File 'lib/trade-o-matic/core/account_order.rb', line 44 def instruction @raw.instruction end |
#limit? ⇒ Boolean
40 41 42 |
# File 'lib/trade-o-matic/core/account_order.rb', line 40 def limit? @raw.limit? end |
#original_pair ⇒ Object
32 33 34 |
# File 'lib/trade-o-matic/core/account_order.rb', line 32 def original_pair @raw.pair end |
#pair ⇒ Object
28 29 30 |
# File 'lib/trade-o-matic/core/account_order.rb', line 28 def pair forced_pair || original_pair end |
#pending_volume ⇒ Object
66 67 68 |
# File 'lib/trade-o-matic/core/account_order.rb', line 66 def pending_volume convert_base(volume - executed_volume) end |
#price ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/trade-o-matic/core/account_order.rb', line 48 def price if limit? convert_quote original_pair.quote.pack @raw.price else nil end end |
#refresh! ⇒ Object
70 71 72 73 |
# File 'lib/trade-o-matic/core/account_order.rb', line 70 def refresh! @raw = backend.fetch_order(session, id) self end |
#status ⇒ Object
36 37 38 |
# File 'lib/trade-o-matic/core/account_order.rb', line 36 def status @raw.status end |
#volume ⇒ Object
TODO: executed_price
58 59 60 |
# File 'lib/trade-o-matic/core/account_order.rb', line 58 def volume convert_base original_pair.base.pack @raw.volume end |