From fdefe2195474d5cd4c6a1bf15461f88e4f025530 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 9 Sep 2022 13:40:31 +0300 Subject: [PATCH] OP-2478 Add ws price feed candle subscription (#25) --- package.json | 2 +- .../PriceFeed/ws/PriceFeedSubscription.ts | 6 +++- .../PriceFeed/ws/priceFeedSubscriptions.ts | 1 + .../PriceFeed/ws/schemas/candleSchema.ts | 29 +++++++++++++++++++ src/services/PriceFeed/ws/schemas/index.ts | 1 + 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/services/PriceFeed/ws/schemas/candleSchema.ts diff --git a/package.json b/package.json index 63565d5..10b4f76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@orionprotocol/sdk", - "version": "0.15.6", + "version": "0.15.7-rc.0", "description": "Orion Protocol SDK", "main": "./lib/esm/index.js", "module": "./lib/esm/index.js", diff --git a/src/services/PriceFeed/ws/PriceFeedSubscription.ts b/src/services/PriceFeed/ws/PriceFeedSubscription.ts index 11574a5..795e318 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'; -import { tickerInfoSchema } from './schemas'; +import { tickerInfoSchema, candleSchema } from './schemas'; import priceSchema from './schemas/priceSchema'; type TickerInfo = { @@ -45,6 +45,10 @@ export const subscriptions = { schema: priceSchema, payload: true as const, }, + [priceFeedSubscriptions.CANDLE]: { + schema: candleSchema, + payload: true 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 9600d13..847700d 100644 --- a/src/services/PriceFeed/ws/priceFeedSubscriptions.ts +++ b/src/services/PriceFeed/ws/priceFeedSubscriptions.ts @@ -2,6 +2,7 @@ const priceFeedSubscriptions = { TICKER: 'ticker', ALL_TICKERS: 'allTickers', LAST_PRICE: 'lastPrice', + CANDLE: 'candle', } as const; export default priceFeedSubscriptions; diff --git a/src/services/PriceFeed/ws/schemas/candleSchema.ts b/src/services/PriceFeed/ws/schemas/candleSchema.ts new file mode 100644 index 0000000..f91ff0d --- /dev/null +++ b/src/services/PriceFeed/ws/schemas/candleSchema.ts @@ -0,0 +1,29 @@ +import { z } from 'zod'; + +const candleSchema = z + .tuple([ + z.string(), // interval [FIVE, FIFTEEN, THIRTY, HOUR, HOUR4, DAY, WEEK] + z.string(), // pair ["orn-usdt"] + z.number(), // timeStart [timestamp] + z.number(), // timeEnd [timestamp] + z.string(), // close + z.string(), // open + z.string(), // high + z.string(), // low + z.string(), // volume + ]) + .transform( + ([interval, pair, timeStart, timeEnd, close, open, high, low, volume]) => ({ + interval, + pair, + timeStart, + timeEnd, + close, + open, + high, + low, + volume, + }), + ); + +export default candleSchema; diff --git a/src/services/PriceFeed/ws/schemas/index.ts b/src/services/PriceFeed/ws/schemas/index.ts index e89a8b7..74329ef 100644 --- a/src/services/PriceFeed/ws/schemas/index.ts +++ b/src/services/PriceFeed/ws/schemas/index.ts @@ -1 +1,2 @@ export { default as tickerInfoSchema } from './tickerInfoSchema'; +export { default as candleSchema } from './candleSchema';