Class: Trader::Order
- Inherits:
-
Object
- Object
- Trader::Order
- Defined in:
- lib/trade-o-matic/structs/order.rb
Constant Summary collapse
- BID =
:bid
- ASK =
:ask
Instance Attribute Summary collapse
-
#instruction ⇒ Object
Returns the value of attribute instruction.
-
#pair ⇒ Object
Returns the value of attribute pair.
Class Method Summary collapse
Instance Method Summary collapse
- #convert_to(_pair, _quote = nil) ⇒ Object
-
#initialize(_pair, _instruction, _volume, _price) ⇒ Order
constructor
A new instance of Order.
- #limit? ⇒ Boolean
- #market? ⇒ Boolean
- #price ⇒ Object
- #price=(_value) ⇒ Object
- #volume ⇒ Object
- #volume=(_value) ⇒ Object
Constructor Details
#initialize(_pair, _instruction, _volume, _price) ⇒ Order
Returns a new instance of Order.
16 17 18 19 20 21 |
# File 'lib/trade-o-matic/structs/order.rb', line 16 def initialize(_pair, _instruction, _volume, _price) @pair = _pair @instruction = _instruction self.volume = _volume self.price = _price end |
Instance Attribute Details
#instruction ⇒ Object
Returns the value of attribute instruction.
14 15 16 |
# File 'lib/trade-o-matic/structs/order.rb', line 14 def instruction @instruction end |
#pair ⇒ Object
Returns the value of attribute pair.
14 15 16 |
# File 'lib/trade-o-matic/structs/order.rb', line 14 def pair @pair end |
Class Method Details
.new_ask(_pair, _volume, _price = nil) ⇒ Object
10 11 12 |
# File 'lib/trade-o-matic/structs/order.rb', line 10 def self.new_ask(_pair, _volume, _price = nil) new _pair, ASK, _volume, _price end |
.new_bid(_pair, _volume, _price = nil) ⇒ Object
6 7 8 |
# File 'lib/trade-o-matic/structs/order.rb', line 6 def self.new_bid(_pair, _volume, _price = nil) new _pair, BID, _volume, _price end |
Instance Method Details
#convert_to(_pair, _quote = nil) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/trade-o-matic/structs/order.rb', line 47 def convert_to(_pair, _quote = nil) _pair = CurrencyPair.for_code _pair, _quote return self if _pair == pair self.class.new(_pair, instruction, volume, price) end |
#limit? ⇒ Boolean
23 24 25 |
# File 'lib/trade-o-matic/structs/order.rb', line 23 def limit? !@price.nil? end |
#market? ⇒ Boolean
27 28 29 |
# File 'lib/trade-o-matic/structs/order.rb', line 27 def market? !limit? end |
#price ⇒ Object
39 40 41 |
# File 'lib/trade-o-matic/structs/order.rb', line 39 def price limit? ? pair.quote.pack(@price) : nil end |
#price=(_value) ⇒ Object
43 44 45 |
# File 'lib/trade-o-matic/structs/order.rb', line 43 def price=(_value) @price = _value.nil? ? nil : pair.quote.unpack(_value, strict: false) end |
#volume ⇒ Object
31 32 33 |
# File 'lib/trade-o-matic/structs/order.rb', line 31 def volume pair.base.pack @volume end |
#volume=(_value) ⇒ Object
35 36 37 |
# File 'lib/trade-o-matic/structs/order.rb', line 35 def volume=(_value) @volume = pair.base.unpack(_value, strict: false) end |