mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-04-14 15:08:00 +03:00
Add new methods to PriceFeed class to get statistics
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import fetchWithValidation from '../../fetchWithValidation';
|
import fetchWithValidation from '../../fetchWithValidation';
|
||||||
|
import { statisticsOverviewSchema, topPairsStatisticsSchema } from './schemas';
|
||||||
import candlesSchema from './schemas/candlesSchema';
|
import candlesSchema from './schemas/candlesSchema';
|
||||||
import { PriceFeedWS } from './ws';
|
import { PriceFeedWS } from './ws';
|
||||||
|
|
||||||
@@ -12,6 +13,8 @@ class PriceFeed {
|
|||||||
this.ws = new PriceFeedWS(this.wsUrl);
|
this.ws = new PriceFeedWS(this.wsUrl);
|
||||||
|
|
||||||
this.getCandles = this.getCandles.bind(this);
|
this.getCandles = this.getCandles.bind(this);
|
||||||
|
this.getStatisticsOverview = this.getStatisticsOverview.bind(this);
|
||||||
|
this.getTopPairStatistics = this.getTopPairStatistics.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCandles = (
|
getCandles = (
|
||||||
@@ -28,12 +31,23 @@ class PriceFeed {
|
|||||||
url.searchParams.append('interval', interval);
|
url.searchParams.append('interval', interval);
|
||||||
url.searchParams.append('exchange', exchange);
|
url.searchParams.append('exchange', exchange);
|
||||||
|
|
||||||
return fetchWithValidation(
|
return fetchWithValidation(url.toString(), candlesSchema);
|
||||||
url.toString(),
|
|
||||||
candlesSchema,
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getStatisticsOverview(exchange = 'ALL') {
|
||||||
|
const url = new URL(`${this.statisticsUrl}/overview`);
|
||||||
|
url.searchParams.append('exchange', exchange);
|
||||||
|
|
||||||
|
return fetchWithValidation(url.toString(), statisticsOverviewSchema);
|
||||||
|
}
|
||||||
|
|
||||||
|
getTopPairStatistics(exchange = 'ALL') {
|
||||||
|
const url = new URL(`${this.statisticsUrl}/top-pairs`);
|
||||||
|
url.searchParams.append('exchange', exchange);
|
||||||
|
|
||||||
|
return fetchWithValidation(url.toString(), topPairsStatisticsSchema);
|
||||||
|
}
|
||||||
|
|
||||||
get wsUrl() {
|
get wsUrl() {
|
||||||
const url = new URL(this.apiUrl);
|
const url = new URL(this.apiUrl);
|
||||||
const wsProtocol = url.protocol === 'https:' ? 'wss' : 'ws';
|
const wsProtocol = url.protocol === 'https:' ? 'wss' : 'ws';
|
||||||
@@ -43,10 +57,12 @@ class PriceFeed {
|
|||||||
get candlesUrl() {
|
get candlesUrl() {
|
||||||
return `${this.apiUrl}/api/v1/candles`;
|
return `${this.apiUrl}/api/v1/candles`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get statisticsUrl() {
|
||||||
|
return `${this.apiUrl}/api/v1/statistics`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export * as schemas from './schemas';
|
export * as schemas from './schemas';
|
||||||
|
|
||||||
export {
|
export { PriceFeed };
|
||||||
PriceFeed,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1 +1,5 @@
|
|||||||
export { default as candlesSchema } from './candlesSchema';
|
export { default as candlesSchema } from './candlesSchema';
|
||||||
|
export {
|
||||||
|
statisticsOverviewSchema,
|
||||||
|
topPairsStatisticsSchema,
|
||||||
|
} from './statisticsSchema';
|
||||||
|
|||||||
21
src/services/PriceFeed/schemas/statisticsSchema.ts
Normal file
21
src/services/PriceFeed/schemas/statisticsSchema.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
const statisticsOverview = z.object({
|
||||||
|
volume24h: z.number(),
|
||||||
|
volume7d: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const statisticsOverviewSchema = z.object({
|
||||||
|
time: z.number(),
|
||||||
|
statisticsOverview,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const topPairsStatisticsSchema = z.object({
|
||||||
|
time: z.number(),
|
||||||
|
topPairs: z.array(
|
||||||
|
z.object({
|
||||||
|
assetPair: z.string(),
|
||||||
|
statisticsOverview,
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user