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

@investingwolf/alpaca-broker-api

v0.9.3

Published

Node.js client for alpaca broker API

Downloads

118

Readme

@investingwolf/alpaca-broker-api

Version

Node.js client for the Alpaca Broker API generated from the specs provided here.

Installation

Install via NPM:

npm install @investingwolf/alpaca-broker-api

Usage

Configuration

You will need an Alpaca API key and API secret. You can then create an Alpaca client as follows:

const {AlpacaApi, AlpacaEnvironments} = require('@investingwolf/alpaca-broker-api');

const alpaca = new AlpacaApi({
    apiKey: 'your-api-key',
    apiSecret: 'your-api-secret',
    basePath: AlpacaEnvironments.sandbox, // or AlpacaEnvironments.production
});

Making API Calls

Here is an example API call:

const {body: account} = await alpaca.accounts.accountsPost({
  contact: {
    email_address: '[email protected]',
    phone_number: '555-666-7788',
    // ...
  },
  // ...
});

All methods accept an optional options object as the last parameter, which can be used to set additional headers:

const {body: account} = await alpaca.accounts.accountsPost({
    // ...
}, {
    headers: {'x-some-header': 'some-value'}
});

Error Handling

API errors are instances of the HttpError class (which can be imported). Errors have both response and statusCode properties.

Accounts API

See Alpaca accounts documentation for descriptions of each endpoint.

// deleteAccount(String, Options?)
alpaca.accounts.deleteAccount(accountId);

// getAccount(String, Options?)
alpaca.accounts.getAccount(accountId);

// getAccounts(String?, Options?)
alpaca.accounts.getAccounts(query);

// getAccountActivities(String?, String?, String?, String?, String?, Number?, String?, Options?)
alpaca.accounts.getAccountActivities(date, until, after, direction, accountId, pageSize, pageToken);

// getAccountActivitiesByType(String, String?, String?, String?, String?, String?, Number?, String?, Options?)
alpaca.accounts.getAccountActivitiesByType(activityType, date, until, after, direction, accountId, pageSize, pageToken);

// getTradingAccount(String, Options?)
alpaca.accounts.getTradingAccount(accountId);

// patchAccount(String, AccountUpdate, Options?)
alpaca.accounts.patchAccount(accountId, accountUpdate);

// postAccount(AccountCreationObject, Options?)
alpaca.accounts.postAccount(accountCreationObject);

Assets API

See Alpaca assets documentation for descriptions of each endpoint.

// getAssetById(String, Options?)
alpaca.assets.getAssetById(assetId);

// getAssetBySymbol(String, Options?)
alpaca.assets.getAssetBySymbol(symbol);

// getAssets(Options?)
alpaca.assets.getAssets();

Calendar API

See Alpaca calendar documentation for descriptions of each endpoint.

// getCalendar(String?, String?, Options?)
alpaca.calendar.getCalendar(start, end);

Clock API

See Alpaca clock documentation for descriptions of each endpoint.

// getClock(Options?)
alpaca.clock.getClock();

Documents API

See Alpaca documents documentation for descriptions of each endpoint.

// documentsDocumentIdGet(String, Options?)
alpaca.documents.documentsDocumentIdGet(documentId);

// getDocumentDownload(String, String, Options?)
alpaca.documents.getDocumentDownload(accountId, documentId);

// getDocuments(String, String?, String?, Options?)
alpaca.documents.getDocuments(accountId, startDate, endDate);

// postDocumentUpload(String, DocumentUpload, Options?)
alpaca.documents.postDocumentUpload(accountId, documentUpload);

Events API

See Alpaca events documentation for descriptions of each endpoint.

// eventsAccountsStatusGet(Date?, Date?, Number?, Number?, Options?)
alpaca.events.eventsAccountsStatusGet(since, until, sinceId, untilId);

// eventsJournalsStatusGet(Date?, Date?, Number?, Number?, Options?)
alpaca.events.eventsJournalsStatusGet(since, until, sinceId, untilId);

Funding API

See Alpaca funding documentation for descriptions of each endpoint.

// deleteAchRelationship(String, String, Options?)
alpaca.funding.deleteAchRelationship(accountId, achRelationshipId);

// deleteRecipientBank(String, String, Options?)
alpaca.funding.deleteRecipientBank(accountId, bankId);

// deleteTransfer(String, String, Options?)
alpaca.funding.deleteTransfer(accountId, transferId);

// getAchRelationships(String, String? Options?)
alpaca.funding.getAchRelationships(accountId, statuses);

// getRecipientBanks(String, String?, String?, Options?)
alpaca.funding.getRecipientBanks(accountId, status, bankName);

// getTransfers(String, String?, Number?, Number? Options?)
alpaca.funding.getTransfers(accountId, direction, limit, offset);

// postAchRelationship(String, AchRelationshipData, Options?)
alpaca.funding.postAchRelationship(accountId, achRelationshipData);

// postRecipientBank(String, BankData, Options?)
alpaca.funding.postRecipientBank(accountId, bankData);

// postTransfer(String, TransferData, Options?)
alpaca.funding.postTransfer(accountId, transferData);

Journals API

See Alpaca journals documentation for descriptions of each endpoint.

// deleteJournal(String, Options?)
alpaca.journals.deleteJournal(journalId);

// getJournals(String?, String?, String?, String?, String?, String?, Options?)
alpaca.journals.getJournals(after, before, status, entryType, toAccount, fromAccount);

// postJournals(JournalData, Options?)
alpaca.journals.postJournals(journalData);

// postJournalsBatch(BatchJournalRequest, Options?)
alpaca.journals.postJournalsBatch(batchJournalRequest);

OAuth API

See Alpaca OAuth documentation for descriptions of each endpoint.

// oauthAuthorizePost(OAuthAuthorizeObject, Options?)
alpaca.oauth.oauthAuthorizePost(oauthAuthorizeObject);

// oauthClientsClientIdGet(String, String?, String?, String?, Options?)
alpaca.oauth.oauthClientsClientIdGet(clientId, responseType, redirectUri, scope);

// oauthTokenPost(OAuthTokenObject, Options?)
alpaca.oauth.oauthTokenPost(oauthTokenObject);

Trading API

See Alpaca trading documentation for descriptions of each endpoint.

// deleteOrder(String, String, Options?)
alpaca.trading.deleteOrder(accountId, orderId);

// deleteOrders(String, Options?)
alpaca.trading.deleteOrders(accountId);

// getOrder(String, String, Options?)
alpaca.trading.getOrder(accountId, orderId);

// getOrders(String, String?, Number?, Date?, Date?, String?, Boolean?, String?, Options?)
alpaca.trading.getOrders(accountId, status, limit, after, until, direction, nested, symbols);

// getPositions(String, Options?)
alpaca.trading.getPositions(accountId);

// deletePosition(String, String, String?, String?, Options?)
alpaca.trading.deletePosition(accountId, symbol, qty, percentage);

// patchOrder(String, String, PatchOrder, Options?)
alpaca.trading.patchOrder(accountId, orderId, patchOrder);

// postOrder(String, CreateOrder, Options?)
alpaca.trading.postOrder(accountId, createOrder);

// getPortfolioHistory(String, String?, String?, String?, Boolean?, Options?)
alpaca.trading.getPortfolioHistory(accountId, period, timeframe, dateEnd, extendedHours);