Class: Kucoin::Models::OHLCV

Inherits:
Base
  • Object
show all
Defined in:
lib/kucoin/models/ohlcv.rb

Constant Summary collapse

MAPPING =
{
  timestamp:  :time,
  open:       :float,
  high:       :float,
  low:        :float,
  close:      :float,
  volume:     :float
}

Class Method Summary collapse

Methods inherited from Base

#attributes, #initialize

Constructor Details

This class inherits a constructor from Kucoin::Models::Base

Class Method Details

.parse(data) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/kucoin/models/ohlcv.rb', line 13

def self.parse(data)
  ohlcvs      =   []
  
  timestamps  =   data.fetch("t", [])
  opens       =   data.fetch("o", [])
  highs       =   data.fetch("h", [])
  lows        =   data.fetch("l", [])
  closes      =   data.fetch("c", [])
  volumes     =   data.fetch("v", [])
  
  if timestamps&.any? && opens&.any? && highs&.any? && lows&.any? && closes&.any? && volumes&.any?
    timestamps.each_with_index do |timestamp, index|
      item    =   {timestamp: timestamp, open: opens[index], high: highs[index], low: lows[index], close: closes[index], volume: volumes[index]}  
      ohlcvs <<   ::Kucoin::Models::OHLCV.new(item)
    end
  end
  
  return ohlcvs
end