diff --git a/package-lock.json b/package-lock.json index f7f2955..1d4e89e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index 4969549..ad77939 100644 --- a/src/services/PriceFeed/ws/PriceFeedSubscription.ts +++ b/src/services/PriceFeed/ws/PriceFeedSubscription.ts @@ -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; diff --git a/src/services/PriceFeed/ws/priceFeedSubscriptions.ts b/src/services/PriceFeed/ws/priceFeedSubscriptions.ts index 847700d..cdd7d88 100644 --- a/src/services/PriceFeed/ws/priceFeedSubscriptions.ts +++ b/src/services/PriceFeed/ws/priceFeedSubscriptions.ts @@ -3,6 +3,7 @@ const priceFeedSubscriptions = { ALL_TICKERS: 'allTickers', LAST_PRICE: 'lastPrice', CANDLE: 'candle', + CEX: 'cexPrices' } as const; export default priceFeedSubscriptions; diff --git a/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts new file mode 100644 index 0000000..a12dfa6 --- /dev/null +++ b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts @@ -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 + +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; \ No newline at end of file diff --git a/src/services/PriceFeed/ws/schemas/index.ts b/src/services/PriceFeed/ws/schemas/index.ts index 4ca9486..2e55e91 100644 --- a/src/services/PriceFeed/ws/schemas/index.ts +++ b/src/services/PriceFeed/ws/schemas/index.ts @@ -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';