Class: Quant::Ticks::Spot

Inherits:
Value
  • Object
show all
Defined in:
lib/quant/ticks/spot.rb

Constant Summary

Constants included from Quant::TimeMethods

Quant::TimeMethods::EPOCH_DATE, Quant::TimeMethods::EPOCH_TIME

Instance Attribute Summary

Attributes inherited from Value

#base_volume, #close_price, #close_timestamp, #doji, #green, #high_price, #interval, #low_price, #open_price, #open_timestamp, #series, #target_volume, #trades

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Value

#==, #assign_series, #assign_series!, #inspect, #to_json

Methods included from Quant::TimeMethods

epoch_date, epoch_time, #extract_time

Constructor Details

#initialize(close_timestamp:, close_price:, interval: nil, base_volume: 0.0, target_volume: 0.0, trades: 0) ⇒ Spot

Returns a new instance of Spot.



14
15
16
17
# File 'lib/quant/ticks/spot.rb', line 14

def initialize(close_timestamp:, close_price:, interval: nil, base_volume: 0.0, target_volume: 0.0, trades: 0)
  super(price: close_price, timestamp: close_timestamp, interval: interval, volume: base_volume, trades: trades)
  @target_volume = target_volume.to_i
end

Class Method Details

.from(hash) ⇒ Object



6
7
8
# File 'lib/quant/ticks/spot.rb', line 6

def self.from(hash)
  new(close_timestamp: hash["ct"], close_price: hash["c"], base_volume: hash["bv"], target_volume: hash["tv"])
end

.from_json(json) ⇒ Object



10
11
12
# File 'lib/quant/ticks/spot.rb', line 10

def self.from_json(json)
  from Oj.load(json)
end

Instance Method Details

#corresponding?(other) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/quant/ticks/spot.rb', line 19

def corresponding?(other)
  close_timestamp == other.close_timestamp
end

#to_hObject



23
24
25
26
27
28
29
30
# File 'lib/quant/ticks/spot.rb', line 23

def to_h
  { "ct" => close_timestamp,
    "c" => close_price,
    "iv" => interval.to_s,
    "bv" => base_volume,
    "tv" => target_volume,
    "t" => trades }
end