OP-2478 Add ws price feed candle subscription (#25)

This commit is contained in:
Dmitry
2022-09-09 13:40:31 +03:00
committed by GitHub
parent 050a719e08
commit fdefe21954
5 changed files with 37 additions and 2 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -2,6 +2,7 @@ const priceFeedSubscriptions = {
TICKER: 'ticker',
ALL_TICKERS: 'allTickers',
LAST_PRICE: 'lastPrice',
CANDLE: 'candle',
} as const;
export default priceFeedSubscriptions;

View File

@@ -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;

View File

@@ -1 +1,2 @@
export { default as tickerInfoSchema } from './tickerInfoSchema';
export { default as candleSchema } from './candleSchema';