@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.mjs CHANGED
@@ -1801,6 +1801,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
1801
1801
  }
1802
1802
  const [trades, setTrades] = useState([]);
1803
1803
  const [isLoading, setIsLoading] = useState(false);
1804
+ useState(() => symbol);
1804
1805
  const { limit = 50 } = options;
1805
1806
  const ws = useWS();
1806
1807
  useEffect(() => {
@@ -1825,23 +1826,30 @@ var useMarketTradeStream = (symbol, options = {}) => {
1825
1826
  );
1826
1827
  }, [symbol]);
1827
1828
  useEffect(() => {
1828
- if (trades.length <= 0)
1829
- return;
1830
- const unsubscript = ws.subscribe(`@${symbol}/@trade`, {
1831
- onMessage: (data) => {
1832
- setTrades((prev) => {
1833
- const arr = [data, ...prev];
1834
- if (arr.length > limit) {
1835
- arr.pop();
1836
- }
1837
- return arr;
1838
- });
1829
+ const unsubscript = ws.subscribe(
1830
+ {
1831
+ id: `${symbol}@trade`,
1832
+ event: "subscribe",
1833
+ topic: `${symbol}@trade`,
1834
+ ts: Date.now()
1835
+ },
1836
+ {
1837
+ onMessage: (data) => {
1838
+ setTrades((prev) => {
1839
+ const arr = [__spreadProps(__spreadValues({}, data), { ts: Date.now() }), ...prev];
1840
+ if (arr.length > limit) {
1841
+ arr.pop();
1842
+ }
1843
+ return arr;
1844
+ });
1845
+ }
1839
1846
  }
1840
- });
1847
+ );
1841
1848
  return () => {
1842
1849
  unsubscript == null ? void 0 : unsubscript();
1843
1850
  };
1844
- }, [symbol, trades]);
1851
+ }, [symbol]);
1852
+ console.log("trades", trades);
1845
1853
  return { data: trades, isLoading };
1846
1854
  };
1847
1855
  var useMarginRatio = () => {
@@ -1849,7 +1857,7 @@ var useMarginRatio = () => {
1849
1857
  const { data: markPrices } = useMarkPricesStream();
1850
1858
  const { totalCollateral } = useCollateral();
1851
1859
  const marginRatio = useMemo(() => {
1852
- if (!rows || !markPrices || !totalCollateral) {
1860
+ if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
1853
1861
  return 0;
1854
1862
  }
1855
1863
  const ratio = account.totalMarginRatio({