@orderly.network/hooks 2.12.0-alpha.0 → 2.12.1-alpha.0

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
@@ -4,7 +4,7 @@ import useSWR5__default, { mutate } from 'swr';
4
4
  import * as useSWR5 from 'swr';
5
5
  export { useSWR5 as swr };
6
6
  export { unstable_serialize, default as useSWR, useSWRConfig } from 'swr';
7
- import { TesnetTokenFallback, ArbitrumSepoliaTokenInfo, SolanaDevnetTokenInfo, OrderType, OrderSide, MarginMode, SDKError, TrackerEventName, AccountStatusEnum, AlgoOrderType, AlgoOrderRootType, OrderStatus, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, EMPTY_LIST, EMPTY_OBJECT, isNativeTokenChecker, nativeTokenAddress, ChainKey, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, ChainNamespace, MaxUint256, DEPOSIT_FEE_RATE, ETHEREUM_MAINNET_CHAINID, LedgerWalletKey, SOLANA_TESTNET_CHAINID, MONAD_TESTNET_CHAINID, ABSTRACT_TESTNET_CHAINID, BSC_TESTNET_CHAINID, SolanaChains, PositionType, DistributionType, TriggerPriceType } from '@orderly.network/types';
7
+ import { TesnetTokenFallback, ArbitrumSepoliaTokenInfo, SolanaDevnetTokenInfo, MarginMode, OrderType, OrderSide, SDKError, TrackerEventName, AccountStatusEnum, AlgoOrderType, AlgoOrderRootType, OrderStatus, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, EMPTY_LIST, EMPTY_OBJECT, isNativeTokenChecker, nativeTokenAddress, ChainKey, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, ChainNamespace, MaxUint256, DEPOSIT_FEE_RATE, ETHEREUM_MAINNET_CHAINID, LedgerWalletKey, SOLANA_TESTNET_CHAINID, MONAD_TESTNET_CHAINID, ABSTRACT_TESTNET_CHAINID, BSC_TESTNET_CHAINID, SolanaChains, PositionType, DistributionType, TriggerPriceType } from '@orderly.network/types';
8
8
  import { zero, windowGuard, getTimestamp, getGlobalObject, Decimal, timeConvertString, isTestnet, getPrecisionByNumber, getBBOType, camelCaseToUnderscoreCase, commify, todpIfNeed, getTPSLDirection } from '@orderly.network/utils';
9
9
  import useSWRMutation from 'swr/mutation';
10
10
  import useConstant from 'use-constant';
@@ -49,9 +49,9 @@ function useMarketCategoriesConfig() {
49
49
  // src/version.ts
50
50
  if (typeof window !== "undefined") {
51
51
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
52
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.12.0-alpha.0";
52
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.12.1-alpha.0";
53
53
  }
54
- var version_default = "2.12.0-alpha.0";
54
+ var version_default = "2.12.1-alpha.0";
55
55
  var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
56
56
  var noCacheConfig = {
57
57
  dedupingInterval: 0,
@@ -3411,7 +3411,10 @@ var useGetRwaSymbolOpenTimeInterval = (symbol, thresholdMinutes = 30) => {
3411
3411
  };
3412
3412
  var useSymbolsInfo = () => {
3413
3413
  const symbolsInfo = useAppStore((state) => state.symbolsInfo);
3414
- return useMemo(() => createGetter({ ...symbolsInfo }), [symbolsInfo]);
3414
+ return useMemo(
3415
+ () => createGetter(symbolsInfo ? { ...symbolsInfo } : symbolsInfo),
3416
+ [symbolsInfo]
3417
+ );
3415
3418
  };
3416
3419
  var useSymbolsInfoStore = () => {
3417
3420
  return useAppStore((state) => state.symbolsInfo);
@@ -9714,6 +9717,9 @@ var PriceValidationStrategy = class {
9714
9717
  }
9715
9718
  const price = new Decimal(order_price);
9716
9719
  const { symbol } = config;
9720
+ if (!symbol) {
9721
+ return;
9722
+ }
9717
9723
  const { quote_max, quote_min, quote_dp, price_range, price_scope } = symbol;
9718
9724
  const maxPriceNumber = order.maxPrice(config.markPrice, price_range);
9719
9725
  const minPriceNumber = order.minPrice(config.markPrice, price_range);
@@ -9760,6 +9766,9 @@ var TriggerPriceValidationStrategy = class {
9760
9766
  validate(values, config) {
9761
9767
  const { trigger_price } = values;
9762
9768
  const { symbol } = config;
9769
+ if (!symbol) {
9770
+ return;
9771
+ }
9763
9772
  const { quote_max, quote_min } = symbol;
9764
9773
  if (!trigger_price) {
9765
9774
  return OrderValidation.required("trigger_price");
@@ -9806,6 +9815,9 @@ var QuantityValidationStrategy = class {
9806
9815
  validate(values, config) {
9807
9816
  let { order_quantity, total, order_price } = values;
9808
9817
  const { maxQty, symbol } = config;
9818
+ if (!symbol) {
9819
+ return;
9820
+ }
9809
9821
  const { base_min, base_dp, quote_dp } = symbol;
9810
9822
  if (!order_quantity && total && order_price) {
9811
9823
  const totalNumber = new Decimal(total);
@@ -18560,108 +18572,65 @@ var initialOrderState = {
18560
18572
  tp_trigger_price: "",
18561
18573
  sl_trigger_price: "",
18562
18574
  total: "",
18563
- symbol: ""
18575
+ symbol: "",
18576
+ side: OrderSide.BUY,
18577
+ order_type: OrderType.LIMIT,
18578
+ margin_mode: MarginMode.CROSS
18564
18579
  };
18565
- var useOrderStore = create()(
18566
- immer((set, get3) => ({
18567
- entry: {
18568
- side: OrderSide.BUY,
18569
- order_type: OrderType.LIMIT,
18570
- ...initialOrderState
18571
- },
18572
- estLeverage: null,
18573
- estLiquidationPrice: null,
18574
- errors: {},
18575
- actions: {
18576
- initOrder: (symbol, options) => {
18577
- set((state) => {
18578
- state.entry = {
18579
- ...initialOrderState,
18580
- symbol,
18581
- side: options?.side ?? OrderSide.BUY,
18582
- order_type: options?.order_type ?? OrderType.LIMIT,
18583
- margin_mode: options?.margin_mode ?? MarginMode.CROSS
18584
- };
18585
- state.estLeverage = null;
18586
- state.estLiquidationPrice = null;
18587
- state.errors = {};
18580
+ var useOrderEntryNextInternal = (symbol, options = {}) => {
18581
+ const { symbolInfo, symbolLeverage } = options;
18582
+ const [orderEntity, setOrderEntity] = useState(
18583
+ () => ({
18584
+ ...initialOrderState,
18585
+ ...options.initialOrder,
18586
+ symbol
18587
+ })
18588
+ );
18589
+ const actions = useMemo(
18590
+ () => ({
18591
+ initOrder: (sym, opts) => {
18592
+ setOrderEntity({
18593
+ ...initialOrderState,
18594
+ symbol: sym,
18595
+ side: opts?.side ?? OrderSide.BUY,
18596
+ order_type: opts?.order_type ?? OrderType.LIMIT,
18597
+ margin_mode: opts?.margin_mode ?? MarginMode.CROSS
18588
18598
  });
18589
18599
  },
18590
- hasTP_SL: () => {
18591
- const order = get3().entry;
18592
- return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
18593
- },
18594
- updateOrderComputed: (data) => {
18595
- set(
18596
- (state) => {
18597
- state.estLeverage = data.estLeverage;
18598
- state.estLiquidationPrice = data.estLiquidationPrice;
18599
- },
18600
- false
18601
- // "updateOrderComputed"
18602
- );
18603
- },
18604
18600
  updateOrder: (order) => {
18605
- set(
18606
- (state) => {
18607
- state.entry = {
18608
- ...state.entry,
18609
- ...order
18610
- };
18611
- },
18612
- false
18613
- // "updateOrder"
18614
- );
18601
+ setOrderEntity((prev) => ({ ...prev, ...order }));
18615
18602
  },
18616
18603
  updateOrderByKey: (key, value) => {
18617
- set(
18618
- (state) => {
18619
- state.entry[key] = value;
18620
- },
18621
- false
18622
- // "updateOrderByKey"
18623
- );
18624
- },
18625
- restoreOrder: (order) => {
18626
- set(
18627
- (state) => {
18628
- state.entry = order;
18629
- },
18630
- false
18631
- // "restoreOrder"
18632
- );
18604
+ setOrderEntity((prev) => ({ ...prev, [key]: value }));
18633
18605
  },
18634
18606
  resetOrder: (_order) => {
18635
- set(
18636
- (state) => {
18637
- state.entry.order_price = "";
18638
- state.entry.order_quantity = "";
18639
- state.entry.trigger_price = "";
18640
- state.entry.total = "";
18641
- state.entry.tp_trigger_price = "";
18642
- state.entry.tp_pnl = "";
18643
- state.entry.tp_offset = "";
18644
- state.entry.tp_offset_percentage = "";
18645
- state.entry.sl_trigger_price = "";
18646
- state.entry.sl_pnl = "";
18647
- state.entry.sl_offset = "";
18648
- state.entry.sl_offset_percentage = "";
18649
- },
18650
- true
18651
- // "resetOrder"
18652
- );
18607
+ setOrderEntity((prev) => ({
18608
+ ...prev,
18609
+ order_price: "",
18610
+ order_quantity: "",
18611
+ trigger_price: "",
18612
+ total: "",
18613
+ tp_trigger_price: "",
18614
+ tp_pnl: "",
18615
+ tp_offset: "",
18616
+ tp_offset_percentage: "",
18617
+ sl_trigger_price: "",
18618
+ sl_pnl: "",
18619
+ sl_offset: "",
18620
+ sl_offset_percentage: ""
18621
+ }));
18622
+ },
18623
+ hasTP_SL: () => {
18624
+ const order = orderEntity;
18625
+ return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
18653
18626
  }
18654
- }
18655
- }))
18656
- );
18657
- var useOrderEntryNextInternal = (symbol, options = {}) => {
18658
- const { symbolInfo, symbolLeverage } = options;
18659
- const orderEntity = useOrderStore((state) => state.entry);
18660
- const orderEntryActions = useOrderStore((state) => state.actions);
18627
+ }),
18628
+ [orderEntity]
18629
+ );
18661
18630
  useEffect(() => {
18662
- orderEntryActions.initOrder(symbol, options.initialOrder);
18631
+ actions.initOrder(symbol, options.initialOrder);
18663
18632
  if (options.initialOrder) {
18664
- orderEntryActions.updateOrder(options.initialOrder);
18633
+ actions.updateOrder(options.initialOrder);
18665
18634
  }
18666
18635
  }, [symbol]);
18667
18636
  const calculate2 = useCallback(
@@ -18679,10 +18648,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18679
18648
  );
18680
18649
  const setValue = (key, value, additional) => {
18681
18650
  if (!symbolInfo) {
18682
- orderEntryActions.updateOrderByKey(key, value);
18651
+ actions.updateOrderByKey(key, value);
18683
18652
  return;
18684
18653
  }
18685
- const currentEntry = useOrderStore.getState().entry;
18654
+ const currentEntry = orderEntity;
18686
18655
  const { markPrice } = additional ?? { markPrice: 0 };
18687
18656
  let newValues = calculate2(
18688
18657
  { ...currentEntry },
@@ -18716,7 +18685,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18716
18685
  if (sl_ROI) {
18717
18686
  newValues.sl_ROI = sl_ROI;
18718
18687
  }
18719
- orderEntryActions.updateOrder(newValues);
18688
+ actions.updateOrder(newValues);
18720
18689
  return newValues;
18721
18690
  };
18722
18691
  const calculateTPSL = (key, newValues, markPrice, symbolInfo2) => {
@@ -18763,11 +18732,10 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18763
18732
  };
18764
18733
  const setValues = (values, additional) => {
18765
18734
  if (!symbolInfo) {
18766
- orderEntryActions.updateOrder(values);
18735
+ actions.updateOrder(values);
18767
18736
  return;
18768
18737
  }
18769
- const currentEntry = useOrderStore.getState().entry;
18770
- let newValues = { ...currentEntry };
18738
+ let newValues = { ...orderEntity };
18771
18739
  Object.keys(values).forEach((key) => {
18772
18740
  newValues = calculate2(
18773
18741
  newValues,
@@ -18777,30 +18745,28 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18777
18745
  symbolInfo
18778
18746
  );
18779
18747
  });
18780
- orderEntryActions.updateOrder(newValues);
18748
+ actions.updateOrder(newValues);
18781
18749
  return newValues;
18782
18750
  };
18783
18751
  const setValuesRaw = (values) => {
18784
18752
  if (!symbolInfo) {
18785
- orderEntryActions.updateOrder(values);
18753
+ actions.updateOrder(values);
18786
18754
  return;
18787
18755
  }
18788
- const currentEntry = useOrderStore.getState().entry;
18789
18756
  const newValues = {
18790
- ...currentEntry,
18757
+ ...orderEntity,
18791
18758
  ...values
18792
18759
  };
18793
- orderEntryActions.updateOrder(newValues);
18760
+ actions.updateOrder(newValues);
18794
18761
  return newValues;
18795
18762
  };
18796
18763
  const onMarkPriceUpdated = useCallback(
18797
18764
  (markPrice, baseOn = []) => {
18798
18765
  if (!options.symbolInfo) return;
18799
- const currentEntry = useOrderStore.getState().entry;
18800
- let newValues = { ...currentEntry };
18766
+ let newValues = { ...orderEntity };
18801
18767
  if (baseOn.length === 0) {
18802
18768
  newValues = calculate2(
18803
- { ...currentEntry },
18769
+ { ...orderEntity },
18804
18770
  "order_price",
18805
18771
  markPrice,
18806
18772
  markPrice,
@@ -18811,7 +18777,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18811
18777
  newValues = calculate2(
18812
18778
  { ...newValues },
18813
18779
  key,
18814
- currentEntry[key],
18780
+ orderEntity[key],
18815
18781
  markPrice,
18816
18782
  options.symbolInfo
18817
18783
  );
@@ -18830,9 +18796,9 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18830
18796
  newValues.sl_ROI = sl_ROI;
18831
18797
  }
18832
18798
  }
18833
- orderEntryActions.updateOrder(newValues);
18799
+ actions.updateOrder(newValues);
18834
18800
  },
18835
- [calculate2, options.symbolInfo, orderEntryActions]
18801
+ [calculate2, options.symbolInfo, symbolLeverage, orderEntity]
18836
18802
  );
18837
18803
  const validate = (order, creator, options2) => {
18838
18804
  return creator?.validate(order, {
@@ -18850,7 +18816,7 @@ var useOrderEntryNextInternal = (symbol, options = {}) => {
18850
18816
  const submitOrder = useCallback(() => {
18851
18817
  }, [orderEntity]);
18852
18818
  const resetOrder = (order) => {
18853
- orderEntryActions.resetOrder(order);
18819
+ actions.resetOrder(order);
18854
18820
  };
18855
18821
  return {
18856
18822
  formattedOrder: orderEntity,
@@ -18893,8 +18859,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
18893
18859
  const symbolConfig = useSymbolsInfo();
18894
18860
  const accountInfo = useAccountInfo();
18895
18861
  const positions3 = usePositions();
18896
- const entry = useOrderStore((s) => s.entry);
18897
- const effectiveMarginMode = options?.initialOrder?.margin_mode ?? entry?.margin_mode ?? MarginMode.CROSS;
18862
+ const effectiveMarginMode = options?.initialOrder?.margin_mode ?? MarginMode.CROSS;
18898
18863
  const symbolLeverage = useLeverageBySymbol(symbol, effectiveMarginMode);
18899
18864
  const symbolInfo = symbolConfig[symbol]();
18900
18865
  const markPrice = actions.getMarkPriceBySymbol(symbol);
@@ -19338,6 +19303,107 @@ var useOrderEntry2 = (symbol, options = {}) => {
19338
19303
  symbolLeverage
19339
19304
  };
19340
19305
  };
19306
+ var initialOrderState2 = {
19307
+ order_price: "",
19308
+ order_quantity: "",
19309
+ trigger_price: "",
19310
+ tp_trigger_price: "",
19311
+ sl_trigger_price: "",
19312
+ total: "",
19313
+ symbol: ""
19314
+ };
19315
+ var useOrderStore = create()(
19316
+ immer((set, get3) => ({
19317
+ entry: {
19318
+ side: OrderSide.BUY,
19319
+ order_type: OrderType.LIMIT,
19320
+ ...initialOrderState2
19321
+ },
19322
+ estLeverage: null,
19323
+ estLiquidationPrice: null,
19324
+ errors: {},
19325
+ actions: {
19326
+ initOrder: (symbol, options) => {
19327
+ set((state) => {
19328
+ state.entry = {
19329
+ ...initialOrderState2,
19330
+ symbol,
19331
+ side: options?.side ?? OrderSide.BUY,
19332
+ order_type: options?.order_type ?? OrderType.LIMIT,
19333
+ margin_mode: options?.margin_mode ?? MarginMode.CROSS
19334
+ };
19335
+ state.estLeverage = null;
19336
+ state.estLiquidationPrice = null;
19337
+ state.errors = {};
19338
+ });
19339
+ },
19340
+ hasTP_SL: () => {
19341
+ const order = get3().entry;
19342
+ return typeof order.tp_trigger_price !== "undefined" || typeof order.sl_trigger_price !== "undefined";
19343
+ },
19344
+ updateOrderComputed: (data) => {
19345
+ set(
19346
+ (state) => {
19347
+ state.estLeverage = data.estLeverage;
19348
+ state.estLiquidationPrice = data.estLiquidationPrice;
19349
+ },
19350
+ false
19351
+ // "updateOrderComputed"
19352
+ );
19353
+ },
19354
+ updateOrder: (order) => {
19355
+ set(
19356
+ (state) => {
19357
+ state.entry = {
19358
+ ...state.entry,
19359
+ ...order
19360
+ };
19361
+ },
19362
+ false
19363
+ // "updateOrder"
19364
+ );
19365
+ },
19366
+ updateOrderByKey: (key, value) => {
19367
+ set(
19368
+ (state) => {
19369
+ state.entry[key] = value;
19370
+ },
19371
+ false
19372
+ // "updateOrderByKey"
19373
+ );
19374
+ },
19375
+ restoreOrder: (order) => {
19376
+ set(
19377
+ (state) => {
19378
+ state.entry = order;
19379
+ },
19380
+ false
19381
+ // "restoreOrder"
19382
+ );
19383
+ },
19384
+ resetOrder: (_order) => {
19385
+ set(
19386
+ (state) => {
19387
+ state.entry.order_price = "";
19388
+ state.entry.order_quantity = "";
19389
+ state.entry.trigger_price = "";
19390
+ state.entry.total = "";
19391
+ state.entry.tp_trigger_price = "";
19392
+ state.entry.tp_pnl = "";
19393
+ state.entry.tp_offset = "";
19394
+ state.entry.tp_offset_percentage = "";
19395
+ state.entry.sl_trigger_price = "";
19396
+ state.entry.sl_pnl = "";
19397
+ state.entry.sl_offset = "";
19398
+ state.entry.sl_offset_percentage = "";
19399
+ },
19400
+ true
19401
+ // "resetOrder"
19402
+ );
19403
+ }
19404
+ }
19405
+ }))
19406
+ );
19341
19407
  var useOrderEntity = (order, options) => {
19342
19408
  const { symbol } = order;
19343
19409
  const { maxQty } = options || {};