JS Library for Waves data services
Usage
const DataServiceClient = require('@waves/data-service-client-js').default;
const client = new DataServiceClient({
rootUrl: 'http://api.wavesplatform.com/v0',
fetch: req => window.fetch(req).then(res => res.text()),
parse: str => JSON.parse(str),
});
(async () => {
const { data } = await client.getAssets('WAVES');
})();
Methods
Response format
{ data, ...meta }
All methods do GET requests, until query is under 2k symbols, then automatically switch to POST
await client.getAssets('WAVES');
await client.getAssets('WAVES', '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS');
await client.getAssetsByTicker('WAVES');
await client.getAssetsByTicker('*');
const getPairs = client.getPairs('MATCHER_ID');
await getPairs([
'WAVES/8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS',
'WAVES/474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu'
]);
await client.getExchangeTxs('8rEwYY4wQ4bkEkk95EiyeQnvnonX6TAnU6eiBAbVSADk');
await client.getExchangeTxs({
timeStart?: string | Date | number;
timeEnd?: string | Date | number;
matcher?: string;
sender?: string;
amountAsset?: string | Asset;
priceAsset?: string | Asset;
limit?: number;
sort?: 'asc'|'desc';
});
await client.getExchangeTxs();
const alias1 = await client.aliases.getById('@askerych');
const alias2 = await client.aliases.getByAddress(
'3P5uMgn1xvrm7g3sbUVAGLtetkNUa1AHn2M'
);
await client.getCandles(amountAsset: string, priceAsset: string, {
timeStart: string | Date | number;
timeEnd?: string | Date | number;
interval: string;
});
await client.getCandles('WAVES', '8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS', {
timeStart: '2018-12-01',
timeEnd: '2018-12-31',
interval: '1d'
});
type Response<T> = {
data: T;
fetchMore?: TFunction;
};
const response1 = await client.getExchangeTxs({ limit: 1, sort: 'asc' });
const data1 = response1.data;
const response2 = await res1.fetchMore(2);
Custom init params
You can set custom fetcher, parser and transformer for library.
type TLibOptions = {
rootUrl: string;
fetch?: TFunction;
parse?: TParser;
transform?: TFunction;
};
The path is fetch -> parse -> transform
Fetch must return string!
Fetch accepts (url, options)
Fetch by default is fetch(...).then(res => res.text())
Parse by default is JSON.parse.bind(JSON)
, you can use json-bigint
's parse if you want to add support for bignumbers.
Transform function has next signature by default (it depends on your parse function):
({
__type,
data,
...rest
}) => any
Basically you can switch on __type and do transformations.