@orderly.network/hooks 1.1.4-alpha.2 → 1.1.4-alpha.4

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.2";
28
+ declare const _default: "1.1.4-alpha.4";
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.2";
28
+ declare const _default: "1.1.4-alpha.4";
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.2";
31
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.4-alpha.4";
32
32
  }
33
- var version_default = "1.1.4-alpha.2";
33
+ var version_default = "1.1.4-alpha.4";
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") {
@@ -2328,7 +2330,9 @@ var OrderFactory = class {
2328
2330
  }
2329
2331
  };
2330
2332
  function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2333
+ let isNewVersion = false;
2331
2334
  if (typeof symbolOrOrder === "object") {
2335
+ isNewVersion = true;
2332
2336
  if (!symbolOrOrder.symbol) {
2333
2337
  throw new types.SDKError("symbol is required");
2334
2338
  }
@@ -2469,7 +2473,8 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2469
2473
  needParse?.order_type_ext,
2470
2474
  needParse?.symbol,
2471
2475
  needParse?.reduce_only,
2472
- needParse?.side
2476
+ needParse?.side,
2477
+ needParse?.visible_quantity
2473
2478
  ]);
2474
2479
  const createOrder = (values) => {
2475
2480
  if (!values.symbol) {
@@ -2607,8 +2612,17 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2607
2612
  markPrice
2608
2613
  ]);
2609
2614
  React.useEffect(() => {
2610
- if (!optionsValue?.watchOrderbook)
2611
- return;
2615
+ if (isNewVersion) {
2616
+ if (!optionsValue?.watchOrderbook) {
2617
+ throw new types.SDKError(
2618
+ "In order to calculate the estimated liquidation price, the `options.watchOrderbook` parameter must be set to true."
2619
+ );
2620
+ }
2621
+ } else {
2622
+ if (!optionsValue?.watchOrderbook) {
2623
+ return;
2624
+ }
2625
+ }
2612
2626
  ee.on("orderbook:update", onOrderbookUpdate);
2613
2627
  return () => {
2614
2628
  ee.off("orderbook_update", onOrderbookUpdate);
@@ -2620,8 +2634,14 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2620
2634
  const getPriceAndQty = (symbolOrOrder2) => {
2621
2635
  let quantity = Number(symbolOrOrder2.order_quantity);
2622
2636
  const orderPrice = Number(symbolOrOrder2.order_price);
2623
- if (isNaN(quantity) || quantity <= 0 || askAndBid.current.length === 0)
2637
+ if (isNaN(quantity) || quantity <= 0) {
2624
2638
  return null;
2639
+ }
2640
+ if (!!options?.watchOrderbook && askAndBid.current.length === 0) {
2641
+ throw new types.SDKError(
2642
+ "Please check if you are using the `useOrderbookStream` hook or if the orderBook has data."
2643
+ );
2644
+ }
2625
2645
  if ((symbolOrOrder2.order_type === types.OrderType.LIMIT || symbolOrOrder2.order_type === types.OrderType.STOP_LIMIT) && isNaN(orderPrice))
2626
2646
  return null;
2627
2647
  let price;