{"id":18843272,"url":"https://github.com/alpacahq/alpaca-trade-api-js","last_synced_at":"2025-05-14T11:10:46.891Z","repository":{"id":38455350,"uuid":"148262592","full_name":"alpacahq/alpaca-trade-api-js","owner":"alpacahq","description":"Node.js library for Alpaca Trade API.","archived":false,"fork":false,"pushed_at":"2025-01-16T09:25:46.000Z","size":815,"stargazers_count":537,"open_issues_count":42,"forks_count":139,"subscribers_count":46,"default_branch":"master","last_synced_at":"2025-04-12T18:47:32.654Z","etag":null,"topics":["api","hacktoberfest","javascript","trading"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@alpacahq/alpaca-trade-api","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alpacahq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-11T04:58:58.000Z","updated_at":"2025-04-09T00:36:10.000Z","dependencies_parsed_at":"2024-08-26T09:44:08.894Z","dependency_job_id":"860ca77f-b9bf-49eb-986b-9450644b1cbc","html_url":"https://github.com/alpacahq/alpaca-trade-api-js","commit_stats":{"total_commits":315,"total_committers":39,"mean_commits":8.076923076923077,"dds":0.8222222222222222,"last_synced_commit":"b08f46d0a86ef4036968c2229a98cd61f69202c0"},"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Falpaca-trade-api-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Falpaca-trade-api-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Falpaca-trade-api-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alpacahq%2Falpaca-trade-api-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alpacahq","download_url":"https://codeload.github.com/alpacahq/alpaca-trade-api-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254129489,"owners_count":22019628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","hacktoberfest","javascript","trading"],"created_at":"2024-11-08T02:57:23.431Z","updated_at":"2025-05-14T11:10:46.853Z","avatar_url":"https://github.com/alpacahq.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Alpaca Trade API JS\n\n[![npm version](https://img.shields.io/npm/v/@alpacahq/alpaca-trade-api.svg)](https://www.npmjs.com/package/@alpacahq/alpaca-trade-api)\n[![CircleCI](https://circleci.com/gh/alpacahq/alpaca-trade-api-js.svg?style=shield)](https://circleci.com/gh/alpacahq/alpaca-trade-api-js)\n\nNode.js library for Alpaca Trade API.\n\n## API Documentation\n\nThe REST API documentation can be found in https://docs.alpaca.markets. For detailed information about an endpoint, please consult the REST API docs. Documentation specific to this library can be found below.\n\n### News\n\nWe introduced Typescript support recently, which allows you to use strongly typed data structures and better IDE experience if you are using it.\n\n## Installation\n\n```sh\nnpm install --save @alpacahq/alpaca-trade-api\n```\n\n## Runtime Dependencies\n\n- Node.js v16.9 or newer\n- npm version 6 and above\n\n\n## Usage\n\nImport the module first.\n\n```js\nconst Alpaca = require('@alpacahq/alpaca-trade-api')\n```\n\nInstantiate the API with config options, obtained from the dashboard at app.alpaca.markets.\n\n```js\nconst alpaca = new Alpaca({\n  keyId: 'AKFZXJH121U18SHHDRFO',\n  secretKey: 'pnq4YHlpMF3LhfLyOvmdfLmlz6BnASrTPQIASeiU',\n  paper: true,\n})\n```\n\nNote: `keyId` and `secretKey` may also be specified by setting the `APCA_API_KEY_ID` and `APCA_API_SECRET_KEY` environment variables, respectively. Also, rather than specifying `paper`, you may set `APCA_API_BASE_URL` as an environment variable to direct your API calls to the paper trading API.\n\nCall methods, which will return a promise.\n\n```js\nalpaca.getAccount().then((account) =\u003e {\n  console.log('Current Account:', account)\n})\n```\n\nThe websocket api is a good way to watch and react to the market\nwe have 2 types of websockets:\n- data websocket: get updates to data equities\n- account/trade websocket: get updates on your account\n\nplease refer to this [example](https://github.com/alpacahq/alpaca-trade-api-js/blob/master/examples/websocket_example_datav2.js)\ncode to see how to use the websockets.\n\n##### Data WS\nThe Alapca websocket service now supports V2. Make sure you update your old sample code accordingly.\u003cbr\u003e\nYou could use it even if you don't have a funded account. \u003cbr\u003e\n\n\n## Methods\n\nAs a general rule, required method parameters are passed as plain function arguments, and the final parameter is an object containing any optional parameters to the method.\n\n### Account API\n\n#### Get Account\n\nCalls `GET /account` and returns the current account.\n\n```ts\ngetAccount() =\u003e Promise\u003cAccount\u003e\n```\n\n### Account Configurations API\n\n#### Get Account Configurations\n\nCalls `GET /account/configurations` and returns the current account configurations.\n\n```ts\ngetAccountConfigurations() =\u003e Promise\u003cAccountConfigurations\u003e\n```\n\n#### Update Account Configurations\n\nCalls `PATCH /account/configurations` to update the account configurations, and returns\nthe updated configurations.\n\n```ts\nupdateAccountConfigurations(AccountConfigurations) =\u003e Promise\u003cAccountConfigurations\u003e\n```\n\n#### Get Account Activities\n\nCalls `GET /account/activities` and returns account activities.\n\n```ts\ngetAccountActivities({\n  activityTypes: string | string[], // Any valid activity type\n  until: Date,\n  after: Date,\n  direction: string,\n  date: Date,\n  pageSize: number,\n  pageToken: string\n}) =\u003e Promise\u003cAccountActivity[]\u003e\n```\n\n### Portfolio History API\n\n#### Get Portfolio History\n\nCalls `GET /account/portfolio/history` and returns portfolio history.\n\n```ts\ngetPortfolioHistory({\n  date_start: Date,\n  date_end: Date,\n  period: '1M' | '3M' | '6M' | '1A' | 'all' | 'intraday',\n  timeframe: '1Min' | '5Min' | '15Min' | '1H' | '1D',\n  extended_hours: Boolean\n}) =\u003e Promise\u003cPortfolioHistory\u003e\n```\n\n### Orders API\n\n#### Create Order\n\nCalls `POST /orders` and creates a new order.\n\n```ts\ncreateOrder({\n  symbol: string, // any valid ticker symbol\n  qty: number,\n  notional: number, // qty or notional required, not both\n  side: 'buy' | 'sell',\n  type: 'market' | 'limit' | 'stop' | 'stop_limit' | 'trailing_stop',\n  time_in_force: 'day' | 'gtc' | 'opg' | 'ioc',\n  limit_price: number, // optional,\n  stop_price: number, // optional,\n  client_order_id: string, // optional,\n  extended_hours: boolean, // optional,\n  order_class: string, // optional,\n  take_profit: object, // optional,\n  stop_loss: object, // optional,\n  trail_price: string, // optional,\n  trail_percent: string // optional,\n}) =\u003e Promise\u003cOrder\u003e\n```\n\n#### Get Orders\n\n  Calls `GET /orders` and returns a list of orders.\n\n```ts\ngetOrders({\n  status: 'open' | 'closed' | 'all',\n  after: Date,\n  until: Date,\n  limit: number,\n  direction: 'asc' | 'desc'\n}) =\u003e Promise\u003cOrder[]\u003e\n```\n\n#### Get Order by ID\n\nCalls `GET /orders/{id}` and returns an order.\n\n```ts\ngetOrder(uuid) =\u003e Promise\u003cOrder\u003e\n```\n\n#### Get Order by Client ID\n\nCalls `GET /orders:by_client_order_id` and returns an order by `client_order_id`.\nYou can set `client_order_id` upon order creation to more easily keep track of your orders.\n\n```ts\ngetOrderByClientOrderId(string) =\u003e Promise\u003cOrder\u003e\n```\n\n#### Update Order by ID\n\nCalls `PATCH /orders/{id}` and updates an existing open order. The updated order will have\na new ID.\n\n```ts\nreplaceOrder(uuid) =\u003e Promise\u003cOrder\u003e\n```\n\n#### Cancel Order\n\nCalls `DELETE /orders/{id}` and deletes an order.\n\n```ts\ncancelOrder(uuid) =\u003e Promise\n```\n\n#### Cancel all Orders\n\nCalls `DELETE /orders` and deletes all open orders.\n\n```ts\ncancelAllOrders() =\u003e Promise\n```\n\n### Positions API\n\n#### Get Position\n\nCalls `GET /positions/{symbol}` and returns a position.\n\n```ts\ngetPosition(symbol) =\u003e Promise\u003cPosition\u003e\n```\n\n#### Get All Positions\n\nCalls `GET /positions` and returns all positions.\n\n```ts\ngetPositions() =\u003e Promise\u003cPosition[]\u003e\n```\n\n#### Close a Position\nCalls `DELETE /positions/{symbol}` and liquidates your position in the given symbol.\n\n```ts\nclosePosition(symbol) =\u003e Promise\n```\n\n#### Close all Positions\nCalls `DELETE /positions` and liquidates all open positions.\n\n```ts\ncloseAllPositions() =\u003e Promise\n```\n\n### Assets API\n\n#### Get All Assets\n\nCalls `GET /assets` and returns assets matching your parameters.\n\n```ts\ngetAssets({\n  status: 'active' | 'inactive',\n  asset_class: string\n}) =\u003e Promise\u003cAsset[]\u003e\n```\n\n#### Get information about an asset\n\nCalls `GET /assets/{symbol}` and returns an asset entity.\n\n```ts\ngetAsset(symbol) =\u003e Promise\u003cAsset\u003e\n```\n\n### Calendar API\n\nCalls `GET /calendar` and returns the market calendar.\n\n```ts\ngetCalendar({ start: Date, end: Date }) =\u003e Promise\u003cCalendar[]\u003e\n```\n\n### Clock API\n\nCalls `GET /clock` and returns the market clock.\n\n```ts\ngetClock() =\u003e Promise\u003cClock\u003e\n```\n\n### Watchlist API\navailable methods for you to use:\n\n```js\nmodule.exports = {\n    getWatchlists,\n    getWatchlist,\n    addWatchlist,\n    addToWatchlist,\n    updateWatchlist,\n    deleteWatchlist,\n    deleteFromWatchlist,\n}\n```\n\n#### Get All Watchlists\n```js\nalpaca.getWatchlists().then((response) =\u003e {\n  console.log(response)\n})\n```\n\n#### Get Specific Watchlist\n```js\n // xxxx.. are the watchlist id you get on creation or with get all\n alpaca.getWatchlist('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx').then((response) =\u003e {\n   console.log(response)\n })\n```\n\n#### Add a Watchlist\n```js\nalpaca.addWatchlist(\"myWatchList\", []).then((response) =\u003e {\n  console.log(response)\n})\n```\n#### Add to Watchlist\n\n```js\nalpaca.addToWatchlist('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', \"AAPL\").then((response) =\u003e {\n  console.log(response)\n})\n```\n#### Update a Watchlist\n```js\nalpaca.updateWatchlist(\"myWatchList\", [\"AAPL\", \"GOOG\"]).then((response) =\u003e {\n  console.log(response)\n})\n```\n#### Delete a Watchlist\n```js\nalpaca.deleteWatchlist('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx').then((response) =\u003e {\n  console.log(response)\n})\n```\n\n#### Delete from Watchlist\n```js\nalpaca.deleteFromWatchlist('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', \"AAPL\").then((response) =\u003e {\n  console.log(response)\n})\n```\n\n### Data API - Stocks\n\n#### Trades\n```ts\ngetTradesV2(\n  symbol: string,\n  options: GetTradesParams,\n  config?: any,\n): AsyncGenerator\u003cAlpacaTrade, void, unknown\u003e;\n```\n```ts\ngetMultiTradesV2(\n  symbols: Array\u003cstring\u003e,\n  options: GetTradesParams,\n  config?: any,\n): Promise\u003cMap\u003cstring, AlpacaTrade[]\u003e\u003e;\n```\n```ts\ngetMultiTradesAsyncV2(\n  symbols: Array\u003cstring\u003e,\n  options: GetTradesParams,\n  config?: any,\n): AsyncGenerator\u003cAlpacaTrade, void, unknown\u003e;\n```\n```ts\ngetLatestTrade(\n  symbol: string,\n  config?: any,\n): Promise\u003cAlpacaTrade\u003e;\n```\n```ts\ngetLatestTrades(\n  symbols: Array\u003cstring\u003e,\n  config?: any,\n): Promise\u003cMap\u003cstring, AlpacaTrade\u003e\u003e;\n```\n##### Example\n```ts\nconst trade = await alpaca.getLatestTrade('AAPL');\nconsole.log(trade);\n```\n###### Output:\n```python\n{\n  Timestamp: '2022-04-14T13:54:24.907840256Z',\n  Exchange: 'P',\n  Price: 169.33,\n  Size: 100,\n  Conditions: [ '@' ],\n  ID: 12272,\n  Tape: 'C'\n}\n```\n\n#### Quotes\n```ts\ngetQuotesV2(\n  symbol: string,\n  options: GetQuotesParams,\n  config?: any,\n): AsyncGenerator\u003cAlpacaQuote, void, unknown\u003e;\n```\n```ts\ngetMultiQuotesV2(\n  symbols: Array\u003cstring\u003e,\n  options: GetQuotesParams,\n  config?: any,\n): Promise\u003cMap\u003cstring, AlpacaQuote[]\u003e\u003e;\n```\n```ts\ngetMultiQuotesAsyncV2(\n  symbols: Array\u003cstring\u003e,\n  options: GetQuotesParams,\n  config?: any,\n): AsyncGenerator\u003cAlpacaQuote, void, unknown\u003e;\n```\n```ts\n getLatestQuote(\n   symbol: string,\n   config?: any,\n): Promise\u003cAlpacaQuote\u003e;\n```\n```ts\ngetLatestQuotes(\n   symbols: Array\u003cstring\u003e,\n   config?: any,\n): Promise\u003cMap\u003cstring, AlpacaQuote\u003e\u003e;\n```\n##### Example\n```ts\nconst trades = await alpaca.getMultiTradesV2([\"PFE\", \"SPY\"], {\n  start: \"2022-04-18T08:30:00Z\",\n  end: \"2022-04-18T08:31:00Z\",\n  limit: 2,\n});\nconsole.log(trades);\n```\n###### Output:\n```ruby\n{\n  'PFE' =\u003e [\n    {\n      Timestamp: '2022-04-18T08:30:59.988642304Z',\n      Exchange: 'P',\n      Price: 53.25,\n      Size: 5,\n      Conditions: [Array],\n      ID: 52983525028174,\n      Tape: 'A',\n      Symbol: 'PFE'\n    }\n  ],\n  'SPY' =\u003e [\n    {\n      Timestamp: '2022-04-18T08:30:00.066013952Z',\n      Exchange: 'P',\n      Price: 436.39,\n      Size: 1,\n      Conditions: [Array],\n      ID: 52983525028949,\n      Tape: 'B',\n      Symbol: 'SPY'\n    }\n  ]\n}\n```\n\n##### Bars\n```ts\n getBarsV2(\n   symbol: string,\n   options: GetBarsParams,\n   config?: any,\n ): AsyncGenerator\u003cAlpacaBar, void, unknown\u003e;\n```\n```ts\ngetMultiBarsV2(\n  symbols: Array\u003cstring\u003e,\n  options: GetBarsParams,\n  config?: any,\n): Promise\u003cMap\u003cstring, AlpacaBar[]\u003e\u003e;\n```\n```ts\n getMultiBarsAsyncV2(\n   symbols: Array\u003cstring\u003e,\n   options: GetBarsParams,\n   config?: any,\n ): AsyncGenerator\u003cAlpacaBar, void, unknown\u003e;\n```\n```ts\n getLatestBar(\n  symbol: string,\n  config?: any,\n): Promise\u003cAlpacaBar\u003e;\n```\n```ts\ngetLatestBars(\n  symbols: Array\u003cstring\u003e,\n  config?: any,\n): Promise\u003cMap\u003cstring, AlpacaBar\u003e\u003e;\n```\n##### Example\n```ts\nconst bars = alpaca.getBarsV2(\"AAPL\", {\n  start: \"2022-04-01\",\n  end: \"2022-04-02\",\n  timeframe: alpaca.newTimeframe(30, alpaca.timeframeUnit.MIN),\n  limit: 2,\n});\nconst got = [];\nfor await (let b of bars) {\n  got.push(b);\n}\nconsole.log(got);\n```\n###### Output:\n```python\n[\n  {\n    Timestamp: '2022-04-01T08:00:00Z',\n    OpenPrice: 175.25,\n    HighPrice: 175.88,\n    LowPrice: 175.1,\n    ClosePrice: 175.35,\n    Volume: 30015,\n    TradeCount: 721,\n    VWAP: 175.357657\n  },\n  {\n    Timestamp: '2022-04-01T08:30:00Z',\n    OpenPrice: 175.32,\n    HighPrice: 175.37,\n    LowPrice: 175.26,\n    ClosePrice: 175.26,\n    Volume: 5929,\n    TradeCount: 123,\n    VWAP: 175.332243\n  }\n]\n```\n\n##### Snapshots\n```ts\ngetSnapshot(\n  symbol: string,\n  config?: any,\n): Promise\u003cAlpacaSnapshot\u003e;\n```\n```ts\ngetSnapshots(\n  symbols: Array\u003cstring\u003e,\n  config?: any,\n): Promise\u003cAlpacaSnapshot[]\u003e;\n```\n##### Example\n```ts\nconst snapshot = await alpaca.getSnapshot(\"TSLA\");\nconsole.log(snapshot);\n```\n###### Output:\n```python\n{\n  symbol: 'TSLA',\n  LatestTrade: {\n    Timestamp: '2022-04-19T10:09:23.844940801Z',\n    Exchange: 'Q',\n    Price: 1003,\n    Size: 501,\n    Conditions: [ '@', 'F', 'T' ],\n    ID: 1861,\n    Tape: 'C'\n  },\n  LatestQuote: {\n    Timestamp: '2022-04-19T10:10:09.139921353Z',\n    AskExchange: 'Q',\n    AskPrice: 1004.38,\n    AskSize: 1,\n    BidExchange: 'Q',\n    BidPrice: 1001,\n    BidSize: 3,\n    Conditions: [ 'R' ],\n    Tape: 'C'\n  },\n  MinuteBar: {\n    Timestamp: '2022-04-19T10:09:00Z',\n    OpenPrice: 1003,\n    HighPrice: 1003,\n    LowPrice: 1003,\n    ClosePrice: 1003,\n    Volume: 647,\n    TradeCount: 17,\n    VWAP: 1003.071345\n  },\n  DailyBar: {\n    Timestamp: '2022-04-18T04:00:00Z',\n    OpenPrice: 989.19,\n    HighPrice: 1014.92,\n    LowPrice: 973.41,\n    ClosePrice: 1004.29,\n    Volume: 17209682,\n    TradeCount: 543314,\n    VWAP: 997.42604\n  },\n  PrevDailyBar: {\n    Timestamp: '2022-04-14T04:00:00Z',\n    OpenPrice: 998.51,\n    HighPrice: 1012.7099,\n    LowPrice: 982.19,\n    ClosePrice: 985,\n    Volume: 19449944,\n    TradeCount: 579328,\n    VWAP: 991.712944\n  }\n}\n```\nMore detailed examples of stock data endpoints can be found in this [file](https://github.com/alpacahq/alpaca-trade-api-js/blob/master/examples/marketdataV2.ts).\n\n##### News\n```ts\n getNews(\n   options: GetNewsParams,\n   config?: any,\n ): Promise\u003cAlpacaNews[]\u003e;\n```\nDetails of the `options` parameter can be found [here](https://github.com/alpacahq/alpaca-trade-api-js/blob/687e58c8ff03cc70b56fc57844d78ca7801e0f85/lib/resources/datav2/rest_v2.ts#L714).\n##### Example\n```ts\n const news = await alpaca.getNews({});\n console.log(news[0]);\n```\n###### Output:\n```python\n{\n  ID: 26682466,\n  Headline: 'Plug Power Enters Agreement With Walmart Pursuant To Which The Co. Will Deliver Liquid Green Hydrogen To New And Existing Walmart Sites In The United States',\n  Author: 'Bill Haddad',\n  CreatedAt: '2022-04-19T10:09:38Z',\n  UpdatedAt: '2022-04-19T10:09:39Z',\n  Summary: '',\n  URL: 'https://www.benzinga.com/news/22/04/26682466/plug-power-enters-agreement-with-walmart-pursuant-to-which-the-co-will-deliver-liquid-green-hydrogen',\n  Images: [],\n  Symbols: [ 'PLUG', 'WMT' ],\n  Source: 'benzinga'\n}\n```\n### Data API - Crypto\nAll the functions are similar to the stock ones.\n#### Trades\n* ```ts\n    getCryptoTrades(\n      symbols: Array\u003cstring\u003e,\n      options: GetCryptoTradesParams,\n      config?: any,\n    ): AsyncGenerator\u003cCryptoTrade, void, unknown\u003e;\n  ```\n* ```ts\n    getLatestCryptoTrades(\n      symbols: Array\u003cstring\u003e,\n      config?: any\n    ): Promise\u003cMap\u003cstring, CryptoTrade\u003e\u003e;\n  ```\n\n#### Quotes\n* ```ts\n    getCryptoQuotes(\n      symbols: Array\u003cstring\u003e,\n      options: GetCryptoQuotesParams,\n      config?: any,\n    ): AsyncGenerator\u003cCryptoQuote, void, unknown\u003e;\n  ```\n* ```ts\n   getLatestCryptoQuotes(\n    symbols: Array\u003cstring\u003e,\n    config?: any,\n  ): Promise\u003cMap\u003cstring, CryptoQuote\u003e\u003e;\n  ```\n\n#### Bars\n* ```ts\n     getCryptoBars(\n      symbols: Array\u003cstring\u003e,\n      options: GetCryptoBarsParams,\n      config?: any,\n    ): AsyncGenerator\u003cCryptoBar, void, unknown\u003e;\n  ```\n* ```ts\n    getLatestCryptoBars(\n      symbols: Array\u003cstring\u003e,\n      config?: any,\n    ): Promise\u003cMap\u003cstring, CryptoBar\u003e\u003e;\n  ```\n\n#### Snapshots\n* ```ts\n    getCryptoSnapshots(\n      symbol: Array\u003cstring\u003e,\n      config?: any,\n    ): Promise\u003cCryptoSnapshot\u003e;\n  ```\n\n### Data API - Options\n#### Bars\n* ```ts\n    getOptionBars(\n      symbols: Array\u003cstring\u003e,\n      options: GetOptionBarsParams,\n      config?: any,\n    ): Promise\u003cMap\u003cstring, AlpacaOptionBar[]\u003e\u003e;\n  ```\n#### Trades\n* ```ts\n    getOptionTrades(\n      symbols: Array\u003cstring\u003e,\n      options: GetOptionTradesParams,\n      config = any,\n    ): Promise\u003cMap\u003cstring, AlpacaOptionTrade[]\u003e\u003e;\n  ```\n* ```ts\n    getOptionLatestTrades(\n      symbols: Array\u003cstring\u003e,\n      config = any,\n    ): Promise\u003cMap\u003cstring, AlpacaOptionTrade\u003e\u003e;\n  ```\n#### Quotes\n* ```ts\n   getOptionLatestQuotes(\n     symbols: Array\u003cstring\u003e,\n     config = any,\n   ): Promise\u003cMap\u003cstring, AlpacaOptionQuote\u003e\u003e;\n  ```\n#### Snapshots\n* ```ts\n    getOptionSnapshots(\n      symbols: Array\u003cstring\u003e,\n      config = any,\n    ): Promise\u003cAlpacaOptionSnapshot[]\u003e;\n  ```\n* ```ts\n    getOptionChain(\n      underlyingSymbols: string,\n      options: GetOptionChainParams,\n      config = any,\n    ): Promise\u003cAlpacaOptionSnapshot[]\u003e;\n  ```\n\n### Data API - Corporate Actions\n* ```ts\n    getCorporateActions(\n      symbols: Array\u003cstring\u003e,\n      options: GetCorporateActionParams,\n      config = any\n    ): Promise\u003cCorporateActions | undefined\u003e;\n  ```\n\n### Websockets\nYou can use data websocket with or without a funded account.\n#### Working with websocket\n```ts\nconst websocket = alpaca.data_stream_v2;\nwebsocket.onConnect(() =\u003e {\n  websocket.subscribeForTrades([\"AAPL\"]);\n});\nwebsocket.onStateChange((status) =\u003e {\n  console.log(\"Status:\", status);\n});\nwebsocket.onError((err) =\u003e {\n  console.log(\"Error:\", err);\n});\nwebsocket.onStockTrade((trade) =\u003e {\n  console.log(\"Trade:\", trade);\n});\nwebsocket.connect();\n```\n###### Output:\n```python\nStatus: connecting\nStatus: authenticating\nStatus: connected\nStatus: authenticated\nTrade:  {\n  T: 't',\n  Symbol: 'AAPL',\n  ID: 68,\n  Exchange: 'V',\n  Price: 165.02,\n  Size: 50,\n  Conditions: [ '@', 'T', 'I' ],\n  Tape: 'C',\n  Timestamp: 2022-04-19T12:50:29.214Z\n}\n```\n* The websocket is created when you first create the Alpaca instance\n* `const websocket = alpaca.data_stream_v2`: Get the websocket client instance.\n* `websocket.connect()`: Connect to the Alpaca server using websocket.\n* `websocket.onConnect(() =\u003e {})`: all the following code will be executed after\n  the user authentication. You can also subscribe and unsubscribe for data\n  outside this function.\n* `websocket.subscribeForTrades([\"AAPL\"])`: Subscribe for trades data for the\n  given symbol(s). You can do the same with quotes, bars, dailyBars, updatedBars, statuses and lulds.\n* `websocket.onStockTrade((trade) =\u003e {})`: Get the data by subscribing for the trade data event\n  in JS/TS and process it inside this function.\n* `websocket.unsubscribeFromTrades([\"symbol\"])`: Unsubscribe from symbol(s).\n* `websocket.onDisconnect(() =\u003e {})` and `websocket.disconnect()`: the function\n  inside the `onDisconnect` will run when you disconnect then closes the connection\n  between the client and server.\n\u003cbr\u003e\u003cbr\u003e\nWebsocket client for real-time crypto and news data work the same. For a detailed example please take a look\nat this [file](https://github.com/alpacahq/alpaca-trade-api-js/blob/master/examples/websocket_example_datav2.js).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpacahq%2Falpaca-trade-api-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falpacahq%2Falpaca-trade-api-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falpacahq%2Falpaca-trade-api-js/lists"}