@investingwolf/alpaca-broker-api
TypeScript icon, indicating that this package has built-in type declarations

0.9.3 • Public • Published

@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: 'cool_alpaca@example.com',
    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);

/@investingwolf/alpaca-broker-api/

    Package Sidebar

    Install

    npm i @investingwolf/alpaca-broker-api

    Weekly Downloads

    1

    Version

    0.9.3

    License

    MIT

    Unpacked Size

    494 kB

    Total Files

    162

    Last publish

    Collaborators

    • investingwolf