mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 14:42:38 +03:00
OP-2478 Add ws price feed candle subscription (#25)
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -2,6 +2,7 @@ const priceFeedSubscriptions = {
|
||||
TICKER: 'ticker',
|
||||
ALL_TICKERS: 'allTickers',
|
||||
LAST_PRICE: 'lastPrice',
|
||||
CANDLE: 'candle',
|
||||
} as const;
|
||||
|
||||
export default priceFeedSubscriptions;
|
||||
|
||||
29
src/services/PriceFeed/ws/schemas/candleSchema.ts
Normal file
29
src/services/PriceFeed/ws/schemas/candleSchema.ts
Normal 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;
|
||||
@@ -1 +1,2 @@
|
||||
export { default as tickerInfoSchema } from './tickerInfoSchema';
|
||||
export { default as candleSchema } from './candleSchema';
|
||||
|
||||
Reference in New Issue
Block a user