SDKs
JavaScript/Typescript
User Methods
Market
Prices

Prices

Returns the current market prices for the symbols supported by the API. Prices are updated every 100ms.

The prices can be returned in either standard json or a compressed format. Note that the UID corresponds to the UID assigned to the brand or project you are requesting the prices for and is required in order to guarantee the correct spreads are returned.

Usage

import { MarketPrices } from '@tradrapi/trading-sdk';
 
const prices: MarketPrices[] = await tradrApi.markets.prices('UID', { format: 'json' });

Response

The response for market prices will depend on the format requested. In the case of json the response will be an array of MarketPrices objects.

interface MarketPrices {
  // The timestamp of the price in seconds UTC
  timestamp: number;
  // The symbol the price belongs to
  symbol: string;
  // The total bid volume in lots
  volume: number | null;
  // The bid price
  bid: number;
  // The bid direction, 1 indicating up, 0 indicating down
  bidDir: number;
  // The ask price
  ask: number;
  // The ask direction, 1 indicating up, 0 indicating down
  askDir: number;
  // The number of digits after the decimal point
  digits: number;
  // The applicable spread on the symbol
  spread: number | string;
}

In the case of compressed the response will be a string of pipe separated values:

ADAUSD|0.2568|0.2689|121|08:38:27
AVAUSD|9.93|10.15|22|08:37:01
AAPL|176.24|176.49|25|19:59:59
BATUSD|0.17279|0.173|21|08:37:49
DASHUSD|24.75|25.26|51|08:38:26
BA|217.13|217.43|30|20:00:00
USDTRY|26.49035|26.56446|7411|08:38:41
BCHUSD|189.57|192.19|262|08:38:45

In order to obtain a realtime stream of prices, we recommend the use of the TradrAPI socket to stream these prices to your application as they change. For more information on the socket, please see the socket documentation.