Class: RTCBX::Candles::Candle

Inherits:
Object
  • Object
show all
Defined in:
lib/rtcbx/candles/candle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(epoch, matches) ⇒ Candle

Returns a new instance of Candle.



7
8
9
10
11
12
13
14
# File 'lib/rtcbx/candles/candle.rb', line 7

def initialize(epoch, matches)
  @time = epoch
  @low = matches.map {|message| BigDecimal.new(message.fetch('price'))}.min
  @high = matches.map {|message| BigDecimal.new(message.fetch('price'))}.max
  @open = BigDecimal.new(matches.first.fetch('price'))
  @close = BigDecimal.new(matches.last.fetch('price'))
  @volume = matches.reduce(BigDecimal(0)) {|sum, message| sum + BigDecimal.new(message.fetch('size'))}
end

Instance Attribute Details

#closeObject (readonly)

Returns the value of attribute close.



5
6
7
# File 'lib/rtcbx/candles/candle.rb', line 5

def close
  @close
end

#highObject (readonly)

Returns the value of attribute high.



5
6
7
# File 'lib/rtcbx/candles/candle.rb', line 5

def high
  @high
end

#lowObject (readonly)

Returns the value of attribute low.



5
6
7
# File 'lib/rtcbx/candles/candle.rb', line 5

def low
  @low
end

#openObject (readonly)

Returns the value of attribute open.



5
6
7
# File 'lib/rtcbx/candles/candle.rb', line 5

def open
  @open
end

#timeObject (readonly)

Returns the value of attribute time.



5
6
7
# File 'lib/rtcbx/candles/candle.rb', line 5

def time
  @time
end

#volumeObject (readonly)

Returns the value of attribute volume.



5
6
7
# File 'lib/rtcbx/candles/candle.rb', line 5

def volume
  @volume
end

Instance Method Details

#to_hObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/rtcbx/candles/candle.rb', line 16

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