@master-chief/alpaca-ts
Version:
A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.
182 lines • 6.71 kB
JavaScript
import { cloneDeep } from "lodash-es";
const BASE = "https://data.alpaca.markets";
// todo: this is a temporary hack
const customBase = (httpRequest) => {
const clonedRequest = cloneDeep(httpRequest);
clonedRequest.config.BASE = BASE;
return clonedRequest;
};
/**
* Get Bar data for multiple stock symbols
* The Multi Bars API returns aggregate historical data for multiple given ticker symbols over a specified time period.
*
* Returned results are sorted by symbol first then by Bar timestamp. This means that you are likely to see only one symbol in your first response if there are enough Bars for that symbol to hit the limit you requested on that request.
*
* In these situations if you keep requesting again with the next_page_token you will eventually reach the next symbols if any Bars were found for them.
* @returns MultiBarsResponse Successful response
* @throws ApiError
*/
export const getStockBars = (httpRequest, { symbols, timeframe, start, end, limit, pageToken, adjustment, feed, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/bars",
query: {
symbols: symbols,
start: start,
end: end,
timeframe: timeframe,
limit: limit,
page_token: pageToken,
adjustment: adjustment,
feed: feed,
},
});
};
/**
* Get Latest Bar data for multiple stock symbols
* The Bars API returns aggregate historical data for the requested security. Returns the latest bar data for the queried stock symbols.
* @returns LatestMultiBarsResponse OK
* @throws ApiError
*/
export const getStockBarsLatest = (httpRequest, { symbols, feed, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/bars/latest",
query: {
symbols: symbols,
feed: feed,
},
});
};
/**
* Get Trade data for multiple stock symbols
* The Multi Trades API provides historical trade data for multiple given ticker symbols over a specified time period.
*
* Returned results are sorted by symbol first then by Trade timestamp. This means that you are likely to see only one symbol in your first response if there are enough Trades for that symbol to hit the limit you requested on that request.
*
* In these situations if you keep requesting again with the next_page_token you will eventually reach the next symbols if any Trades were found for them.
* @returns MultiTradesResponse Successful response
* @throws ApiError
*/
export const getStockTrades = (httpRequest, { symbols, start, end, limit, pageToken, feed, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/trades",
query: {
symbols: symbols,
start: start,
end: end,
limit: limit,
page_token: pageToken,
feed: feed,
},
});
};
/**
* Get Latest Trades data for multiple stock symbols
* Returns the latest trades data for the queried stock symbols.
* @returns LatestMultiTradesResponse OK
* @throws ApiError
*/
export const getStockTradesLatest = (httpRequest, { symbols, feed, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/trades/latest",
query: {
symbols: symbols,
feed: feed,
},
});
};
/**
* Get Quotes for multiple stock symbols
* The Multi Quotes API provides NBBO quotes for multiple given ticker symbols over a specified time period.
*
* Returned results are sorted by symbol first then by Quote timestamp. This means that you are likely to see only one symbol in your first response if there are enough Quotes for that symbol to hit the limit you requested on that request.
*
* In these situations if you keep requesting again with the next_page_token you will eventually reach the next symbols if any Quotes were found for them.
* @returns MultiQuotesReponse Successful response
*
* @throws ApiError
*/
export const getStockQuotes = (httpRequest, { symbols, start, end, limit, pageToken, feed, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/quotes",
query: {
symbols: symbols,
start: start,
end: end,
limit: limit,
page_token: pageToken,
feed: feed,
},
});
};
/**
* Get Latest Quotes for multiple stock symbols
* Returns the latest quotes data for the queried stock symbols.
* @returns LatestMultiQuotesResponse OK
* @throws ApiError
*/
export const getStockQuotesLatest = (httpRequest, { symbols, feed, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/quotes/latest",
query: {
symbols: symbols,
feed: feed,
},
});
};
/**
* Get Snapshots for multiple stock symbols
* The Snapshot API for multiple tickers provides the latest trade, latest quote, minute bar daily bar and previous daily bar data for the given ticker symbols.
* @returns MultiSnapshotResponse Successful response
* @throws ApiError
*/
export const getStockSnapshots = (httpRequest, { symbols, feed, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/snapshots",
query: {
symbols: symbols,
feed: feed,
},
});
};
/**
* Get List of supported exchanges
* Returns a json object representing the exchanges we support. The keys are the short form codes you will see in our responses and the values are their respective full names.
* @returns ExchangesResponse OK
* @throws ApiError
*/
export const getStockMetaExchanges = (httpRequest) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/meta/exchanges",
});
};
/**
* Get list of Conditions
* Each feed/exchange uses its own set of codes to identify trade and quote conditions, so the same condition may have a different code depending on the originator of the data.
*
* See [Our documentation](https://alpaca.markets/docs/market-data/#conditions) for more information
* @returns any OK
*
* Response is a JSON object mapping a condition to a plain text description
* @throws ApiError
*/
export const getStockMetaConditions = (httpRequest, { type, tape, }) => {
return customBase(httpRequest).request({
method: "GET",
url: "/v2/stocks/meta/conditions/{type}",
path: {
type: type,
},
query: {
tape: tape,
},
});
};
//# sourceMappingURL=stock.js.map