OHLCHelper (ohlc v1.2.4)

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 current candle type(pullish or bearish).

Gets the rounded timestamp based on the timeframe.

Returns all available timeframes in seconds.

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)

@spec format_to_float(any()) :: float() | false

Helper function for formatting the value to float.

Link to this function

gen_trades(timeframe, min_price, max_price, volume, timeframe_multiplier \\ 1, timeframe_divider \\ 1)

This function is deprecated. Will be removed in v2.x. Use OHLCFactory.gen_trades/1 instead..
@spec gen_trades(OHLC.timeframe(), number(), number(), number(), integer(), integer()) ::
  list()

Generates trades from provided arguments.

Parameters:

  • timeframe - Timeframe used for rounding the timestamp. Available values are: :minute, :hour, :day, :week
  • min_price - The minimum price on the generated trades
  • max_price - The maximum price on the generated trades
  • volume - The volume each trade has
  • timeframe_multiplier - If you'd like to generate less trades per candle then you can increase the size of the timeframe_divider parameter(1-100) otherwise leave empty.
  • timeframe_divider - Is used for generating multiple candles of the same timeframe.
Link to this function

generate_empty_candle(timeframe \\ nil)

This function is deprecated. Will be removed in v2.x. Use OHLCFactory.gen_empty_candle/1 instead..
@spec generate_empty_candle(OHLC.timeframe() | nil) :: OHLC.candle()

Generates and returns empty candle.

If provided with timeframe stime and etime will be generated based on current time.

Link to this function

get_candle_type(open, close)

@spec get_candle_type(number(), number()) :: :bullish | :bearish

Gets the current candle type(pullish or bearish).

Returns :bullish - if close price > open price. bearish - if previous close price <= open price.

Link to this function

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

@spec get_time_rounded(number(), OHLC.timeframe(), list() | nil) ::
  number()
  | %DateTime{
      calendar: term(),
      day: term(),
      hour: term(),
      microsecond: term(),
      minute: term(),
      month: term(),
      second: term(),
      std_offset: term(),
      time_zone: term(),
      utc_offset: term(),
      year: term(),
      zone_abbr: term()
    }

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

get_timeframes()

@spec get_timeframes() :: list()

Returns all available timeframes in seconds.

Link to this function

trades_total_volume(trades)

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

Calculates the total volume from trades.

Link to this function

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

@spec validate_data(OHLC.candles() | nil, OHLC.trades() | nil) ::
  :ok | {:error, atom()}

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