Skip to content

💰 An unofficial API to programatically access your Hargreaves Lansdown account.

License

Notifications You must be signed in to change notification settings

jamiehaywood/hargreaves

Repository files navigation

UNOFFICIAL API

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

⚠️ This project is in maintenance mode ⚠️

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

Install

npm install hargreaves-lansdown
yarn add hargreaves-lansdown

Usage

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();
})();

Things to note

This package is versioned according to SemVer. However, it is still in active development and ⚠️ versions < 1.0.0 are unstable and may potentially have breaking changes in every release. ⚠️ With this in mind, if you install this from NPM, make sure you pin your version of hargreaves-lansdown

If building & consuming from source, make sure you use a separate fork.

Contributing

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.

Commits

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.

Code style & standards

This repo uses Prettier, pretty standard nowadays (pardon the pun..!). ESLint is on the roadmap of being added.

Notes

getInDepth()

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;
}

logout()

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.

Future Updates

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 ➡️ Buy Me A Coffee or in real life!

About

💰 An unofficial API to programatically access your Hargreaves Lansdown account.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published