UNPKG

@master-chief/alpaca-ts

Version:

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

129 lines 5.16 kB
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 Trade data for multiple crypto symbols * The Multi Trades API provides historical trade data for a list of given crypto symbols on a specified date. Returns trades for the queried crypto symbols. * * 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 getCryptoTrades = (httpRequest, { symbols, start, end, exchanges, limit, pageToken, }) => customBase(httpRequest).request({ method: "GET", url: "/v1beta3/crypto/us/trades", query: { start: start, end: end, exchanges: exchanges, limit: limit, page_token: pageToken, symbols: symbols, }, }); /** * Get Latest Trade data for multiple Crypto symbols * Provides latest trade data for a list of given crypto symbols. * @returns LatestMultiTradesResponse OK * @throws ApiError */ export const getCryptoTradesLatest = (httpRequest, { symbols, exchange, }) => customBase(httpRequest).request({ method: "GET", url: "/v1beta3/crypto/us/trades/latest", query: { symbols, exchange, }, }); /** * Get Bars for multiple Crypto symbols * returns aggregate historical data for the requested crypto symbols. * * 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 getCryptoBars = (httpRequest, { symbols, timeframe, start, end, pageToken, limit, exchanges, }) => customBase(httpRequest).request({ method: "GET", url: "/v1beta3/crypto/us/bars", query: { symbols: symbols, start: start, end: end, timeframe: timeframe, page_token: pageToken, limit: limit, exchanges: exchanges, }, }); /** * Get Latest Bars for multiple Crypto symbols * returns latest historical data for the requested crypto symbols for a specific exchange * @returns LatestMultiBarsResponse OK * @throws ApiError */ export const getCryptoBarsLatest = (httpRequest, { symbols, }) => customBase(httpRequest).request({ method: "GET", url: "/v1beta3/crypto/us/latest/bars", query: { symbols }, }); /** * Get Quotes for multiple crypto symbols * The Multi Quotes API provides quotes for a list of given crypto symbols at a specified date. Returns quotes for each of the queried crypto symbols. * * 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 getCryptoQuotes = (httpRequest, { symbols, start, end, exchanges, limit, pageToken, }) => customBase(httpRequest).request({ method: "GET", url: "/v1beta3/crypto/us/quotes", query: { start: start, end: end, exchanges: exchanges, limit: limit, page_token: pageToken, symbols: symbols, }, }); /** * Get Latest Quotes for multiple Crypto symbols * Provides latest quotes for a list of given crypto symbols. * @returns LatestMultiQuotesResponse OK * @throws ApiError */ export const getCryptoQuotesLatest = (httpRequest, { symbols, exchange, }) => customBase(httpRequest).request({ method: "GET", url: "/v1beta3/crypto/us/latest/quotes", query: { symbols: symbols, exchange: exchange, }, }); /** * Get Snapshots for multiple crypto symbols * The Multi Snapshot API returns the latest trade, latest quote, minute bar daily bar, and previous daily bar data for list of given crypto symbols. * @returns MultiSnapshotResponse Successful response * @throws ApiError */ export const getCryptoSnapshots = (httpRequest, { exchange, symbols, }) => customBase(httpRequest).request({ method: "GET", url: "/v1beta3/crypto/us/snapshots", query: { exchange: exchange, symbols: symbols, }, }); //# sourceMappingURL=crypto.js.map