@orderly.network/hooks 1.1.4-alpha.3 → 1.1.4-alpha.5

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
@@ -25,7 +25,7 @@ declare global {
25
25
  };
26
26
  }
27
27
  }
28
- declare const _default: "1.1.4-alpha.3";
28
+ declare const _default: "1.1.4-alpha.5";
29
29
 
30
30
  type useQueryOptions<T> = SWRConfiguration & {
31
31
  formatter?: (data: any) => T;
@@ -244,21 +244,30 @@ type UseOrderEntryReturn = {
244
244
  metaState: UseOrderEntryMetaState;
245
245
  symbolConfig: API.SymbolExt;
246
246
  };
247
- type OrderParams = Required<Pick<OrderEntity, "side" | "order_type" | "symbol">> & Partial<Omit<OrderEntity, "side" | "symbol" | "order_type">> & {};
247
+ type OrderParams = Required<Pick<OrderEntity, "side" | "order_type" | "symbol">> & Partial<Omit<OrderEntity, "side" | "symbol" | "order_type">>;
248
248
  /**
249
249
  * Create Order
250
250
  * @example
251
251
  * ```tsx
252
+ * import { useOrderEntry } from "@orderly.network/hooks";
253
+ * import {OrderSide, OrderType} from '@orderly.network/types';
254
+ *
252
255
  * const { formattedOrder, onSubmit, helper } = useOrderEntry({
253
256
  * symbol: "PERP_ETH_USDC",
254
257
  * side: OrderSide.BUY,
255
258
  * order_type: OrderType.LIMIT,
256
259
  * order_price: 10000,
257
260
  * order_quantity: 1,
261
+ * },{
262
+ * // **Note:** it's required
263
+ * watchOrderbook: true,
258
264
  * });
259
265
  * ```
260
266
  */
261
267
  declare function useOrderEntry(order: OrderParams, options?: UseOrderEntryOptions): UseOrderEntryReturn;
268
+ /**
269
+ * @deprecated
270
+ */
262
271
  declare function useOrderEntry(symbol: string, side: OrderSide, reduceOnly: boolean): UseOrderEntryReturn;
263
272
 
264
273
  declare const useSymbolsInfo: () => Record<string, any>;
package/dist/index.d.ts CHANGED
@@ -25,7 +25,7 @@ declare global {
25
25
  };
26
26
  }
27
27
  }
28
- declare const _default: "1.1.4-alpha.3";
28
+ declare const _default: "1.1.4-alpha.5";
29
29
 
30
30
  type useQueryOptions<T> = SWRConfiguration & {
31
31
  formatter?: (data: any) => T;
@@ -244,21 +244,30 @@ type UseOrderEntryReturn = {
244
244
  metaState: UseOrderEntryMetaState;
245
245
  symbolConfig: API.SymbolExt;
246
246
  };
247
- type OrderParams = Required<Pick<OrderEntity, "side" | "order_type" | "symbol">> & Partial<Omit<OrderEntity, "side" | "symbol" | "order_type">> & {};
247
+ type OrderParams = Required<Pick<OrderEntity, "side" | "order_type" | "symbol">> & Partial<Omit<OrderEntity, "side" | "symbol" | "order_type">>;
248
248
  /**
249
249
  * Create Order
250
250
  * @example
251
251
  * ```tsx
252
+ * import { useOrderEntry } from "@orderly.network/hooks";
253
+ * import {OrderSide, OrderType} from '@orderly.network/types';
254
+ *
252
255
  * const { formattedOrder, onSubmit, helper } = useOrderEntry({
253
256
  * symbol: "PERP_ETH_USDC",
254
257
  * side: OrderSide.BUY,
255
258
  * order_type: OrderType.LIMIT,
256
259
  * order_price: 10000,
257
260
  * order_quantity: 1,
261
+ * },{
262
+ * // **Note:** it's required
263
+ * watchOrderbook: true,
258
264
  * });
259
265
  * ```
260
266
  */
261
267
  declare function useOrderEntry(order: OrderParams, options?: UseOrderEntryOptions): UseOrderEntryReturn;
268
+ /**
269
+ * @deprecated
270
+ */
262
271
  declare function useOrderEntry(symbol: string, side: OrderSide, reduceOnly: boolean): UseOrderEntryReturn;
263
272
 
264
273
  declare const useSymbolsInfo: () => Record<string, any>;
package/dist/index.js CHANGED
@@ -28,9 +28,9 @@ var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscriptio
28
28
  // src/version.ts
29
29
  if (typeof window !== "undefined") {
30
30
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
31
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.4-alpha.3";
31
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.4-alpha.5";
32
32
  }
33
- var version_default = "1.1.4-alpha.3";
33
+ var version_default = "1.1.4-alpha.5";
34
34
  var fetcher = (url, init = {}, queryOptions) => net.get(url, init, queryOptions?.formatter);
35
35
  var OrderlyContext = React.createContext({
36
36
  // configStore: new MemoryConfigStore(),
@@ -446,6 +446,8 @@ var useWS = () => {
446
446
  account5.on("change:status", (nextState) => {
447
447
  if (nextState.status === types.AccountStatusEnum.EnableTrading && nextState.accountId) {
448
448
  websocketClient.openPrivate(nextState.accountId);
449
+ } else {
450
+ websocketClient.closePrivate();
449
451
  }
450
452
  });
451
453
  if (typeof window !== "undefined") {
@@ -970,20 +972,24 @@ var reduceOrderbook = (depth, level, data) => {
970
972
  let bids = reduceItems(depth, level, data.bids);
971
973
  if (asks.length !== 0 && bids.length !== 0 && asks[0][0] <= bids[0][0]) {
972
974
  if (asks.length === 1) {
973
- const [price, qty, newQuantity] = asks[0];
975
+ const [price, qty, newQuantity, newAmount] = asks[0];
974
976
  asks.shift();
975
- asks.push([price + (depth === void 0 ? 0 : depth), qty, newQuantity]);
977
+ asks.push([price + (depth === void 0 ? 0 : depth), qty, newQuantity, newAmount]);
976
978
  } else {
977
979
  const [bidPrice] = bids[0];
978
980
  while (asks.length > 0) {
979
- const [askPrice, askQty, newQuantity] = asks[0];
981
+ const [askPrice, askQty, newQuantity, newAmount] = asks[0];
980
982
  if (askPrice <= bidPrice) {
981
983
  asks.shift();
982
984
  for (let index = 0; index < asks.length; index++) {
983
985
  if (index === 0) {
984
- asks[index][1] += askQty;
986
+ const quantity = asks[index][1] + askQty;
987
+ asks[index][1] = quantity;
988
+ asks[index][2] = quantity;
989
+ asks[index][3] += newAmount;
990
+ } else {
991
+ asks[index][3] += newAmount;
985
992
  }
986
- asks[index][2] += newQuantity;
987
993
  }
988
994
  } else {
989
995
  break;
@@ -2328,7 +2334,9 @@ var OrderFactory = class {
2328
2334
  }
2329
2335
  };
2330
2336
  function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2337
+ let isNewVersion = false;
2331
2338
  if (typeof symbolOrOrder === "object") {
2339
+ isNewVersion = true;
2332
2340
  if (!symbolOrOrder.symbol) {
2333
2341
  throw new types.SDKError("symbol is required");
2334
2342
  }
@@ -2469,7 +2477,8 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2469
2477
  needParse?.order_type_ext,
2470
2478
  needParse?.symbol,
2471
2479
  needParse?.reduce_only,
2472
- needParse?.side
2480
+ needParse?.side,
2481
+ needParse?.visible_quantity
2473
2482
  ]);
2474
2483
  const createOrder = (values) => {
2475
2484
  if (!values.symbol) {
@@ -2607,8 +2616,17 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2607
2616
  markPrice
2608
2617
  ]);
2609
2618
  React.useEffect(() => {
2610
- if (!optionsValue?.watchOrderbook)
2611
- return;
2619
+ if (isNewVersion) {
2620
+ if (!optionsValue?.watchOrderbook) {
2621
+ throw new types.SDKError(
2622
+ "In order to calculate the estimated liquidation price, the `options.watchOrderbook` parameter must be set to true."
2623
+ );
2624
+ }
2625
+ } else {
2626
+ if (!optionsValue?.watchOrderbook) {
2627
+ return;
2628
+ }
2629
+ }
2612
2630
  ee.on("orderbook:update", onOrderbookUpdate);
2613
2631
  return () => {
2614
2632
  ee.off("orderbook_update", onOrderbookUpdate);
@@ -2620,8 +2638,14 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2620
2638
  const getPriceAndQty = (symbolOrOrder2) => {
2621
2639
  let quantity = Number(symbolOrOrder2.order_quantity);
2622
2640
  const orderPrice = Number(symbolOrOrder2.order_price);
2623
- if (isNaN(quantity) || quantity <= 0 || askAndBid.current.length === 0)
2641
+ if (isNaN(quantity) || quantity <= 0) {
2624
2642
  return null;
2643
+ }
2644
+ if (!!options?.watchOrderbook && askAndBid.current.length === 0) {
2645
+ throw new types.SDKError(
2646
+ "Please check if you are using the `useOrderbookStream` hook or if the orderBook has data."
2647
+ );
2648
+ }
2625
2649
  if ((symbolOrOrder2.order_type === types.OrderType.LIMIT || symbolOrOrder2.order_type === types.OrderType.STOP_LIMIT) && isNaN(orderPrice))
2626
2650
  return null;
2627
2651
  let price;