Candlestick data, prices, order books, position books for market analysis.
Get candlestick data for an instrument.
candles(
instrument: string,
queryParams: {
price?: 'M' | 'B' | 'A' | 'BA' | 'MBA';
granularity?: string;
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[] }
Example:
ctx.instrument.candles('EUR_USD', {
price: 'M',
granularity: 'H1',
count: 100
}, (response) => {
if (response.isSuccess()) {
response.body.candles.forEach(candle => {
if (candle.complete) {
console.log(candle.time, candle.mid.c);
}
});
}
});Get current price snapshot.
price(
instrument: string,
queryParams: { time?: string },
responseHandler: (response: Response) => void
): void;Response: { price: Price }
Get historical price range.
prices(
instrument: string,
queryParams: { from: string; to: string },
responseHandler: (response: Response) => void
): void;Response: { prices: Price[] }
Get order book snapshot.
orderBook(
instrument: string,
queryParams: { time?: string },
responseHandler: (response: Response) => void
): void;Response: { orderBook: OrderBook }
Example:
ctx.instrument.orderBook('EUR_USD', {}, (response) => {
if (response.isSuccess()) {
const book = response.body.orderBook;
book.buckets.forEach(bucket => {
console.log(bucket.price, bucket.longCountPercent, bucket.shortCountPercent);
});
}
});Get position book snapshot.
positionBook(
instrument: string,
queryParams: { time?: string },
responseHandler: (response: Response) => void
): void;Response: { positionBook: PositionBook }
interface Candlestick {
time: string;
bid?: CandlestickData;
ask?: CandlestickData;
mid?: CandlestickData;
volume: number;
complete: boolean;
}
interface CandlestickData {
o: string;
h: string;
l: string;
c: string;
}interface OrderBook {
instrument: string;
time: string;
price: string;
bucketWidth: string;
buckets: OrderBookBucket[];
}
interface OrderBookBucket {
price: string;
longCountPercent: string;
shortCountPercent: string;
}interface PositionBook {
instrument: string;
time: string;
price: string;
bucketWidth: string;
buckets: PositionBookBucket[];
}
interface PositionBookBucket {
price: string;
longCountPercent: string;
shortCountPercent: string;
}Complete instrument specification.
interface Instrument {
name: string;
type: string;
displayName: string;
pipLocation: number;
displayPrecision: number;
tradeUnitsPrecision: number;
minimumTradeSize: string;
maximumTrailingStopDistance: string;
minimumTrailingStopDistance: string;
maximumPositionSize: string;
maximumOrderUnits: string;
marginRate: string;
commission: InstrumentCommission;
guaranteedStopLossOrderMode?: string;
guaranteedStopLossOrderExecutionPremium?: string;
guaranteedStopLossOrderLevelRestriction?: GuaranteedStopLossOrderLevelRestriction;
}interface InstrumentCommission {
commission: string;
unitsTraded: string;
minimumCommission: string;
}interface GuaranteedStopLossOrderLevelRestriction {
volume: string;
priceRange: string;
}ctx.instrument.candles('EUR_USD', { granularity: 'H1', count: 100 }, (response) => {
if (response.isSuccess()) {
console.log('Candles:', response.body.candles.length);
} else if (response.isClientError()) {
console.error('Client error:', response.body.errorCode, response.body.errorMessage);
}
});