From d602a64561f81e2bbf538c3f28a095acf7b69171 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Tue, 25 Jul 2023 17:31:37 +0300 Subject: [PATCH] get all tickers --- package.json | 2 +- src/services/PriceFeed/index.ts | 15 ++++++++++++++- .../PriceFeed/schemas/allTickersSchema.ts | 10 ++++++++++ src/services/PriceFeed/schemas/index.ts | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src/services/PriceFeed/schemas/allTickersSchema.ts diff --git a/package.json b/package.json index 3af0a35..f9ed326 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/services/PriceFeed/index.ts b/src/services/PriceFeed/index.ts index 5eb0c1a..f2253c3 100644 --- a/src/services/PriceFeed/index.ts +++ b/src/services/PriceFeed/index.ts @@ -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'; diff --git a/src/services/PriceFeed/schemas/allTickersSchema.ts b/src/services/PriceFeed/schemas/allTickersSchema.ts new file mode 100644 index 0000000..40c56b6 --- /dev/null +++ b/src/services/PriceFeed/schemas/allTickersSchema.ts @@ -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(); diff --git a/src/services/PriceFeed/schemas/index.ts b/src/services/PriceFeed/schemas/index.ts index 42837d7..fb38a26 100644 --- a/src/services/PriceFeed/schemas/index.ts +++ b/src/services/PriceFeed/schemas/index.ts @@ -3,3 +3,4 @@ export { statisticsOverviewSchema, topPairsStatisticsSchema, } from './statisticsSchema.js'; +export { allTickersSchema } from './allTickersSchema.js';