@pear-protocol/hyperliquid-sdk 0.1.4 → 0.1.5
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 +33 -3
- package/dist/store/historicalPriceDataStore.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1068,6 +1068,7 @@ interface TokenHistoricalPriceData {
|
|
|
1068
1068
|
candles: CandleData[];
|
|
1069
1069
|
oldestTime: number | null;
|
|
1070
1070
|
latestTime: number | null;
|
|
1071
|
+
requestedRanges: HistoricalRange[];
|
|
1071
1072
|
}
|
|
1072
1073
|
interface HistoricalPriceDataState {
|
|
1073
1074
|
historicalPriceData: Record<string, TokenHistoricalPriceData>;
|
package/dist/index.js
CHANGED
|
@@ -1819,6 +1819,22 @@ const getIntervalSeconds = (interval) => {
|
|
|
1819
1819
|
default: return 60;
|
|
1820
1820
|
}
|
|
1821
1821
|
};
|
|
1822
|
+
/**
|
|
1823
|
+
* Merges overlapping or adjacent ranges to prevent unbounded growth
|
|
1824
|
+
*/
|
|
1825
|
+
const mergeRanges = (ranges, newRange) => {
|
|
1826
|
+
const all = [...ranges, newRange].sort((a, b) => a.start - b.start);
|
|
1827
|
+
const merged = [];
|
|
1828
|
+
for (const r of all) {
|
|
1829
|
+
if (merged.length === 0 || r.start > merged[merged.length - 1].end) {
|
|
1830
|
+
merged.push({ start: r.start, end: r.end });
|
|
1831
|
+
}
|
|
1832
|
+
else {
|
|
1833
|
+
merged[merged.length - 1].end = Math.max(merged[merged.length - 1].end, r.end);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
return merged;
|
|
1837
|
+
};
|
|
1822
1838
|
const useHistoricalPriceDataStore = create((set, get) => ({
|
|
1823
1839
|
historicalPriceData: {},
|
|
1824
1840
|
loadingTokens: new Set(),
|
|
@@ -1837,7 +1853,8 @@ const useHistoricalPriceDataStore = create((set, get) => ({
|
|
|
1837
1853
|
interval,
|
|
1838
1854
|
candles: sortedCandles,
|
|
1839
1855
|
oldestTime: sortedCandles.length > 0 ? sortedCandles[0].t : null,
|
|
1840
|
-
latestTime: sortedCandles.length > 0 ? sortedCandles[sortedCandles.length - 1].t : null
|
|
1856
|
+
latestTime: sortedCandles.length > 0 ? sortedCandles[sortedCandles.length - 1].t : null,
|
|
1857
|
+
requestedRanges: [range]
|
|
1841
1858
|
}
|
|
1842
1859
|
}
|
|
1843
1860
|
};
|
|
@@ -1849,6 +1866,8 @@ const useHistoricalPriceDataStore = create((set, get) => ({
|
|
|
1849
1866
|
// Update time pointers
|
|
1850
1867
|
const oldestTime = mergedCandles.length > 0 ? mergedCandles[0].t : null;
|
|
1851
1868
|
const latestTime = mergedCandles.length > 0 ? mergedCandles[mergedCandles.length - 1].t : null;
|
|
1869
|
+
// Merge requested ranges
|
|
1870
|
+
const mergedRanges = mergeRanges(existing.requestedRanges || [], range);
|
|
1852
1871
|
return {
|
|
1853
1872
|
historicalPriceData: {
|
|
1854
1873
|
...state.historicalPriceData,
|
|
@@ -1856,7 +1875,8 @@ const useHistoricalPriceDataStore = create((set, get) => ({
|
|
|
1856
1875
|
...existing,
|
|
1857
1876
|
candles: mergedCandles,
|
|
1858
1877
|
oldestTime,
|
|
1859
|
-
latestTime
|
|
1878
|
+
latestTime,
|
|
1879
|
+
requestedRanges: mergedRanges
|
|
1860
1880
|
}
|
|
1861
1881
|
}
|
|
1862
1882
|
};
|
|
@@ -1866,7 +1886,17 @@ const useHistoricalPriceDataStore = create((set, get) => ({
|
|
|
1866
1886
|
const { historicalPriceData } = get();
|
|
1867
1887
|
const key = createKey(symbol, interval);
|
|
1868
1888
|
const tokenData = historicalPriceData[key];
|
|
1869
|
-
if (!tokenData
|
|
1889
|
+
if (!tokenData)
|
|
1890
|
+
return false;
|
|
1891
|
+
// Check if we've already attempted to fetch this range (prevents infinite loops for tokens with no data)
|
|
1892
|
+
const requestedRanges = tokenData.requestedRanges || [];
|
|
1893
|
+
for (const range of requestedRanges) {
|
|
1894
|
+
if (range.start <= startTime && range.end >= endTime) {
|
|
1895
|
+
return true; // Already attempted this fetch
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
// Fallback: check actual data coverage
|
|
1899
|
+
if (tokenData.oldestTime === null || tokenData.latestTime === null)
|
|
1870
1900
|
return false;
|
|
1871
1901
|
const intervalMilisecond = getIntervalSeconds(interval) * 1000;
|
|
1872
1902
|
const hasStartCoverage = tokenData.oldestTime <= startTime;
|
|
@@ -9,6 +9,7 @@ interface TokenHistoricalPriceData {
|
|
|
9
9
|
candles: CandleData[];
|
|
10
10
|
oldestTime: number | null;
|
|
11
11
|
latestTime: number | null;
|
|
12
|
+
requestedRanges: HistoricalRange[];
|
|
12
13
|
}
|
|
13
14
|
interface HistoricalPriceDataState {
|
|
14
15
|
historicalPriceData: Record<string, TokenHistoricalPriceData>;
|