@orderly.network/trading 2.9.1 → 2.10.0-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
@@ -2498,40 +2498,6 @@ var init_header_desktop = __esm({
2498
2498
  };
2499
2499
  }
2500
2500
  });
2501
- var MiddlePriceView;
2502
- var init_midPriceView = __esm({
2503
- "src/components/base/orderBook/midPriceView.tsx"() {
2504
- MiddlePriceView = (props) => {
2505
- const {
2506
- markPrice = 0,
2507
- lastPrice,
2508
- quote_dp,
2509
- className,
2510
- iconSize = 18
2511
- } = props;
2512
- const [prevLastPrice, middlePrice] = lastPrice;
2513
- const down = middlePrice < prevLastPrice;
2514
- const up = middlePrice > prevLastPrice;
2515
- return /* @__PURE__ */ jsxs(
2516
- Flex,
2517
- {
2518
- gap: 1,
2519
- className: cn(
2520
- up ? "oui-text-trade-profit" : down ? "oui-text-trade-loss" : "",
2521
- className
2522
- ),
2523
- children: [
2524
- /* @__PURE__ */ jsx(Text.numeral, { dp: quote_dp, intensity: 98, children: middlePrice }),
2525
- /* @__PURE__ */ jsxs(Box, { width: 19, children: [
2526
- down && /* @__PURE__ */ jsx(ArrowDownShortIcon, { size: iconSize, color: "danger", opacity: 1 }),
2527
- up && /* @__PURE__ */ jsx(ArrowUpShortIcon, { size: iconSize, color: "success", opacity: 1 })
2528
- ] })
2529
- ]
2530
- }
2531
- );
2532
- };
2533
- }
2534
- });
2535
2501
  var MarkPriceView, DesktopLayout2, MobileLayout2, FlagIcon;
2536
2502
  var init_markPrice = __esm({
2537
2503
  "src/components/base/orderBook/markPrice.tsx"() {
@@ -2637,12 +2603,114 @@ var init_markPrice = __esm({
2637
2603
  };
2638
2604
  }
2639
2605
  });
2606
+ var UNDERLINE_CLASS, MiddlePriceView, DesktopLayout3, MobileLayout3;
2607
+ var init_midPriceView = __esm({
2608
+ "src/components/base/orderBook/midPriceView.tsx"() {
2609
+ UNDERLINE_CLASS = "oui-cursor-pointer oui-underline oui-decoration-dashed oui-decoration-1 oui-underline-offset-4 oui-decoration-base-contrast oui-inline-flex";
2610
+ MiddlePriceView = (props) => {
2611
+ const { isMobile } = useScreen();
2612
+ return isMobile ? /* @__PURE__ */ jsx(MobileLayout3, { ...props }) : /* @__PURE__ */ jsx(DesktopLayout3, { ...props });
2613
+ };
2614
+ DesktopLayout3 = (props) => {
2615
+ const { lastPrice, quote_dp, className, iconSize = 18 } = props;
2616
+ const { t } = useTranslation();
2617
+ const [prevLastPrice, middlePrice] = lastPrice;
2618
+ const down = middlePrice < prevLastPrice;
2619
+ const up = middlePrice > prevLastPrice;
2620
+ return /* @__PURE__ */ jsx(
2621
+ Tooltip,
2622
+ {
2623
+ content: t("trading.orderBook.middlePrice.tooltip"),
2624
+ className: "oui-max-w-[240px]",
2625
+ children: /* @__PURE__ */ jsx("span", { className: UNDERLINE_CLASS, children: /* @__PURE__ */ jsxs(
2626
+ Flex,
2627
+ {
2628
+ gap: 1,
2629
+ className: cn(
2630
+ up ? "oui-text-trade-profit" : down ? "oui-text-trade-loss" : "",
2631
+ className
2632
+ ),
2633
+ children: [
2634
+ /* @__PURE__ */ jsx(Text.numeral, { dp: quote_dp, intensity: 98, children: middlePrice }),
2635
+ /* @__PURE__ */ jsxs(Box, { width: 19, children: [
2636
+ down && /* @__PURE__ */ jsx(ArrowDownShortIcon, { size: iconSize, color: "danger", opacity: 1 }),
2637
+ up && /* @__PURE__ */ jsx(ArrowUpShortIcon, { size: iconSize, color: "success", opacity: 1 })
2638
+ ] })
2639
+ ]
2640
+ }
2641
+ ) })
2642
+ }
2643
+ );
2644
+ };
2645
+ MobileLayout3 = (props) => {
2646
+ const { lastPrice, quote_dp, className, iconSize = 18 } = props;
2647
+ const [open, setOpen] = useState(false);
2648
+ const { t } = useTranslation();
2649
+ const [prevLastPrice, middlePrice] = lastPrice;
2650
+ const down = middlePrice < prevLastPrice;
2651
+ const up = middlePrice > prevLastPrice;
2652
+ const handleTriggerClick = () => setOpen(true);
2653
+ const handleKeyDown = (e) => {
2654
+ if (e.key === "Enter" || e.key === " ") {
2655
+ e.preventDefault();
2656
+ setOpen(true);
2657
+ }
2658
+ };
2659
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
2660
+ /* @__PURE__ */ jsx(
2661
+ "span",
2662
+ {
2663
+ role: "button",
2664
+ tabIndex: 0,
2665
+ className: UNDERLINE_CLASS,
2666
+ onClick: handleTriggerClick,
2667
+ onKeyDown: handleKeyDown,
2668
+ "aria-label": t("trading.orderBook.middlePrice.tooltip"),
2669
+ children: /* @__PURE__ */ jsxs(
2670
+ Flex,
2671
+ {
2672
+ gap: 1,
2673
+ className: cn(
2674
+ up ? "oui-text-trade-profit" : down ? "oui-text-trade-loss" : "",
2675
+ className
2676
+ ),
2677
+ children: [
2678
+ /* @__PURE__ */ jsx(Text.numeral, { dp: quote_dp, intensity: 98, children: middlePrice }),
2679
+ /* @__PURE__ */ jsxs(Box, { width: 19, children: [
2680
+ down && /* @__PURE__ */ jsx(ArrowDownShortIcon, { size: iconSize, color: "danger", opacity: 1 }),
2681
+ up && /* @__PURE__ */ jsx(ArrowUpShortIcon, { size: iconSize, color: "success", opacity: 1 })
2682
+ ] })
2683
+ ]
2684
+ }
2685
+ )
2686
+ }
2687
+ ),
2688
+ /* @__PURE__ */ jsx(
2689
+ SimpleDialog,
2690
+ {
2691
+ size: "xs",
2692
+ open,
2693
+ onOpenChange: setOpen,
2694
+ title: t("common.tips"),
2695
+ actions: {
2696
+ primary: {
2697
+ label: t("common.ok"),
2698
+ onClick: () => setOpen(false)
2699
+ }
2700
+ },
2701
+ children: /* @__PURE__ */ jsx(Text, { children: t("trading.orderBook.middlePrice.tooltip") })
2702
+ }
2703
+ )
2704
+ ] });
2705
+ };
2706
+ }
2707
+ });
2640
2708
  var DesktopMarkPrice, Spread;
2641
2709
  var init_markPrice_desktop = __esm({
2642
2710
  "src/components/desktop/orderBook/markPrice.desktop.tsx"() {
2643
- init_orderContext();
2644
- init_midPriceView();
2645
2711
  init_markPrice();
2712
+ init_midPriceView();
2713
+ init_orderContext();
2646
2714
  DesktopMarkPrice = (props) => {
2647
2715
  const { markPrice = 0, lastPrice, asks, bids, symbolInfo } = props;
2648
2716
  const { showTotal } = useOrderBookContext();
@@ -2865,12 +2933,25 @@ var init_fundingRate_ui = __esm({
2865
2933
  };
2866
2934
  }
2867
2935
  });
2868
- var useFundingRateModalScript;
2936
+ var TIMEFRAME_CONFIG, useFundingRateModalScript;
2869
2937
  var init_fundingRateModal_script = __esm({
2870
2938
  "src/components/mobile/fundingRateModal/fundingRateModal.script.tsx"() {
2939
+ TIMEFRAME_CONFIG = [
2940
+ { key: "1H", hours: 1 },
2941
+ { key: "4H", hours: 4 },
2942
+ { key: "1D", hours: 24 },
2943
+ { key: "7D", hours: 168 },
2944
+ { key: "30D", hours: 720 },
2945
+ { key: "1Y", hours: 8760 }
2946
+ ];
2871
2947
  useFundingRateModalScript = (options) => {
2872
2948
  const { data, isLoading } = useFundingDetails(options.symbol);
2873
- const { last_funding_rate, est_funding_rate } = useFundingRateBySymbol(options.symbol) ?? {};
2949
+ const {
2950
+ last_funding_rate,
2951
+ est_funding_rate,
2952
+ next_funding_time,
2953
+ last_funding_rate_timestamp
2954
+ } = useFundingRateBySymbol(options.symbol) ?? {};
2874
2955
  const [{ aggregated, rows }] = usePositionStream(options.symbol);
2875
2956
  const { notional } = aggregated ?? {};
2876
2957
  const fundingPeriod = useMemo(() => {
@@ -2897,12 +2978,6 @@ var init_fundingRateModal_script = __esm({
2897
2978
  }
2898
2979
  return `${new Decimal(last_funding_rate).mul(100).toNumber()}%`;
2899
2980
  }, [last_funding_rate]);
2900
- const estFundingRate = useMemo(() => {
2901
- if (!est_funding_rate) {
2902
- return void 0;
2903
- }
2904
- return `${new Decimal(est_funding_rate).mul(100).toNumber()}%`;
2905
- }, [est_funding_rate]);
2906
2981
  const estFundingFee = useMemo(() => {
2907
2982
  if (!est_funding_rate || !notional || rows.length === 0) {
2908
2983
  return "--";
@@ -2922,23 +2997,30 @@ var init_fundingRateModal_script = __esm({
2922
2997
  const annualized = calculateAnnualizedRate(rate, data.funding_period);
2923
2998
  return annualized ? `${annualized}%` : void 0;
2924
2999
  }, [last_funding_rate, data?.funding_period]);
2925
- const estFundingRateAnnualized = useMemo(() => {
2926
- if (!est_funding_rate || !data?.funding_period) {
2927
- return void 0;
3000
+ const settlementIntervalHours = useMemo(() => {
3001
+ if (!next_funding_time || !last_funding_rate_timestamp) return 8;
3002
+ const diff = next_funding_time - last_funding_rate_timestamp;
3003
+ return diff / 36e5;
3004
+ }, [next_funding_time, last_funding_rate_timestamp]);
3005
+ const estFundingRateByTimeframe = useMemo(() => {
3006
+ if (est_funding_rate === void 0 || est_funding_rate === null || settlementIntervalHours <= 0) {
3007
+ return [];
2928
3008
  }
2929
- const rate = new Decimal(est_funding_rate).mul(100).toNumber();
2930
- const annualized = calculateAnnualizedRate(rate, data.funding_period);
2931
- return annualized ? `${annualized}%` : void 0;
2932
- }, [est_funding_rate, data?.funding_period]);
3009
+ return TIMEFRAME_CONFIG.map(({ key, hours }) => {
3010
+ const rate = new Decimal(est_funding_rate).mul(hours).div(settlementIntervalHours).mul(100);
3011
+ const str = rate.toFixed(5);
3012
+ const trimmed = str.replace(/\.?0+$/, "") || "0";
3013
+ return { timeframe: key, value: `${trimmed}%` };
3014
+ });
3015
+ }, [est_funding_rate, settlementIntervalHours]);
2933
3016
  return {
2934
3017
  fundingPeriod,
2935
3018
  capFunding,
2936
3019
  floorFunding,
2937
3020
  lastFundingRate,
2938
- estFundingRate,
2939
3021
  estFundingFee,
2940
3022
  lastFundingRateAnnualized,
2941
- estFundingRateAnnualized
3023
+ estFundingRateByTimeframe
2942
3024
  };
2943
3025
  };
2944
3026
  }
@@ -2953,10 +3035,9 @@ var init_fundingRateModal_ui = __esm({
2953
3035
  capFunding,
2954
3036
  floorFunding,
2955
3037
  lastFundingRate,
2956
- estFundingRate,
2957
3038
  estFundingFee,
2958
3039
  lastFundingRateAnnualized,
2959
- estFundingRateAnnualized
3040
+ estFundingRateByTimeframe
2960
3041
  } = props;
2961
3042
  const renderRow = (label, value, annualizedValue) => {
2962
3043
  if (!value) {
@@ -2993,10 +3074,13 @@ var init_fundingRateModal_ui = __esm({
2993
3074
  lastFundingRate,
2994
3075
  lastFundingRateAnnualized
2995
3076
  ),
2996
- renderRow(
2997
- t("trading.fundingRate.estimatedFundingRate"),
2998
- estFundingRate,
2999
- estFundingRateAnnualized
3077
+ estFundingRateByTimeframe.map(
3078
+ ({ timeframe, value }) => renderRow(
3079
+ t("trading.fundingRate.estFundingRateWithTimeframe", {
3080
+ timeframe
3081
+ }),
3082
+ value
3083
+ )
3000
3084
  ),
3001
3085
  renderRow(t("trading.fundingRate.estimatedFundingFee"), estFundingFee),
3002
3086
  /* @__PURE__ */ jsx(Divider, { my: 4, className: "oui-w-full", intensity: 8 }),
@@ -7780,7 +7864,7 @@ var LazyOrderBookAndTradesWidget = React12.lazy(
7780
7864
  };
7781
7865
  })
7782
7866
  );
7783
- var DesktopLayout3 = (props) => {
7867
+ var DesktopLayout4 = (props) => {
7784
7868
  const {
7785
7869
  resizeable,
7786
7870
  panelSize,
@@ -8610,7 +8694,7 @@ var MaybeEqual = () => {
8610
8694
  }
8611
8695
  );
8612
8696
  };
8613
- var MobileLayout3 = (props) => {
8697
+ var MobileLayout4 = (props) => {
8614
8698
  const { t } = useTranslation();
8615
8699
  const { isRwa, open, closeTimeInterval } = useGetRwaSymbolInfo(props.symbol);
8616
8700
  useEffect(() => {
@@ -8715,7 +8799,7 @@ var MobileLayout3 = (props) => {
8715
8799
  onOpenChange: props.onOpenMarketsSheetChange,
8716
8800
  classNames: {
8717
8801
  body: "oui-h-full oui-pb-0",
8718
- content: "oui-w-[280px] !oui-p-0"
8802
+ content: "!oui-w-[372px] !oui-max-w-[372px] !oui-p-0"
8719
8803
  },
8720
8804
  contentProps: { side: "left", closeable: false },
8721
8805
  children: /* @__PURE__ */ jsx(
@@ -8749,10 +8833,10 @@ var MobileLayout3 = (props) => {
8749
8833
  var Trading = (props) => {
8750
8834
  const { isMobile } = useScreen();
8751
8835
  if (isMobile) {
8752
- return /* @__PURE__ */ jsx(MobileLayout3, { ...props });
8836
+ return /* @__PURE__ */ jsx(MobileLayout4, { ...props });
8753
8837
  }
8754
8838
  return /* @__PURE__ */ jsx(
8755
- DesktopLayout3,
8839
+ DesktopLayout4,
8756
8840
  {
8757
8841
  className: "oui-h-[calc(100vh_-_48px_-_29px)] oui-bg-base-10",
8758
8842
  ...props