mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
Add new methods to PriceFeed class to get statistics (#29)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@orionprotocol/sdk",
|
||||
"version": "0.15.18",
|
||||
"version": "0.15.19-rc.1",
|
||||
"description": "Orion Protocol SDK",
|
||||
"main": "./lib/esm/index.js",
|
||||
"module": "./lib/esm/index.js",
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import fetchWithValidation from '../../fetchWithValidation';
|
||||
import { Exchange } from '../../types';
|
||||
import { statisticsOverviewSchema, topPairsStatisticsSchema } from './schemas';
|
||||
import candlesSchema from './schemas/candlesSchema';
|
||||
import { PriceFeedWS } from './ws';
|
||||
|
||||
@@ -12,6 +14,8 @@ class PriceFeed {
|
||||
this.ws = new PriceFeedWS(this.wsUrl);
|
||||
|
||||
this.getCandles = this.getCandles.bind(this);
|
||||
this.getStatisticsOverview = this.getStatisticsOverview.bind(this);
|
||||
this.getTopPairStatistics = this.getTopPairStatistics.bind(this);
|
||||
}
|
||||
|
||||
getCandles = (
|
||||
@@ -19,7 +23,7 @@ class PriceFeed {
|
||||
timeStart: number,
|
||||
timeEnd: number,
|
||||
interval: '5m' | '30m' | '1h' | '1d',
|
||||
exchange = 'all',
|
||||
exchange = 'all'
|
||||
) => {
|
||||
const url = new URL(this.candlesUrl);
|
||||
url.searchParams.append('symbol', symbol);
|
||||
@@ -28,12 +32,23 @@ class PriceFeed {
|
||||
url.searchParams.append('interval', interval);
|
||||
url.searchParams.append('exchange', exchange);
|
||||
|
||||
return fetchWithValidation(
|
||||
url.toString(),
|
||||
candlesSchema,
|
||||
);
|
||||
return fetchWithValidation(url.toString(), candlesSchema);
|
||||
};
|
||||
|
||||
getStatisticsOverview(exchange: Exchange | 'ALL' = 'ALL') {
|
||||
const url = new URL(`${this.statisticsUrl}/overview`);
|
||||
url.searchParams.append('exchange', exchange);
|
||||
|
||||
return fetchWithValidation(url.toString(), statisticsOverviewSchema);
|
||||
}
|
||||
|
||||
getTopPairStatistics(exchange: Exchange | 'ALL' = 'ALL') {
|
||||
const url = new URL(`${this.statisticsUrl}/top-pairs`);
|
||||
url.searchParams.append('exchange', exchange);
|
||||
|
||||
return fetchWithValidation(url.toString(), topPairsStatisticsSchema);
|
||||
}
|
||||
|
||||
get wsUrl() {
|
||||
const url = new URL(this.apiUrl);
|
||||
const wsProtocol = url.protocol === 'https:' ? 'wss' : 'ws';
|
||||
@@ -43,10 +58,12 @@ class PriceFeed {
|
||||
get candlesUrl() {
|
||||
return `${this.apiUrl}/api/v1/candles`;
|
||||
}
|
||||
|
||||
get statisticsUrl() {
|
||||
return `${this.apiUrl}/api/v1/statistics`;
|
||||
}
|
||||
}
|
||||
|
||||
export * as schemas from './schemas';
|
||||
|
||||
export {
|
||||
PriceFeed,
|
||||
};
|
||||
export { PriceFeed };
|
||||
|
||||
@@ -1 +1,5 @@
|
||||
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