@orderly.network/hooks 0.0.31 → 0.0.33
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.js +26 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1020,6 +1020,7 @@ var parseHolding = (holding, markPrices) => {
|
|
|
1020
1020
|
var usePositionStream = (symbol, options) => {
|
|
1021
1021
|
var _a;
|
|
1022
1022
|
const symbolInfo = useSymbolsInfo();
|
|
1023
|
+
useAccount();
|
|
1023
1024
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1024
1025
|
const { data: holding } = usePrivateQuery(
|
|
1025
1026
|
"/v1/client/holding",
|
|
@@ -1033,7 +1034,9 @@ var usePositionStream = (symbol, options) => {
|
|
|
1033
1034
|
const { data, error } = usePrivateQuery(`/v1/positions`, __spreadProps(__spreadValues({
|
|
1034
1035
|
// revalidateOnFocus: false,
|
|
1035
1036
|
// revalidateOnReconnect: false,
|
|
1036
|
-
dedupingInterval: 5e3
|
|
1037
|
+
dedupingInterval: 5e3,
|
|
1038
|
+
keepPreviousData: false,
|
|
1039
|
+
revalidateIfStale: true
|
|
1037
1040
|
}, options), {
|
|
1038
1041
|
formatter: (data2) => data2,
|
|
1039
1042
|
onError: (err) => {
|
|
@@ -1810,6 +1813,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
1810
1813
|
}
|
|
1811
1814
|
const [trades, setTrades] = React2.useState([]);
|
|
1812
1815
|
const [isLoading, setIsLoading] = React2.useState(false);
|
|
1816
|
+
React2.useState(() => symbol);
|
|
1813
1817
|
const { limit = 50 } = options;
|
|
1814
1818
|
const ws = useWS();
|
|
1815
1819
|
React2.useEffect(() => {
|
|
@@ -1834,23 +1838,30 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
1834
1838
|
);
|
|
1835
1839
|
}, [symbol]);
|
|
1836
1840
|
React2.useEffect(() => {
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1841
|
+
const unsubscript = ws.subscribe(
|
|
1842
|
+
{
|
|
1843
|
+
id: `${symbol}@trade`,
|
|
1844
|
+
event: "subscribe",
|
|
1845
|
+
topic: `${symbol}@trade`,
|
|
1846
|
+
ts: Date.now()
|
|
1847
|
+
},
|
|
1848
|
+
{
|
|
1849
|
+
onMessage: (data) => {
|
|
1850
|
+
setTrades((prev) => {
|
|
1851
|
+
const arr = [__spreadProps(__spreadValues({}, data), { ts: Date.now() }), ...prev];
|
|
1852
|
+
if (arr.length > limit) {
|
|
1853
|
+
arr.pop();
|
|
1854
|
+
}
|
|
1855
|
+
return arr;
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1848
1858
|
}
|
|
1849
|
-
|
|
1859
|
+
);
|
|
1850
1860
|
return () => {
|
|
1851
1861
|
unsubscript == null ? void 0 : unsubscript();
|
|
1852
1862
|
};
|
|
1853
|
-
}, [symbol
|
|
1863
|
+
}, [symbol]);
|
|
1864
|
+
console.log("trades", trades);
|
|
1854
1865
|
return { data: trades, isLoading };
|
|
1855
1866
|
};
|
|
1856
1867
|
var useMarginRatio = () => {
|
|
@@ -1858,7 +1869,7 @@ var useMarginRatio = () => {
|
|
|
1858
1869
|
const { data: markPrices } = useMarkPricesStream();
|
|
1859
1870
|
const { totalCollateral } = useCollateral();
|
|
1860
1871
|
const marginRatio = React2.useMemo(() => {
|
|
1861
|
-
if (!rows || !markPrices || !totalCollateral) {
|
|
1872
|
+
if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
|
|
1862
1873
|
return 0;
|
|
1863
1874
|
}
|
|
1864
1875
|
const ratio = futures.account.totalMarginRatio({
|