From 4a20b90db0afa158ff687c2a1af35f6832468d4e Mon Sep 17 00:00:00 2001 From: lambdagit Date: Tue, 5 Sep 2023 09:56:45 +0300 Subject: [PATCH 1/4] cexPrices in PF --- .../PriceFeed/ws/PriceFeedSubscription.ts | 6 +++- .../PriceFeed/ws/priceFeedSubscriptions.ts | 1 + .../PriceFeed/ws/schemas/cexPricesSchema.ts | 31 +++++++++++++++++++ src/services/PriceFeed/ws/schemas/index.ts | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 src/services/PriceFeed/ws/schemas/cexPricesSchema.ts 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..8a895cb --- /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.string(), // 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'; From 24cd59dc26fd121db2af489e486a17ec4dfdd14b Mon Sep 17 00:00:00 2001 From: lambdagit Date: Tue, 5 Sep 2023 11:16:01 +0300 Subject: [PATCH 2/4] rc-ver (0.19.80-rc) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 217796d..2bf33bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.79", + "version": "0.19.80-rc", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", From 9ac991ec6c63613896f712c921471d57d532282e Mon Sep 17 00:00:00 2001 From: lambdagit Date: Tue, 5 Sep 2023 16:23:14 +0300 Subject: [PATCH 3/4] fix cexPrices schema & ver up --- package.json | 2 +- src/services/PriceFeed/ws/schemas/cexPricesSchema.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2bf33bb..2606b86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.19.80-rc", + "version": "0.19.80-rc1", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js", diff --git a/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts index 8a895cb..a12dfa6 100644 --- a/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts +++ b/src/services/PriceFeed/ws/schemas/cexPricesSchema.ts @@ -2,7 +2,7 @@ import { z } from 'zod'; const cexPriceTickerInfoSchema = z.tuple([ z.string(), // pair name - z.string(), // lastPrice + z.number(), // lastPrice ]).transform(([pairName, lastPrice]) => ({ pairName:pairName.toUpperCase(), lastPrice, From 982998ea9b99ba33f9b906386793790ef2d71685 Mon Sep 17 00:00:00 2001 From: Kirill Litvinov Date: Thu, 7 Mar 2024 16:18:28 +0300 Subject: [PATCH 4/4] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 55fdb08..a16dee8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.64", + "version": "0.20.66", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@orionprotocol/sdk", - "version": "0.20.64", + "version": "0.20.66", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/package.json b/package.json index c092461..e4f1a72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.20.66-rc1", + "version": "0.20.66", "description": "Orion Protocol SDK", "main": "./lib/index.cjs", "module": "./lib/index.js",