@orderly.network/hooks 2.0.1-alpha.6 → 2.0.1-alpha.7
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 +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +58 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
package/dist/index.d.mts
CHANGED
|
@@ -27,7 +27,7 @@ declare global {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
declare const _default: "2.0.1-alpha.
|
|
30
|
+
declare const _default: "2.0.1-alpha.7";
|
|
31
31
|
|
|
32
32
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
33
33
|
formatter?: (data: any) => T;
|
|
@@ -1049,7 +1049,15 @@ declare const DefaultLayoutConfig: PosterLayoutConfig;
|
|
|
1049
1049
|
declare const cleanStringStyle: (str: string | number) => string;
|
|
1050
1050
|
declare function formatNumber(qty?: string | number, dp?: number | string): string | undefined;
|
|
1051
1051
|
|
|
1052
|
-
declare function checkNotional(
|
|
1052
|
+
declare function checkNotional(props: {
|
|
1053
|
+
base_tick: number;
|
|
1054
|
+
price?: string | number;
|
|
1055
|
+
qty?: string | number;
|
|
1056
|
+
min_notional?: number;
|
|
1057
|
+
quote_dp?: number;
|
|
1058
|
+
base_dp?: number;
|
|
1059
|
+
quote_tick?: number;
|
|
1060
|
+
}): string | undefined;
|
|
1053
1061
|
|
|
1054
1062
|
declare const findTPSLFromOrders: (orders: API.AlgoOrder[], symbol: string) => Partial<AlgoOrderEntity> | undefined;
|
|
1055
1063
|
declare const findTPSLFromOrder: (order: API.AlgoOrder) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare global {
|
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
declare const _default: "2.0.1-alpha.
|
|
30
|
+
declare const _default: "2.0.1-alpha.7";
|
|
31
31
|
|
|
32
32
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
33
33
|
formatter?: (data: any) => T;
|
|
@@ -1049,7 +1049,15 @@ declare const DefaultLayoutConfig: PosterLayoutConfig;
|
|
|
1049
1049
|
declare const cleanStringStyle: (str: string | number) => string;
|
|
1050
1050
|
declare function formatNumber(qty?: string | number, dp?: number | string): string | undefined;
|
|
1051
1051
|
|
|
1052
|
-
declare function checkNotional(
|
|
1052
|
+
declare function checkNotional(props: {
|
|
1053
|
+
base_tick: number;
|
|
1054
|
+
price?: string | number;
|
|
1055
|
+
qty?: string | number;
|
|
1056
|
+
min_notional?: number;
|
|
1057
|
+
quote_dp?: number;
|
|
1058
|
+
base_dp?: number;
|
|
1059
|
+
quote_tick?: number;
|
|
1060
|
+
}): string | undefined;
|
|
1053
1061
|
|
|
1054
1062
|
declare const findTPSLFromOrders: (orders: API.AlgoOrder[], symbol: string) => Partial<AlgoOrderEntity> | undefined;
|
|
1055
1063
|
declare const findTPSLFromOrder: (order: API.AlgoOrder) => {
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var useSWR = require('swr');
|
|
|
4
4
|
var net = require('@orderly.network/net');
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var useSWRMutation = require('swr/mutation');
|
|
7
|
-
var
|
|
7
|
+
var useConstant = require('use-constant');
|
|
8
8
|
var core = require('@orderly.network/core');
|
|
9
9
|
var utils = require('@orderly.network/utils');
|
|
10
10
|
var types = require('@orderly.network/types');
|
|
@@ -27,7 +27,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
|
27
27
|
var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
|
|
28
28
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
29
29
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
30
|
-
var
|
|
30
|
+
var useConstant__default = /*#__PURE__*/_interopDefault(useConstant);
|
|
31
31
|
var useSWRInfinite__default = /*#__PURE__*/_interopDefault(useSWRInfinite);
|
|
32
32
|
var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscription);
|
|
33
33
|
|
|
@@ -40,9 +40,9 @@ var __export = (target, all) => {
|
|
|
40
40
|
// src/version.ts
|
|
41
41
|
if (typeof window !== "undefined") {
|
|
42
42
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
43
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.1-alpha.
|
|
43
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.1-alpha.7";
|
|
44
44
|
}
|
|
45
|
-
var version_default = "2.0.1-alpha.
|
|
45
|
+
var version_default = "2.0.1-alpha.7";
|
|
46
46
|
var fetcher = (url, init = {}, queryOptions) => net.get(url, init, queryOptions?.formatter);
|
|
47
47
|
var OrderlyContext = React.createContext({
|
|
48
48
|
// configStore: new MemoryConfigStore(),
|
|
@@ -52,6 +52,11 @@ var OrderlyProvider = OrderlyContext.Provider;
|
|
|
52
52
|
// src/useConfig.ts
|
|
53
53
|
function useConfig(key, defaultValue) {
|
|
54
54
|
const { configStore } = React.useContext(OrderlyContext);
|
|
55
|
+
if (!configStore) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
"useConfig must be used within OrderlyConfigProvider or OrderlyAppProvider"
|
|
58
|
+
);
|
|
59
|
+
}
|
|
55
60
|
if (typeof key !== "undefined") {
|
|
56
61
|
if (typeof defaultValue !== "undefined") {
|
|
57
62
|
return configStore.getOr(key, defaultValue);
|
|
@@ -108,7 +113,7 @@ var useAccountInstance = () => {
|
|
|
108
113
|
"keyStore is not defined, please use OrderlyProvider and provide keyStore"
|
|
109
114
|
);
|
|
110
115
|
}
|
|
111
|
-
const account5 =
|
|
116
|
+
const account5 = useConstant__default.default(() => {
|
|
112
117
|
let account6 = core.SimpleDI.get("account");
|
|
113
118
|
if (!account6) {
|
|
114
119
|
account6 = new core.Account(
|
|
@@ -355,7 +360,7 @@ var usePreLoadData = () => {
|
|
|
355
360
|
};
|
|
356
361
|
};
|
|
357
362
|
var useEventEmitter = () => {
|
|
358
|
-
return
|
|
363
|
+
return useConstant__default.default(() => {
|
|
359
364
|
let ee = core.SimpleDI.get("EE");
|
|
360
365
|
if (!ee) {
|
|
361
366
|
ee = new core.EventEmitter();
|
|
@@ -464,7 +469,7 @@ function useLocalStorage(key, initialValue) {
|
|
|
464
469
|
var WS_NAME = "nativeWebsocketClient";
|
|
465
470
|
var useWS = () => {
|
|
466
471
|
const { configStore } = React.useContext(OrderlyContext);
|
|
467
|
-
const ws =
|
|
472
|
+
const ws = useConstant__default.default(() => {
|
|
468
473
|
let websocketClient = core.SimpleDI.get(WS_NAME);
|
|
469
474
|
const account5 = core.SimpleDI.get(core.Account.instanceName);
|
|
470
475
|
if (!websocketClient) {
|
|
@@ -1705,7 +1710,7 @@ var IndexPriceCalculator = class extends BaseCalculator {
|
|
|
1705
1710
|
// src/useCalculatorService.ts
|
|
1706
1711
|
var useCalculatorService = () => {
|
|
1707
1712
|
const { get: get3 } = useSimpleDI();
|
|
1708
|
-
const calculatorService =
|
|
1713
|
+
const calculatorService = useConstant__default.default(() => {
|
|
1709
1714
|
let calculatorService2 = get3(CalculatorServiceID);
|
|
1710
1715
|
if (!calculatorService2) {
|
|
1711
1716
|
const positionCalculator = new PositionCalculator();
|
|
@@ -4112,6 +4117,7 @@ var useDeposit = (options) => {
|
|
|
4112
4117
|
}, [account5, fetchBalance, quantity, depositFee, options?.address]);
|
|
4113
4118
|
const loopGetBalance = async () => {
|
|
4114
4119
|
getBalanceListener.current && clearTimeout(getBalanceListener.current);
|
|
4120
|
+
const time = account5.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3;
|
|
4115
4121
|
getBalanceListener.current = setTimeout(async () => {
|
|
4116
4122
|
try {
|
|
4117
4123
|
const balance2 = await fetchBalanceHandler(
|
|
@@ -4122,7 +4128,7 @@ var useDeposit = (options) => {
|
|
|
4122
4128
|
loopGetBalance();
|
|
4123
4129
|
} catch (err) {
|
|
4124
4130
|
}
|
|
4125
|
-
},
|
|
4131
|
+
}, time);
|
|
4126
4132
|
};
|
|
4127
4133
|
const getDepositFee = React.useCallback(
|
|
4128
4134
|
async (quantity2) => {
|
|
@@ -4501,19 +4507,35 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
4501
4507
|
// }),
|
|
4502
4508
|
};
|
|
4503
4509
|
}
|
|
4504
|
-
function checkNotional(
|
|
4505
|
-
|
|
4510
|
+
function checkNotional(props) {
|
|
4511
|
+
const { price, base_tick, qty, min_notional, base_dp, quote_dp, quote_tick } = props;
|
|
4512
|
+
if (price !== void 0 && qty !== void 0 && min_notional !== void 0) {
|
|
4506
4513
|
try {
|
|
4507
4514
|
const calcNotional = new utils.Decimal(price).mul(new utils.Decimal(qty)).toNumber();
|
|
4508
|
-
const notional = Number.parseFloat(`${
|
|
4509
|
-
|
|
4510
|
-
|
|
4515
|
+
const notional = Number.parseFloat(`${min_notional}`);
|
|
4516
|
+
if (calcNotional < notional) {
|
|
4517
|
+
let minQty = new utils.Decimal(notional).div(price).toDecimalPlaces(base_dp, utils.Decimal.ROUND_DOWN).add(base_tick ?? 0);
|
|
4518
|
+
if (base_tick && base_tick > 0) {
|
|
4519
|
+
minQty = new utils.Decimal(
|
|
4520
|
+
getRoundedDownDivision(minQty.toNumber(), base_tick)
|
|
4521
|
+
);
|
|
4522
|
+
}
|
|
4523
|
+
const newMinNotional = minQty.mul(price).add(quote_tick ?? 0).toFixed(quote_dp);
|
|
4524
|
+
return `The order value should be greater or equal to ${newMinNotional} USDC`;
|
|
4525
|
+
}
|
|
4526
|
+
return void 0;
|
|
4511
4527
|
} catch (e) {
|
|
4512
4528
|
return void 0;
|
|
4513
4529
|
}
|
|
4514
4530
|
}
|
|
4515
4531
|
return void 0;
|
|
4516
4532
|
}
|
|
4533
|
+
function getRoundedDownDivision(value, tick) {
|
|
4534
|
+
const decimalValue = new utils.Decimal(value);
|
|
4535
|
+
const decimalTick = new utils.Decimal(tick);
|
|
4536
|
+
const quotient = decimalValue.dividedToIntegerBy(decimalTick);
|
|
4537
|
+
return quotient.mul(decimalTick).toNumber();
|
|
4538
|
+
}
|
|
4517
4539
|
|
|
4518
4540
|
// src/services/orderCreator/baseCreator.ts
|
|
4519
4541
|
var BaseOrderCreator = class {
|
|
@@ -4543,12 +4565,12 @@ var BaseOrderCreator = class {
|
|
|
4543
4565
|
const errors = {};
|
|
4544
4566
|
const { maxQty, symbol, markPrice } = configs;
|
|
4545
4567
|
let { order_quantity, total, order_price, reduce_only, order_type } = values2;
|
|
4546
|
-
const { min_notional } = symbol || {};
|
|
4568
|
+
const { min_notional, base_tick, quote_dp, quote_tick, base_dp } = symbol || {};
|
|
4547
4569
|
if (!order_quantity) {
|
|
4548
4570
|
if (total && order_price) {
|
|
4549
|
-
const { quote_dp } = configs.symbol;
|
|
4571
|
+
const { quote_dp: quote_dp2 } = configs.symbol;
|
|
4550
4572
|
const totalNumber = new utils.Decimal(total);
|
|
4551
|
-
const qty = totalNumber.dividedBy(order_price).toFixed(
|
|
4573
|
+
const qty = totalNumber.dividedBy(order_price).toFixed(quote_dp2);
|
|
4552
4574
|
order_quantity = qty;
|
|
4553
4575
|
}
|
|
4554
4576
|
}
|
|
@@ -4558,26 +4580,34 @@ var BaseOrderCreator = class {
|
|
|
4558
4580
|
message: "Quantity is required"
|
|
4559
4581
|
};
|
|
4560
4582
|
} else {
|
|
4561
|
-
const { base_min, quote_dp, base_dp } = configs.symbol;
|
|
4583
|
+
const { base_min, quote_dp: quote_dp2, base_dp: base_dp2 } = configs.symbol;
|
|
4562
4584
|
const qty = new utils.Decimal(order_quantity);
|
|
4563
4585
|
if (qty.lt(base_min)) {
|
|
4564
4586
|
errors.order_quantity = {
|
|
4565
4587
|
type: "min",
|
|
4566
4588
|
message: `Quantity must be greater than ${new utils.Decimal(base_min).todp(
|
|
4567
|
-
|
|
4589
|
+
base_dp2
|
|
4568
4590
|
)}`
|
|
4569
4591
|
};
|
|
4570
4592
|
} else if (qty.gt(maxQty)) {
|
|
4571
4593
|
errors.order_quantity = {
|
|
4572
4594
|
type: "max",
|
|
4573
4595
|
message: `Quantity must be less than ${new utils.Decimal(maxQty).todp(
|
|
4574
|
-
|
|
4596
|
+
base_dp2
|
|
4575
4597
|
)}`
|
|
4576
4598
|
};
|
|
4577
4599
|
}
|
|
4578
4600
|
}
|
|
4579
4601
|
const price = `${order_type}`.includes("MARKET") ? markPrice : order_price;
|
|
4580
|
-
const notionalHintStr = checkNotional(
|
|
4602
|
+
const notionalHintStr = checkNotional({
|
|
4603
|
+
base_tick,
|
|
4604
|
+
quote_tick,
|
|
4605
|
+
price,
|
|
4606
|
+
qty: order_quantity,
|
|
4607
|
+
min_notional,
|
|
4608
|
+
quote_dp,
|
|
4609
|
+
base_dp
|
|
4610
|
+
});
|
|
4581
4611
|
if (notionalHintStr !== void 0 && !reduce_only) {
|
|
4582
4612
|
errors.total = {
|
|
4583
4613
|
type: "min",
|
|
@@ -6340,20 +6370,20 @@ var OrderlyConfigProvider = (props) => {
|
|
|
6340
6370
|
"If you have provided a custom `configStore` and the `brokerId` is set in the `configStore`, please remove the `brokerId` prop."
|
|
6341
6371
|
);
|
|
6342
6372
|
}
|
|
6343
|
-
const innerConfigStore =
|
|
6373
|
+
const innerConfigStore = React.useMemo(() => {
|
|
6344
6374
|
return new ProxyConfigStore(
|
|
6345
6375
|
configStore || new ExtendedConfigStore({ brokerId, brokerName, networkId })
|
|
6346
6376
|
);
|
|
6347
|
-
});
|
|
6348
|
-
const innerKeyStore =
|
|
6377
|
+
}, [configStore, brokerId, brokerName, networkId]);
|
|
6378
|
+
const innerKeyStore = React.useMemo(() => {
|
|
6349
6379
|
return keyStore || new core.LocalStorageStore(networkId);
|
|
6350
|
-
});
|
|
6351
|
-
const innerWalletAdapters =
|
|
6380
|
+
}, [networkId, keyStore]);
|
|
6381
|
+
const innerWalletAdapters = React.useMemo(() => {
|
|
6352
6382
|
return walletAdapters || [
|
|
6353
6383
|
new defaultEvmAdapter.DefaultEVMWalletAdapter(new web3ProviderEthers.EthersProvider()),
|
|
6354
6384
|
new defaultSolanaAdapter.DefaultSolanaWalletAdapter()
|
|
6355
6385
|
];
|
|
6356
|
-
});
|
|
6386
|
+
}, [walletAdapters]);
|
|
6357
6387
|
React.useLayoutEffect(() => {
|
|
6358
6388
|
let account6 = core.SimpleDI.get(core.Account.instanceName);
|
|
6359
6389
|
if (!account6) {
|
|
@@ -14105,7 +14135,7 @@ Object.defineProperty(exports, "useSWRConfig", {
|
|
|
14105
14135
|
});
|
|
14106
14136
|
Object.defineProperty(exports, "useConstant", {
|
|
14107
14137
|
enumerable: true,
|
|
14108
|
-
get: function () { return
|
|
14138
|
+
get: function () { return useConstant__default.default; }
|
|
14109
14139
|
});
|
|
14110
14140
|
exports.AssetHistoryStatusEnum = AssetHistoryStatusEnum;
|
|
14111
14141
|
exports.DefaultLayoutConfig = DefaultLayoutConfig;
|