@orderly.network/hooks 0.0.91 → 0.0.93

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.d.mts CHANGED
@@ -5,7 +5,7 @@ import * as _orderly_network_core from '@orderly.network/core';
5
5
  import { Account, AccountState, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, IContract, EventEmitter } from '@orderly.network/core';
6
6
  import * as react from 'react';
7
7
  import react__default, { FC, PropsWithChildren } from 'react';
8
- import { NetworkId, OrderSide, OrderEntity, API, WSMessage, WS_WalletStatusEnum } from '@orderly.network/types';
8
+ import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
9
9
  export { default as useConstant } from 'use-constant';
10
10
  import { WS } from '@orderly.network/net';
11
11
  import * as swr__internal from 'swr/_internal';
@@ -231,26 +231,12 @@ declare const useFundingRate: (symbol: string) => {
231
231
 
232
232
  declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => any[];
233
233
 
234
- declare enum OrderStatus {
235
- FILLED = "FILLED",
236
- PARTIAL_FILLED = "PARTIAL_FILLED",
237
- CANCELED = "CANCELED",
238
- NEW = "NEW",
239
- COMPLETED = "COMPLETED",
240
- INCOMPLETE = "INCOMPLETE"
241
- }
242
234
  declare const useOrderStream: ({ status, symbol, side, size, }?: {
243
235
  symbol?: string | undefined;
244
236
  status?: OrderStatus | undefined;
245
237
  size?: number | undefined;
246
238
  side?: OrderSide | undefined;
247
- }) => (any[] | {
248
- isLoading: boolean;
249
- loadMore: () => void;
250
- cancelAllOrders: () => void;
251
- updateOrder: (orderId: string, order: OrderEntity) => any;
252
- cancelOrder: (orderId: string, symbol?: string) => any;
253
- } | null)[];
239
+ }) => any;
254
240
 
255
241
  interface MarketTradeStreamOptions {
256
242
  limit?: number;
@@ -356,10 +342,6 @@ declare const useBalance: () => any;
356
342
 
357
343
  declare const usePrivateDataObserver: () => void;
358
344
 
359
- declare const useExecutionReport: (options?: {
360
- onMessage?: ((data: any) => void) | undefined;
361
- } | undefined) => any;
362
-
363
345
  interface Info {
364
346
  symbol: string;
365
347
  quote_min: number;
@@ -489,4 +471,4 @@ declare const useSwap: () => {
489
471
  status: WS_WalletStatusEnum;
490
472
  };
491
473
 
492
- export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
474
+ export { AppStateErrors, DataSourceProvider, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import * as _orderly_network_core from '@orderly.network/core';
5
5
  import { Account, AccountState, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, IContract, EventEmitter } from '@orderly.network/core';
6
6
  import * as react from 'react';
7
7
  import react__default, { FC, PropsWithChildren } from 'react';
8
- import { NetworkId, OrderSide, OrderEntity, API, WSMessage, WS_WalletStatusEnum } from '@orderly.network/types';
8
+ import { NetworkId, OrderSide, OrderEntity, API, WSMessage, OrderStatus, WS_WalletStatusEnum } from '@orderly.network/types';
9
9
  export { default as useConstant } from 'use-constant';
10
10
  import { WS } from '@orderly.network/net';
11
11
  import * as swr__internal from 'swr/_internal';
@@ -231,26 +231,12 @@ declare const useFundingRate: (symbol: string) => {
231
231
 
232
232
  declare const usePositionStream: (symbol?: string, options?: SWRConfiguration) => any[];
233
233
 
234
- declare enum OrderStatus {
235
- FILLED = "FILLED",
236
- PARTIAL_FILLED = "PARTIAL_FILLED",
237
- CANCELED = "CANCELED",
238
- NEW = "NEW",
239
- COMPLETED = "COMPLETED",
240
- INCOMPLETE = "INCOMPLETE"
241
- }
242
234
  declare const useOrderStream: ({ status, symbol, side, size, }?: {
243
235
  symbol?: string | undefined;
244
236
  status?: OrderStatus | undefined;
245
237
  size?: number | undefined;
246
238
  side?: OrderSide | undefined;
247
- }) => (any[] | {
248
- isLoading: boolean;
249
- loadMore: () => void;
250
- cancelAllOrders: () => void;
251
- updateOrder: (orderId: string, order: OrderEntity) => any;
252
- cancelOrder: (orderId: string, symbol?: string) => any;
253
- } | null)[];
239
+ }) => any;
254
240
 
255
241
  interface MarketTradeStreamOptions {
256
242
  limit?: number;
@@ -356,10 +342,6 @@ declare const useBalance: () => any;
356
342
 
357
343
  declare const usePrivateDataObserver: () => void;
358
344
 
359
- declare const useExecutionReport: (options?: {
360
- onMessage?: ((data: any) => void) | undefined;
361
- } | undefined) => any;
362
-
363
345
  interface Info {
364
346
  symbol: string;
365
347
  quote_min: number;
@@ -489,4 +471,4 @@ declare const useSwap: () => {
489
471
  status: WS_WalletStatusEnum;
490
472
  };
491
473
 
492
- export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
474
+ export { AppStateErrors, DataSourceProvider, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
package/dist/index.js CHANGED
@@ -165,7 +165,7 @@ var useMutation = (url, method = "POST", options) => {
165
165
  };
166
166
  var signatureMiddleware = (useSWRNext) => {
167
167
  const { apiBaseUrl } = React2.useContext(OrderlyContext);
168
- return (key, fetcher4, config) => {
168
+ return (key, fetcher3, config) => {
169
169
  try {
170
170
  const extendedFetcher = async (args) => {
171
171
  let url = Array.isArray(args) ? args[0] : args;
@@ -177,7 +177,7 @@ var signatureMiddleware = (useSWRNext) => {
177
177
  url
178
178
  };
179
179
  const signature = await signer.sign(payload);
180
- return fetcher4(fullUrl, {
180
+ return fetcher3(fullUrl, {
181
181
  headers: {
182
182
  ...signature,
183
183
  "orderly-account-id": account5.accountId
@@ -718,15 +718,10 @@ var mergeItems = (data, update) => {
718
718
  return data;
719
719
  };
720
720
  var mergeOrderbook = (data, update) => {
721
- const asks = mergeItems(data.asks, update.asks).sort(asksSortFn);
722
- const bids = mergeItems(data.bids, update.bids).sort(bidsSortFn);
723
- if (asks.length > 0) {
724
- const firstPrice = asks[0][0];
725
- const index = bids.findIndex((item) => item[0] < firstPrice);
726
- if (index > 0) {
727
- bids.splice(0, index + 1);
728
- }
729
- }
721
+ let asks = [...data.asks];
722
+ let bids = [...data.bids];
723
+ asks = mergeItems(asks, update.asks).sort(asksSortFn);
724
+ bids = mergeItems(bids, update.bids).sort(bidsSortFn);
730
725
  return {
731
726
  asks,
732
727
  bids
@@ -770,9 +765,12 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
770
765
  if (ignore)
771
766
  return;
772
767
  if (!!message) {
773
- const reduceOrderbookData = reduceOrderbook(depth, level, message);
774
- setRequestData(reduceOrderbookData);
775
- setData(reduceOrderbookData);
768
+ let bids = [...message.bids.sort(bidsSortFn)];
769
+ bids = bids.filter((item) => !isNaN(item[0]) && item[1] > 0);
770
+ let asks = [...message.asks.sort(asksSortFn)];
771
+ asks = asks.filter((item) => !isNaN(item[0]) && item[1] > 0);
772
+ setRequestData({ bids, asks });
773
+ setData({ bids: [...bids], asks: [...asks] });
776
774
  }
777
775
  setIsLoading(false);
778
776
  }
@@ -788,6 +786,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
788
786
  React2.useEffect(() => {
789
787
  if (!requestData)
790
788
  return;
789
+ let ignore = false;
791
790
  const subscription = ws.subscribe(
792
791
  {
793
792
  event: "subscribe",
@@ -795,15 +794,17 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
795
794
  },
796
795
  {
797
796
  onMessage: (message) => {
797
+ if (ignore)
798
+ return;
798
799
  setData((data2) => {
799
800
  const mergedData = !message.asks && !message.bids ? data2 : mergeOrderbook(data2, message);
800
- const reducedData = reduceOrderbook(depth, level, mergedData);
801
- return reducedData;
801
+ return mergedData;
802
802
  });
803
803
  }
804
804
  }
805
805
  );
806
806
  return () => {
807
+ ignore = true;
807
808
  subscription?.();
808
809
  };
809
810
  }, [symbol, requestData]);
@@ -829,10 +830,11 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
829
830
  React2.useEffect(() => {
830
831
  prevMiddlePrice.current = middlePrice;
831
832
  }, [middlePrice]);
833
+ const reducedData = reduceOrderbook(depth, level, data);
832
834
  return [
833
835
  {
834
- asks: data.asks.slice(-level),
835
- bids: data.bids.slice(0, level),
836
+ asks: reducedData.asks.slice(-level),
837
+ bids: reducedData.bids.slice(0, level),
836
838
  markPrice,
837
839
  middlePrice: [prevMiddlePrice.current, middlePrice]
838
840
  },
@@ -1263,6 +1265,197 @@ var useHoldingStream = () => {
1263
1265
  isLoading
1264
1266
  };
1265
1267
  };
1268
+ var usePrivateInfiniteQuery = (getKey, options) => {
1269
+ const { formatter, ...restOptions } = options || {};
1270
+ const account5 = useAccount();
1271
+ const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
1272
+ const result = useSWRInfinite__default.default(
1273
+ (pageIndex, previousPageData) => account5.state.status >= types.AccountStatusEnum.EnableTrading ? getKey(pageIndex, previousPageData) : null,
1274
+ (url, init) => net.get(url, init, formatter),
1275
+ {
1276
+ ...restOptions,
1277
+ use: [signatureMiddleware, ...middleware]
1278
+ }
1279
+ );
1280
+ return result;
1281
+ };
1282
+ var useOrderStream = ({
1283
+ status,
1284
+ symbol,
1285
+ side,
1286
+ size = 100
1287
+ } = {}) => {
1288
+ const ws = useWS();
1289
+ const { data: markPrices = {} } = useMarkPricesStream();
1290
+ const [doCancelOrder] = useMutation("/v1/order", "DELETE");
1291
+ const [doUpdateOrder] = useMutation("/v1/order", "PUT");
1292
+ const ordersResponse = usePrivateInfiniteQuery(
1293
+ (pageIndex, previousPageData) => {
1294
+ if (previousPageData && !previousPageData.length)
1295
+ return null;
1296
+ const search = new URLSearchParams([
1297
+ ["size", size.toString()],
1298
+ ["page", `${pageIndex + 1}`]
1299
+ ]);
1300
+ if (status) {
1301
+ search.set(`status`, status);
1302
+ }
1303
+ if (symbol) {
1304
+ search.set(`symbol`, symbol);
1305
+ }
1306
+ if (side) {
1307
+ search.set(`side`, side);
1308
+ }
1309
+ return `/v1/orders?${search.toString()}`;
1310
+ },
1311
+ {
1312
+ initialSize: 1,
1313
+ onError: (err) => {
1314
+ console.error("fetch failed::::", err);
1315
+ },
1316
+ formatter: (data) => data
1317
+ }
1318
+ );
1319
+ const orders = React2.useMemo(() => {
1320
+ if (!ordersResponse.data) {
1321
+ return null;
1322
+ }
1323
+ return ordersResponse.data?.map((item) => item.rows)?.flat().map((item) => {
1324
+ return {
1325
+ ...item,
1326
+ mark_price: markPrices[item.symbol] ?? 0
1327
+ };
1328
+ });
1329
+ }, [ordersResponse.data, markPrices]);
1330
+ const total = React2.useMemo(() => {
1331
+ return ordersResponse.data?.[0]?.meta?.total || 0;
1332
+ }, [ordersResponse.data]);
1333
+ React2.useEffect(() => {
1334
+ const unsubscribe = ws.privateSubscribe(
1335
+ {
1336
+ id: "executionreport_orders",
1337
+ event: "subscribe",
1338
+ topic: "executionreport",
1339
+ ts: Date.now()
1340
+ },
1341
+ {
1342
+ onMessage: (data) => {
1343
+ const { status: status2, orderId, timestamp } = data;
1344
+ ordersResponse.mutate((prevData) => {
1345
+ const newOrder = {
1346
+ order_id: data.orderId,
1347
+ symbol: data.symbol,
1348
+ created_time: data.timestamp,
1349
+ quantity: data.quantity,
1350
+ side: data.side,
1351
+ executed: data.totalExecutedQuantity,
1352
+ price: data.price
1353
+ };
1354
+ const dataList = prevData?.map((item) => item.rows)?.flat() || [];
1355
+ if (status2 === types.OrderStatus.NEW) {
1356
+ if (!prevData) {
1357
+ return {
1358
+ meta: {
1359
+ total: 1,
1360
+ records_per_page: size,
1361
+ current_page: 1
1362
+ },
1363
+ rows: [newOrder]
1364
+ };
1365
+ }
1366
+ const total2 = (prevData?.[0]?.meta?.total || 0) + 1;
1367
+ const isNew = !dataList.find((item) => item.order_id === orderId);
1368
+ if (isNew) {
1369
+ const list = [newOrder, ...dataList];
1370
+ return rePageData(list, total2, size);
1371
+ }
1372
+ return prevData;
1373
+ }
1374
+ if (status2 === types.OrderStatus.CANCELLED || status2 === types.OrderStatus.FILLED) {
1375
+ const total2 = (prevData?.[0]?.meta?.total || 0) - 1;
1376
+ const list = dataList.filter(
1377
+ (order2) => order2.order_id !== orderId
1378
+ );
1379
+ return rePageData(list, total2, size);
1380
+ }
1381
+ if (status2 === types.OrderStatus.PARTIAL_FILLED) {
1382
+ return editPageData(dataList, newOrder);
1383
+ }
1384
+ if (status2 === types.OrderStatus.REPLACED) {
1385
+ return editPageData(dataList, newOrder);
1386
+ }
1387
+ return prevData;
1388
+ });
1389
+ }
1390
+ }
1391
+ );
1392
+ return () => unsubscribe();
1393
+ }, []);
1394
+ const cancelAllOrders = React2.useCallback(() => {
1395
+ }, [ordersResponse.data]);
1396
+ const updateOrder = React2.useCallback((orderId, order2) => {
1397
+ return doUpdateOrder({ ...order2, order_id: orderId });
1398
+ }, []);
1399
+ const cancelOrder = React2.useCallback((orderId, symbol2) => {
1400
+ return doCancelOrder(null, {
1401
+ order_id: orderId,
1402
+ symbol: symbol2
1403
+ }).then((res) => {
1404
+ if (res.success) ; else {
1405
+ throw new Error(res.message);
1406
+ }
1407
+ });
1408
+ }, []);
1409
+ const loadMore = () => {
1410
+ ordersResponse.setSize(ordersResponse.size + 1);
1411
+ };
1412
+ return [
1413
+ orders,
1414
+ {
1415
+ total,
1416
+ isLoading: ordersResponse.isLoading,
1417
+ loadMore,
1418
+ cancelAllOrders,
1419
+ updateOrder,
1420
+ cancelOrder
1421
+ }
1422
+ ];
1423
+ };
1424
+ function rePageData(list, total, pageSize) {
1425
+ const newData = [];
1426
+ let rows = [];
1427
+ let current_page = 0;
1428
+ for (let i = 0; i < list.length; i++) {
1429
+ rows.push(list[i]);
1430
+ if ((i + 1) % pageSize === 0 || i === list.length - 1) {
1431
+ newData.push({
1432
+ meta: {
1433
+ records_per_page: pageSize,
1434
+ total,
1435
+ current_page: current_page + 1
1436
+ },
1437
+ rows: [...rows]
1438
+ });
1439
+ rows = [];
1440
+ }
1441
+ }
1442
+ console.log("rePageData", list, total, newData);
1443
+ return newData;
1444
+ }
1445
+ function editPageData(list, newOrder) {
1446
+ const newData = list.map((item) => {
1447
+ return {
1448
+ ...item,
1449
+ rows: item.rows.map((row) => {
1450
+ if (row.order_id === newOrder.order_id) {
1451
+ return { ...row, newOrder };
1452
+ }
1453
+ return row;
1454
+ })
1455
+ };
1456
+ });
1457
+ return newData;
1458
+ }
1266
1459
 
1267
1460
  // src/orderly/useCollateral.ts
1268
1461
  var positionsPath = ramda.pathOr([], [0, "rows"]);
@@ -1270,9 +1463,7 @@ ramda.pathOr(0, [0, "totalCollateral"]);
1270
1463
  var useCollateral = (options = { dp: 6 }) => {
1271
1464
  const { dp } = options;
1272
1465
  const positions2 = usePositionStream();
1273
- const { data: orders } = usePrivateQuery(
1274
- `/v1/orders?status=NEW`
1275
- );
1466
+ const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
1276
1467
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1277
1468
  const symbolInfo = useSymbolsInfo();
1278
1469
  const { data: markPrices } = useMarkPricesStream();
@@ -1319,9 +1510,7 @@ var useCollateral = (options = { dp: 6 }) => {
1319
1510
  var positionsPath2 = ramda.pathOr([], [0, "rows"]);
1320
1511
  var useMaxQty = (symbol, side, reduceOnly = false) => {
1321
1512
  const positionsData = usePositionStream();
1322
- const { data: orders } = usePrivateQuery(
1323
- `/v1/orders?status=NEW`
1324
- );
1513
+ const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
1325
1514
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1326
1515
  const symbolInfo = useSymbolsInfo();
1327
1516
  const { totalCollateral } = useCollateral();
@@ -1810,119 +1999,6 @@ var useFundingRate = (symbol) => {
1810
1999
  countDown
1811
2000
  };
1812
2001
  };
1813
- var fetcher3 = (url, init) => net.get(url, init);
1814
- var usePrivateInfiniteQuery = (getKey, options) => {
1815
- const account5 = useAccount();
1816
- const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
1817
- const result = useSWRInfinite__default.default(
1818
- (pageIndex, previousPageData) => account5.state.status >= types.AccountStatusEnum.EnableTrading ? getKey(pageIndex, previousPageData) : null,
1819
- fetcher3,
1820
- {
1821
- ...options,
1822
- use: [signatureMiddleware, ...middleware]
1823
- }
1824
- );
1825
- return result;
1826
- };
1827
- var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
1828
- OrderStatus2["FILLED"] = "FILLED";
1829
- OrderStatus2["PARTIAL_FILLED"] = "PARTIAL_FILLED";
1830
- OrderStatus2["CANCELED"] = "CANCELED";
1831
- OrderStatus2["NEW"] = "NEW";
1832
- OrderStatus2["COMPLETED"] = "COMPLETED";
1833
- OrderStatus2["INCOMPLETE"] = "INCOMPLETE";
1834
- return OrderStatus2;
1835
- })(OrderStatus || {});
1836
- var useOrderStream = ({
1837
- status,
1838
- symbol,
1839
- side,
1840
- size = 10
1841
- } = {}) => {
1842
- const ee = useEventEmitter();
1843
- const { data: markPrices = {} } = useMarkPricesStream();
1844
- const [doCancelOrder] = useMutation("/v1/order", "DELETE");
1845
- const [doUpdateOrder] = useMutation("/v1/order", "PUT");
1846
- const ordersResponse = usePrivateInfiniteQuery(
1847
- (pageIndex, previousPageData) => {
1848
- if (previousPageData && !previousPageData.length)
1849
- return null;
1850
- const search = new URLSearchParams([
1851
- ["size", size.toString()],
1852
- ["page", `${pageIndex + 1}`]
1853
- // [`status`, status],
1854
- ]);
1855
- if (status) {
1856
- search.set(`status`, status);
1857
- }
1858
- if (symbol) {
1859
- search.set(`symbol`, symbol);
1860
- }
1861
- if (side) {
1862
- search.set(`side`, side);
1863
- }
1864
- return `/v1/orders?${search.toString()}`;
1865
- },
1866
- {
1867
- initialSize: 1,
1868
- onError: (err) => {
1869
- console.error("fetch failed::::", err);
1870
- }
1871
- }
1872
- );
1873
- const orders = React2.useMemo(() => {
1874
- if (!ordersResponse.data) {
1875
- return null;
1876
- }
1877
- return ordersResponse.data?.flat().map((item) => {
1878
- return {
1879
- ...item,
1880
- mark_price: markPrices[item.symbol] ?? 0
1881
- };
1882
- });
1883
- }, [ordersResponse.data, markPrices]);
1884
- React2.useEffect(() => {
1885
- const handler = () => {
1886
- ordersResponse.mutate();
1887
- };
1888
- ee.on("orders:changed", handler);
1889
- return () => {
1890
- ee.off("orders:changed", handler);
1891
- };
1892
- }, []);
1893
- const cancelAllOrders = React2.useCallback(() => {
1894
- }, [ordersResponse.data]);
1895
- const updateOrder = React2.useCallback((orderId, order2) => {
1896
- return doUpdateOrder({ ...order2, order_id: orderId });
1897
- }, []);
1898
- const cancelOrder = React2.useCallback((orderId, symbol2) => {
1899
- return doCancelOrder(null, {
1900
- order_id: orderId,
1901
- symbol: symbol2
1902
- }).then((res) => {
1903
- if (res.success) {
1904
- return ordersResponse.mutate().then(() => {
1905
- return res;
1906
- });
1907
- } else {
1908
- throw new Error(res.message);
1909
- }
1910
- });
1911
- }, []);
1912
- const loadMore = () => {
1913
- ordersResponse.setSize(ordersResponse.size + 1);
1914
- };
1915
- return [
1916
- orders,
1917
- {
1918
- isLoading: ordersResponse.isLoading,
1919
- loadMore,
1920
- cancelAllOrders,
1921
- updateOrder,
1922
- cancelOrder
1923
- }
1924
- ];
1925
- };
1926
2002
  var useMarketTradeStream = (symbol, options = {}) => {
1927
2003
  if (!symbol) {
1928
2004
  throw new Error("useTradeStream: symbol is required");
@@ -3468,16 +3544,7 @@ var useBalance = () => {
3468
3544
  var usePrivateDataObserver = () => {
3469
3545
  const ws = useWS();
3470
3546
  const { mutate: mutate2 } = useSWR.useSWRConfig();
3471
- const ee = useEventEmitter();
3472
3547
  const { state } = useAccount();
3473
- React2.useEffect(() => {
3474
- const unsubscribe = ws.privateSubscribe("executionreport", {
3475
- onMessage: (data) => {
3476
- ee.emit("orders:changed");
3477
- }
3478
- });
3479
- return () => unsubscribe?.();
3480
- }, [state.accountId]);
3481
3548
  React2.useEffect(() => {
3482
3549
  if (!state.accountId)
3483
3550
  return;
@@ -3527,24 +3594,6 @@ var usePrivateDataObserver = () => {
3527
3594
  };
3528
3595
  }, [state.accountId]);
3529
3596
  };
3530
- var useExecutionReport = (options) => {
3531
- const ws = useWS();
3532
- const { data } = useSWRSubscription__default.default("executionreport", (_, { next }) => {
3533
- const unsubscribe = ws.privateSubscribe({
3534
- id: "executionreport",
3535
- event: "subscribe",
3536
- topic: "executionreport",
3537
- ts: Date.now()
3538
- }, {
3539
- onMessage: (data2) => {
3540
- options?.onMessage?.(data2);
3541
- next(data2);
3542
- }
3543
- });
3544
- return () => unsubscribe();
3545
- });
3546
- return data;
3547
- };
3548
3597
 
3549
3598
  // src/apis/index.ts
3550
3599
  var apis_exports = {};
@@ -4187,7 +4236,6 @@ Object.defineProperty(exports, 'useConstant', {
4187
4236
  get: function () { return useConstant__default.default; }
4188
4237
  });
4189
4238
  exports.DataSourceProvider = DataSourceProvider;
4190
- exports.OrderStatus = OrderStatus;
4191
4239
  exports.OrderlyContext = OrderlyContext;
4192
4240
  exports.OrderlyProvider = OrderlyProvider;
4193
4241
  exports.apis = apis_exports;
@@ -4204,7 +4252,6 @@ exports.useConfig = useConfig;
4204
4252
  exports.useCrossSwap = useCrossSwap;
4205
4253
  exports.useDeposit = useDeposit;
4206
4254
  exports.useEventEmitter = useEventEmitter;
4207
- exports.useExecutionReport = useExecutionReport;
4208
4255
  exports.useFetures = useFetures;
4209
4256
  exports.useFundingRate = useFundingRate;
4210
4257
  exports.useHoldingStream = useHoldingStream;