Module: RTCBX::Orderbook::BookAnalysis
- Included in:
- RTCBX::Orderbook
- Defined in:
- lib/rtcbx/orderbook/book_analysis.rb
Overview
Simple collection of commands to get info about the orderbook. Add our own methods for calculating whatever it is you feel like calculating.
Instance Method Summary collapse
- #ask_count ⇒ Object
- #ask_volume ⇒ Object
- #average ⇒ Object
- #average_ask ⇒ Object
- #average_bid ⇒ Object
- #best ⇒ Object
- #best_ask ⇒ Object
- #best_bid ⇒ Object
- #bid_count ⇒ Object
- #bid_volume ⇒ Object
- #count ⇒ Object
- #spread ⇒ Object
- #summarize ⇒ Object
- #volume ⇒ Object
Instance Method Details
#ask_count ⇒ Object
11 12 13 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 11 def ask_count @asks.count end |
#ask_volume ⇒ Object
23 24 25 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 23 def ask_volume @asks.map { |x| x.fetch(:size) }.inject(:+) end |
#average ⇒ Object
41 42 43 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 41 def average { bid: average_bid, ask: average_ask } end |
#average_ask ⇒ Object
36 37 38 39 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 36 def average_ask asks = @asks.map { |x| x.fetch(:price) } asks.inject(:+) / asks.count end |
#average_bid ⇒ Object
31 32 33 34 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 31 def average_bid bids = @bids.map { |x| x.fetch(:price) } bids.inject(:+) / bids.count end |
#best ⇒ Object
53 54 55 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 53 def best { bid: best_bid, ask: best_ask } end |
#best_ask ⇒ Object
49 50 51 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 49 def best_ask @asks.sort_by { |x| x.fetch(:price) }.first end |
#best_bid ⇒ Object
45 46 47 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 45 def best_bid @bids.sort_by { |x| x.fetch(:price) }.last end |
#bid_count ⇒ Object
7 8 9 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 7 def bid_count @bids.count end |
#bid_volume ⇒ Object
19 20 21 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 19 def bid_volume @bids.map { |x| x.fetch(:size) }.inject(:+) end |
#count ⇒ Object
15 16 17 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 15 def count { bid: bid_count, ask: ask_count } end |
#spread ⇒ Object
57 58 59 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 57 def spread best_ask.fetch(:price) - best_bid.fetch(:price) end |
#summarize ⇒ Object
61 62 63 64 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 61 def summarize print "# of asks: #{ask_count}\n# of bids: #{bid_count}\nAsk volume: #{ask_volume.to_s('F')}\nBid volume: #{bid_volume.to_s('F')}\n" $stdout.flush end |
#volume ⇒ Object
27 28 29 |
# File 'lib/rtcbx/orderbook/book_analysis.rb', line 27 def volume { bid: bid_volume, ask: ask_volume } end |