@orderly.network/hooks 2.0.3 → 2.0.4
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 +74 -44
- package/dist/index.d.ts +74 -44
- package/dist/index.js +45 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -60,9 +60,9 @@ var __export = (target, all) => {
|
|
|
60
60
|
// src/version.ts
|
|
61
61
|
if (typeof window !== "undefined") {
|
|
62
62
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
63
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.
|
|
63
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.4";
|
|
64
64
|
}
|
|
65
|
-
var version_default = "2.0.
|
|
65
|
+
var version_default = "2.0.4";
|
|
66
66
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
67
67
|
var OrderlyContext = React.createContext({
|
|
68
68
|
// configStore: new MemoryConfigStore(),
|
|
@@ -2189,7 +2189,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
2189
2189
|
}
|
|
2190
2190
|
const level = options?.level ?? 10;
|
|
2191
2191
|
const padding = options?.padding ?? true;
|
|
2192
|
-
React.useState(null);
|
|
2192
|
+
const [requestData, setRequestData] = React.useState(null);
|
|
2193
2193
|
const [data, setData] = React.useState(initial);
|
|
2194
2194
|
const [isLoading, setIsLoading] = React.useState(true);
|
|
2195
2195
|
const config = useSymbolsInfo()[symbol];
|
|
@@ -3065,7 +3065,10 @@ var useFundingRate = (symbol) => {
|
|
|
3065
3065
|
if (utils.getTimestamp() > next_funding_time) {
|
|
3066
3066
|
return null;
|
|
3067
3067
|
}
|
|
3068
|
-
return new utils.Decimal(Number(est_funding_rate2) * 100).toFixed(
|
|
3068
|
+
return new utils.Decimal(Number(est_funding_rate2) * 100).toFixed(
|
|
3069
|
+
4,
|
|
3070
|
+
utils.Decimal.ROUND_DOWN
|
|
3071
|
+
);
|
|
3069
3072
|
}, [data]);
|
|
3070
3073
|
return {
|
|
3071
3074
|
...data,
|
|
@@ -3739,7 +3742,7 @@ var useMarginRatio = () => {
|
|
|
3739
3742
|
}, [rows, notional]);
|
|
3740
3743
|
return { marginRatio, currentLeverage, mmr };
|
|
3741
3744
|
};
|
|
3742
|
-
var TestNetWhiteList = [421614, 901901901
|
|
3745
|
+
var TestNetWhiteList = [421614, 901901901];
|
|
3743
3746
|
function useChains(networkId, options = {}) {
|
|
3744
3747
|
const { pick: pickField, ...swrOptions } = options;
|
|
3745
3748
|
const {
|
|
@@ -4028,7 +4031,7 @@ var useWithdraw = (options) => {
|
|
|
4028
4031
|
const networkId = useConfig("networkId");
|
|
4029
4032
|
const [_, { findByChainId }] = useChains(void 0);
|
|
4030
4033
|
const ee = useEventEmitter();
|
|
4031
|
-
useHoldingStream();
|
|
4034
|
+
const { usdc } = useHoldingStream();
|
|
4032
4035
|
const maxAmount = React.useMemo(() => {
|
|
4033
4036
|
return freeCollateral;
|
|
4034
4037
|
}, [freeCollateral]);
|
|
@@ -4460,7 +4463,7 @@ var useSymbolPriceRange = (symbol, side, price) => {
|
|
|
4460
4463
|
return range;
|
|
4461
4464
|
};
|
|
4462
4465
|
function offsetToPrice(inputs) {
|
|
4463
|
-
const {
|
|
4466
|
+
const { offset, entryPrice, orderType, orderSide } = inputs;
|
|
4464
4467
|
if (!offset)
|
|
4465
4468
|
return;
|
|
4466
4469
|
if (orderSide === types.OrderSide.BUY) {
|
|
@@ -4477,7 +4480,7 @@ function offsetToPrice(inputs) {
|
|
|
4477
4480
|
}
|
|
4478
4481
|
}
|
|
4479
4482
|
function priceToOffset(inputs, options = {}) {
|
|
4480
|
-
const {
|
|
4483
|
+
const { price, entryPrice, orderType, orderSide } = inputs;
|
|
4481
4484
|
const { symbol } = options;
|
|
4482
4485
|
let decimal;
|
|
4483
4486
|
if (orderSide === types.OrderSide.BUY) {
|
|
@@ -4498,7 +4501,7 @@ function priceToOffset(inputs, options = {}) {
|
|
|
4498
4501
|
return decimal.abs().toNumber();
|
|
4499
4502
|
}
|
|
4500
4503
|
function offsetPercentageToPrice(inputs) {
|
|
4501
|
-
const {
|
|
4504
|
+
const { percentage, entryPrice, orderType, orderSide } = inputs;
|
|
4502
4505
|
if (!percentage)
|
|
4503
4506
|
return;
|
|
4504
4507
|
if (orderSide === types.OrderSide.BUY) {
|
|
@@ -4515,7 +4518,7 @@ function offsetPercentageToPrice(inputs) {
|
|
|
4515
4518
|
}
|
|
4516
4519
|
}
|
|
4517
4520
|
function priceToOffsetPercentage(inputs) {
|
|
4518
|
-
const {
|
|
4521
|
+
const { price, entryPrice, orderType, orderSide } = inputs;
|
|
4519
4522
|
if (orderSide === types.OrderSide.BUY) {
|
|
4520
4523
|
if (entryPrice === 0)
|
|
4521
4524
|
return 0;
|
|
@@ -4641,7 +4644,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
4641
4644
|
case "sl_offset": {
|
|
4642
4645
|
offset = inputs.value;
|
|
4643
4646
|
trigger_price = offsetToPrice({
|
|
4644
|
-
qty,
|
|
4645
4647
|
offset: Number(inputs.value),
|
|
4646
4648
|
entryPrice,
|
|
4647
4649
|
orderSide: inputs.orderSide,
|
|
@@ -4653,7 +4655,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
4653
4655
|
case "sl_offset_percentage": {
|
|
4654
4656
|
offset_percentage = inputs.value;
|
|
4655
4657
|
trigger_price = offsetPercentageToPrice({
|
|
4656
|
-
qty,
|
|
4657
4658
|
percentage: Number(`${inputs.value}`.replace(/\.0{0,2}$/, "")),
|
|
4658
4659
|
entryPrice,
|
|
4659
4660
|
orderSide: inputs.orderSide,
|
|
@@ -4678,7 +4679,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
4678
4679
|
),
|
|
4679
4680
|
[`${keyPrefix}offset`]: offset ?? priceToOffset(
|
|
4680
4681
|
{
|
|
4681
|
-
qty,
|
|
4682
4682
|
price: Number(trigger_price),
|
|
4683
4683
|
entryPrice,
|
|
4684
4684
|
orderSide: inputs.orderSide,
|
|
@@ -4687,7 +4687,6 @@ function tpslCalculateHelper(key, inputs, options = {}) {
|
|
|
4687
4687
|
options
|
|
4688
4688
|
),
|
|
4689
4689
|
[`${keyPrefix}offset_percentage`]: offset_percentage ?? priceToOffsetPercentage({
|
|
4690
|
-
qty,
|
|
4691
4690
|
price: Number(trigger_price),
|
|
4692
4691
|
entryPrice,
|
|
4693
4692
|
orderSide: inputs.orderSide,
|
|
@@ -5718,7 +5717,6 @@ var useTaskProfitAndStopLossInternal = (position, options) => {
|
|
|
5718
5717
|
const newValue = tpslCalculateHelper(
|
|
5719
5718
|
key,
|
|
5720
5719
|
{
|
|
5721
|
-
key,
|
|
5722
5720
|
value,
|
|
5723
5721
|
entryPrice: position.average_open_price,
|
|
5724
5722
|
qty: side === types.OrderSide.BUY ? Number(prev.quantity) : -Number(prev.quantity),
|
|
@@ -6173,6 +6171,19 @@ function useMaintenanceStatus() {
|
|
|
6173
6171
|
endTime
|
|
6174
6172
|
};
|
|
6175
6173
|
}
|
|
6174
|
+
var useStorageLedgerAddress = () => {
|
|
6175
|
+
const [ledgerWallet, setLedgerWallet] = useLocalStorage(types.LedgerWalletKey, []);
|
|
6176
|
+
const setLedgerAddress = (address) => {
|
|
6177
|
+
if (!ledgerWallet.includes(address)) {
|
|
6178
|
+
const arr = [...ledgerWallet, address];
|
|
6179
|
+
setLedgerWallet(arr);
|
|
6180
|
+
}
|
|
6181
|
+
};
|
|
6182
|
+
return {
|
|
6183
|
+
setLedgerAddress,
|
|
6184
|
+
ledgerWallet
|
|
6185
|
+
};
|
|
6186
|
+
};
|
|
6176
6187
|
var usePrivateDataObserver = (options) => {
|
|
6177
6188
|
const ws = useWS();
|
|
6178
6189
|
const ee = useEventEmitter();
|
|
@@ -6318,34 +6329,37 @@ var usePrivateDataObserver = (options) => {
|
|
|
6318
6329
|
const key = ["/v1/positions", state.accountId];
|
|
6319
6330
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
6320
6331
|
onMessage: (data) => {
|
|
6321
|
-
const { positions:
|
|
6332
|
+
const { positions: nextPositions } = data;
|
|
6322
6333
|
useSWR.mutate(
|
|
6323
6334
|
key,
|
|
6324
6335
|
(prevPositions) => {
|
|
6325
6336
|
if (!!prevPositions) {
|
|
6326
|
-
const
|
|
6337
|
+
const newPositions = {
|
|
6327
6338
|
...prevPositions,
|
|
6328
6339
|
rows: prevPositions.rows.map((row) => {
|
|
6329
|
-
const itemIndex =
|
|
6340
|
+
const itemIndex = nextPositions.findIndex(
|
|
6330
6341
|
(item) => item.symbol === row.symbol
|
|
6331
6342
|
);
|
|
6332
6343
|
if (itemIndex >= 0) {
|
|
6333
|
-
const itemArr =
|
|
6344
|
+
const itemArr = nextPositions.splice(itemIndex, 1);
|
|
6334
6345
|
const item = itemArr[0];
|
|
6346
|
+
if (item.averageOpenPrice === 0) {
|
|
6347
|
+
return row;
|
|
6348
|
+
}
|
|
6335
6349
|
return object2underscore(item);
|
|
6336
6350
|
}
|
|
6337
6351
|
return row;
|
|
6338
6352
|
})
|
|
6339
6353
|
};
|
|
6340
|
-
if (
|
|
6341
|
-
|
|
6342
|
-
...
|
|
6343
|
-
...
|
|
6354
|
+
if (nextPositions.length > 0) {
|
|
6355
|
+
newPositions.rows = [
|
|
6356
|
+
...newPositions.rows,
|
|
6357
|
+
...nextPositions.map((item) => {
|
|
6344
6358
|
return object2underscore(item);
|
|
6345
6359
|
})
|
|
6346
6360
|
];
|
|
6347
6361
|
}
|
|
6348
|
-
return
|
|
6362
|
+
return newPositions;
|
|
6349
6363
|
}
|
|
6350
6364
|
},
|
|
6351
6365
|
{
|
|
@@ -6935,7 +6949,6 @@ function tpslInputHandle(inputs) {
|
|
|
6935
6949
|
const _tpslValue = tpslCalculateHelper(
|
|
6936
6950
|
input,
|
|
6937
6951
|
{
|
|
6938
|
-
key: input,
|
|
6939
6952
|
value,
|
|
6940
6953
|
entryPrice: price,
|
|
6941
6954
|
// order price or mark price
|
|
@@ -7595,7 +7608,7 @@ var qrPaint = (ctx, options) => {
|
|
|
7595
7608
|
var DataPaint = class extends BasePaint {
|
|
7596
7609
|
constructor() {
|
|
7597
7610
|
super(...arguments);
|
|
7598
|
-
this.positionInfoCellWidth =
|
|
7611
|
+
this.positionInfoCellWidth = 90;
|
|
7599
7612
|
this.DEFAULT_PROFIT_COLOR = "rgb(0,181,159)";
|
|
7600
7613
|
this.DEFAULT_LOSS_COLOR = "rgb(255,103,194)";
|
|
7601
7614
|
this.transformTop = 0;
|
|
@@ -7763,10 +7776,12 @@ var DataPaint = class extends BasePaint {
|
|
|
7763
7776
|
options
|
|
7764
7777
|
);
|
|
7765
7778
|
const { position } = layout;
|
|
7779
|
+
const informations = options.data?.position?.informations || [];
|
|
7766
7780
|
(options.data?.position.informations.length ?? 0) === 2;
|
|
7767
|
-
|
|
7768
|
-
|
|
7769
|
-
let
|
|
7781
|
+
const col = informations.length > 4 ? 3 : 2;
|
|
7782
|
+
informations.forEach((info, index) => {
|
|
7783
|
+
let left = position.left + index % col * this.positionInfoCellWidth;
|
|
7784
|
+
let top = position.top + Math.floor(index / col) * 38 + this.transformTop;
|
|
7770
7785
|
this._drawText(info.title, {
|
|
7771
7786
|
left: this._ratio(left),
|
|
7772
7787
|
top: this._ratio(top),
|
|
@@ -14674,6 +14689,7 @@ exports.useSessionStorage = useSessionStorage;
|
|
|
14674
14689
|
exports.useSettleSubscription = useSettleSubscription;
|
|
14675
14690
|
exports.useSimpleDI = useSimpleDI;
|
|
14676
14691
|
exports.useStatisticsDaily = useStatisticsDaily;
|
|
14692
|
+
exports.useStorageLedgerAddress = useStorageLedgerAddress;
|
|
14677
14693
|
exports.useSymbolLeverage = useSymbolLeverage;
|
|
14678
14694
|
exports.useSymbolPriceRange = useSymbolPriceRange;
|
|
14679
14695
|
exports.useSymbolsInfo = useSymbolsInfo;
|