mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-22 21:59:44 +03:00
cexPrices in PF
This commit is contained in:
@@ -2,7 +2,7 @@ import WebSocket from 'isomorphic-ws';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import priceFeedSubscriptions from './priceFeedSubscriptions.js';
|
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 priceSchema from './schemas/priceSchema.js';
|
||||||
import type { Json } from '../../../types.js';
|
import type { Json } from '../../../types.js';
|
||||||
import allTickersSchema from './schemas/allTickersSchema.js';
|
import allTickersSchema from './schemas/allTickersSchema.js';
|
||||||
@@ -24,6 +24,10 @@ export const subscriptions = {
|
|||||||
schema: candleSchema,
|
schema: candleSchema,
|
||||||
payload: true as const,
|
payload: true as const,
|
||||||
},
|
},
|
||||||
|
[priceFeedSubscriptions.CEX]: {
|
||||||
|
schema: cexPricesSchema,
|
||||||
|
payload: false as const,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SubscriptionType = keyof typeof subscriptions;
|
export type SubscriptionType = keyof typeof subscriptions;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const priceFeedSubscriptions = {
|
|||||||
ALL_TICKERS: 'allTickers',
|
ALL_TICKERS: 'allTickers',
|
||||||
LAST_PRICE: 'lastPrice',
|
LAST_PRICE: 'lastPrice',
|
||||||
CANDLE: 'candle',
|
CANDLE: 'candle',
|
||||||
|
CEX: 'cexPrices'
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default priceFeedSubscriptions;
|
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.string(), // 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 candleSchema } from './candleSchema.js';
|
||||||
export { default as priceSchema } from './priceSchema.js';
|
export { default as priceSchema } from './priceSchema.js';
|
||||||
export { default as allTickersSchema } from './allTickersSchema.js';
|
export { default as allTickersSchema } from './allTickersSchema.js';
|
||||||
|
export { default as cexPricesSchema } from './cexPricesSchema.js';
|
||||||
|
|||||||
Reference in New Issue
Block a user