@hyperix/hooks 0.1.13 → 0.1.15

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 CHANGED
@@ -1,9 +1,13 @@
1
+ export * from "./use-all-mids.js";
1
2
  export * from "./use-l2-book.js";
3
+ export * from "./use-all-dexs-clearing-house-state.js";
2
4
  export * from "./use-historical-orders.js";
3
5
  export * from "./use-open-orders.js";
4
6
  export * from "./use-trade-history.js";
5
7
  export * from "./use-trades.js";
6
8
  export * from "./use-order-history.js";
9
+ export * from "./use-positions.js";
10
+ export * from "./use-symbol-converter.js";
7
11
  export * from "./use-user-fundings.js";
8
12
  export * from "./use-user-fills.js";
9
13
  export * from "./use-user-non-funding-ledger-updates.js";
package/dist/index.js CHANGED
@@ -1,9 +1,13 @@
1
+ export * from "./use-all-mids.js";
1
2
  export * from "./use-l2-book.js";
3
+ export * from "./use-all-dexs-clearing-house-state.js";
2
4
  export * from "./use-historical-orders.js";
3
5
  export * from "./use-open-orders.js";
4
6
  export * from "./use-trade-history.js";
5
7
  export * from "./use-trades.js";
6
8
  export * from "./use-order-history.js";
9
+ export * from "./use-positions.js";
10
+ export * from "./use-symbol-converter.js";
7
11
  export * from "./use-user-fundings.js";
8
12
  export * from "./use-user-fills.js";
9
13
  export * from "./use-user-non-funding-ledger-updates.js";
@@ -0,0 +1,8 @@
1
+ import { type UseSubscribeState } from "@outofgas/react-stream";
2
+ import type { AllDexsClearinghouseStateEvent } from "@nktkas/hyperliquid/api/subscription";
3
+ export type AllDexsClearingHouseStateData = AllDexsClearinghouseStateEvent;
4
+ export type UseAllDexsClearingHouseStateOptions = {
5
+ enabled?: boolean;
6
+ onUpdate?: (event: AllDexsClearinghouseStateEvent) => void;
7
+ };
8
+ export declare function useAllDexsClearingHouseState(user: `0x${string}`, options?: UseAllDexsClearingHouseStateOptions): UseSubscribeState<AllDexsClearingHouseStateData>;
@@ -0,0 +1,26 @@
1
+ import { useSubscribe } from "@outofgas/react-stream";
2
+ import { wsClient } from "./config/hl.js";
3
+ export function useAllDexsClearingHouseState(user, options = {}) {
4
+ const { enabled: enabledOverride, onUpdate } = options;
5
+ const enabled = enabledOverride ?? Boolean(user);
6
+ return useSubscribe({
7
+ key: ["all-dexs-clearing-house-state", user],
8
+ enabled,
9
+ subscribe: async ({ onData, onError }) => {
10
+ const subscription = await wsClient.allDexsClearinghouseState({ user }, (event) => {
11
+ try {
12
+ onUpdate?.(event);
13
+ onData(event);
14
+ }
15
+ catch (error) {
16
+ onError(error instanceof Error
17
+ ? error
18
+ : new Error("Failed to process all dexs clearing house state event"));
19
+ }
20
+ });
21
+ return {
22
+ unsubscribe: () => subscription.unsubscribe(),
23
+ };
24
+ },
25
+ });
26
+ }
@@ -0,0 +1,8 @@
1
+ import { type UseSubscribeState } from "@outofgas/react-stream";
2
+ import type { AllMidsEvent } from "@nktkas/hyperliquid/api/subscription";
3
+ export type AllMidsData = AllMidsEvent;
4
+ export type UseAllMidsOptions = {
5
+ enabled?: boolean;
6
+ onUpdate?: (event: AllMidsEvent) => void;
7
+ };
8
+ export declare function useAllMids(options?: UseAllMidsOptions): UseSubscribeState<AllMidsData>;
@@ -0,0 +1,25 @@
1
+ import { useSubscribe } from "@outofgas/react-stream";
2
+ import { wsClient } from "./config/hl.js";
3
+ export function useAllMids(options = {}) {
4
+ const { enabled = true, onUpdate } = options;
5
+ return useSubscribe({
6
+ key: ["all-mids"],
7
+ enabled,
8
+ subscribe: async ({ onData, onError }) => {
9
+ const subscription = await wsClient.allMids((event) => {
10
+ try {
11
+ onUpdate?.(event);
12
+ onData(event);
13
+ }
14
+ catch (error) {
15
+ onError(error instanceof Error
16
+ ? error
17
+ : new Error("Failed to process all mids event"));
18
+ }
19
+ });
20
+ return {
21
+ unsubscribe: () => subscription.unsubscribe(),
22
+ };
23
+ },
24
+ });
25
+ }
@@ -0,0 +1,4 @@
1
+ import type { UseSubscribeState } from "@outofgas/react-stream";
2
+ import { type AllDexsClearingHouseStateData, type UseAllDexsClearingHouseStateOptions } from "./use-all-dexs-clearing-house-state.js";
3
+ export type Position = AllDexsClearingHouseStateData["clearinghouseStates"][number][1]["assetPositions"][number];
4
+ export declare function usePositions(user: `0x${string}`, options?: UseAllDexsClearingHouseStateOptions): UseSubscribeState<Position[]>;
@@ -0,0 +1,15 @@
1
+ import { useMemo } from "react";
2
+ import { useAllDexsClearingHouseState, } from "./use-all-dexs-clearing-house-state.js";
3
+ export function usePositions(user, options = {}) {
4
+ const positionsState = useAllDexsClearingHouseState(user, options);
5
+ const data = useMemo(() => {
6
+ return positionsState.data?.clearinghouseStates
7
+ .map(([, state]) => state.assetPositions)
8
+ .flatMap((positions) => positions)
9
+ .sort((left, right) => Number(left.position.positionValue) < Number(right.position.positionValue) ? 1 : -1);
10
+ }, [positionsState.data]);
11
+ return {
12
+ ...positionsState,
13
+ data,
14
+ };
15
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperix/hooks",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",