import * as market_pb from './generated/market_pb'; import { DataMapper } from './Publisher'; import { Blockchain, ConvertCommon, Erc20Asset } from './typesCommon'; import { MessageFactory } from './typesConvert'; export type CryptoCurrency = 'BTC' | 'ETC' | 'ETH'; export type StablecoinCurrency = 'DAI' | 'USDT' | 'USDC'; export type CountryCurrency = 'USD' | 'EUR' | 'CAD' | 'GBP' | 'RUB' | 'JPY' | 'CHF' | 'CNY' | 'MXN' | 'BRL' | 'HKD' | 'KRW' | 'SGD' | 'INR'; export type TestCurrency = 'MONOPOLY' | 'KOVAN' | 'TEST_BTC' | 'TEST_BTC_V4' | 'SEPOLIA'; export type BaseCurrency = CryptoCurrency | StablecoinCurrency | CountryCurrency | TestCurrency; export type AnyCurrency = BaseCurrency | Erc20Asset; /** * Currency pair */ export type Pair = { base: AnyCurrency; target: AnyCurrency; }; /** * Request the rate at specified moment. */ export type GetRatesRequestAt = { /** * Request the rate at the specified moment. */ timestamp: number | Date; /** * The rates */ pairs: Pair[]; }; /** * Request the rate at the moment of the specified block. */ export type GetRatesRequestByBlock = { /** * Request the rate at the moment of the specified block. */ block: BlockRefAtHeight | BlockRefAtHash; /** * The rates */ pairs: Pair[]; }; /** * Reference to a block by its height. */ export type BlockRefAtHeight = { /** * The blockchain to which the block belongs. */ blockchain: Blockchain; /** * The height of the block. */ height: number; }; /** * Reference to a block by its hash. */ export type BlockRefAtHash = { /** * The blockchain to which the block belongs. */ blockchain: Blockchain; /** * The hash of the block. */ hash: string; }; /** * Request the latest available rate. * Note, there rates are averaged from multiple exchanges and it always a slight delay to fetch the trades. * Because of that, when requesting the latest rate, it may fluctuate a little between the requests. */ export type GetRatesRequestLatest = Pair[] | { pairs: Pair[]; }; /** * Request the rates. It can be either the latest available rates, or the rates at the specified moment (timestamp or block). */ export type GetRatesRequest = GetRatesRequestLatest | GetRatesRequestAt | GetRatesRequestByBlock; export type GetRateSeriesRequest = { /** The pair to get rate */ pair: Pair; /** * Granularity for the timestamp points in the response * Note that the timestamps in the response are aligned by the granularity, i.e., when asked with granularity of an Hour the response contains prices for HH:00:00 timestamp */ granularity: "SECOND" | "MINUTE" | "5_MINUTES" | "15_MINUTES" | "HOUR" | "DAY" | "WEEK"; /** * Start timestamp of the period to get rates for (inclusive) */ from: number | Date; /** * End timestamp of the period to get rates for (inclusive) */ to: number | Date; }; /** * Currency pair with the exchange rate. */ export type Rate = { base: AnyCurrency; target: AnyCurrency; /** * exchange rate decimal encoded as a string */ rate: string; /** * Timestamp of the moment when the rate was established. * It points to the moment when the last time one of the components of the pair was traded, which affected the rate. * It's assumed that if there were no trades between that moment, and the moment of the request then the rate is still valid. * I.e., it's the last known evidence of the rate. If multiple pairs requested, the timestamp of each pair may be different. */ timestamp?: Date; }; export type RateAt = { /** * exchange rate decimal encoded as a string */ rate: string; /** * Timestamp of the moment when the rate was established. * It points to the moment when the last time one of the components of the pair was traded, which affected the rate. * It's assumed that if there were no trades between that moment, and the moment of the request then the rate is still valid. * I.e., it's the last known evidence of the rate */ timestamp: Date; }; export type GetRatesResponse = Rate[]; export type GetRateSeriesResponse = { pair: Pair; rates: RateAt[]; }; export declare class ConvertMarket { private readonly factory; private common; constructor(factory: MessageFactory, common?: ConvertCommon); pair(pair: Pair): market_pb.Pair; pairResponse(rate: market_pb.Rate | market_pb.Pair): Pair; /** * Convert TypeScript type to Protobuf message * @param request */ ratesRequest(request: GetRatesRequest): market_pb.GetRatesRequest; /** * Convert Protobuf message to TypeScript type */ ratesResponse(): DataMapper; rateSeriesRequest(request: GetRateSeriesRequest): market_pb.GetRateSeriesRequest; rateSeriesResponse(): DataMapper; }