OHLCHelper (ohlc v1.0.0)

OHLC Helper module containing all the helper functions.

Link to this section Summary

Functions

Helper function for formatting the value to float.

Generates and returns empty candle.

Gets the rounded timestamp based on the timeframe.

Calculates the total volume from trades.

Validates the data used for generating the OHLC candles. Accepts lists of candles, trades or both.

Link to this section Functions

Link to this function

format_to_float(value)

Specs

format_to_float(any()) :: float() | {:error, binary()}

Helper function for formatting the value to float.

Link to this function

generate_empty_candle()

Specs

generate_empty_candle() :: OHLC.candle()

Generates and returns empty candle.

Link to this function

get_time_rounded(timestamp, timeframe, opts \\ [])

Specs

get_time_rounded(number(), OHLC.timeframe(), list() | nil) ::
  number() | DateTime

Gets the rounded timestamp based on the timeframe.

Parameters:

  • timestamp - Unix timestamp which will be rounded.
  • timeframe - Timeframe used for rounding the timestamp. Available values are: :minute, :hour, :day, :week
  • opts - Options for rounding the timestamp. Available values are:
    • {:format, :stamp | :struct} - Returned value will be unix timestamp or DateTime struct.
    • {:type, :down | :up | :jump} - Timestamp will be rounded up, down or jump to the next time cycle. Default is :up.
Link to this function

trades_total_volume(trades)

Specs

trades_total_volume(OHLC.trades()) :: float()

Calculates the total volume from trades.

Link to this function

validate_data(candles \\ [], trades \\ [])

Specs

validate_data(OHLC.candles() | nil, OHLC.trades() | nil) ::
  :ok | {:error, binary()}

Validates the data used for generating the OHLC candles. Accepts lists of candles, trades or both.