@hyperix/hooks 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +11 -1
- package/dist/index.js +30 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,11 +7,21 @@ type L2Book = {
|
|
|
7
7
|
bids: L2BookLevel[];
|
|
8
8
|
asks: L2BookLevel[];
|
|
9
9
|
maxCumulativeSize: number;
|
|
10
|
+
levels: {
|
|
11
|
+
nSigFigs: number;
|
|
12
|
+
tick: string;
|
|
13
|
+
}[];
|
|
14
|
+
spread: number;
|
|
15
|
+
spreadPercent: number;
|
|
10
16
|
};
|
|
11
17
|
type UseL2BookOptions = {
|
|
12
18
|
depth?: number;
|
|
13
19
|
nSigFigs?: number;
|
|
14
20
|
};
|
|
21
|
+
declare function calcOrderbookLevels(price: number): {
|
|
22
|
+
nSigFigs: number;
|
|
23
|
+
tick: string;
|
|
24
|
+
}[];
|
|
15
25
|
declare const useL2Book: (coin: string, options?: UseL2BookOptions) => _outofgas_react_stream.UseSubscribeState<L2Book>;
|
|
16
26
|
|
|
17
|
-
export { type L2Book, type L2BookLevel, type UseL2BookOptions, useDebouncedValue, useL2Book };
|
|
27
|
+
export { type L2Book, type L2BookLevel, type UseL2BookOptions, calcOrderbookLevels, useDebouncedValue, useL2Book };
|
package/dist/index.js
CHANGED
|
@@ -2197,7 +2197,26 @@ var wsTransport = new WebSocketTransport();
|
|
|
2197
2197
|
var wsClient = new SubscriptionClient({ transport: wsTransport });
|
|
2198
2198
|
|
|
2199
2199
|
// src/use-l2-book.ts
|
|
2200
|
-
var EMPTY_L2_BOOK = {
|
|
2200
|
+
var EMPTY_L2_BOOK = {
|
|
2201
|
+
bids: [],
|
|
2202
|
+
asks: [],
|
|
2203
|
+
maxCumulativeSize: 0,
|
|
2204
|
+
levels: [],
|
|
2205
|
+
spread: 0,
|
|
2206
|
+
spreadPercent: 0
|
|
2207
|
+
};
|
|
2208
|
+
var HL_NSIGFIGS = [5, 4, 3, 2];
|
|
2209
|
+
function calcOrderbookLevels(price) {
|
|
2210
|
+
if (!price || price <= 0) return [];
|
|
2211
|
+
const magnitude = Math.floor(Math.log10(price));
|
|
2212
|
+
return HL_NSIGFIGS.map((nSigFigs) => {
|
|
2213
|
+
const tick = new decimal_default(10).pow(magnitude - nSigFigs + 1).toFixed();
|
|
2214
|
+
return {
|
|
2215
|
+
nSigFigs,
|
|
2216
|
+
tick
|
|
2217
|
+
};
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2201
2220
|
function withCumulativeSize(levels, depth) {
|
|
2202
2221
|
let cumulativeSize = new decimal_default(0);
|
|
2203
2222
|
const slicedLevels = depth === void 0 ? levels : levels.slice(0, depth);
|
|
@@ -2217,10 +2236,18 @@ function formatL2Book(levels, depth) {
|
|
|
2217
2236
|
...formattedAsks.map(([, , cumulativeSize]) => cumulativeSize),
|
|
2218
2237
|
0
|
|
2219
2238
|
);
|
|
2239
|
+
const ask1 = formattedAsks?.length > 0 ? formattedAsks[0][0] : 1;
|
|
2240
|
+
const bid1 = formattedBids?.length > 0 ? formattedBids[0][0] : 1;
|
|
2241
|
+
const midPrice = new decimal_default(ask1).plus(bid1).div(2).toNumber();
|
|
2242
|
+
const spread = new decimal_default(ask1).minus(bid1).toNumber();
|
|
2243
|
+
const spreadPercent = new decimal_default(spread).div(midPrice).toNumber();
|
|
2220
2244
|
return {
|
|
2221
2245
|
bids: formattedBids,
|
|
2222
2246
|
asks: formattedAsks,
|
|
2223
|
-
maxCumulativeSize
|
|
2247
|
+
maxCumulativeSize,
|
|
2248
|
+
levels: calcOrderbookLevels(midPrice),
|
|
2249
|
+
spread,
|
|
2250
|
+
spreadPercent
|
|
2224
2251
|
};
|
|
2225
2252
|
}
|
|
2226
2253
|
var useL2Book = (coin, options = {}) => {
|
|
@@ -2240,6 +2267,7 @@ var useL2Book = (coin, options = {}) => {
|
|
|
2240
2267
|
});
|
|
2241
2268
|
};
|
|
2242
2269
|
export {
|
|
2270
|
+
calcOrderbookLevels,
|
|
2243
2271
|
useDebouncedValue,
|
|
2244
2272
|
useL2Book
|
|
2245
2273
|
};
|