get all tickers

This commit is contained in:
Kirill Litvinov
2023-07-25 17:31:37 +03:00
parent 176f703104
commit d602a64561
4 changed files with 26 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.19.36",
"version": "0.19.37-rc1",
"description": "Orion Protocol SDK",
"main": "./lib/index.cjs",
"module": "./lib/index.js",

View File

@@ -1,6 +1,6 @@
import { fetchWithValidation } from 'simple-typed-fetch';
import type { BasicAuthCredentials, Exchange } from '../../types.js';
import { statisticsOverviewSchema, topPairsStatisticsSchema } from './schemas/index.js';
import { allTickersSchema, statisticsOverviewSchema, topPairsStatisticsSchema } from './schemas/index.js';
import candlesSchema from './schemas/candlesSchema.js';
import { PriceFeedWS } from './ws/index.js';
@@ -23,6 +23,7 @@ class PriceFeed {
this.getCandles = this.getCandles.bind(this);
this.getStatisticsOverview = this.getStatisticsOverview.bind(this);
this.getTopPairStatistics = this.getTopPairStatistics.bind(this);
this.getAllTickers = this.getAllTickers.bind(this);
}
get basicAuthHeaders() {
@@ -77,6 +78,14 @@ class PriceFeed {
);
}
getAllTickers = () => {
return fetchWithValidation(
`${this.tickersUrl}/all`,
allTickersSchema,
{ headers: this.basicAuthHeaders }
);
}
get wsUrl() {
const url = new URL(this.apiUrl);
const wsProtocol = url.protocol === 'https:' ? 'wss' : 'ws';
@@ -90,6 +99,10 @@ class PriceFeed {
get statisticsUrl() {
return `${this.apiUrl}/api/v1/statistics`;
}
get tickersUrl() {
return `${this.apiUrl}/api/v1/ticker`;
}
}
export * as schemas from './schemas/index.js';

View File

@@ -0,0 +1,10 @@
import { z } from 'zod'
const tickerSchema = z.object({
pair: z.string(),
volume24: z.number(),
change24: z.number(),
lastPrice: z.number(),
});
export const allTickersSchema = tickerSchema.array();

View File

@@ -3,3 +3,4 @@ export {
statisticsOverviewSchema,
topPairsStatisticsSchema,
} from './statisticsSchema.js';
export { allTickersSchema } from './allTickersSchema.js';