This is an unofficial SDK to programatically access your Hargreaves Lansdown account
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.
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
There are examples of use in doc/examples/
You will need to pass your authentication credentials to the code, either in a file or via environment variables.
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")
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"
Please see the various script examples:
- doc/examples/account_holdings_list.py
- doc/examples/deals_execute.py
- doc/examples/pending_orders_list.py
- doc/examples/pending_orders_cancel.py
- doc/examples/search_security.py
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
You are welcome to suggest a new feature by raising an issue, or indeed to contribute