class RTCBX::Candles::Candle
Attributes
close[R]
Candle
values, this is standard
high[R]
Candle
values, this is standard
low[R]
Candle
values, this is standard
open[R]
Candle
values, this is standard
time[R]
Candle
values, this is standard
volume[R]
Candle
values, this is standard
Public Class Methods
new(epoch, matches)
click to toggle source
Create a new Candle
from an epoch, and all the messages sent during the interval of the candle
# File lib/rtcbx/candles/candle.rb, line 11 def initialize(epoch, matches) @time = Time.at(epoch) @low = matches.map { |message| BigDecimal(message.fetch('price')) }.min @high = matches.map { |message| BigDecimal(message.fetch('price')) }.max @open = BigDecimal(matches.first.fetch('price')) @close = BigDecimal(matches.last.fetch('price')) @volume = matches.reduce(BigDecimal(0)) { |sum, message| sum + BigDecimal(message.fetch('size')) } end
Public Instance Methods
to_h()
click to toggle source
Return a Hash
representation of the Candle
# File lib/rtcbx/candles/candle.rb, line 21 def to_h { start: Time.at(@time), low: @low.to_s('F'), high: @high.to_s('F'), open: @open.to_s('F'), close: @close.to_s('F'), volume: @volume.to_s('F') } end