@orderly.network/hooks 0.0.30 → 0.0.32

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 CHANGED
@@ -1810,6 +1810,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
1810
1810
  }
1811
1811
  const [trades, setTrades] = React2.useState([]);
1812
1812
  const [isLoading, setIsLoading] = React2.useState(false);
1813
+ React2.useState(() => symbol);
1813
1814
  const { limit = 50 } = options;
1814
1815
  const ws = useWS();
1815
1816
  React2.useEffect(() => {
@@ -1834,23 +1835,30 @@ var useMarketTradeStream = (symbol, options = {}) => {
1834
1835
  );
1835
1836
  }, [symbol]);
1836
1837
  React2.useEffect(() => {
1837
- if (trades.length <= 0)
1838
- return;
1839
- const unsubscript = ws.subscribe(`@${symbol}/@trade`, {
1840
- onMessage: (data) => {
1841
- setTrades((prev) => {
1842
- const arr = [data, ...prev];
1843
- if (arr.length > limit) {
1844
- arr.pop();
1845
- }
1846
- return arr;
1847
- });
1838
+ const unsubscript = ws.subscribe(
1839
+ {
1840
+ id: `${symbol}@trade`,
1841
+ event: "subscribe",
1842
+ topic: `${symbol}@trade`,
1843
+ ts: Date.now()
1844
+ },
1845
+ {
1846
+ onMessage: (data) => {
1847
+ setTrades((prev) => {
1848
+ const arr = [__spreadProps(__spreadValues({}, data), { ts: Date.now() }), ...prev];
1849
+ if (arr.length > limit) {
1850
+ arr.pop();
1851
+ }
1852
+ return arr;
1853
+ });
1854
+ }
1848
1855
  }
1849
- });
1856
+ );
1850
1857
  return () => {
1851
1858
  unsubscript == null ? void 0 : unsubscript();
1852
1859
  };
1853
- }, [symbol, trades]);
1860
+ }, [symbol]);
1861
+ console.log("trades", trades);
1854
1862
  return { data: trades, isLoading };
1855
1863
  };
1856
1864
  var useMarginRatio = () => {
@@ -1858,7 +1866,7 @@ var useMarginRatio = () => {
1858
1866
  const { data: markPrices } = useMarkPricesStream();
1859
1867
  const { totalCollateral } = useCollateral();
1860
1868
  const marginRatio = React2.useMemo(() => {
1861
- if (!rows || !markPrices || !totalCollateral) {
1869
+ if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
1862
1870
  return 0;
1863
1871
  }
1864
1872
  const ratio = futures.account.totalMarginRatio({