tdameritrade_client.utils package¶
Submodules¶
tdameritrade_client.utils.create_certs module¶
-
tdameritrade_client.utils.create_certs.create_certificate(key_pair: OpenSSL.crypto.PKey, digest: str = 'sha256') → OpenSSL.crypto.X509¶ Generate a certificate given a certificate request.
Parameters: - key_pair – A public/private key pair generated by OpenSSL.crypto.
- digest – Digest method to use for signing. Default is sha256.
Returns: The signed certificate in an X509 object.
-
tdameritrade_client.utils.create_certs.create_key_pair(bits: int) → OpenSSL.crypto.PKey¶ Create a public/private key pair.
Parameters: bits – Number of bits to use in the key Returns: The public/private key pair in a PKey object
-
tdameritrade_client.utils.create_certs.get_serial_number()¶ Checks a for a version file in the source code and increments for a new certificate. (Solves SEC_ERROR_REUSED_ISSUER_AND_SERIAL exception during access token exchange).
Returns: Serial number to use for the new certificate
tdameritrade_client.utils.tools module¶
-
tdameritrade_client.utils.tools.check_auth(func: Callable) → Callable¶ Decorator that ensures auth has been run before calling func :param func: The decorated function
-
tdameritrade_client.utils.tools.process_price_history(candles_response: Dict[KT, VT], start_date: datetime.datetime = None) → Dict[KT, VT]¶ Turn timestamps into datetimes and remove entries before start_date.
Performs post processing on a response from a price history call. Converts timestamps to UTC human readable dates and removes dates that are before start_date
Parameters: - candles_response – A response from a call to the price history endpoint
- start_date – An optional datetime used if calling get_dated_price_history to filter results
Returns: Candles with human readable dates only after start_date
Raises: ValueError– If the response was an error
-
tdameritrade_client.utils.tools.validate_price_history_args(symbol: str, frequency_type: str = None, frequency: int = None, period_type: str = 'day', period: int = None, start_date: datetime.datetime = None, end_date: datetime.datetime = None, need_extended_hours_data: bool = True) → Dict[KT, VT]¶ Ensures all variables passed to a self.get_price_history() call are valid with respect to one another.
See the following API definition for a source on all of the following rules: https://developer.tdameritrade.com/price-history/apis/get/marketdata/%7Bsymbol%7D/pricehistory
Parameters: - symbol – Ticker symbol to search for.
- frequency_type – The type of frequency with which a new candle is formed. Must be either ‘minute’, ‘daily’, ‘weekly’, or ‘monthly’.
- frequency – Frequency with which to return candles.
- period_type – The type of period-data to return. Must be either ‘day’, ‘month’, ‘year’, or ‘ytd’. Default: ‘day’.
- period – The length of periodType over which to receive price history.
- start_date – Start date for price history period. Given with endDate as an alternative to period.
- end_date – End date for price history period. Given with endDate as an alternative to period.
- need_extended_hours_data – False to only return regular market hours data. Default: True.
Returns: Dict of params to pass to self._get_url for a proper API call.
Raises: ValueError– If passed arguments are invalid.