Merge branch 'main' into pmm

This commit is contained in:
kigastu
2024-03-11 15:50:05 +03:00
committed by GitHub
5 changed files with 40 additions and 3 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@orionprotocol/sdk",
"version": "0.20.66-rc",
"version": "0.20.66-rc2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@orionprotocol/sdk",
"version": "0.20.66-rc",
"version": "0.20.66-rc2",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {

View File

@@ -2,7 +2,7 @@ import WebSocket from 'isomorphic-ws';
import { z } from 'zod';
import { v4 as uuidv4 } from 'uuid';
import priceFeedSubscriptions from './priceFeedSubscriptions.js';
import { tickerInfoSchema, candleSchema } from './schemas/index.js';
import { tickerInfoSchema, candleSchema, cexPricesSchema } from './schemas/index.js';
import priceSchema from './schemas/priceSchema.js';
import type { Json } from '../../../types.js';
import allTickersSchema from './schemas/allTickersSchema.js';
@@ -24,6 +24,10 @@ export const subscriptions = {
schema: candleSchema,
payload: true as const,
},
[priceFeedSubscriptions.CEX]: {
schema: cexPricesSchema,
payload: false as const,
},
};
export type SubscriptionType = keyof typeof subscriptions;

View File

@@ -3,6 +3,7 @@ const priceFeedSubscriptions = {
ALL_TICKERS: 'allTickers',
LAST_PRICE: 'lastPrice',
CANDLE: 'candle',
CEX: 'cexPrices'
} as const;
export default priceFeedSubscriptions;

View File

@@ -0,0 +1,31 @@
import { z } from 'zod';
const cexPriceTickerInfoSchema = z.tuple([
z.string(), // pair name
z.number(), // lastPrice
]).transform(([pairName, lastPrice]) => ({
pairName:pairName.toUpperCase(),
lastPrice,
}));
type CEXPriceTickerInfo = z.infer<typeof cexPriceTickerInfoSchema>
const cexPricesSchema = z.unknown().array()
.transform((tickers) => {
const data = [...tickers];
data.shift();
const parsedData = cexPriceTickerInfoSchema.array().parse(data);
return parsedData.reduce<
Partial<
Record<
string,
CEXPriceTickerInfo
>
>
>((prev, pairData) => ({
...prev,
[pairData.pairName]: pairData,
}), {});
});
export default cexPricesSchema;

View File

@@ -2,3 +2,4 @@ export { default as tickerInfoSchema } from './tickerInfoSchema.js';
export { default as candleSchema } from './candleSchema.js';
export { default as priceSchema } from './priceSchema.js';
export { default as allTickersSchema } from './allTickersSchema.js';
export { default as cexPricesSchema } from './cexPricesSchema.js';