Skip to content

Unofficial Python SDK for Hargreaves Lansdowne

License

Notifications You must be signed in to change notification settings

dastra/hargreaves-sdk-python

Repository files navigation

Unofficial SDK

This is an unofficial SDK to programatically access your Hargreaves Lansdown account

Motivation

I wanted to programatically access my Hargreaves Lansdown accounts, but they do not currently offer an API. This SDK accesses your accounts via their website, and allows you to list your holdings.
This codebase started life as a port to Python of Jamie Haywood's Javascript package.

Installation

Install via pip

pip3 install git+https://github.com/dastra/[email protected]#egg=hargreaves

Or add the following line to your requirements.txt file:

git+https://github.com/dastra/[email protected]#egg=hargreaves

Usage

There are examples of use in doc/examples/

Secrets

You will need to pass your authentication credentials to the code, either in a file or via environment variables.

Secrets File

You will need to create a secrets.json file containing your login credentials.
The format is:

{
  "username": "tuser",
  "password": "tpass",
  "date_of_birth": "011286", // Format DDMMYY
  "secure_number": "123456"
}

Which is then passed to the API config loader:

config = load_api_config("./secrets.json")

Secrets Environment Variables

As an alternative to storing your secrets in a file, you can set them as environment variables:

export HL_USERNAME = "tuser2"
export HL_PASSWORD = "tpass2"
export HL_DATE_OF_BIRTH = "011285" # Format DDMMYY
export HL_SECURE_NUMBER = "654321"

Usage Example

Please see the various script examples:

Analysing Issues

Assuming you have pre-recorded a use-case in a Firefox browser and saved the HAR file locally to the "./session_cache/my-recording.har" file you can run the following command to filter out the Hargreaves Lansdown request "noise" and convert it to a set of Markdown files

PYTHONPATH=. python3 hargreaves/utils/har2md.py ./session_cache/my-recording.har

You can then compare the markdown files to scraper sessions (HAR files converted to markdown). For more information read https://github.com/eladeon/requests-tracker-python/blob/main/README.md

Contributing

You are welcome to suggest a new feature by raising an issue, or indeed to contribute