@orderly.network/hooks 2.0.1-alpha.6 → 2.0.1-preview.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 +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +70 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -35
- 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-
|
|
30
|
+
declare const _default: "2.0.1-preview.0";
|
|
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-
|
|
30
|
+
declare const _default: "2.0.1-preview.0";
|
|
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-
|
|
43
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.1-preview.0";
|
|
44
44
|
}
|
|
45
|
-
var version_default = "2.0.1-
|
|
45
|
+
var version_default = "2.0.1-preview.0";
|
|
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();
|
|
@@ -2739,9 +2744,12 @@ var filterMarkets = (params) => {
|
|
|
2739
2744
|
isFavorite: type == 0 /* FAVORITES */ ? true : favoriteKeys.includes(item.symbol)
|
|
2740
2745
|
}));
|
|
2741
2746
|
};
|
|
2747
|
+
function isEmpty(value) {
|
|
2748
|
+
return value === void 0 || value === null;
|
|
2749
|
+
}
|
|
2742
2750
|
function get8hFunding2(est_funding_rate, funding_period) {
|
|
2743
2751
|
let funding8h = 0;
|
|
2744
|
-
if (est_funding_rate
|
|
2752
|
+
if (isEmpty(est_funding_rate)) {
|
|
2745
2753
|
return null;
|
|
2746
2754
|
}
|
|
2747
2755
|
if (funding_period) {
|
|
@@ -2754,7 +2762,7 @@ function get24hChange2(params) {
|
|
|
2754
2762
|
if (change !== void 0) {
|
|
2755
2763
|
return change;
|
|
2756
2764
|
}
|
|
2757
|
-
if (close
|
|
2765
|
+
if (!isEmpty(close) && !isEmpty(open)) {
|
|
2758
2766
|
if (open === 0) {
|
|
2759
2767
|
return 0;
|
|
2760
2768
|
}
|
|
@@ -3482,7 +3490,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
3482
3490
|
return 0;
|
|
3483
3491
|
const getSymbolInfo = symbolInfo[symbol];
|
|
3484
3492
|
const filterAlgoOrders = orders.filter(
|
|
3485
|
-
(item) => item.algo_order_id === void 0
|
|
3493
|
+
(item) => item.algo_order_id === void 0 || item.algo_type === "BRACKET"
|
|
3486
3494
|
);
|
|
3487
3495
|
const buyOrdersQty = perp.account.getQtyFromOrdersBySide(
|
|
3488
3496
|
filterAlgoOrders,
|
|
@@ -4112,6 +4120,7 @@ var useDeposit = (options) => {
|
|
|
4112
4120
|
}, [account5, fetchBalance, quantity, depositFee, options?.address]);
|
|
4113
4121
|
const loopGetBalance = async () => {
|
|
4114
4122
|
getBalanceListener.current && clearTimeout(getBalanceListener.current);
|
|
4123
|
+
const time = account5.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3;
|
|
4115
4124
|
getBalanceListener.current = setTimeout(async () => {
|
|
4116
4125
|
try {
|
|
4117
4126
|
const balance2 = await fetchBalanceHandler(
|
|
@@ -4122,7 +4131,7 @@ var useDeposit = (options) => {
|
|
|
4122
4131
|
loopGetBalance();
|
|
4123
4132
|
} catch (err) {
|
|
4124
4133
|
}
|
|
4125
|
-
},
|
|
4134
|
+
}, time);
|
|
4126
4135
|
};
|
|
4127
4136
|
const getDepositFee = React.useCallback(
|
|
4128
4137
|
async (quantity2) => {
|
|
@@ -4501,19 +4510,35 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
4501
4510
|
// }),
|
|
4502
4511
|
};
|
|
4503
4512
|
}
|
|
4504
|
-
function checkNotional(
|
|
4505
|
-
|
|
4513
|
+
function checkNotional(props) {
|
|
4514
|
+
const { price, base_tick, qty, min_notional, base_dp, quote_dp, quote_tick } = props;
|
|
4515
|
+
if (price !== void 0 && qty !== void 0 && min_notional !== void 0) {
|
|
4506
4516
|
try {
|
|
4507
4517
|
const calcNotional = new utils.Decimal(price).mul(new utils.Decimal(qty)).toNumber();
|
|
4508
|
-
const notional = Number.parseFloat(`${
|
|
4509
|
-
|
|
4510
|
-
|
|
4518
|
+
const notional = Number.parseFloat(`${min_notional}`);
|
|
4519
|
+
if (calcNotional < notional) {
|
|
4520
|
+
let minQty = new utils.Decimal(notional).div(price).toDecimalPlaces(base_dp, utils.Decimal.ROUND_DOWN).add(base_tick ?? 0);
|
|
4521
|
+
if (base_tick && base_tick > 0) {
|
|
4522
|
+
minQty = new utils.Decimal(
|
|
4523
|
+
getRoundedDownDivision(minQty.toNumber(), base_tick)
|
|
4524
|
+
);
|
|
4525
|
+
}
|
|
4526
|
+
const newMinNotional = minQty.mul(price).add(quote_tick ?? 0).toFixed(quote_dp);
|
|
4527
|
+
return `The order value should be greater or equal to ${newMinNotional} USDC`;
|
|
4528
|
+
}
|
|
4529
|
+
return void 0;
|
|
4511
4530
|
} catch (e) {
|
|
4512
4531
|
return void 0;
|
|
4513
4532
|
}
|
|
4514
4533
|
}
|
|
4515
4534
|
return void 0;
|
|
4516
4535
|
}
|
|
4536
|
+
function getRoundedDownDivision(value, tick) {
|
|
4537
|
+
const decimalValue = new utils.Decimal(value);
|
|
4538
|
+
const decimalTick = new utils.Decimal(tick);
|
|
4539
|
+
const quotient = decimalValue.dividedToIntegerBy(decimalTick);
|
|
4540
|
+
return quotient.mul(decimalTick).toNumber();
|
|
4541
|
+
}
|
|
4517
4542
|
|
|
4518
4543
|
// src/services/orderCreator/baseCreator.ts
|
|
4519
4544
|
var BaseOrderCreator = class {
|
|
@@ -4543,12 +4568,12 @@ var BaseOrderCreator = class {
|
|
|
4543
4568
|
const errors = {};
|
|
4544
4569
|
const { maxQty, symbol, markPrice } = configs;
|
|
4545
4570
|
let { order_quantity, total, order_price, reduce_only, order_type } = values2;
|
|
4546
|
-
const { min_notional } = symbol || {};
|
|
4571
|
+
const { min_notional, base_tick, quote_dp, quote_tick, base_dp } = symbol || {};
|
|
4547
4572
|
if (!order_quantity) {
|
|
4548
4573
|
if (total && order_price) {
|
|
4549
|
-
const { quote_dp } = configs.symbol;
|
|
4574
|
+
const { quote_dp: quote_dp2 } = configs.symbol;
|
|
4550
4575
|
const totalNumber = new utils.Decimal(total);
|
|
4551
|
-
const qty = totalNumber.dividedBy(order_price).toFixed(
|
|
4576
|
+
const qty = totalNumber.dividedBy(order_price).toFixed(quote_dp2);
|
|
4552
4577
|
order_quantity = qty;
|
|
4553
4578
|
}
|
|
4554
4579
|
}
|
|
@@ -4558,26 +4583,34 @@ var BaseOrderCreator = class {
|
|
|
4558
4583
|
message: "Quantity is required"
|
|
4559
4584
|
};
|
|
4560
4585
|
} else {
|
|
4561
|
-
const { base_min, quote_dp, base_dp } = configs.symbol;
|
|
4586
|
+
const { base_min, quote_dp: quote_dp2, base_dp: base_dp2 } = configs.symbol;
|
|
4562
4587
|
const qty = new utils.Decimal(order_quantity);
|
|
4563
4588
|
if (qty.lt(base_min)) {
|
|
4564
4589
|
errors.order_quantity = {
|
|
4565
4590
|
type: "min",
|
|
4566
4591
|
message: `Quantity must be greater than ${new utils.Decimal(base_min).todp(
|
|
4567
|
-
|
|
4592
|
+
base_dp2
|
|
4568
4593
|
)}`
|
|
4569
4594
|
};
|
|
4570
4595
|
} else if (qty.gt(maxQty)) {
|
|
4571
4596
|
errors.order_quantity = {
|
|
4572
4597
|
type: "max",
|
|
4573
4598
|
message: `Quantity must be less than ${new utils.Decimal(maxQty).todp(
|
|
4574
|
-
|
|
4599
|
+
base_dp2
|
|
4575
4600
|
)}`
|
|
4576
4601
|
};
|
|
4577
4602
|
}
|
|
4578
4603
|
}
|
|
4579
4604
|
const price = `${order_type}`.includes("MARKET") ? markPrice : order_price;
|
|
4580
|
-
const notionalHintStr = checkNotional(
|
|
4605
|
+
const notionalHintStr = checkNotional({
|
|
4606
|
+
base_tick,
|
|
4607
|
+
quote_tick,
|
|
4608
|
+
price,
|
|
4609
|
+
qty: order_quantity,
|
|
4610
|
+
min_notional,
|
|
4611
|
+
quote_dp,
|
|
4612
|
+
base_dp
|
|
4613
|
+
});
|
|
4581
4614
|
if (notionalHintStr !== void 0 && !reduce_only) {
|
|
4582
4615
|
errors.total = {
|
|
4583
4616
|
type: "min",
|
|
@@ -5850,7 +5883,7 @@ function useMaintenanceStatus() {
|
|
|
5850
5883
|
const [startTime, setStartTime] = React.useState();
|
|
5851
5884
|
const [endTime, setEndTime] = React.useState();
|
|
5852
5885
|
const [brokerName, setBrokerName] = React.useState("Orderly network");
|
|
5853
|
-
const { data: systemInfo, mutate: mutate3 } = useQuery(`/v1/public/system_info`, {
|
|
5886
|
+
const { data: systemInfo, mutate: mutate3 } = useQuery(`/v1/public/system_info?source=maintenance`, {
|
|
5854
5887
|
revalidateOnFocus: false,
|
|
5855
5888
|
errorRetryCount: 2,
|
|
5856
5889
|
errorRetryInterval: 200
|
|
@@ -5858,18 +5891,18 @@ function useMaintenanceStatus() {
|
|
|
5858
5891
|
const ws = useWS();
|
|
5859
5892
|
const config = useConfig();
|
|
5860
5893
|
React.useEffect(() => {
|
|
5861
|
-
if (!systemInfo
|
|
5894
|
+
if (!systemInfo) {
|
|
5862
5895
|
return;
|
|
5863
5896
|
}
|
|
5864
5897
|
const brokerName2 = config.get("brokerName");
|
|
5865
5898
|
if (brokerName2) {
|
|
5866
5899
|
setBrokerName(brokerName2);
|
|
5867
5900
|
}
|
|
5868
|
-
if (systemInfo.
|
|
5869
|
-
setStartTime(systemInfo.
|
|
5870
|
-
setEndTime(systemInfo.
|
|
5901
|
+
if (systemInfo.scheduled_maintenance) {
|
|
5902
|
+
setStartTime(systemInfo.scheduled_maintenance.start_time);
|
|
5903
|
+
setEndTime(systemInfo.scheduled_maintenance.end_time);
|
|
5871
5904
|
}
|
|
5872
|
-
if (systemInfo.
|
|
5905
|
+
if (systemInfo.status === 2) {
|
|
5873
5906
|
setStatus(2);
|
|
5874
5907
|
}
|
|
5875
5908
|
}, [systemInfo, config]);
|
|
@@ -6340,20 +6373,20 @@ var OrderlyConfigProvider = (props) => {
|
|
|
6340
6373
|
"If you have provided a custom `configStore` and the `brokerId` is set in the `configStore`, please remove the `brokerId` prop."
|
|
6341
6374
|
);
|
|
6342
6375
|
}
|
|
6343
|
-
const innerConfigStore =
|
|
6376
|
+
const innerConfigStore = React.useMemo(() => {
|
|
6344
6377
|
return new ProxyConfigStore(
|
|
6345
6378
|
configStore || new ExtendedConfigStore({ brokerId, brokerName, networkId })
|
|
6346
6379
|
);
|
|
6347
|
-
});
|
|
6348
|
-
const innerKeyStore =
|
|
6380
|
+
}, [configStore, brokerId, brokerName, networkId]);
|
|
6381
|
+
const innerKeyStore = React.useMemo(() => {
|
|
6349
6382
|
return keyStore || new core.LocalStorageStore(networkId);
|
|
6350
|
-
});
|
|
6351
|
-
const innerWalletAdapters =
|
|
6383
|
+
}, [networkId, keyStore]);
|
|
6384
|
+
const innerWalletAdapters = React.useMemo(() => {
|
|
6352
6385
|
return walletAdapters || [
|
|
6353
6386
|
new defaultEvmAdapter.DefaultEVMWalletAdapter(new web3ProviderEthers.EthersProvider()),
|
|
6354
6387
|
new defaultSolanaAdapter.DefaultSolanaWalletAdapter()
|
|
6355
6388
|
];
|
|
6356
|
-
});
|
|
6389
|
+
}, [walletAdapters]);
|
|
6357
6390
|
React.useLayoutEffect(() => {
|
|
6358
6391
|
let account6 = core.SimpleDI.get(core.Account.instanceName);
|
|
6359
6392
|
if (!account6) {
|
|
@@ -14105,7 +14138,7 @@ Object.defineProperty(exports, "useSWRConfig", {
|
|
|
14105
14138
|
});
|
|
14106
14139
|
Object.defineProperty(exports, "useConstant", {
|
|
14107
14140
|
enumerable: true,
|
|
14108
|
-
get: function () { return
|
|
14141
|
+
get: function () { return useConstant__default.default; }
|
|
14109
14142
|
});
|
|
14110
14143
|
exports.AssetHistoryStatusEnum = AssetHistoryStatusEnum;
|
|
14111
14144
|
exports.DefaultLayoutConfig = DefaultLayoutConfig;
|