@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.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
- 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
- });
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, trades]);
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({