candle
candle
Classes:
Name | Description |
---|---|
Candle |
|
Candle
Candle(
open: float,
high: float,
low: float,
close: float,
volume: int,
timestamp: Optional[datetime | str] = None,
timeframe: Optional[str | TimeFrame | timedelta | int] = None,
indicators: Optional[
Dict[str, float | Dict[str, float | None] | None]
] = None,
sub_indicators: Optional[
Dict[str, float | Dict[str, float | None] | None]
] = None,
)
Methods:
Name | Description |
---|---|
from_dict |
Create a |
from_dicts |
Create's a list of |
from_list |
Create a |
from_lists |
Create a list of |
merge |
Merge another |
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'
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 |
Returns:
Name | Type | Description |
---|---|---|
Candle |
Candle
|
A |
Source code in hexital/core/candle.py
from_dicts
staticmethod
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'
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 |
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.
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 |
Returns:
Name | Type | Description |
---|---|---|
Candle |
Candle
|
A |
Source code in hexital/core/candle.py
from_lists
staticmethod
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.
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 |
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
open
if the merged candle's timestamp is earlier than the start timestamp. - Updates the
close
if the merged candle's timestamp is more recent. - Updates
high
andlow
based on the maximum and minimum values of the two candles. - Increases the
volume
by the volume of the merged candle. - Increments the
aggregation_factor
to account for the merged data. - Resets calculated indicators and cleans any derived values.