Class: Trader::Book
- Inherits:
-
Object
- Object
- Trader::Book
- Defined in:
- lib/trade-o-matic/structs/book.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#ask_slope ⇒ Object
readonly
Returns the value of attribute ask_slope.
-
#bid_slope ⇒ Object
readonly
Returns the value of attribute bid_slope.
-
#pair ⇒ Object
readonly
Returns the value of attribute pair.
Instance Method Summary collapse
- #add_ask(_price, _volume) ⇒ Object
- #add_bid(_price, _volume) ⇒ Object
- #add_transaction(_price, _volume, _time) ⇒ Object
-
#initialize(_pair) ⇒ Book
constructor
A new instance of Book.
- #prepare(_ref_time = nil) ⇒ Object
- #volume(_period_seconds) ⇒ Object
Constructor Details
Instance Attribute Details
#ask_slope ⇒ Object (readonly)
Returns the value of attribute ask_slope.
3 4 5 |
# File 'lib/trade-o-matic/structs/book.rb', line 3 def ask_slope @ask_slope end |
#bid_slope ⇒ Object (readonly)
Returns the value of attribute bid_slope.
3 4 5 |
# File 'lib/trade-o-matic/structs/book.rb', line 3 def bid_slope @bid_slope end |
#pair ⇒ Object (readonly)
Returns the value of attribute pair.
3 4 5 |
# File 'lib/trade-o-matic/structs/book.rb', line 3 def pair @pair end |
Instance Method Details
#add_ask(_price, _volume) ⇒ Object
31 32 33 |
# File 'lib/trade-o-matic/structs/book.rb', line 31 def add_ask(_price, _volume) ask_slope.add_order _price, _volume end |
#add_bid(_price, _volume) ⇒ Object
27 28 29 |
# File 'lib/trade-o-matic/structs/book.rb', line 27 def add_bid(_price, _volume) bid_slope.add_order _price, _volume end |
#add_transaction(_price, _volume, _time) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/trade-o-matic/structs/book.rb', line 18 def add_transaction(_price, _volume, _time) @transactions << Transaction.new( Price.new(pair.quote, _price), Price.new(pair.base, _volume), _time ) nil end |
#prepare(_ref_time = nil) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/trade-o-matic/structs/book.rb', line 11 def prepare(_ref_time=nil) @ref_time = _ref_time || Time.now @transactions = [] @bid_slope.reset @ask_slope.reset end |
#volume(_period_seconds) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/trade-o-matic/structs/book.rb', line 35 def volume(_period_seconds) ref_time = @ref_time - _period_seconds amount = @transactions.inject(0.0) do |r, trx| if trx.time >= ref_time r + trx.volume.amount else r end end Price.new pair.base, amount end |