py_alpaca_api.models.model_utils

Attributes

KEY_PROCESSORS

Functions

get_dict_str_value(→ str)

Returns the string value of a specific key within a dictionary.

parse_date(→ str)

Parses a date value from a dictionary using a specified key.

get_dict_float_value(→ float)

param data_dict:

A dictionary containing the data.

get_dict_int_value(→ int)

param data_dict:

A dictionary containing key-value pairs.

extract_class_data(data_dict, field_processors, data_class)

Extracts and processes data from a dictionary based on a given data class and field processors.

Module Contents

py_alpaca_api.models.model_utils.get_dict_str_value(data_dict: dict, key: str) str[source]

Returns the string value of a specific key within a dictionary.

Parameters:
  • data_dict (dict) – The dictionary containing the data.

  • key (str) – The key to retrieve the value from.

Returns:

The string value associated with the specified key. If the key does not exist in the dictionary or its value is None, an empty string will be returned.

Return type:

str

py_alpaca_api.models.model_utils.parse_date(data_dict: dict, key: str) str[source]

Parses a date value from a dictionary using a specified key.

Parameters:
  • data_dict (dict) – The dictionary from which to extract the date value.

  • key (str) – The key in the dictionary representing the date value.

Returns:

The parsed date value as a formatted string.

Return type:

str

py_alpaca_api.models.model_utils.get_dict_float_value(data_dict: dict, key: str) float[source]
Parameters:
  • data_dict (dict) – A dictionary containing the data.

  • key (str) – The key to look for in the data_dict.

Returns:

The value associated with the specified key in the data_dict as a float. If the key is not found or if the value is not of float type, returns 0.0.

Return type:

float

py_alpaca_api.models.model_utils.get_dict_int_value(data_dict: dict, key: str) int[source]
Parameters:
  • data_dict – A dictionary containing key-value pairs.

  • key – The key whose corresponding value is to be returned.

Returns:

The integer value associated with the given key in the data_dict. If the key is not present or the corresponding value is not an integer, 0 is returned.

Return type:

int

py_alpaca_api.models.model_utils.KEY_PROCESSORS[source]
py_alpaca_api.models.model_utils.extract_class_data(data_dict: dict, field_processors: dict, data_class: type[Any])[source]

Extracts and processes data from a dictionary based on a given data class and field processors.

Parameters:
  • data_dict (dict) – The dictionary containing the data to be processed.

  • field_processors (Dict) – A dictionary of field processors.

  • data_class (type[Any]) – The data class used to define the fields and types.

Returns:

A dictionary containing processed data, with keys corresponding to the fields of the data class.

Return type:

dict

Raises:

KeyError – When a field processor is not found for a specific data type.