Class: Quant::Ticks::Serializers::OHLC

Inherits:
Tick
  • Object
show all
Defined in:
lib/quant/ticks/serializers/ohlc.rb

Instance Attribute Summary

Attributes inherited from Tick

#indicators, #series

Class Method Summary collapse

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.

Examples:

json =
Quant::Ticks::Serializers::Tick.from_json(json, tick_class: Quant::Ticks::Spot)

Parameters:

Returns:



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

Examples:

Quant::Ticks::Serializers::Tick.to_h(tick)
# => { "ot" => [Time], "ct" => [Time], "o" => 1.0, "h" => 2.0,
#      "l" => 0.5, "c" => 1.5, "bv" => 6.0, "tv" => 5.0, "t" => 1, "g" => true, "j" => true }

Parameters:

Returns:

  • (Hash)


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.open_timestamp,
    "ct" => tick.close_timestamp,

    "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