npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

schwab-api

v1.0.2

Published

**This is not an official API or even a stable recreation of a Charles Schwab API. Functionality may change with any updates made by Schwab.**

Downloads

15

Readme

Schwab API

This is not an official API or even a stable recreation of a Charles Schwab API. Functionality may change with any updates made by Schwab.

Sponsor Me! Downloads GitHub stars GitHub issues GitHub license

This project was originally ported from the itsjafer/schwab-api Python library, but has diverged significantly in it's logic from the original source material. Nevertheless, if you enjoy this project, go give that one some love!

This package enables buying and selling securities programmatically on Charles Schwab. Currently, we use a headless browser to automate logging in in order to get authorization cookies. All other functionality is done through web requests made to Schwab's own API.

Getting Started

Installing

Install using npm:

$ npm i schwab-api

Quickstart

Here's some code that logs in, gets all account holdings, and makes a stock purchase:

// Import Schwab
const { Schwab, TradeType, Logging: { defaults: { logger } } } = require(`schwab-api`);

// Initialize a new instance of the Schwab class and initialize it
// with youre credentials.
const schwab = new Schwab({
    username: 'your-username',
    password: 'your-password'
});

// Authentication is performed automatically for each request, meaning
// you do not have to manually log-in each time you use the API. It
// will handle that internally including re-authenticating when a
// session is expired.

// Retrieve the account information.
schwab.getAccountInfo().then(accountInfo => {
    // Print the account information.
    const accountIdsStr = accountInfo.Accounts.map(
        account => account.AccountId
    ).join(', ');
    logger.info(`The following account numbers were found: ${accountIdsStr}`);

    // Perform a trade
    const accountId = accountInfo.Accounts[0].AccountId;
    schwab.trade({
        tradeType: TradeType.Buy,
        ticker: 'AAPL',
        quantity: 1,
        accountId: accountId,
        verifyOnly: true // setting to true will only run verification
                         // and not confirmation.
    }).then(res => {
        // If you're doing a `verifyOnly`, only the `verification` object will
        // have data. If you want the same data for `confirmation`, look at
        // the `confirmation` object instead.
        if (res.verification.successful()) {
            logger.info(`The order verification was successful.`);
            logger.info(`The order verification produced the following messages:`);
            logger.info(`${JSON.stringify(res.verification.messages())}`);    
        } else {
            logger.error(`The order verification was not successful.`);
            logger.error(`The order verification produced the following messages:`);
            logger.error(`${JSON.stringify(res.verification.messages())}`);    
        }
    }).catch(err => {
        logger.error(`The order verification was not successful.`);
        logger.error(`The order verification produced the following error:`);
        logger.error(`${err.stack}`);
    });
}).catch(err => {
    logger.error(`Retrieving account information was not successful.`);
    logger.error(`The attempt to retrieve account information produced the following error:`);
    logger.error(`${err.stack}`);
});