mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-22 21:59:44 +03:00
OP-2478 Add ws price feed candle subscription (#25)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@orionprotocol/sdk",
|
"name": "@orionprotocol/sdk",
|
||||||
"version": "0.15.6",
|
"version": "0.15.7-rc.0",
|
||||||
"description": "Orion Protocol SDK",
|
"description": "Orion Protocol SDK",
|
||||||
"main": "./lib/esm/index.js",
|
"main": "./lib/esm/index.js",
|
||||||
"module": "./lib/esm/index.js",
|
"module": "./lib/esm/index.js",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import WebSocket from 'isomorphic-ws';
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import priceFeedSubscriptions from './priceFeedSubscriptions';
|
import priceFeedSubscriptions from './priceFeedSubscriptions';
|
||||||
import { tickerInfoSchema } from './schemas';
|
import { tickerInfoSchema, candleSchema } from './schemas';
|
||||||
import priceSchema from './schemas/priceSchema';
|
import priceSchema from './schemas/priceSchema';
|
||||||
|
|
||||||
type TickerInfo = {
|
type TickerInfo = {
|
||||||
@@ -45,6 +45,10 @@ export const subscriptions = {
|
|||||||
schema: priceSchema,
|
schema: priceSchema,
|
||||||
payload: true as const,
|
payload: true as const,
|
||||||
},
|
},
|
||||||
|
[priceFeedSubscriptions.CANDLE]: {
|
||||||
|
schema: candleSchema,
|
||||||
|
payload: true as const,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export type SubscriptionType = keyof typeof subscriptions;
|
export type SubscriptionType = keyof typeof subscriptions;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const priceFeedSubscriptions = {
|
|||||||
TICKER: 'ticker',
|
TICKER: 'ticker',
|
||||||
ALL_TICKERS: 'allTickers',
|
ALL_TICKERS: 'allTickers',
|
||||||
LAST_PRICE: 'lastPrice',
|
LAST_PRICE: 'lastPrice',
|
||||||
|
CANDLE: 'candle',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export default priceFeedSubscriptions;
|
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 tickerInfoSchema } from './tickerInfoSchema';
|
||||||
|
export { default as candleSchema } from './candleSchema';
|
||||||
|
|||||||
Reference in New Issue
Block a user