@orderly.network/hooks 0.0.28 → 0.0.30
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.mts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +39 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -435,7 +435,6 @@ function useLocalStorage(key, initialValue) {
|
|
|
435
435
|
},
|
|
436
436
|
[storedValue]
|
|
437
437
|
);
|
|
438
|
-
console.log("storedValue", storedValue);
|
|
439
438
|
useEffect(() => {
|
|
440
439
|
setStoredValue(readValue());
|
|
441
440
|
}, []);
|
|
@@ -672,6 +671,7 @@ var reduceOrderbook = (depth, level, data) => {
|
|
|
672
671
|
var mergeItems = (data, update) => {
|
|
673
672
|
if (data.length === 0)
|
|
674
673
|
return update;
|
|
674
|
+
data = data.filter(([price]) => !isNaN(price));
|
|
675
675
|
while (update.length > 0) {
|
|
676
676
|
const item = update.shift();
|
|
677
677
|
if (item) {
|
|
@@ -724,6 +724,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
724
724
|
ws.onceSubscribe(
|
|
725
725
|
{
|
|
726
726
|
event: "request",
|
|
727
|
+
id: `${symbol}@orderbook`,
|
|
727
728
|
params: {
|
|
728
729
|
type: "orderbook",
|
|
729
730
|
symbol
|
|
@@ -879,10 +880,10 @@ function quantityInputHandle(inputs) {
|
|
|
879
880
|
price = Number(values.order_price);
|
|
880
881
|
}
|
|
881
882
|
const total = quantity.mul(price);
|
|
882
|
-
|
|
883
|
+
total.dp();
|
|
883
884
|
return [
|
|
884
885
|
__spreadProps(__spreadValues({}, values), {
|
|
885
|
-
total: total.todp(
|
|
886
|
+
total: total.todp(2).toNumber()
|
|
886
887
|
}),
|
|
887
888
|
input,
|
|
888
889
|
value,
|
|
@@ -1799,29 +1800,48 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
1799
1800
|
throw new Error("useTradeStream: symbol is required");
|
|
1800
1801
|
}
|
|
1801
1802
|
const [trades, setTrades] = useState([]);
|
|
1802
|
-
const
|
|
1803
|
-
const {
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1803
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
1804
|
+
const { limit = 50 } = options;
|
|
1805
|
+
const ws = useWS();
|
|
1806
|
+
useEffect(() => {
|
|
1807
|
+
setIsLoading(true);
|
|
1808
|
+
setTrades(() => []);
|
|
1809
|
+
ws.onceSubscribe(
|
|
1810
|
+
{
|
|
1811
|
+
id: `${symbol}@trade`,
|
|
1812
|
+
event: "request",
|
|
1813
|
+
params: {
|
|
1814
|
+
type: "trade",
|
|
1815
|
+
symbol,
|
|
1816
|
+
limit
|
|
1817
|
+
}
|
|
1818
|
+
},
|
|
1819
|
+
{
|
|
1820
|
+
onMessage: (data) => {
|
|
1821
|
+
setIsLoading(false);
|
|
1808
1822
|
setTrades(() => data);
|
|
1809
1823
|
}
|
|
1810
|
-
return data;
|
|
1811
1824
|
}
|
|
1812
|
-
|
|
1813
|
-
);
|
|
1814
|
-
const ws = useWS();
|
|
1825
|
+
);
|
|
1826
|
+
}, [symbol]);
|
|
1815
1827
|
useEffect(() => {
|
|
1828
|
+
if (trades.length <= 0)
|
|
1829
|
+
return;
|
|
1816
1830
|
const unsubscript = ws.subscribe(`@${symbol}/@trade`, {
|
|
1817
1831
|
onMessage: (data) => {
|
|
1818
|
-
|
|
1832
|
+
setTrades((prev) => {
|
|
1833
|
+
const arr = [data, ...prev];
|
|
1834
|
+
if (arr.length > limit) {
|
|
1835
|
+
arr.pop();
|
|
1836
|
+
}
|
|
1837
|
+
return arr;
|
|
1838
|
+
});
|
|
1819
1839
|
}
|
|
1820
1840
|
});
|
|
1821
1841
|
return () => {
|
|
1822
1842
|
unsubscript == null ? void 0 : unsubscript();
|
|
1823
1843
|
};
|
|
1824
|
-
}, []);
|
|
1844
|
+
}, [symbol, trades]);
|
|
1825
1845
|
return { data: trades, isLoading };
|
|
1826
1846
|
};
|
|
1827
1847
|
var useMarginRatio = () => {
|
|
@@ -1829,6 +1849,9 @@ var useMarginRatio = () => {
|
|
|
1829
1849
|
const { data: markPrices } = useMarkPricesStream();
|
|
1830
1850
|
const { totalCollateral } = useCollateral();
|
|
1831
1851
|
const marginRatio = useMemo(() => {
|
|
1852
|
+
if (!rows || !markPrices || !totalCollateral) {
|
|
1853
|
+
return 0;
|
|
1854
|
+
}
|
|
1832
1855
|
const ratio = account.totalMarginRatio({
|
|
1833
1856
|
totalCollateral,
|
|
1834
1857
|
markPrices,
|
|
@@ -1839,7 +1862,7 @@ var useMarginRatio = () => {
|
|
|
1839
1862
|
const currentLeverage = useMemo(() => {
|
|
1840
1863
|
return account.currentLeverage(marginRatio);
|
|
1841
1864
|
}, [marginRatio]);
|
|
1842
|
-
return
|
|
1865
|
+
return { marginRatio, currentLeverage };
|
|
1843
1866
|
};
|
|
1844
1867
|
var useChains = (networkId, options = {}) => {
|
|
1845
1868
|
const _a = options, swrOptions = __objRest(_a, ["filter", "pick"]);
|