Class: Trader::AccountOrder

Inherits:
Object
  • Object
show all
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

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_volumeObject



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

Returns:

  • (Boolean)


80
81
82
# File 'lib/trade-o-matic/core/account_order.rb', line 80

def finished?
  status == CLOSED or status == CANCELED
end

#idObject



24
25
26
# File 'lib/trade-o-matic/core/account_order.rb', line 24

def id
  @raw.id
end

#instructionObject



44
45
46
# File 'lib/trade-o-matic/core/account_order.rb', line 44

def instruction
  @raw.instruction
end

#limit?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/trade-o-matic/core/account_order.rb', line 40

def limit?
  @raw.limit?
end

#original_pairObject



32
33
34
# File 'lib/trade-o-matic/core/account_order.rb', line 32

def original_pair
  @raw.pair
end

#pairObject



28
29
30
# File 'lib/trade-o-matic/core/account_order.rb', line 28

def pair
  forced_pair || original_pair
end

#pending_volumeObject



66
67
68
# File 'lib/trade-o-matic/core/account_order.rb', line 66

def pending_volume
  convert_base(volume - executed_volume)
end

#priceObject



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

#statusObject



36
37
38
# File 'lib/trade-o-matic/core/account_order.rb', line 36

def status
  @raw.status
end

#volumeObject

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