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.



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_volumeObject



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

Returns:

  • (Boolean)


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

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

#idObject



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

def id
  @raw.id
end

#instructionObject



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

def instruction
  @raw.instruction
end

#limit?Boolean

Returns:

  • (Boolean)


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

def limit?
  @raw.limit?
end

#original_pairObject



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

def original_pair
  @raw.pair
end

#pairObject



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

def pair
  forced_pair || original_pair
end

#pending_volumeObject



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

def pending_volume
  convert_base(volume - executed_volume)
end

#priceObject



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

#statusObject



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

def status
  @raw.status
end

#volumeObject

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