@orderly.network/hooks 0.0.91 → 0.0.92

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
@@ -693,40 +693,41 @@ var reduceOrderbook = (depth, level, data) => {
693
693
  bids: bids.length < level ? bids.concat(paddingFn(level - bids.length)) : bids
694
694
  };
695
695
  };
696
- var mergeItems = (data, update) => {
697
- if (data.length === 0)
698
- return update;
699
- data = data.filter(([price]) => !isNaN(price));
700
- while (update.length > 0) {
701
- const item = update.shift();
702
- if (item) {
703
- const [price, quantity] = item;
704
- const index = data.findIndex(([p], index2) => p === price);
705
- if (index === -1) {
706
- if (quantity === 0)
707
- continue;
708
- data.push(item);
709
- } else {
710
- if (quantity === 0) {
711
- data.splice(index, 1);
712
- } else {
713
- data[index] = item;
696
+ var mergeOrderbook = (data, update) => {
697
+ const asks = [...data.asks];
698
+ const bids = [...data.bids];
699
+ update.asks.forEach((element) => {
700
+ for (let index = 0; index < asks.length; index++) {
701
+ if (element[1] === 0) {
702
+ if (element[0] === asks[index][0]) {
703
+ asks.splice(index, 1);
704
+ break;
714
705
  }
706
+ } else if (element[0] === asks[index][0]) {
707
+ asks[index] = element;
708
+ break;
709
+ } else if (element[0] < asks[index][0]) {
710
+ asks.splice(index, 0, element);
711
+ break;
715
712
  }
716
713
  }
717
- }
718
- return data;
719
- };
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);
714
+ });
715
+ update.bids.forEach((element) => {
716
+ for (let index = 0; index < bids.length; index++) {
717
+ if (element[1] === 0) {
718
+ if (element[0] === bids[index][0]) {
719
+ bids.splice(index, 1);
720
+ break;
721
+ }
722
+ } else if (element[0] === bids[index][0]) {
723
+ bids[index] = element;
724
+ break;
725
+ } else if (element[0] > bids[index][0]) {
726
+ bids.splice(index, 0, element);
727
+ break;
728
+ }
728
729
  }
729
- }
730
+ });
730
731
  return {
731
732
  asks,
732
733
  bids
@@ -770,9 +771,14 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
770
771
  if (ignore)
771
772
  return;
772
773
  if (!!message) {
773
- const reduceOrderbookData = reduceOrderbook(depth, level, message);
774
- setRequestData(reduceOrderbookData);
775
- setData(reduceOrderbookData);
774
+ let bids = message.bids.sort(bidsSortFn);
775
+ bids = bids.filter((item) => !isNaN(item[0]));
776
+ bids = bids.filter((item) => item[1] > 0);
777
+ let asks = message.asks.sort(asksSortFn);
778
+ asks = asks.filter((item) => !isNaN(item[0]));
779
+ asks = asks.filter((item) => item[1] > 0);
780
+ setRequestData({ bids, asks });
781
+ setData({ bids, asks });
776
782
  }
777
783
  setIsLoading(false);
778
784
  }
@@ -788,6 +794,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
788
794
  React2.useEffect(() => {
789
795
  if (!requestData)
790
796
  return;
797
+ let ignore = false;
791
798
  const subscription = ws.subscribe(
792
799
  {
793
800
  event: "subscribe",
@@ -795,15 +802,17 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
795
802
  },
796
803
  {
797
804
  onMessage: (message) => {
805
+ if (ignore)
806
+ return;
798
807
  setData((data2) => {
799
808
  const mergedData = !message.asks && !message.bids ? data2 : mergeOrderbook(data2, message);
800
- const reducedData = reduceOrderbook(depth, level, mergedData);
801
- return reducedData;
809
+ return mergedData;
802
810
  });
803
811
  }
804
812
  }
805
813
  );
806
814
  return () => {
815
+ ignore = true;
807
816
  subscription?.();
808
817
  };
809
818
  }, [symbol, requestData]);
@@ -829,10 +838,11 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
829
838
  React2.useEffect(() => {
830
839
  prevMiddlePrice.current = middlePrice;
831
840
  }, [middlePrice]);
841
+ const reducedData = reduceOrderbook(depth, level, data);
832
842
  return [
833
843
  {
834
- asks: data.asks.slice(-level),
835
- bids: data.bids.slice(0, level),
844
+ asks: reducedData.asks.slice(-level),
845
+ bids: reducedData.bids.slice(0, level),
836
846
  markPrice,
837
847
  middlePrice: [prevMiddlePrice.current, middlePrice]
838
848
  },
@@ -1263,6 +1273,197 @@ var useHoldingStream = () => {
1263
1273
  isLoading
1264
1274
  };
1265
1275
  };
1276
+ var usePrivateInfiniteQuery = (getKey, options) => {
1277
+ const { formatter, ...restOptions } = options || {};
1278
+ const account5 = useAccount();
1279
+ const middleware = Array.isArray(restOptions?.use) ? restOptions?.use ?? [] : [];
1280
+ const result = useSWRInfinite__default.default(
1281
+ (pageIndex, previousPageData) => account5.state.status >= types.AccountStatusEnum.EnableTrading ? getKey(pageIndex, previousPageData) : null,
1282
+ (url, init) => net.get(url, init, formatter),
1283
+ {
1284
+ ...restOptions,
1285
+ use: [signatureMiddleware, ...middleware]
1286
+ }
1287
+ );
1288
+ return result;
1289
+ };
1290
+ var useOrderStream = ({
1291
+ status,
1292
+ symbol,
1293
+ side,
1294
+ size = 100
1295
+ } = {}) => {
1296
+ const ws = useWS();
1297
+ const { data: markPrices = {} } = useMarkPricesStream();
1298
+ const [doCancelOrder] = useMutation("/v1/order", "DELETE");
1299
+ const [doUpdateOrder] = useMutation("/v1/order", "PUT");
1300
+ const ordersResponse = usePrivateInfiniteQuery(
1301
+ (pageIndex, previousPageData) => {
1302
+ if (previousPageData && !previousPageData.length)
1303
+ return null;
1304
+ const search = new URLSearchParams([
1305
+ ["size", size.toString()],
1306
+ ["page", `${pageIndex + 1}`]
1307
+ ]);
1308
+ if (status) {
1309
+ search.set(`status`, status);
1310
+ }
1311
+ if (symbol) {
1312
+ search.set(`symbol`, symbol);
1313
+ }
1314
+ if (side) {
1315
+ search.set(`side`, side);
1316
+ }
1317
+ return `/v1/orders?${search.toString()}`;
1318
+ },
1319
+ {
1320
+ initialSize: 1,
1321
+ onError: (err) => {
1322
+ console.error("fetch failed::::", err);
1323
+ },
1324
+ formatter: (data) => data
1325
+ }
1326
+ );
1327
+ const orders = React2.useMemo(() => {
1328
+ if (!ordersResponse.data) {
1329
+ return null;
1330
+ }
1331
+ return ordersResponse.data?.map((item) => item.rows)?.flat().map((item) => {
1332
+ return {
1333
+ ...item,
1334
+ mark_price: markPrices[item.symbol] ?? 0
1335
+ };
1336
+ });
1337
+ }, [ordersResponse.data, markPrices]);
1338
+ const total = React2.useMemo(() => {
1339
+ return ordersResponse.data?.[0]?.meta?.total || 0;
1340
+ }, [ordersResponse.data]);
1341
+ React2.useEffect(() => {
1342
+ const unsubscribe = ws.privateSubscribe(
1343
+ {
1344
+ id: "executionreport_orders",
1345
+ event: "subscribe",
1346
+ topic: "executionreport",
1347
+ ts: Date.now()
1348
+ },
1349
+ {
1350
+ onMessage: (data) => {
1351
+ const { status: status2, orderId, timestamp } = data;
1352
+ ordersResponse.mutate((prevData) => {
1353
+ const newOrder = {
1354
+ order_id: data.orderId,
1355
+ symbol: data.symbol,
1356
+ created_time: data.timestamp,
1357
+ quantity: data.quantity,
1358
+ side: data.side,
1359
+ executed: data.totalExecutedQuantity,
1360
+ price: data.price
1361
+ };
1362
+ const dataList = prevData?.map((item) => item.rows)?.flat() || [];
1363
+ if (status2 === types.OrderStatus.NEW) {
1364
+ if (!prevData) {
1365
+ return {
1366
+ meta: {
1367
+ total: 1,
1368
+ records_per_page: size,
1369
+ current_page: 1
1370
+ },
1371
+ rows: [newOrder]
1372
+ };
1373
+ }
1374
+ const total2 = (prevData?.[0]?.meta?.total || 0) + 1;
1375
+ const isNew = !dataList.find((item) => item.order_id === orderId);
1376
+ if (isNew) {
1377
+ const list = [newOrder, ...dataList];
1378
+ return rePageData(list, total2, size);
1379
+ }
1380
+ return prevData;
1381
+ }
1382
+ if (status2 === types.OrderStatus.CANCELLED || status2 === types.OrderStatus.FILLED) {
1383
+ const total2 = (prevData?.[0]?.meta?.total || 0) - 1;
1384
+ const list = dataList.filter(
1385
+ (order2) => order2.order_id !== orderId
1386
+ );
1387
+ return rePageData(list, total2, size);
1388
+ }
1389
+ if (status2 === types.OrderStatus.PARTIAL_FILLED) {
1390
+ return editPageData(dataList, newOrder);
1391
+ }
1392
+ if (status2 === types.OrderStatus.REPLACED) {
1393
+ return editPageData(dataList, newOrder);
1394
+ }
1395
+ return prevData;
1396
+ });
1397
+ }
1398
+ }
1399
+ );
1400
+ return () => unsubscribe();
1401
+ }, []);
1402
+ const cancelAllOrders = React2.useCallback(() => {
1403
+ }, [ordersResponse.data]);
1404
+ const updateOrder = React2.useCallback((orderId, order2) => {
1405
+ return doUpdateOrder({ ...order2, order_id: orderId });
1406
+ }, []);
1407
+ const cancelOrder = React2.useCallback((orderId, symbol2) => {
1408
+ return doCancelOrder(null, {
1409
+ order_id: orderId,
1410
+ symbol: symbol2
1411
+ }).then((res) => {
1412
+ if (res.success) ; else {
1413
+ throw new Error(res.message);
1414
+ }
1415
+ });
1416
+ }, []);
1417
+ const loadMore = () => {
1418
+ ordersResponse.setSize(ordersResponse.size + 1);
1419
+ };
1420
+ return [
1421
+ orders,
1422
+ {
1423
+ total,
1424
+ isLoading: ordersResponse.isLoading,
1425
+ loadMore,
1426
+ cancelAllOrders,
1427
+ updateOrder,
1428
+ cancelOrder
1429
+ }
1430
+ ];
1431
+ };
1432
+ function rePageData(list, total, pageSize) {
1433
+ const newData = [];
1434
+ let rows = [];
1435
+ let current_page = 0;
1436
+ for (let i = 0; i < list.length; i++) {
1437
+ rows.push(list[i]);
1438
+ if ((i + 1) % pageSize === 0 || i === list.length - 1) {
1439
+ newData.push({
1440
+ meta: {
1441
+ records_per_page: pageSize,
1442
+ total,
1443
+ current_page: current_page + 1
1444
+ },
1445
+ rows: [...rows]
1446
+ });
1447
+ rows = [];
1448
+ }
1449
+ }
1450
+ console.log("rePageData", list, total, newData);
1451
+ return newData;
1452
+ }
1453
+ function editPageData(list, newOrder) {
1454
+ const newData = list.map((item) => {
1455
+ return {
1456
+ ...item,
1457
+ rows: item.rows.map((row) => {
1458
+ if (row.order_id === newOrder.order_id) {
1459
+ return { ...row, newOrder };
1460
+ }
1461
+ return row;
1462
+ })
1463
+ };
1464
+ });
1465
+ return newData;
1466
+ }
1266
1467
 
1267
1468
  // src/orderly/useCollateral.ts
1268
1469
  var positionsPath = ramda.pathOr([], [0, "rows"]);
@@ -1270,9 +1471,7 @@ ramda.pathOr(0, [0, "totalCollateral"]);
1270
1471
  var useCollateral = (options = { dp: 6 }) => {
1271
1472
  const { dp } = options;
1272
1473
  const positions2 = usePositionStream();
1273
- const { data: orders } = usePrivateQuery(
1274
- `/v1/orders?status=NEW`
1275
- );
1474
+ const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
1276
1475
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1277
1476
  const symbolInfo = useSymbolsInfo();
1278
1477
  const { data: markPrices } = useMarkPricesStream();
@@ -1319,9 +1518,7 @@ var useCollateral = (options = { dp: 6 }) => {
1319
1518
  var positionsPath2 = ramda.pathOr([], [0, "rows"]);
1320
1519
  var useMaxQty = (symbol, side, reduceOnly = false) => {
1321
1520
  const positionsData = usePositionStream();
1322
- const { data: orders } = usePrivateQuery(
1323
- `/v1/orders?status=NEW`
1324
- );
1521
+ const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
1325
1522
  const { data: accountInfo } = usePrivateQuery("/v1/client/info");
1326
1523
  const symbolInfo = useSymbolsInfo();
1327
1524
  const { totalCollateral } = useCollateral();
@@ -1810,119 +2007,6 @@ var useFundingRate = (symbol) => {
1810
2007
  countDown
1811
2008
  };
1812
2009
  };
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
2010
  var useMarketTradeStream = (symbol, options = {}) => {
1927
2011
  if (!symbol) {
1928
2012
  throw new Error("useTradeStream: symbol is required");
@@ -3468,16 +3552,7 @@ var useBalance = () => {
3468
3552
  var usePrivateDataObserver = () => {
3469
3553
  const ws = useWS();
3470
3554
  const { mutate: mutate2 } = useSWR.useSWRConfig();
3471
- const ee = useEventEmitter();
3472
3555
  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
3556
  React2.useEffect(() => {
3482
3557
  if (!state.accountId)
3483
3558
  return;
@@ -3527,24 +3602,6 @@ var usePrivateDataObserver = () => {
3527
3602
  };
3528
3603
  }, [state.accountId]);
3529
3604
  };
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
3605
 
3549
3606
  // src/apis/index.ts
3550
3607
  var apis_exports = {};
@@ -4187,7 +4244,6 @@ Object.defineProperty(exports, 'useConstant', {
4187
4244
  get: function () { return useConstant__default.default; }
4188
4245
  });
4189
4246
  exports.DataSourceProvider = DataSourceProvider;
4190
- exports.OrderStatus = OrderStatus;
4191
4247
  exports.OrderlyContext = OrderlyContext;
4192
4248
  exports.OrderlyProvider = OrderlyProvider;
4193
4249
  exports.apis = apis_exports;
@@ -4204,7 +4260,6 @@ exports.useConfig = useConfig;
4204
4260
  exports.useCrossSwap = useCrossSwap;
4205
4261
  exports.useDeposit = useDeposit;
4206
4262
  exports.useEventEmitter = useEventEmitter;
4207
- exports.useExecutionReport = useExecutionReport;
4208
4263
  exports.useFetures = useFetures;
4209
4264
  exports.useFundingRate = useFundingRate;
4210
4265
  exports.useHoldingStream = useHoldingStream;