@orderly.network/hooks 2.1.3 → 2.2.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.d.mts CHANGED
@@ -14,8 +14,8 @@ export { default as useConstant } from 'use-constant';
14
14
  import { WS } from '@orderly.network/net';
15
15
  import * as react from 'react';
16
16
  import { PropsWithChildren, FC, ReactNode } from 'react';
17
- import { SolanaWalletProvider } from '@orderly.network/default-solana-adapter';
18
17
  import { EIP1193Provider } from '@web3-onboard/common';
18
+ import { SolanaWalletProvider } from '@orderly.network/default-solana-adapter';
19
19
  import * as swr_subscription from 'swr/subscription';
20
20
  import * as _orderly_network_utils from '@orderly.network/utils';
21
21
  export * from 'use-debounce';
@@ -29,7 +29,7 @@ declare global {
29
29
  };
30
30
  }
31
31
  }
32
- declare const _default: "2.1.3";
32
+ declare const _default: "2.2.0";
33
33
 
34
34
  type useQueryOptions<T> = SWRConfiguration & {
35
35
  formatter?: (data: any) => T;
@@ -58,7 +58,23 @@ type HTTP_METHOD = "POST" | "PUT" | "DELETE" | "GET";
58
58
  /**
59
59
  * This hook is used to execute API requests for data mutation, such as POST, DELETE, PUT, etc.
60
60
  */
61
- declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E>) => readonly [(data: Record<string, any> | null, params?: Record<string, any>, options?: SWRMutationConfiguration<T, E>) => Promise<any>, {
61
+ declare const useMutation: <T, E>(
62
+ /**
63
+ * The URL to send the request to. If the URL does not start with "http",
64
+ * it will be prefixed with the API base URL.
65
+ */
66
+ url: string,
67
+ /**
68
+ * The HTTP method to use for the request. Defaults to "POST".
69
+ */
70
+ method?: HTTP_METHOD,
71
+ /**
72
+ * The configuration object for the mutation.
73
+ * @see [useSWRMutation](https://swr.vercel.app/docs/mutation#api)
74
+ *
75
+ * @link https://swr.vercel.app/docs/mutation#api
76
+ */
77
+ options?: SWRMutationConfiguration<T, E>) => readonly [(data: Record<string, any> | null, params?: Record<string, any>, options?: SWRMutationConfiguration<T, E>) => Promise<any>, {
62
78
  readonly data: any;
63
79
  readonly error: E | undefined;
64
80
  readonly reset: () => void;
@@ -263,6 +279,7 @@ interface WalletState {
263
279
  accounts: WalletAccount[];
264
280
  chains: ConnectedChain[];
265
281
  instance?: unknown;
282
+ additionalInfo?: Record<string, any>;
266
283
  }
267
284
  interface WalletConnectorContextState {
268
285
  connect: (options?: any) => Promise<WalletState[]>;
@@ -489,7 +506,17 @@ declare const useMarkPrice: (symbol: string) => {
489
506
 
490
507
  declare const useIndexPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
491
508
 
492
- declare const useLeverage: () => any;
509
+ declare const useLeverage: () => {
510
+ readonly update: (data: {
511
+ leverage: number;
512
+ }) => Promise<{
513
+ max_leverage: string | number;
514
+ } | undefined>;
515
+ readonly isLoading: boolean;
516
+ readonly leverageLevers: number[];
517
+ readonly curLeverage: number;
518
+ readonly maxLeverage: number;
519
+ };
493
520
 
494
521
  declare const useTickerStream: (symbol: string) => API.MarketInfo & {
495
522
  change?: number;
@@ -521,7 +548,11 @@ declare const useFundingRateHistory: () => {
521
548
  };
522
549
 
523
550
  type PriceMode = "markPrice" | "lastPrice";
524
- declare const usePositionStream: (symbol?: string, options?: SWRConfiguration & {
551
+ declare const usePositionStream: (
552
+ /**
553
+ * If symbol is passed, only the position of that symbol will be returned.
554
+ */
555
+ symbol?: string, options?: SWRConfiguration & {
525
556
  calcMode?: PriceMode;
526
557
  /**
527
558
  * If true, the pending order will be included in the result.
@@ -563,7 +594,11 @@ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration &
563
594
  }];
564
595
 
565
596
  type CombineOrderType = AlgoOrderRootType | "ALL";
566
- declare const useOrderStream: (params: {
597
+ declare const useOrderStream: (
598
+ /**
599
+ * Orders query params
600
+ */
601
+ params: {
567
602
  symbol?: string;
568
603
  status?: OrderStatus;
569
604
  page?: number;
@@ -838,7 +873,11 @@ ComputedAlgoOrder, {
838
873
  isUpdateMutating: boolean;
839
874
  }];
840
875
 
841
- declare const useTPSLOrder: (position: Partial<API.PositionTPSLExt> & Pick<API.PositionTPSLExt, "symbol" | "average_open_price" | "position_qty">, options?: {
876
+ declare const useTPSLOrder: (
877
+ /**
878
+ * Position that needs to set take profit and stop loss
879
+ */
880
+ position: Partial<API.PositionTPSLExt> & Pick<API.PositionTPSLExt, "symbol" | "average_open_price" | "position_qty">, options?: {
842
881
  /**
843
882
  * You can set the default value for the take profit and stop loss order,
844
883
  * it is usually used when editing order
@@ -1133,7 +1172,11 @@ type DrawOptions = {
1133
1172
  * });
1134
1173
  * ```
1135
1174
  */
1136
- declare const usePoster: (data: DrawOptions, options?: {
1175
+ declare const usePoster: (
1176
+ /**
1177
+ * The options to draw the poster
1178
+ */
1179
+ data: DrawOptions, options?: {
1137
1180
  /**
1138
1181
  * The ratio of the poster
1139
1182
  */
package/dist/index.d.ts CHANGED
@@ -14,8 +14,8 @@ export { default as useConstant } from 'use-constant';
14
14
  import { WS } from '@orderly.network/net';
15
15
  import * as react from 'react';
16
16
  import { PropsWithChildren, FC, ReactNode } from 'react';
17
- import { SolanaWalletProvider } from '@orderly.network/default-solana-adapter';
18
17
  import { EIP1193Provider } from '@web3-onboard/common';
18
+ import { SolanaWalletProvider } from '@orderly.network/default-solana-adapter';
19
19
  import * as swr_subscription from 'swr/subscription';
20
20
  import * as _orderly_network_utils from '@orderly.network/utils';
21
21
  export * from 'use-debounce';
@@ -29,7 +29,7 @@ declare global {
29
29
  };
30
30
  }
31
31
  }
32
- declare const _default: "2.1.3";
32
+ declare const _default: "2.2.0";
33
33
 
34
34
  type useQueryOptions<T> = SWRConfiguration & {
35
35
  formatter?: (data: any) => T;
@@ -58,7 +58,23 @@ type HTTP_METHOD = "POST" | "PUT" | "DELETE" | "GET";
58
58
  /**
59
59
  * This hook is used to execute API requests for data mutation, such as POST, DELETE, PUT, etc.
60
60
  */
61
- declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E>) => readonly [(data: Record<string, any> | null, params?: Record<string, any>, options?: SWRMutationConfiguration<T, E>) => Promise<any>, {
61
+ declare const useMutation: <T, E>(
62
+ /**
63
+ * The URL to send the request to. If the URL does not start with "http",
64
+ * it will be prefixed with the API base URL.
65
+ */
66
+ url: string,
67
+ /**
68
+ * The HTTP method to use for the request. Defaults to "POST".
69
+ */
70
+ method?: HTTP_METHOD,
71
+ /**
72
+ * The configuration object for the mutation.
73
+ * @see [useSWRMutation](https://swr.vercel.app/docs/mutation#api)
74
+ *
75
+ * @link https://swr.vercel.app/docs/mutation#api
76
+ */
77
+ options?: SWRMutationConfiguration<T, E>) => readonly [(data: Record<string, any> | null, params?: Record<string, any>, options?: SWRMutationConfiguration<T, E>) => Promise<any>, {
62
78
  readonly data: any;
63
79
  readonly error: E | undefined;
64
80
  readonly reset: () => void;
@@ -263,6 +279,7 @@ interface WalletState {
263
279
  accounts: WalletAccount[];
264
280
  chains: ConnectedChain[];
265
281
  instance?: unknown;
282
+ additionalInfo?: Record<string, any>;
266
283
  }
267
284
  interface WalletConnectorContextState {
268
285
  connect: (options?: any) => Promise<WalletState[]>;
@@ -489,7 +506,17 @@ declare const useMarkPrice: (symbol: string) => {
489
506
 
490
507
  declare const useIndexPrice: (symbol: string) => swr_subscription.SWRSubscriptionResponse<any, any>;
491
508
 
492
- declare const useLeverage: () => any;
509
+ declare const useLeverage: () => {
510
+ readonly update: (data: {
511
+ leverage: number;
512
+ }) => Promise<{
513
+ max_leverage: string | number;
514
+ } | undefined>;
515
+ readonly isLoading: boolean;
516
+ readonly leverageLevers: number[];
517
+ readonly curLeverage: number;
518
+ readonly maxLeverage: number;
519
+ };
493
520
 
494
521
  declare const useTickerStream: (symbol: string) => API.MarketInfo & {
495
522
  change?: number;
@@ -521,7 +548,11 @@ declare const useFundingRateHistory: () => {
521
548
  };
522
549
 
523
550
  type PriceMode = "markPrice" | "lastPrice";
524
- declare const usePositionStream: (symbol?: string, options?: SWRConfiguration & {
551
+ declare const usePositionStream: (
552
+ /**
553
+ * If symbol is passed, only the position of that symbol will be returned.
554
+ */
555
+ symbol?: string, options?: SWRConfiguration & {
525
556
  calcMode?: PriceMode;
526
557
  /**
527
558
  * If true, the pending order will be included in the result.
@@ -563,7 +594,11 @@ declare const usePositionStream: (symbol?: string, options?: SWRConfiguration &
563
594
  }];
564
595
 
565
596
  type CombineOrderType = AlgoOrderRootType | "ALL";
566
- declare const useOrderStream: (params: {
597
+ declare const useOrderStream: (
598
+ /**
599
+ * Orders query params
600
+ */
601
+ params: {
567
602
  symbol?: string;
568
603
  status?: OrderStatus;
569
604
  page?: number;
@@ -838,7 +873,11 @@ ComputedAlgoOrder, {
838
873
  isUpdateMutating: boolean;
839
874
  }];
840
875
 
841
- declare const useTPSLOrder: (position: Partial<API.PositionTPSLExt> & Pick<API.PositionTPSLExt, "symbol" | "average_open_price" | "position_qty">, options?: {
876
+ declare const useTPSLOrder: (
877
+ /**
878
+ * Position that needs to set take profit and stop loss
879
+ */
880
+ position: Partial<API.PositionTPSLExt> & Pick<API.PositionTPSLExt, "symbol" | "average_open_price" | "position_qty">, options?: {
842
881
  /**
843
882
  * You can set the default value for the take profit and stop loss order,
844
883
  * it is usually used when editing order
@@ -1133,7 +1172,11 @@ type DrawOptions = {
1133
1172
  * });
1134
1173
  * ```
1135
1174
  */
1136
- declare const usePoster: (data: DrawOptions, options?: {
1175
+ declare const usePoster: (
1176
+ /**
1177
+ * The options to draw the poster
1178
+ */
1179
+ data: DrawOptions, options?: {
1137
1180
  /**
1138
1181
  * The ratio of the poster
1139
1182
  */
package/dist/index.js CHANGED
@@ -61,9 +61,9 @@ var __export = (target, all) => {
61
61
  // src/version.ts
62
62
  if (typeof window !== "undefined") {
63
63
  window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
64
- window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.1.3";
64
+ window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.2.0";
65
65
  }
66
- var version_default = "2.1.3";
66
+ var version_default = "2.2.0";
67
67
  var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
68
68
  var OrderlyContext = React.createContext({
69
69
  // configStore: new MemoryConfigStore(),
@@ -3144,30 +3144,59 @@ var useMarkPricesStream = () => {
3144
3144
  const data = useMarkPriceStore((state) => state.markPrices);
3145
3145
  return { data };
3146
3146
  };
3147
+ var generateLeverageLevers = (max3) => {
3148
+ const min3 = 1;
3149
+ const parts = 5;
3150
+ const step = (max3 - min3) / (parts - 1);
3151
+ const result = [];
3152
+ for (let i = 0; i < parts; i++) {
3153
+ result.push(Math.floor(min3 + step * i));
3154
+ }
3155
+ return result;
3156
+ };
3147
3157
  var useLeverage = () => {
3148
- const { data, mutate: mutate3 } = usePrivateQuery("/v1/client/info");
3158
+ const { data, mutate: mutate3 } = usePrivateQuery(
3159
+ "/v1/client/info"
3160
+ );
3149
3161
  const [update, { isMutating }] = useMutation("/v1/client/leverage");
3150
- const { data: config } = useQuery("/v1/public/config", {
3151
- revalidateOnFocus: false
3162
+ const { data: leverageConfig, isLoading } = useQuery("/v1/public/leverage", {
3163
+ revalidateOnFocus: false,
3164
+ errorRetryCount: 3
3165
+ // formatter: (data) => data,
3152
3166
  });
3153
- const updateLeverage = React.useCallback((data2) => {
3154
- return update(data2).then((res) => {
3167
+ const updateLeverage = React.useCallback(
3168
+ async (data2) => {
3169
+ const res = await update(data2);
3155
3170
  if (res.success) {
3156
3171
  return mutate3();
3157
3172
  } else {
3158
3173
  throw new Error(res.message);
3159
3174
  }
3160
- });
3161
- }, []);
3162
- return [
3163
- ramda.prop("max_leverage", data),
3164
- {
3165
- update: updateLeverage,
3166
- isMutating,
3167
- // config: [1, 2, 3, 4, 5, 10, 15, 20],
3168
- config: config ? config?.available_futures_leverage?.split(",").map((item) => parseInt(item)) : []
3169
- }
3170
- ];
3175
+ },
3176
+ [update, mutate3]
3177
+ );
3178
+ const memoizedCurLeverage = React.useMemo(() => {
3179
+ if (data?.max_leverage !== void 0) {
3180
+ return Number(data.max_leverage);
3181
+ }
3182
+ return 1;
3183
+ }, [data?.max_leverage]);
3184
+ const memoizedMaxLeverage = React.useMemo(() => {
3185
+ if (leverageConfig?.max_futures_leverage !== void 0) {
3186
+ return Number(leverageConfig.max_futures_leverage);
3187
+ }
3188
+ return 1;
3189
+ }, [leverageConfig?.max_futures_leverage]);
3190
+ const memoizedLeverageLevers = React.useMemo(() => {
3191
+ return generateLeverageLevers(memoizedMaxLeverage);
3192
+ }, [memoizedMaxLeverage]);
3193
+ return {
3194
+ update: updateLeverage,
3195
+ isLoading: isLoading || isMutating,
3196
+ leverageLevers: memoizedLeverageLevers,
3197
+ curLeverage: memoizedCurLeverage,
3198
+ maxLeverage: memoizedMaxLeverage
3199
+ };
3171
3200
  };
3172
3201
  var useFundingRate = (symbol) => {
3173
3202
  if (!symbol) {
@@ -3893,15 +3922,17 @@ var useMarginRatio = () => {
3893
3922
  }, [rows, notional]);
3894
3923
  return { marginRatio, currentLeverage, mmr };
3895
3924
  };
3896
- var TestNetWhiteList = [421614, 901901901, types.MONAD_TESTNET_CHAINID];
3925
+ var TestNetWhiteList = [
3926
+ types.ARBITRUM_TESTNET_CHAINID,
3927
+ types.SOLANA_TESTNET_CHAINID,
3928
+ types.MONAD_TESTNET_CHAINID,
3929
+ types.ABSTRACT_TESTNET_CHAINID
3930
+ ];
3897
3931
  var testnetTokenFallback = types.TesntTokenFallback([
3898
3932
  types.ArbitrumSepoliaTokenInfo,
3899
3933
  types.SolanaDevnetTokenInfo
3900
3934
  ]);
3901
- var testnetChainFallback = [
3902
- types.ArbitrumSepoliaChainInfo,
3903
- types.SolanaDevnetChainInfo
3904
- ];
3935
+ var testnetChainFallback = [types.ArbitrumSepoliaChainInfo, types.SolanaDevnetChainInfo];
3905
3936
  function useChains(networkId, options = {}) {
3906
3937
  const { pick: pickField, ...swrOptions } = options;
3907
3938
  const {
@@ -4049,7 +4080,7 @@ function _checkChainSupport(chainId, chains) {
4049
4080
  });
4050
4081
  }
4051
4082
  function fillChainsInfo(chains, filter, chainInfos) {
4052
- let _chains = [];
4083
+ const _chains = [];
4053
4084
  chains?.forEach((item) => {
4054
4085
  item.chain_details.forEach((chain) => {
4055
4086
  const chainId = Number(chain.chain_id);
@@ -4085,7 +4116,7 @@ function fillChainsInfo(chains, filter, chainInfos) {
4085
4116
  function filterAndUpdateChains(chains, chainInfos, filter, isTestNet) {
4086
4117
  const filterChains = [];
4087
4118
  chains.forEach((chain) => {
4088
- let _chain = { ...chain };
4119
+ const _chain = { ...chain };
4089
4120
  const networkInfo = chainInfos?.find(
4090
4121
  (item) => item.chain_id == chain.network_infos.chain_id
4091
4122
  );
@@ -4473,6 +4504,7 @@ var useDeposit = (options) => {
4473
4504
  }).then((res) => {
4474
4505
  return updateAllowanceWhenTxSuccess(res.hash);
4475
4506
  }).catch((e) => {
4507
+ throw e;
4476
4508
  });
4477
4509
  },
4478
4510
  [account5, getAllowance, options?.address, dst]