Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@master-chief/alpaca

Package Overview
Dependencies
Maintainers
1
Versions
86
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@master-chief/alpaca

A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
137
decreased by-22.6%
Maintainers
1
Weekly downloads
 
Created
Source

alpaca

Version Language Maintenance Prettier(idk)

A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.

Contents

Installation

> npm i @master-chief/alpaca

Client

A client for handling all account based requests.

Instance

The standard way to initialize the client.

import * as alpaca from '@master-chief/alpaca'

// create the client
const client = new alpaca.Client({
  credentials: {
    key: 'mykey',
    secret: 'mysecret',
  },
  paper: true,
  rate_limit: true,
})

You can also use environment variables which will be applied to every new client.

> set APCA_API_KEY_ID=yourKeyGoesHere
> set APCA_API_SECRET_KEY=yourKeyGoesHere
> set APCA_PAPER=true

Methods

All Client instance methods.

isAuthenticated

Checks if the client is authenticated.

await client.isAuthenticated()
getAccount

Connects to an Alpaca account.

await client.getAccount()
getOrder

Gets a specific order.

await client.getOrder({
  order_id: '6187635d-04e5-485b-8a94-7ce398b2b81c',
})
getOrders

Gets all orders made by the client.

await client.getOrders({
  limit: 25,
  status: 'all',
})
placeOrder

Places an order using your account.

await client.placeOrder({
  symbol: 'SPY',
  qty: 1,
  side: 'buy',
  type: 'market',
  time_in_force: 'day',
})
replaceOrder

Re-places an order(to change some details maybe).

await client.replaceOrder({
  order_id: '69a3db8b-cc63-44da-a26a-e3cca9490308',
  limit_price: 9.74,
})
cancelOrder

Cancels an order.

await client.cancelOrder({
  order_id: '69a3db8b-cc63-44da-a26a-e3cca9490308',
})
cancelOrders

Cancels every single order(be sure to not make a typo here!)

await client.cancelOrders()

More examples are coming soon... give me some time or feel free to contribute.

Stream

An Alpaca websocket API for streamlining the exchange of requests and data to and from the Alpaca servers.

Instance

An API key is allowed 1 simultaneous connection to each server. Connecting to them is easy:

import * as alpaca from '@master-chief/alpaca'

// create the stream
const stream = new alpaca.Stream({
  credentials: {
    key: 'mykey',
    secret: 'mysecret',
  },
  host: alpaca.URL.WSS_MARKET_DATA,
})

// subscribe once authenticated with the server
stream.on('authenticated', () => stream.subscribe(['AM.SPY']))

// listen for new aggregates
stream.on('aggregate_minute', (aggregate) => {
  console.log(aggregate)
})

Contribute

Pull requests are encouraged. 😁

FAQs

Package last updated on 10 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc