@orderly.network/hooks 1.1.4-alpha.3 → 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.mjs CHANGED
@@ -20,9 +20,9 @@ import { createClient } from '@layerzerolabs/scan-client';
20
20
  // src/version.ts
21
21
  if (typeof window !== "undefined") {
22
22
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
23
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.4-alpha.3";
23
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.4-alpha.4";
24
24
  }
25
- var version_default = "1.1.4-alpha.3";
25
+ var version_default = "1.1.4-alpha.4";
26
26
  var fetcher = (url, init = {}, queryOptions) => get(url, init, queryOptions?.formatter);
27
27
  var OrderlyContext = createContext({
28
28
  // configStore: new MemoryConfigStore(),
@@ -438,6 +438,8 @@ var useWS = () => {
438
438
  account5.on("change:status", (nextState) => {
439
439
  if (nextState.status === AccountStatusEnum.EnableTrading && nextState.accountId) {
440
440
  websocketClient.openPrivate(nextState.accountId);
441
+ } else {
442
+ websocketClient.closePrivate();
441
443
  }
442
444
  });
443
445
  if (typeof window !== "undefined") {
@@ -2320,7 +2322,9 @@ var OrderFactory = class {
2320
2322
  }
2321
2323
  };
2322
2324
  function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2325
+ let isNewVersion = false;
2323
2326
  if (typeof symbolOrOrder === "object") {
2327
+ isNewVersion = true;
2324
2328
  if (!symbolOrOrder.symbol) {
2325
2329
  throw new SDKError("symbol is required");
2326
2330
  }
@@ -2461,7 +2465,8 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2461
2465
  needParse?.order_type_ext,
2462
2466
  needParse?.symbol,
2463
2467
  needParse?.reduce_only,
2464
- needParse?.side
2468
+ needParse?.side,
2469
+ needParse?.visible_quantity
2465
2470
  ]);
2466
2471
  const createOrder = (values) => {
2467
2472
  if (!values.symbol) {
@@ -2599,8 +2604,17 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2599
2604
  markPrice
2600
2605
  ]);
2601
2606
  useEffect(() => {
2602
- if (!optionsValue?.watchOrderbook)
2603
- return;
2607
+ if (isNewVersion) {
2608
+ if (!optionsValue?.watchOrderbook) {
2609
+ throw new SDKError(
2610
+ "In order to calculate the estimated liquidation price, the `options.watchOrderbook` parameter must be set to true."
2611
+ );
2612
+ }
2613
+ } else {
2614
+ if (!optionsValue?.watchOrderbook) {
2615
+ return;
2616
+ }
2617
+ }
2604
2618
  ee.on("orderbook:update", onOrderbookUpdate);
2605
2619
  return () => {
2606
2620
  ee.off("orderbook_update", onOrderbookUpdate);
@@ -2612,8 +2626,14 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
2612
2626
  const getPriceAndQty = (symbolOrOrder2) => {
2613
2627
  let quantity = Number(symbolOrOrder2.order_quantity);
2614
2628
  const orderPrice = Number(symbolOrOrder2.order_price);
2615
- if (isNaN(quantity) || quantity <= 0 || askAndBid.current.length === 0)
2629
+ if (isNaN(quantity) || quantity <= 0) {
2616
2630
  return null;
2631
+ }
2632
+ if (!!options?.watchOrderbook && askAndBid.current.length === 0) {
2633
+ throw new SDKError(
2634
+ "Please check if you are using the `useOrderbookStream` hook or if the orderBook has data."
2635
+ );
2636
+ }
2617
2637
  if ((symbolOrOrder2.order_type === OrderType.LIMIT || symbolOrOrder2.order_type === OrderType.STOP_LIMIT) && isNaN(orderPrice))
2618
2638
  return null;
2619
2639
  let price;