Skip to main content

Prices

Retrieve stock prices for any supported stock symbol.

Making Requests

Use the prices() method on the stocks resource to fetch stock prices. The method returns a MarketDataResult which resolves to decoded records by default. The output format is controlled by the outputFormat parameter (or MARKETDATA_OUTPUT_FORMAT env var):

Output FormatResult PayloadDescription
internal (default)StockPrice[] or StockPriceHuman[]Array of decoded price records, one per symbol.
jsonRaw JSON objectThe compressed, array-keyed response object as returned by the API.
csvBlobCSV payload. Use .save(filename) on the result to write it to disk.

prices

// Positional form
prices<P>(
symbols: string | string[],
params?: P,
): MarketDataResult<StockPrice[] | StockPriceHuman[]>

// Object form
prices<P>(
params: P & { symbols: string | string[] },
): MarketDataResult<StockPrice[] | StockPriceHuman[]>

Fetches stock prices for one or more symbols. The return type is narrowed automatically:

  • If human: true (or useHumanReadable: true) → payload is StockPriceHuman[]
  • If outputFormat: "csv" → payload is Blob
  • Otherwise → payload is StockPrice[]

Parameters

  • symbols (string | string[])

    A single symbol string or an array of symbol strings for which to fetch prices.

  • outputFormat (optional)

    The format of the returned data. See Settings for details. Also accepts the alias format.

  • dateFormat (optional)

    The date format to use in the response. Also accepts the alias dateformat. See Settings for details.

  • columns (optional)

    Specify which columns to include in the response. See Settings for details.

  • addHeaders (optional)

    Whether to include headers in CSV output. Also accepts the alias headers. See Settings for details.

  • useHumanReadable (optional)

    Whether to use human-readable field names. Also accepts the alias human. See Settings for details.

  • mode (optional)

    The data mode to use ("live", "cached", "delayed"). See Settings for details.

Returns

import { MarketDataClient } from "marketdata-sdk-js";

const client = new MarketDataClient();

const result = await client.stocks.prices("AAPL");

result.match(
(prices) => console.log(prices[0].mid),
(error) => console.error(error.message),
);

StockPrice

interface StockPrice {
s?: string;
symbol: string;
mid: number;
change: number;
changepct: number;
updated: number;
}

StockPrice represents a single stock price, with short machine-readable field names.

Properties

  • s (string, optional): Status indicator ("ok" for successful responses).
  • symbol (string): The stock symbol.
  • mid (number): The mid price calculated between the ask and bid.
  • change (number): The price change.
  • changepct (number): The fractional price change (e.g. 0.0124 for +1.24%).
  • updated (number): Unix timestamp when the price was last updated.

StockPriceHuman

interface StockPriceHuman {
s?: string;
Symbol: string;
Mid: number;
Change_Price: number;
Change_Percent: number;
Date: number;
}

StockPriceHuman represents a stock price in human-readable format with capitalized, snake-case field names. Returned when human: true (or useHumanReadable: true) is set.

Properties

  • Symbol (string): The stock symbol.
  • Mid (number): The mid price.
  • Change_Price (number): The price change.
  • Change_Percent (number): The percent change.
  • Date (number): Unix timestamp of the update.