This is an unofficial API to programatically access your Hargreaves Lansdown account
I will no longer be adding features / accepting PRs as I have moved my ISA and share holdings to Freetrade. Hargreaves Lansdown's trading and ongoing fees are astronomical, and do not reflect "good value" for me.
If you would like to join Freetrade and get a free share worth between £3 and £200 don't hesitate to use my signup link
npm install hargreaves-lansdown
yarn add hargreaves-lansdown
import HL from 'hargreaves-lansdown'
(async () => {
const credentials = {
username: "",
password: "",
dateOfBirth: "",
secureNumber: "",
};
const hl = new HL();
await hl.authenticate(credentials);
console.log(await hl.getInDepth());
await hl.logout();
})();
This package is versioned according to SemVer. However, it is still in active development and hargreaves-lansdown
If building & consuming from source, make sure you use a separate fork.
I am open to suggestions / contributions for this package. It is very much in active development & I will be maintaining it for the foreseeable future. If you're not confident writing TypeScript / JavaScript, please don't let that hold you back- raise an issue with features you would like to see & I will endeavour to build & release them.
The commit styling adheres to the Conventional Commits specification. Please follow it!
As well as being visually satisfying in the repo, it also serves a purpose for versioning releases correctly.
When code is merged to the master
branch, the commits in that pull request are analysed to determine whether the package version should be incremented by a major, minor or patch version.
This repo uses Prettier, pretty standard nowadays (pardon the pun..!). ESLint is on the roadmap of being added.
This method returns an object with the following interface:
interface IAccounts {
[key: string]: IAccount | undefined;
}
interface IAccount {
stockValue: string;
cashValue: string;
totalValue: string;
available: string;
holdings: IInvestments;
}
interface IInvestments {
[key: string]: IInvestment;
}
interface IInvestment {
[key: string]: any;
stockType: string;
stockInfo: string;
stockLink?: string;
unitsHeld: string;
price: string;
value: string;
cost: string;
gain: string;
gainPercentage: string;
details?: IInvestmentDetails;
ticker: string;
}
interface IInvestmentDetails {
[key: string]: any;
sedol: string;
transactions: ITransactions;
lastDividend: string;
nextDividend: string;
firstDeal: string;
lastDeal: string;
totalDeals: string;
holdingSummary?: IHoldingSummary;
}
interface IHoldingSummary {
[key: string]: any;
highestPricePaid: string;
lowestPricePaid: string;
weightedAvgPaid: string;
highestPriceRecieved: string;
lowestPriceRecieved: string;
weightedAvgRecieved: string;
}
interface ITransactions {
[key: string]: ITransaction;
}
interface ITransaction {
date: string;
type: string;
reference: string;
unitCost: number;
quantity: number;
cost: number;
}
If you are using hargreaves-lansdown
in a continually running server environment, make sure you call logout()
at the end of calling getInDepth()
. This clears session cookies which ensures there are no weird authentication side-effects.
I am currently working on being able to query the accounts in more depth, right down to the individual holdings, and be able to programmatically buy and sell holdings.
If you enjoy using this package, consider buying me a coffee here ➡️ or in real life!