Class: CandleData::Candle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(open_time, open, high, low, close, volume) ⇒ Candle

Returns a new instance of Candle.



5
6
7
8
9
10
11
12
# File 'lib/candle_data/candle.rb', line 5

def initialize(open_time, open, high, low, close, volume)
  @open_time = open_time
  @open = open
  @high = high
  @low = low
  @close = close
  @volume = volume
end

Instance Attribute Details

#closeObject (readonly)

Returns the value of attribute close.



3
4
5
# File 'lib/candle_data/candle.rb', line 3

def close
  @close
end

#highObject (readonly)

Returns the value of attribute high.



3
4
5
# File 'lib/candle_data/candle.rb', line 3

def high
  @high
end

#lowObject (readonly)

Returns the value of attribute low.



3
4
5
# File 'lib/candle_data/candle.rb', line 3

def low
  @low
end

#openObject (readonly)

Returns the value of attribute open.



3
4
5
# File 'lib/candle_data/candle.rb', line 3

def open
  @open
end

#open_timeObject (readonly)

Returns the value of attribute open_time.



3
4
5
# File 'lib/candle_data/candle.rb', line 3

def open_time
  @open_time
end

#volumeObject (readonly)

Returns the value of attribute volume.



3
4
5
# File 'lib/candle_data/candle.rb', line 3

def volume
  @volume
end

Instance Method Details

#to_hObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/candle_data/candle.rb', line 21

def to_h
  {
    open_time: open_time.iso8601,
    open: open.to_s('F'),
    high: high.to_s('F'),
    low: low.to_s('F'),
    close: close.to_s('F'),
    volume: volume.to_s('F')
  }
end

#update(price, volume) ⇒ Object



14
15
16
17
18
19
# File 'lib/candle_data/candle.rb', line 14

def update(price, volume)
  @close = price
  @low   = price if price < @low
  @high  = price if price > @high
  @volume += volume
end