OHLCHelper (ohlc v1.1.6)
OHLC Helper module containing all the helper functions.
Link to this section Summary
Functions
Helper function for formatting the value to float.
Generates trades from provided arguments.
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
format_to_float(value)
Specs
Helper function for formatting the value to float.
gen_trades(timeframe, min_price, max_price, volume, timeframe_multiplier \\ 1, timeframe_divider \\ 1)
Specs
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 tradesmax_price
- The maximum price on the generated tradesvolume
- The volume each trade hasvolume
- The volume each trade hasvolume
- The volume each trade hastimeframe_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.
generate_empty_candle(timeframe \\ nil)
Specs
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.
get_candle_type(open, close)
Specs
Gets the current candle type(pullish or bearish).
Returns
:bullish
- if close price > open price.
bearish
- if previous close price <= open price.
get_time_rounded(timestamp, timeframe, opts \\ [])
Specs
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
.
get_timeframes()
Specs
get_timeframes() :: list()
Returns all available timeframes in seconds.
trades_total_volume(trades)
Specs
trades_total_volume(OHLC.trades()) :: float()
Calculates the total volume from trades.
validate_data(candles \\ [], trades \\ [])
Specs
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.