Added new pairs type: futures

This commit is contained in:
Aleksandr Kraiz
2022-11-16 15:22:11 +04:00
parent a6300ec2c8
commit 0be703ddd1
3 changed files with 15 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@orionprotocol/sdk",
"version": "0.15.15",
"version": "0.16.0-rc.0",
"description": "Orion Protocol SDK",
"main": "./lib/esm/index.js",
"module": "./lib/esm/index.js",

View File

@@ -14,6 +14,7 @@ import { pairConfigSchema } from './schemas';
import {
aggregatedOrderbookSchema, exchangeOrderbookSchema,
} from './schemas/aggregatedOrderbookSchema';
import toUpperCase from '../../utils/toUpperCase';
class OrionAggregator {
private readonly apiUrl: string;
@@ -39,10 +40,15 @@ class OrionAggregator {
this.getExchangeOrderbook = this.getExchangeOrderbook.bind(this);
}
getPairsList = () => fetchWithValidation(
`${this.apiUrl}/api/v1/pairs/list`,
z.array(z.string()),
);
getPairsList = (market: 'spot' | 'futures') => {
const url = new URL(`${this.apiUrl}/api/v1/pairs/list`);
url.searchParams.append('market', toUpperCase(market));
return fetchWithValidation(
url.toString(),
z.array(z.string()),
);
};
getAggregatedOrderbook = (pair: string, depth = 20) => {
const url = new URL(`${this.apiUrl}/api/v1/orderbook`);

4
src/utils/toUpperCase.ts Normal file
View File

@@ -0,0 +1,4 @@
export default function toUpperCase<T extends string>(str: T): Uppercase<T> {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return str.toUpperCase() as Uppercase<T>;
}