Class: Quant::Ticks::Serializers::OHLC
- Defined in:
- lib/quant/ticks/serializers/ohlc.rb
Instance Attribute Summary
Attributes inherited from Tick
Class Method Summary collapse
-
.from(hash, tick_class:) ⇒ Object
Instantiates a tick from a
Hash
. -
.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
Instantiates a tick from a Hash
. The hash keys are expected to be the same as the serialized keys.
Serialized Keys:
-
ot: open timestamp
-
ct: close timestamp
-
o: open price
-
h: high price
-
l: low price
-
c: close price
-
bv: base volume
-
tv: target volume
-
t: trades
-
g: green
-
j: doji
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/quant/ticks/serializers/ohlc.rb', line 33 def self.from(hash, tick_class:) tick_class.new \ open_timestamp: hash["ot"], close_timestamp: hash["ct"], open_price: hash["o"], high_price: hash["h"], low_price: hash["l"], close_price: hash["c"], base_volume: hash["bv"], target_volume: hash["tv"], trades: hash["t"], green: hash["g"], doji: hash["j"] 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/ohlc.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:
-
ot: open timestamp
-
ct: close timestamp
-
o: open price
-
h: high price
-
l: low price
-
c: close price
-
bv: base volume
-
tv: target volume
-
t: trades
-
g: green
-
j: doji
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/quant/ticks/serializers/ohlc.rb', line 73 def self.to_h(tick) { "ot" => tick., "ct" => tick., "o" => tick.open_price, "h" => tick.high_price, "l" => tick.low_price, "c" => tick.close_price, "bv" => tick.base_volume, "tv" => tick.target_volume, "t" => tick.trades, "g" => tick.green, "j" => tick.doji } end |