@orderly.network/hooks 2.7.0 → 2.7.1
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ export { unstable_serialize, default as useSWR, useSWRConfig } from 'swr';
|
|
|
6
6
|
import { TesntTokenFallback, ArbitrumSepoliaTokenInfo, SolanaDevnetTokenInfo, OrderType, OrderSide, SDKError, TrackerEventName, AccountStatusEnum, AlgoOrderType, AlgoOrderRootType, OrderStatus, EMPTY_LIST, EMPTY_OBJECT, ArbitrumSepoliaChainInfo, SolanaDevnetChainInfo, ARBITRUM_TESTNET_CHAINID, SOLANA_TESTNET_CHAINID, MONAD_TESTNET_CHAINID, ABSTRACT_TESTNET_CHAINID, BSC_TESTNET_CHAINID, nativeTokenAddress, ChainKey, chainsInfoMap, ARBITRUM_MAINNET_CHAINID, isNativeTokenChecker, ChainNamespace, MaxUint256, ETHEREUM_MAINNET_CHAINID, DEPOSIT_FEE_RATE, LedgerWalletKey, SolanaChains, PositionType, DistributionType, TriggerPriceType } from '@orderly.network/types';
|
|
7
7
|
import React2, { createContext, useContext, useCallback, useState, useEffect, useMemo, useRef, useId, useLayoutEffect } from 'react';
|
|
8
8
|
import useSWRMutation from 'swr/mutation';
|
|
9
|
-
import { zero, windowGuard, getTimestamp, getGlobalObject, Decimal, timeConvertString, isTestnet, getPrecisionByNumber, camelCaseToUnderscoreCase, commify, todpIfNeed } from '@orderly.network/utils';
|
|
9
|
+
import { zero, windowGuard, getTimestamp, getGlobalObject, Decimal, timeConvertString, isTestnet, getPrecisionByNumber, camelCaseToUnderscoreCase, commify, todpIfNeed, getTPSLDirection } from '@orderly.network/utils';
|
|
10
10
|
import useConstant from 'use-constant';
|
|
11
11
|
export { default as useConstant } from 'use-constant';
|
|
12
12
|
import { SimpleDI, Account, EventEmitter, DefaultConfigStore, EVENT_NAMES, LocalStorageStore } from '@orderly.network/core';
|
|
@@ -36,9 +36,9 @@ var __export = (target, all) => {
|
|
|
36
36
|
// src/version.ts
|
|
37
37
|
if (typeof window !== "undefined") {
|
|
38
38
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
39
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.7.
|
|
39
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.7.1";
|
|
40
40
|
}
|
|
41
|
-
var version_default = "2.7.
|
|
41
|
+
var version_default = "2.7.1";
|
|
42
42
|
var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
|
|
43
43
|
var noCacheConfig = {
|
|
44
44
|
dedupingInterval: 0,
|
|
@@ -1102,21 +1102,27 @@ function offsetPercentageToPrice(inputs) {
|
|
|
1102
1102
|
}
|
|
1103
1103
|
function priceToOffsetPercentage(inputs) {
|
|
1104
1104
|
const { price, entryPrice, orderType, orderSide } = inputs;
|
|
1105
|
+
const direction = getTPSLDirection({
|
|
1106
|
+
side: orderSide,
|
|
1107
|
+
type: orderType === AlgoOrderType.TAKE_PROFIT ? "tp" : "sl",
|
|
1108
|
+
closePrice: price,
|
|
1109
|
+
orderPrice: entryPrice
|
|
1110
|
+
});
|
|
1105
1111
|
if (orderSide === OrderSide.BUY) {
|
|
1106
1112
|
if (entryPrice === 0)
|
|
1107
1113
|
return 0;
|
|
1108
1114
|
if (orderType === AlgoOrderType.TAKE_PROFIT) {
|
|
1109
|
-
return new Decimal(price).div(new Decimal(entryPrice)).minus(1).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1115
|
+
return new Decimal(price).div(new Decimal(entryPrice)).minus(1).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1110
1116
|
}
|
|
1111
|
-
return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1117
|
+
return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1112
1118
|
}
|
|
1113
1119
|
if (orderSide === OrderSide.SELL) {
|
|
1114
1120
|
if (entryPrice === 0)
|
|
1115
1121
|
return 0;
|
|
1116
1122
|
if (orderType === AlgoOrderType.TAKE_PROFIT) {
|
|
1117
|
-
return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).abs().toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1123
|
+
return new Decimal(1).minus(new Decimal(price).div(new Decimal(entryPrice))).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1118
1124
|
}
|
|
1119
|
-
return new Decimal(price).div(new Decimal(entryPrice)).minus(1).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1125
|
+
return new Decimal(price).div(new Decimal(entryPrice)).minus(1).abs().mul(direction).toDecimalPlaces(4, Decimal.ROUND_DOWN).toNumber();
|
|
1120
1126
|
}
|
|
1121
1127
|
}
|
|
1122
1128
|
function pnlToPrice(inputs) {
|
|
@@ -8197,7 +8203,7 @@ var BaseAlgoOrderCreator = class {
|
|
|
8197
8203
|
formatPrice2(quote_min, quote_dp)
|
|
8198
8204
|
);
|
|
8199
8205
|
}
|
|
8200
|
-
if (!!sl_trigger_price && Number(sl_trigger_price)
|
|
8206
|
+
if (!!sl_trigger_price && Number(sl_trigger_price) >= mark_price) {
|
|
8201
8207
|
result.sl_trigger_price = OrderValidation.max(
|
|
8202
8208
|
"sl_trigger_price",
|
|
8203
8209
|
formatPrice2(mark_price, quote_dp)
|
|
@@ -8267,7 +8273,7 @@ var BaseAlgoOrderCreator = class {
|
|
|
8267
8273
|
formatPrice2(quote_max, quote_dp)
|
|
8268
8274
|
);
|
|
8269
8275
|
}
|
|
8270
|
-
if (!!sl_trigger_price && Number(sl_trigger_price)
|
|
8276
|
+
if (!!sl_trigger_price && Number(sl_trigger_price) <= mark_price) {
|
|
8271
8277
|
result.sl_trigger_price = OrderValidation.min(
|
|
8272
8278
|
"sl_trigger_price",
|
|
8273
8279
|
formatPrice2(mark_price, quote_dp)
|