UNPKG

redstone-api

Version:

Javascript library for fetching trusted token pricing data from Redstone data ecosystem

108 lines (107 loc) 3.82 kB
import { ConvertableToDate, RedstoneApiConfigForQueryExec, PriceData } from "./types"; declare type QueryParams = { symbols: string[]; startDate?: ConvertableToDate; endDate?: ConvertableToDate; date?: ConvertableToDate; interval?: number; latest?: boolean; }; export declare class RedstoneQuery { protected params: QueryParams; constructor(params?: {}); /** * Sets a token symbol to fetch * @param symbol - Token symbol string * @returns query object */ symbol(symbol: string): RedstoneQueryForSingleSymbol; /** * Sets token symbols to fetch * @param symbols - Array of strings (token symbols) * @returns query object */ symbols(symbols: string[]): RedstoneQueryForSeveralSymbols; /** * Configures query to fetch prices for all supported tokens. * It doesn't support any params * @returns query object */ allSymbols(): RedstoneQueryForSeveralSymbols; } export declare class RedstoneQueryForSingleOrSeveralSymbols<QueryResultType> { protected params: QueryParams; constructor(params: QueryParams); protected getExecutableQuery<T>(update: any): RedstoneQueryExecutable<T>; /** * Configures query to fetch the latest price/prices * It doesn't support any params * @returns query object */ latest(): RedstoneQueryExecutable<QueryResultType>; /** * Configures query to fetch the price for X hours ago. * @param hoursCount - Number of hours ago * @returns query object */ hoursAgo(hoursCount: number): RedstoneQueryExecutable<QueryResultType>; /** * Configures query to fetch the price for a specific date. * @param date - Date for the historical price (date | timestamp | string) * @returns query object */ atDate(date: ConvertableToDate): RedstoneQueryExecutable<QueryResultType>; } export declare class RedstoneQueryForSingleSymbol extends RedstoneQueryForSingleOrSeveralSymbols<PriceData> { constructor(params: QueryParams); /** * Configures query to fetch the price in a time range. It is important to use fromDate with toDate query methods * @param date - Start date/time for the time range * * @returns query object */ fromDate(date: ConvertableToDate): RedstoneQueryForSingleSymbol; /** * Configures query to fetch the price in a time range. toDate method should go after the fromDate * @param date - End date/time for the time range * * @returns query object */ toDate(date: ConvertableToDate): RedstoneQueryExecutable<PriceData[]>; /** * Configures query to fetch the price for the last few hours * @param hoursCount - Number of hours in the time range * * @returns query object */ forLastHours(hoursCount: number): RedstoneQueryExecutable<PriceData[]>; /** * Configures query to fetch the price for the last few days * @param daysCount - Number of days in the time range * * @returns query object */ forLastDays(daysCount: number): RedstoneQueryExecutable<PriceData[]>; } export declare class RedstoneQueryForSeveralSymbols extends RedstoneQueryForSingleOrSeveralSymbols<{ [symbol: string]: PriceData; }> { constructor(params: QueryParams); } export declare class RedstoneQueryExecutable<QueryResultType> { private params; constructor(params?: {}); /** * Executes the query * * @returns Promise resolving the query result (result type depends on the query) */ exec(redstoneApiConfig?: RedstoneApiConfigForQueryExec): Promise<QueryResultType>; } /** * Initializes and returns an empty query. * It doesn't support any params * @returns query object */ declare const query: () => RedstoneQuery; export default query;