Class: Quant::Ticks::Serializers::Spot
- Defined in:
- lib/quant/ticks/serializers/spot.rb
Instance Attribute Summary
Attributes inherited from Tick
Class Method Summary collapse
- .from(hash, tick_class:) ⇒ Object
-
.from_json(json, tick_class:) ⇒ Quant::Ticks::Tick
Returns a
Quant::Ticks::Tick
from a valid JSONString
. -
.to_h(tick) ⇒ Hash
Returns a
Hash
of the Spot tick’s key properties.
Methods inherited from Tick
#assign_series, #assign_series!, default_serializer_class, #default_serializer_class, #initialize, #interval, #series?, #to_csv, #to_h, #to_json
Constructor Details
This class inherits a constructor from Quant::Ticks::Tick
Class Method Details
.from(hash, tick_class:) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/quant/ticks/serializers/spot.rb', line 42 def self.from(hash, tick_class:) tick_class.new( close_timestamp: hash["ct"], close_price: hash["cp"], base_volume: hash["bv"], target_volume: hash["tv"], trades: hash["t"] ) end |
.from_json(json, tick_class:) ⇒ Quant::Ticks::Tick
Returns a Quant::Ticks::Tick
from a valid JSON String
.
14 15 16 17 |
# File 'lib/quant/ticks/serializers/spot.rb', line 14 def self.from_json(json, tick_class:) hash = Oj.load(json) from(hash, tick_class:) end |
.to_h(tick) ⇒ Hash
Returns a Hash
of the Spot tick’s key properties
Serialized Keys:
-
ct: close timestamp
-
cp: close price
-
bv: base volume
-
tv: target volume
-
t: trades
34 35 36 37 38 39 40 |
# File 'lib/quant/ticks/serializers/spot.rb', line 34 def self.to_h(tick) { "ct" => tick., "cp" => tick.close_price, "bv" => tick.base_volume, "tv" => tick.target_volume, "t" => tick.trades } end |