Module: Coinbot::OrderBook::OrderTrend
- Defined in:
- lib/coinbot/order_book/order_trend.rb
Class Method Summary collapse
-
.help ⇒ Object
Display Usage for this Module.
-
.status(opts = {}) ⇒ Object
- Supported Method Parameters
-
Coinbot::OrderBook::OrderTrend.status( ).
Class Method Details
.help ⇒ Object
Display Usage for this Module
76 77 78 79 80 81 82 83 |
# File 'lib/coinbot/order_book/order_trend.rb', line 76 public_class_method def self.help puts "USAGE: order_trend_indicator_hash = #{self}.status( order_book: 'required - order_book data structure', event: 'required - latest websocket event response' ) " end |
.status(opts = {}) ⇒ Object
- Supported Method Parameters
-
Coinbot::OrderBook::OrderTrend.status( )
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/coinbot/order_book/order_trend.rb', line 12 public_class_method def self.status(opts = {}) indicator_hash = {} order_book = opts[:order_book] event = opts[:event] indicator_status = opts[:indicator_status] # Decent for debugging. # puts event.inspect buy_or_sell = event[:changes].first[0].to_s.to_sym last_order_price = format('%0.2f', event[:changes].first[1]).to_f last_order_size = format('%0.2f', event[:changes].first.last).to_f indicator_hash[:last_order_price] = last_order_price indicator_hash[:last_order_size] = last_order_size case buy_or_sell when :buy order_book[:session_buy_tot] += 1 order_book[:candles].last[:candle_buy_tot] += 1 order_book[:candles].last[:candle_last_buy_price] = last_order_price when :sell order_book[:session_sell_tot] += 1 order_book[:candles].last[:candle_sell_tot] += 1 order_book[:candles].last[:candle_last_sell_price] = last_order_price else raise "UNKNOWN Value in event[:changes] => #{buy_or_sell}" end # session_buy_tot = order_book[:session_buy_tot].to_i candle_buy_tot = order_book[:candles].last[:candle_buy_tot].to_i indicator_hash[:candle_buy_tot] = candle_buy_tot # session_sell_tot = order_book[:session_sell_tot].to_i candle_sell_tot = order_book[:candles].last[:candle_sell_tot].to_i indicator_hash[:candle_sell_tot] = candle_sell_tot # order_difference = 0 if candle_buy_tot > candle_sell_tot order_difference = candle_buy_tot - candle_sell_tot indicator_hash[:color] = :green indicator_hash[:ui] = "BUYS UP BY #{order_difference}" indicator_hash[:status] = "B#{Coinbot.up_arrow}" elsif candle_buy_tot < candle_sell_tot order_difference = candle_sell_tot - candle_buy_tot indicator_hash[:color] = :red indicator_hash[:ui] = "SELLS UP BY #{order_difference}" indicator_hash[:status] = "S#{Coinbot.up_arrow}" else # This Condition is Met When candle_buy_tot == candle_sell_tot indicator_hash[:color] = :yellow indicator_hash[:ui] = 'BUYS == SELLS' indicator_hash[:status] = "F#{Coinbot.up_arrow}" end indicator_status.order_trend = indicator_hash rescue StandardError => e raise e end |