candle
candle
Classes:
| Name | Description |
|---|---|
Candle |
|
Candle
Candle(
open: float,
high: float,
low: float,
close: float,
volume: int,
timestamp: datetime | str | None = None,
timeframe: TimeFramesSource | None = None,
indicators: dict[str, Reading] | None = None,
sub_indicators: dict[str, Reading] | None = None,
aggregation_factor: int | None = None,
)
Methods:
| Name | Description |
|---|---|
admit_for_storage |
Return a candle safe to store in a CandleManager. |
as_dict |
Generates a dict of values from the OHLCV values, with the following keys: |
as_list |
Generates a list of values from the OHLCV values. |
clean_copy |
Create a clean copy with OHLCV data but without indicators, refs, or tag. |
from_dict |
Create a |
from_dicts |
Create's a list of |
from_list |
Create a |
from_lists |
Create a list of |
merge |
Merge another |
Attributes:
| Name | Type | Description |
|---|---|---|
is_clean |
bool
|
True when the candle has no readings, refs, or tag attached. |
Source code in hexital/core/candle.py
admit_for_storage
Return a candle safe to store in a CandleManager.
Source code in hexital/core/candle.py
as_dict
Generates a dict of values from the OHLCV values, with the following keys:
[timestamp, open, high, low, close, volume]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
readings
|
bool
|
Include Candle readings |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A list of the |
dict
|
{open, high, low, close, volume, timestamp, timeframe*} |
|
dict
|
{open, high, low, close, volume, timestamp, indicators, sub_indicators, timeframe*} |
Source code in hexital/core/candle.py
as_list
Generates a list of values from the OHLCV values.
[timestamp, open, high, low, close, volume] in that order.
With an optional timedelta value at the end being the timeframe
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
readings
|
bool
|
Include Candle readings |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of the |
list
|
[timestamp, open, high, low, close, volume, timeframe*] |
|
list
|
[timestamp, open, high, low, close, volume, indicators, sub_indicators, timeframe*] |
Source code in hexital/core/candle.py
clean_copy
clean_copy() -> Candle
Create a clean copy with OHLCV data but without indicators, refs, or tag.
Source code in hexital/core/candle.py
from_dict
classmethod
Create a Candle object from a dictionary representation.
The dictionary is expected to have the following keys: - Required: 'open', 'high', 'low', 'close', 'volume' - Optional: 'timestamp' | 'time' | 'date' - Optional: 'timeframe', 'indicators', 'sub_indicators'
The method extracts the values for these keys. If the optional keys for time ('timestamp', 'time', etc.) are present, the first match is used as the timestamp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candle
|
Dict[str, Any]
|
A dictionary containing the candle data. |
required |
timeframe
|
TimeFramesSource | None
|
Optional fallback timeframe used when the dictionary does not contain a timeframe field. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Candle |
Candle
|
A |
Source code in hexital/core/candle.py
from_dicts
classmethod
from_dicts(
candles: Sequence[dict[str, Any]], timeframe: TimeFramesSource | None = None
) -> list[Candle]
Create's a list of Candle object's from a list of dictionary representation.
Each dictionary is expected to have the following keys: - Required: 'open', 'high', 'low', 'close', 'volume' - Optional: 'timestamp' | 'time' | 'date' - Optional: 'timeframe', 'indicators', 'sub_indicators'
The method extracts the values for these keys. If the optional keys for time ('timestamp',
'time', etc.) are present, the first match is used as the timestamp.
Returning a list of Candle objects initialized with the provided dictionary data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candles
|
List[Dict[str, Any]]
|
A dictionary containing the candle data. |
required |
timeframe
|
TimeFramesSource | None
|
Optional fallback timeframe used when an item does not contain a timeframe field. |
None
|
Returns:
| Type | Description |
|---|---|
list[Candle]
|
List[Candle]: A list of |
Source code in hexital/core/candle.py
from_list
classmethod
Create a Candle object from a list representation.
The list is expected to contain the following elements:
- Required: [open, high, low, close, volume] in that order.
- Optional: A timestamp at the beginning of the list.
- Optional: A timeframe at the end of the list.
- Optional: Dict's indicators, sub_indicators after Volume.
If the first element is a str or datetime, it is treated as the timestamp.
If the last element is a str, int, TimeFrame, or timedelta, it is treated as the timeframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candle
|
list
|
A list containing the candle data. |
required |
timeframe
|
TimeFramesSource | None
|
Optional fallback timeframe used when the list does not contain a timeframe value. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Candle |
Candle
|
A |
Source code in hexital/core/candle.py
from_lists
classmethod
Create a list of Candle object's from a list of list representation.
Each list is expected to contain the following elements:
- Required: [open, high, low, close, volume] in that order.
- Optional: A timestamp at the beginning of the list.
- Optional: A timeframe at the end of the list.
- Optional: Dict's indicators, sub_indicators after Volume.
If the first element is a str or datetime, it is treated as the timestamp.
If the last element is a str, int, TimeFrame, or timedelta, it is treated as the timeframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candles
|
List[list]
|
A list of list's containing the candle data. |
required |
timeframe
|
TimeFramesSource | None
|
Optional fallback timeframe used when an item does not contain a timeframe value. |
None
|
Returns:
| Type | Description |
|---|---|
list[Candle]
|
List[Candle]: A list of |
Source code in hexital/core/candle.py
merge
merge(candle: Candle)
Merge another Candle object into the current candle.
This method updates the current candle by integrating data from the provided candle.
It ensures that the merged values respect the timeframe boundaries and adjusts
attributes such as open, high, low, close, volume, and timestamps accordingly.
Note: - Any calculated indicators will be wiped, as merging modifies the core candle values. - Any conversion or derived values associated with the candle will also be removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candle
|
Candle
|
The |
required |
Behaviour
- Adjusts the
openif the merged candle's timestamp is earlier than the start timestamp. - Updates the
closeif the merged candle's timestamp is more recent. - Updates
highandlowbased on the maximum and minimum values of the two candles. - Increases the
volumeby the volume of the merged candle. - Increments the
aggregation_factorto account for the merged data. - Resets calculated indicators and cleans any derived values.