@orderly.network/hooks 0.0.83 → 0.0.85
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 +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +77 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import useConstant from 'use-constant';
|
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
8
8
|
import { SimpleDI, Account, EventEmitter, utils } from '@orderly.network/core';
|
|
9
9
|
import { AccountStatusEnum, OrderSide, chainsInfoMap, ARBITRUM_TESTNET_CHAINID, ARBITRUM_MAINNET_CHAINID, OrderStatus as OrderStatus$1, WS_WalletStatusEnum, OrderType } from '@orderly.network/types';
|
|
10
|
-
import { Decimal, zero, getPrecisionByNumber, timeConvertString } from '@orderly.network/utils';
|
|
10
|
+
import { Decimal, zero, getPrecisionByNumber, timeConvertString, capitalizeString, transSymbolformString } from '@orderly.network/utils';
|
|
11
11
|
import useSWRSubscription from 'swr/subscription';
|
|
12
12
|
import { pathOr, propOr, compose, head, prop, mergeDeepRight, pick } from 'ramda';
|
|
13
13
|
import { positions, account, order } from '@orderly.network/futures';
|
|
@@ -1028,7 +1028,6 @@ var parseHolding = (holding, markPrices) => {
|
|
|
1028
1028
|
};
|
|
1029
1029
|
var usePositionStream = (symbol, options) => {
|
|
1030
1030
|
const symbolInfo = useSymbolsInfo();
|
|
1031
|
-
useEventEmitter();
|
|
1032
1031
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1033
1032
|
const { data: holding } = usePrivateQuery(
|
|
1034
1033
|
"/v1/client/holding",
|
|
@@ -1068,12 +1067,27 @@ var usePositionStream = (symbol, options) => {
|
|
|
1068
1067
|
item.symbol,
|
|
1069
1068
|
markPrices
|
|
1070
1069
|
);
|
|
1070
|
+
const info = symbolInfo?.[item.symbol];
|
|
1071
1071
|
const notional = positions.notional(item.position_qty, price);
|
|
1072
1072
|
const unrealPnl = positions.unrealizedPnL({
|
|
1073
1073
|
qty: item.position_qty,
|
|
1074
1074
|
openPrice: item.average_open_price,
|
|
1075
1075
|
markPrice: price
|
|
1076
1076
|
});
|
|
1077
|
+
const imr = account.IMR({
|
|
1078
|
+
maxLeverage: accountInfo.max_leverage,
|
|
1079
|
+
baseIMR: info("base_imr"),
|
|
1080
|
+
IMR_Factor: accountInfo.imr_factor[item.symbol],
|
|
1081
|
+
positionNotional: notional,
|
|
1082
|
+
ordersNotional: 0,
|
|
1083
|
+
IMR_factor_power: 4 / 5
|
|
1084
|
+
});
|
|
1085
|
+
const unrealPnlROI = positions.unrealizedPnLROI({
|
|
1086
|
+
positionQty: item.position_qty,
|
|
1087
|
+
openPrice: item.average_open_price,
|
|
1088
|
+
IMR: imr,
|
|
1089
|
+
unrealizedPnL: unrealPnl
|
|
1090
|
+
});
|
|
1077
1091
|
const unsettlementPnL = positions.unsettlementPnL({
|
|
1078
1092
|
positionQty: item.position_qty,
|
|
1079
1093
|
markPrice: price,
|
|
@@ -1093,7 +1107,8 @@ var usePositionStream = (symbol, options) => {
|
|
|
1093
1107
|
mm: 0,
|
|
1094
1108
|
notional,
|
|
1095
1109
|
unsettlement_pnl: unsettlementPnL,
|
|
1096
|
-
unrealized_pnl: unrealPnl
|
|
1110
|
+
unrealized_pnl: unrealPnl,
|
|
1111
|
+
unsettled_pnl_ROI: unrealPnlROI
|
|
1097
1112
|
};
|
|
1098
1113
|
});
|
|
1099
1114
|
return [
|
|
@@ -1448,7 +1463,7 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
1448
1463
|
}
|
|
1449
1464
|
validate(values, config) {
|
|
1450
1465
|
return this.baseValidate(values, config).then((errors) => {
|
|
1451
|
-
const { order_price } = values;
|
|
1466
|
+
const { order_price, side } = values;
|
|
1452
1467
|
if (!order_price) {
|
|
1453
1468
|
errors.order_price = {
|
|
1454
1469
|
type: "required",
|
|
@@ -1460,20 +1475,21 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
1460
1475
|
const { price_range } = symbol;
|
|
1461
1476
|
const maxPriceNumber = maxPrice(config.markPrice, price_range);
|
|
1462
1477
|
const minPriceNumber = minPrice(config.markPrice, price_range);
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
type: "min",
|
|
1466
|
-
message: `price must be greater than ${new Decimal(
|
|
1467
|
-
minPriceNumber
|
|
1468
|
-
).todp(symbol.quote_dp)}`
|
|
1469
|
-
};
|
|
1470
|
-
} else if (price.gt(maxPriceNumber)) {
|
|
1478
|
+
console.log(`side: ${side} value:`, values);
|
|
1479
|
+
if (side === "BUY" && price.gt(maxPriceNumber)) {
|
|
1471
1480
|
errors.order_price = {
|
|
1472
1481
|
type: "max",
|
|
1473
1482
|
message: `price must be less than ${new Decimal(
|
|
1474
1483
|
maxPriceNumber
|
|
1475
1484
|
).todp(symbol.quote_dp)}`
|
|
1476
1485
|
};
|
|
1486
|
+
} else if (side === "SELL" && price.lt(minPriceNumber)) {
|
|
1487
|
+
errors.order_price = {
|
|
1488
|
+
type: "min",
|
|
1489
|
+
message: `price must be greater than ${new Decimal(
|
|
1490
|
+
minPriceNumber
|
|
1491
|
+
).todp(symbol.quote_dp)}`
|
|
1492
|
+
};
|
|
1477
1493
|
}
|
|
1478
1494
|
}
|
|
1479
1495
|
return errors;
|
|
@@ -3522,17 +3538,64 @@ var usePrivateDataObserver = () => {
|
|
|
3522
3538
|
};
|
|
3523
3539
|
}, [state.accountId]);
|
|
3524
3540
|
};
|
|
3525
|
-
var useExecutionReport = () => {
|
|
3541
|
+
var useExecutionReport = (options) => {
|
|
3526
3542
|
const ws = useWS();
|
|
3527
3543
|
const { data } = useSWRSubscription("executionreport", (_, { next }) => {
|
|
3528
|
-
const unsubscribe = ws.privateSubscribe(
|
|
3544
|
+
const unsubscribe = ws.privateSubscribe({
|
|
3545
|
+
id: "executionreport",
|
|
3546
|
+
event: "subscribe",
|
|
3547
|
+
topic: "executionreport",
|
|
3548
|
+
ts: Date.now()
|
|
3549
|
+
}, {
|
|
3529
3550
|
onMessage: (data2) => {
|
|
3551
|
+
options?.onMessage?.(data2);
|
|
3552
|
+
next(data2);
|
|
3530
3553
|
}
|
|
3531
3554
|
});
|
|
3532
3555
|
return () => unsubscribe();
|
|
3533
3556
|
});
|
|
3534
3557
|
return data;
|
|
3535
3558
|
};
|
|
3559
|
+
function parseExecutionReportToToastMsg(data, symbolsInfo) {
|
|
3560
|
+
const { symbol } = data;
|
|
3561
|
+
const getSymbolInfo = symbolsInfo[symbol];
|
|
3562
|
+
const baseTick = getSymbolInfo("base_dp");
|
|
3563
|
+
const { status } = data;
|
|
3564
|
+
const { side } = data;
|
|
3565
|
+
const { quantity } = data;
|
|
3566
|
+
const displaySide = capitalizeString(side);
|
|
3567
|
+
const displaySymbol = transSymbolformString(symbol);
|
|
3568
|
+
const displayQuantity = baseTick === void 0 ? quantity : quantity.toFixed(baseTick);
|
|
3569
|
+
let msg = "";
|
|
3570
|
+
let title = "";
|
|
3571
|
+
switch (status) {
|
|
3572
|
+
case "NEW":
|
|
3573
|
+
title = "Order opened";
|
|
3574
|
+
msg = `Order opened ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3575
|
+
break;
|
|
3576
|
+
case "FILLED":
|
|
3577
|
+
case "PARTIAL_FILLED":
|
|
3578
|
+
const { totalExecutedQuantity } = data;
|
|
3579
|
+
const displayTotalExecutedQuantity = baseTick === void 0 ? totalExecutedQuantity : totalExecutedQuantity.toFixed(baseTick);
|
|
3580
|
+
title = "Order filled";
|
|
3581
|
+
msg = `Order filled ${displaySide} ${displaySymbol} ${displayTotalExecutedQuantity} / ${displayQuantity}`;
|
|
3582
|
+
break;
|
|
3583
|
+
case "CANCELLED":
|
|
3584
|
+
title = "Order cancelled";
|
|
3585
|
+
msg = `Order cancelled ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3586
|
+
break;
|
|
3587
|
+
case "REJECTED":
|
|
3588
|
+
title = "Order rejected";
|
|
3589
|
+
msg = `Order rejected ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3590
|
+
break;
|
|
3591
|
+
}
|
|
3592
|
+
if (msg.length === 0)
|
|
3593
|
+
return null;
|
|
3594
|
+
return {
|
|
3595
|
+
title,
|
|
3596
|
+
msg
|
|
3597
|
+
};
|
|
3598
|
+
}
|
|
3536
3599
|
|
|
3537
3600
|
// src/apis/index.ts
|
|
3538
3601
|
var apis_exports = {};
|
|
@@ -4162,6 +4225,6 @@ var useSwap = () => {
|
|
|
4162
4225
|
};
|
|
4163
4226
|
};
|
|
4164
4227
|
|
|
4165
|
-
export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
|
|
4228
|
+
export { DataSourceProvider, OrderStatus, OrderlyContext, OrderlyProvider, apis_exports as apis, parseExecutionReportToToastMsg, useAccount, useAccountInfo, useAccountInstance, useAppState, useBalance, useBoolean, useChain, useChains, useCollateral, useConfig, useCrossSwap, useDeposit, useEventEmitter, useExecutionReport, useFetures, useFundingRate, useHoldingStream, useIndexPrice, useLazyQuery, useLeverage, useLocalStorage, useMarginRatio, useMarkPrice, useMarkPricesStream, useMarketTradeStream, useMarketsStream, useMaxQty, useMutation, useOpenInterest, useOrderEntry, useOrderStream, useOrderbookStream, usePositionStream, usePreLoadData, usePrivateDataObserver, usePrivateQuery, useQuery, useRunOnce, useSessionStorage, useSettleSubscription, useSwap, useSymbolsInfo, useTickerStream, useTokenInfo, useTopicObserve, useTradingView, useWS, useWalletSubscription, useWithdraw, useWooCrossSwapQuery, useWooSwapQuery };
|
|
4166
4229
|
//# sourceMappingURL=out.js.map
|
|
4167
4230
|
//# sourceMappingURL=index.mjs.map
|