Real-time and historical price data, streaming, candlesticks, conversion factors.
Get non-account-specific base prices.
basePrices(
queryParams: { instruments?: string },
responseHandler: (response: Response) => void
): void;Response: { prices: Price[] }
Get historical price range.
getPriceRange(
instrument: string,
queryParams: { from: string; to: string },
responseHandler: (response: Response) => void
): void;Response: { prices: Price[] }
Get current account-specific prices.
get(
accountID: string,
queryParams: {
instruments: string;
since?: string;
includeUnitsAvailable?: boolean;
includeHomeConversions?: boolean;
},
responseHandler: (response: Response) => void
): void;Response: { prices: ClientPrice[], homeConversions?: HomeConversions[], time: string }
Stream real-time price updates.
stream(
accountID: string,
queryParams: {
instruments: string;
snapshot?: boolean;
},
streamChunkHandler: (chunk: ClientPrice | PricingHeartbeat) => void,
responseHandler: (response: Response) => void
): void;Example:
ctx.pricing.stream(accountID, { instruments: 'EUR_USD', snapshot: true },
(chunk) => {
if (chunk.type === 'HEARTBEAT') {
console.log('Heartbeat:', chunk.time);
} else if (chunk.type === 'PRICE') {
console.log(chunk.instrument, chunk.bids[0].price, chunk.asks[0].price);
}
},
(response) => {
if (response.isError()) {
console.error('Stream error:', response.statusMessage);
}
}
);Get candlestick (OHLC) data.
candles(
accountID: string,
instrument: string,
queryParams: {
price?: 'M' | 'B' | 'A' | 'BA' | 'MBA';
granularity?: string; // S5, M1, H1, D, etc.
count?: number; // max 5000
from?: string;
to?: string;
smooth?: boolean;
includeFirst?: boolean;
dailyAlignment?: number;
alignmentTimezone?: string;
weeklyAlignment?: string;
},
responseHandler: (response: Response) => void
): void;Response: { instrument: string, granularity: string, candles: Candlestick[] }
Granularity Options:
S5, S10, S15, S30M1, M2, M4, M5, M10, M15, M30H1, H2, H3, H4, H6, H8, H12DWMAccount-specific price quote.
class ClientPrice extends Definition {
type: 'PRICE';
instrument: string;
time: string;
status: string;
tradeable: boolean;
bids: PriceBucket[];
asks: PriceBucket[];
closeoutBid: string;
closeoutAsk: string;
quoteHomeConversionFactors?: QuoteHomeConversionFactors;
unitsAvailable?: UnitsAvailable;
}Basic price quote (non-account-specific).
class Price extends Definition {
instrument: string;
tradeable: boolean;
timestamp: string;
baseBid: string;
baseAsk: string;
bids: PriceBucket[];
asks: PriceBucket[];
closeoutBid: string;
closeoutAsk: string;
}Price point with liquidity.
class PriceBucket extends Definition {
price: string;
liquidity: number;
}Conversion factors from quote to home currency.
class QuoteHomeConversionFactors extends Definition {
positiveUnits: string; // For long positions
negativeUnits: string; // For short positions
}Account-level conversion factors.
class HomeConversions extends Definition {
currency: string;
accountGain: string;
accountLoss: string;
positionValue: string;
}Heartbeat message in pricing stream.
class PricingHeartbeat extends Definition {
type: 'HEARTBEAT';
time: string;
}OHLC candlestick data.
interface Candlestick {
time: string;
bid?: CandlestickData;
ask?: CandlestickData;
mid?: CandlestickData;
volume: number;
complete: boolean;
}
interface CandlestickData {
o: string; // Open
h: string; // High
l: string; // Low
c: string; // Close
}ctx.pricing.get(accountID, { instruments: 'EUR_USD' }, (response) => {
if (response.isSuccess()) {
const price = response.body.prices[0];
if (price.tradeable && price.bids.length > 0) {
console.log('Bid:', price.bids[0].price);
}
} else if (response.isClientError()) {
console.error('Client error:', response.body.errorMessage);
}
});