@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.mjs
CHANGED
|
@@ -1011,6 +1011,7 @@ var parseHolding = (holding, markPrices) => {
|
|
|
1011
1011
|
var usePositionStream = (symbol, options) => {
|
|
1012
1012
|
var _a;
|
|
1013
1013
|
const symbolInfo = useSymbolsInfo();
|
|
1014
|
+
useAccount();
|
|
1014
1015
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1015
1016
|
const { data: holding } = usePrivateQuery(
|
|
1016
1017
|
"/v1/client/holding",
|
|
@@ -1024,7 +1025,9 @@ var usePositionStream = (symbol, options) => {
|
|
|
1024
1025
|
const { data, error } = usePrivateQuery(`/v1/positions`, __spreadProps(__spreadValues({
|
|
1025
1026
|
// revalidateOnFocus: false,
|
|
1026
1027
|
// revalidateOnReconnect: false,
|
|
1027
|
-
dedupingInterval: 5e3
|
|
1028
|
+
dedupingInterval: 5e3,
|
|
1029
|
+
keepPreviousData: false,
|
|
1030
|
+
revalidateIfStale: true
|
|
1028
1031
|
}, options), {
|
|
1029
1032
|
formatter: (data2) => data2,
|
|
1030
1033
|
onError: (err) => {
|
|
@@ -1801,6 +1804,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
1801
1804
|
}
|
|
1802
1805
|
const [trades, setTrades] = useState([]);
|
|
1803
1806
|
const [isLoading, setIsLoading] = useState(false);
|
|
1807
|
+
useState(() => symbol);
|
|
1804
1808
|
const { limit = 50 } = options;
|
|
1805
1809
|
const ws = useWS();
|
|
1806
1810
|
useEffect(() => {
|
|
@@ -1825,23 +1829,30 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
1825
1829
|
);
|
|
1826
1830
|
}, [symbol]);
|
|
1827
1831
|
useEffect(() => {
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1832
|
+
const unsubscript = ws.subscribe(
|
|
1833
|
+
{
|
|
1834
|
+
id: `${symbol}@trade`,
|
|
1835
|
+
event: "subscribe",
|
|
1836
|
+
topic: `${symbol}@trade`,
|
|
1837
|
+
ts: Date.now()
|
|
1838
|
+
},
|
|
1839
|
+
{
|
|
1840
|
+
onMessage: (data) => {
|
|
1841
|
+
setTrades((prev) => {
|
|
1842
|
+
const arr = [__spreadProps(__spreadValues({}, data), { ts: Date.now() }), ...prev];
|
|
1843
|
+
if (arr.length > limit) {
|
|
1844
|
+
arr.pop();
|
|
1845
|
+
}
|
|
1846
|
+
return arr;
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1839
1849
|
}
|
|
1840
|
-
|
|
1850
|
+
);
|
|
1841
1851
|
return () => {
|
|
1842
1852
|
unsubscript == null ? void 0 : unsubscript();
|
|
1843
1853
|
};
|
|
1844
|
-
}, [symbol
|
|
1854
|
+
}, [symbol]);
|
|
1855
|
+
console.log("trades", trades);
|
|
1845
1856
|
return { data: trades, isLoading };
|
|
1846
1857
|
};
|
|
1847
1858
|
var useMarginRatio = () => {
|
|
@@ -1849,7 +1860,7 @@ var useMarginRatio = () => {
|
|
|
1849
1860
|
const { data: markPrices } = useMarkPricesStream();
|
|
1850
1861
|
const { totalCollateral } = useCollateral();
|
|
1851
1862
|
const marginRatio = useMemo(() => {
|
|
1852
|
-
if (!rows || !markPrices || !totalCollateral) {
|
|
1863
|
+
if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
|
|
1853
1864
|
return 0;
|
|
1854
1865
|
}
|
|
1855
1866
|
const ratio = account.totalMarginRatio({
|