@hyperix/hooks 0.2.8 → 0.3.0
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/use-funding-history.d.ts +15 -0
- package/dist/use-funding-history.js +17 -0
- package/dist/use-trade-history.js +8 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./use-max-builder-fee.js";
|
|
|
8
8
|
export * from "./use-mid.js";
|
|
9
9
|
export * from "./use-all-dexs-clearing-house-state.js";
|
|
10
10
|
export * from "./use-balances.js";
|
|
11
|
+
export * from "./use-funding-history.js";
|
|
11
12
|
export * from "./use-historical-orders.js";
|
|
12
13
|
export * from "./use-open-orders.js";
|
|
13
14
|
export * from "./use-trade-history.js";
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./use-max-builder-fee.js";
|
|
|
8
8
|
export * from "./use-mid.js";
|
|
9
9
|
export * from "./use-all-dexs-clearing-house-state.js";
|
|
10
10
|
export * from "./use-balances.js";
|
|
11
|
+
export * from "./use-funding-history.js";
|
|
11
12
|
export * from "./use-historical-orders.js";
|
|
12
13
|
export * from "./use-open-orders.js";
|
|
13
14
|
export * from "./use-trade-history.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { FundingHistoryResponse } from "@nktkas/hyperliquid/api/info";
|
|
2
|
+
import { type UseQueryOptions, type UseQueryResult } from "@tanstack/react-query";
|
|
3
|
+
export type FundingHistory = FundingHistoryResponse[number];
|
|
4
|
+
export type FundingHistoryData = FundingHistory[];
|
|
5
|
+
type FundingHistoryQueryKey = [
|
|
6
|
+
"funding-history",
|
|
7
|
+
string,
|
|
8
|
+
number,
|
|
9
|
+
number | undefined
|
|
10
|
+
];
|
|
11
|
+
export type UseFundingHistoryOptions = Omit<UseQueryOptions<FundingHistoryData, Error, FundingHistoryData, FundingHistoryQueryKey>, "queryKey" | "queryFn"> & {
|
|
12
|
+
endTime?: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function useFundingHistory(coin: string, startTime: number, options?: UseFundingHistoryOptions): UseQueryResult<FundingHistoryData, Error>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useQuery, } from "@tanstack/react-query";
|
|
2
|
+
import { infoClient } from "./config/hl.js";
|
|
3
|
+
export function useFundingHistory(coin, startTime, options = {}) {
|
|
4
|
+
const { enabled: enabledOverride, endTime, ...queryOptions } = options;
|
|
5
|
+
const normalizedCoin = coin.trim();
|
|
6
|
+
const enabled = enabledOverride ?? Boolean(normalizedCoin && startTime >= 0);
|
|
7
|
+
return useQuery({
|
|
8
|
+
queryKey: ["funding-history", normalizedCoin, startTime, endTime],
|
|
9
|
+
queryFn: () => infoClient.fundingHistory({
|
|
10
|
+
coin: normalizedCoin,
|
|
11
|
+
startTime,
|
|
12
|
+
endTime,
|
|
13
|
+
}),
|
|
14
|
+
...queryOptions,
|
|
15
|
+
enabled,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -63,6 +63,13 @@ function mergeTradeHistoryFills(pages, realtimeFills) {
|
|
|
63
63
|
}
|
|
64
64
|
return sortTradeHistory([...fillsByKey.values()]);
|
|
65
65
|
}
|
|
66
|
+
function flattenTradeHistoryPages(pages) {
|
|
67
|
+
const fills = [];
|
|
68
|
+
for (const page of pages) {
|
|
69
|
+
fills.push(...page.fills);
|
|
70
|
+
}
|
|
71
|
+
return fills;
|
|
72
|
+
}
|
|
66
73
|
function getLatestPageFromFills(user, fills, fallbackEndTime, pageDurationMs) {
|
|
67
74
|
const endTime = fills[0]?.time ?? fallbackEndTime;
|
|
68
75
|
const startTime = Math.max(0, endTime - pageDurationMs);
|
|
@@ -107,7 +114,7 @@ export function useInfiniteTradeHistory(user, options = {}) {
|
|
|
107
114
|
const selectTradeHistoryData = useMemo(() => (data) => ({
|
|
108
115
|
pages: data.pages,
|
|
109
116
|
user,
|
|
110
|
-
fills:
|
|
117
|
+
fills: flattenTradeHistoryPages(data.pages),
|
|
111
118
|
}), [user]);
|
|
112
119
|
useUserFills(user, {
|
|
113
120
|
aggregateByTime,
|