mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-14 06:02:36 +03:00
Merge branch 'main' into pmm
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -3,6 +3,7 @@ const priceFeedSubscriptions = {
|
||||
ALL_TICKERS: 'allTickers',
|
||||
LAST_PRICE: 'lastPrice',
|
||||
CANDLE: 'candle',
|
||||
CEX: 'cexPrices'
|
||||
} as const;
|
||||
|
||||
export default priceFeedSubscriptions;
|
||||
|
||||
31
src/services/PriceFeed/ws/schemas/cexPricesSchema.ts
Normal file
31
src/services/PriceFeed/ws/schemas/cexPricesSchema.ts
Normal 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;
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user