lightningchart_trader.helper_routines package¶
Submodules¶
lightningchart_trader.helper_routines.helper_routines module¶
- lightningchart_trader.helper_routines.helper_routines.calculate_heikin_ashi_values(xohlc_data)[source]¶
Calculates Heikin Ashi values based on the given dataset.
- Parameters:
xohlc_data (list[list[int | float]]) – XOHLC dataset to calculate from.
- Returns:
List of Heikin Ashi values.
- lightningchart_trader.helper_routines.helper_routines.convert_hex_to_rgba(hex_color)[source]¶
Convert a HEX color string to an RGBA tuple.
- Parameters:
hex_code (str) – A HEX color code in the format ‘#RRGGBB’ or ‘#RRGGBBAA’.
- Returns:
- A tuple (R, G, B, A) where R, G, B, and A are integers between 0 and 255.
If no alpha channel is provided in the HEX string, the alpha will be excluded from the result.
- Return type:
tuple
- lightningchart_trader.helper_routines.helper_routines.convert_rgba_to_hex(r, g, b, a=None)[source]¶
Convert an RGB or RGBA color value to a HEX color string.
- Parameters:
r (int) – Red component, an integer between 0 and 255.
g (int) – Green component, an integer between 0 and 255.
b (int) – Blue component, an integer between 0 and 255.
a (int, optional) – Alpha component, an integer between 0 and 255. If not provided, the alpha will be excluded from the result.
- Returns:
A HEX string representing the color in the format ‘#RRGGBB’ or ‘#RRGGBBAA’.
- Return type:
str
- lightningchart_trader.helper_routines.helper_routines.convert_to_xohlc(data)[source]¶
Converts various data formats (CSV, list of dicts, list of lists, DataFrame) into XOHLC format. The function is case insensitive for column names (e.g., “Open” == “open” == “OPEN”).
- Parameters:
data (str | list | dict | DataFrame) –
Path to CSV file (str)
List of dictionaries (list[dict])
Single dictionary (dict)
List of lists (list[list])
Pandas DataFrame (DataFrame)
- Returns:
Data in XOHLC format -> [[Index, Open, High, Low, Close], …]
- Return type:
list
Example Usage:¶
>>> convert_to_xohlc("your_csv_file.csv") >>> convert_to_xohlc(df) # Pandas DataFrame >>> convert_to_xohlc([{"OPEN":1.1, "HIGH":1.2, "LOW":1.0, "CLOSE":1.15, "DATE":"Jan 1, 1970"}]) # List of Dicts >>> convert_to_xohlc([[1.1, 1.2, 1.0, 1.15, "Jan 1, 1970"]]) # List of Lists
- lightningchart_trader.helper_routines.helper_routines.extract_close_values(xohlc_data)[source]¶
Extracts all Close values from the current dataset.
- Parameters:
xohlc_data (list[list[int | float]]) – XOHLC data values to extract from.
- Returns:
List of Close values, or empty list if unable to extract.
- lightningchart_trader.helper_routines.helper_routines.extract_high_values(xohlc_data)[source]¶
Extracts all High values from the current dataset.
- Parameters:
xohlc_data (list[list[int | float]]) – XOHLC data values to extract from.
- Returns:
List of High values, or empty list if unable to extract.
- lightningchart_trader.helper_routines.helper_routines.extract_low_values(xohlc_data)[source]¶
Extracts all Low values from the current dataset.
- Parameters:
xohlc_data (list[list[int | float]]) – XOHLC data values to extract from.
- Returns:
List of Low values, or empty list if unable to extract.
- lightningchart_trader.helper_routines.helper_routines.extract_open_values(xohlc_data)[source]¶
Extracts all Open values from the current dataset.
- Parameters:
xohlc_data (list[list[int | float]]) – XOHLC data values to extract from.
- Returns:
List of Open values, or empty list if unable to extract.
- lightningchart_trader.helper_routines.helper_routines.extract_position_values(xohlc_data)[source]¶
Extracts all position values (X-values) from the current dataset.
- Parameters:
xohlc_data (list[list[int | float]]) – XOHLC data values to extract from.
- Returns:
List of positions values, or empty list if unable to extract.
- lightningchart_trader.helper_routines.helper_routines.read_csv_string(csv_input, start_date=None, end_date=None, delimiter=',')[source]¶
Parses a CSV string or file into separate OHLCV arrays, similar to JS readCsvString().
- Parameters:
csv_input (str) – Either a file path or a raw CSV string.
start_date (str | None) – Optional filter, exclude rows before this date (Format: “YYYY-MM-DD”).
end_date (str | None) – Optional filter, exclude rows after this date (Format: “YYYY-MM-DD”).
delimiter (str) – The delimiter used in the CSV (default: ,).
- Returns:
- A list containing:
Array of date strings
Array of Open values
Array of High values
Array of Low values
Array of Close values
Array of Volumes (or empty if not in CSV)
Array of Open Interests (or empty if not in CSV)
- Return type:
list
Example Usage:¶
>>> csv_data = '''Date,Open,High,Low,Close,Volume,OpenInterest ... 2024-01-01,100,105,99,104,5000,200 ... 2024-01-02,104,106,102,105,5500,210 ... 2024-01-03,105,107,103,106,6000,220''' >>> parsed_data = read_csv_string(csv_data, start_date="2024-01-02") >>> print(parsed_data)
>>> parsed_file = read_csv_string("your_csv_file.csv") >>> print(parsed_file)