@orderly.network/hooks 0.0.84 → 0.0.86
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 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +31 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -53
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -359,8 +359,6 @@ declare const useExecutionReport: (options?: {
|
|
|
359
359
|
onMessage?: ((data: any) => void) | undefined;
|
|
360
360
|
} | undefined) => any;
|
|
361
361
|
|
|
362
|
-
declare function parseExecutionReportToToastMsg(data: any, symbolsInfo: any): any | null;
|
|
363
|
-
|
|
364
362
|
interface Info {
|
|
365
363
|
symbol: string;
|
|
366
364
|
quote_min: number;
|
|
@@ -490,4 +488,4 @@ declare const useSwap: () => {
|
|
|
490
488
|
status: WS_WalletStatusEnum;
|
|
491
489
|
};
|
|
492
490
|
|
|
493
|
-
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis,
|
|
491
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -359,8 +359,6 @@ declare const useExecutionReport: (options?: {
|
|
|
359
359
|
onMessage?: ((data: any) => void) | undefined;
|
|
360
360
|
} | undefined) => any;
|
|
361
361
|
|
|
362
|
-
declare function parseExecutionReportToToastMsg(data: any, symbolsInfo: any): any | null;
|
|
363
|
-
|
|
364
362
|
interface Info {
|
|
365
363
|
symbol: string;
|
|
366
364
|
quote_min: number;
|
|
@@ -490,4 +488,4 @@ declare const useSwap: () => {
|
|
|
490
488
|
status: WS_WalletStatusEnum;
|
|
491
489
|
};
|
|
492
490
|
|
|
493
|
-
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index as apis,
|
|
491
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
package/dist/index.js
CHANGED
|
@@ -755,6 +755,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
755
755
|
const eventEmitter = useEventEmitter();
|
|
756
756
|
React2.useEffect(() => {
|
|
757
757
|
setIsLoading(true);
|
|
758
|
+
let ignore = false;
|
|
758
759
|
ws.onceSubscribe(
|
|
759
760
|
{
|
|
760
761
|
event: "request",
|
|
@@ -766,6 +767,8 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
766
767
|
},
|
|
767
768
|
{
|
|
768
769
|
onMessage: (message) => {
|
|
770
|
+
if (ignore)
|
|
771
|
+
return;
|
|
769
772
|
if (!!message) {
|
|
770
773
|
const reduceOrderbookData = reduceOrderbook(depth, level, message);
|
|
771
774
|
setRequestData(reduceOrderbookData);
|
|
@@ -777,6 +780,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
777
780
|
);
|
|
778
781
|
return () => {
|
|
779
782
|
setRequestData(null);
|
|
783
|
+
ignore = true;
|
|
780
784
|
setData(INIT_DATA);
|
|
781
785
|
};
|
|
782
786
|
}, [symbol, depth]);
|
|
@@ -1037,7 +1041,6 @@ var parseHolding = (holding, markPrices) => {
|
|
|
1037
1041
|
};
|
|
1038
1042
|
var usePositionStream = (symbol, options) => {
|
|
1039
1043
|
const symbolInfo = useSymbolsInfo();
|
|
1040
|
-
useEventEmitter();
|
|
1041
1044
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1042
1045
|
const { data: holding } = usePrivateQuery(
|
|
1043
1046
|
"/v1/client/holding",
|
|
@@ -1077,12 +1080,27 @@ var usePositionStream = (symbol, options) => {
|
|
|
1077
1080
|
item.symbol,
|
|
1078
1081
|
markPrices
|
|
1079
1082
|
);
|
|
1083
|
+
const info = symbolInfo?.[item.symbol];
|
|
1080
1084
|
const notional = futures.positions.notional(item.position_qty, price);
|
|
1081
1085
|
const unrealPnl = futures.positions.unrealizedPnL({
|
|
1082
1086
|
qty: item.position_qty,
|
|
1083
1087
|
openPrice: item.average_open_price,
|
|
1084
1088
|
markPrice: price
|
|
1085
1089
|
});
|
|
1090
|
+
const imr = futures.account.IMR({
|
|
1091
|
+
maxLeverage: accountInfo.max_leverage,
|
|
1092
|
+
baseIMR: info("base_imr"),
|
|
1093
|
+
IMR_Factor: accountInfo.imr_factor[item.symbol],
|
|
1094
|
+
positionNotional: notional,
|
|
1095
|
+
ordersNotional: 0,
|
|
1096
|
+
IMR_factor_power: 4 / 5
|
|
1097
|
+
});
|
|
1098
|
+
const unrealPnlROI = futures.positions.unrealizedPnLROI({
|
|
1099
|
+
positionQty: item.position_qty,
|
|
1100
|
+
openPrice: item.average_open_price,
|
|
1101
|
+
IMR: imr,
|
|
1102
|
+
unrealizedPnL: unrealPnl
|
|
1103
|
+
});
|
|
1086
1104
|
const unsettlementPnL = futures.positions.unsettlementPnL({
|
|
1087
1105
|
positionQty: item.position_qty,
|
|
1088
1106
|
markPrice: price,
|
|
@@ -1102,7 +1120,8 @@ var usePositionStream = (symbol, options) => {
|
|
|
1102
1120
|
mm: 0,
|
|
1103
1121
|
notional,
|
|
1104
1122
|
unsettlement_pnl: unsettlementPnL,
|
|
1105
|
-
unrealized_pnl: unrealPnl
|
|
1123
|
+
unrealized_pnl: unrealPnl,
|
|
1124
|
+
unsettled_pnl_ROI: unrealPnlROI
|
|
1106
1125
|
};
|
|
1107
1126
|
});
|
|
1108
1127
|
return [
|
|
@@ -1457,7 +1476,7 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
1457
1476
|
}
|
|
1458
1477
|
validate(values, config) {
|
|
1459
1478
|
return this.baseValidate(values, config).then((errors) => {
|
|
1460
|
-
const { order_price } = values;
|
|
1479
|
+
const { order_price, side } = values;
|
|
1461
1480
|
if (!order_price) {
|
|
1462
1481
|
errors.order_price = {
|
|
1463
1482
|
type: "required",
|
|
@@ -1469,20 +1488,21 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
1469
1488
|
const { price_range } = symbol;
|
|
1470
1489
|
const maxPriceNumber = maxPrice(config.markPrice, price_range);
|
|
1471
1490
|
const minPriceNumber = minPrice(config.markPrice, price_range);
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
type: "min",
|
|
1475
|
-
message: `price must be greater than ${new utils.Decimal(
|
|
1476
|
-
minPriceNumber
|
|
1477
|
-
).todp(symbol.quote_dp)}`
|
|
1478
|
-
};
|
|
1479
|
-
} else if (price.gt(maxPriceNumber)) {
|
|
1491
|
+
console.log(`side: ${side} value:`, values);
|
|
1492
|
+
if (side === "BUY" && price.gt(maxPriceNumber)) {
|
|
1480
1493
|
errors.order_price = {
|
|
1481
1494
|
type: "max",
|
|
1482
1495
|
message: `price must be less than ${new utils.Decimal(
|
|
1483
1496
|
maxPriceNumber
|
|
1484
1497
|
).todp(symbol.quote_dp)}`
|
|
1485
1498
|
};
|
|
1499
|
+
} else if (side === "SELL" && price.lt(minPriceNumber)) {
|
|
1500
|
+
errors.order_price = {
|
|
1501
|
+
type: "min",
|
|
1502
|
+
message: `price must be greater than ${new utils.Decimal(
|
|
1503
|
+
minPriceNumber
|
|
1504
|
+
).todp(symbol.quote_dp)}`
|
|
1505
|
+
};
|
|
1486
1506
|
}
|
|
1487
1507
|
}
|
|
1488
1508
|
return errors;
|
|
@@ -3549,46 +3569,6 @@ var useExecutionReport = (options) => {
|
|
|
3549
3569
|
});
|
|
3550
3570
|
return data;
|
|
3551
3571
|
};
|
|
3552
|
-
function parseExecutionReportToToastMsg(data, symbolsInfo) {
|
|
3553
|
-
const { symbol } = data;
|
|
3554
|
-
const getSymbolInfo = symbolsInfo[symbol];
|
|
3555
|
-
const baseTick = getSymbolInfo("base_dp");
|
|
3556
|
-
const { status } = data;
|
|
3557
|
-
const { side } = data;
|
|
3558
|
-
const { quantity } = data;
|
|
3559
|
-
const displaySide = utils.capitalizeString(side);
|
|
3560
|
-
const displaySymbol = utils.transSymbolformString(symbol);
|
|
3561
|
-
const displayQuantity = baseTick === void 0 ? quantity : quantity.toFixed(baseTick);
|
|
3562
|
-
let msg = "";
|
|
3563
|
-
let title = "";
|
|
3564
|
-
switch (status) {
|
|
3565
|
-
case "NEW":
|
|
3566
|
-
title = "Order opened";
|
|
3567
|
-
msg = `Order opened ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3568
|
-
break;
|
|
3569
|
-
case "FILLED":
|
|
3570
|
-
case "PARTIAL_FILLED":
|
|
3571
|
-
const { totalExecutedQuantity } = data;
|
|
3572
|
-
const displayTotalExecutedQuantity = baseTick === void 0 ? totalExecutedQuantity : totalExecutedQuantity.toFixed(baseTick);
|
|
3573
|
-
title = "Order filled";
|
|
3574
|
-
msg = `Order filled ${displaySide} ${displaySymbol} ${displayTotalExecutedQuantity} / ${displayQuantity}`;
|
|
3575
|
-
break;
|
|
3576
|
-
case "CANCELLED":
|
|
3577
|
-
title = "Order cancelled";
|
|
3578
|
-
msg = `Order cancelled ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3579
|
-
break;
|
|
3580
|
-
case "REJECTED":
|
|
3581
|
-
title = "Order rejected";
|
|
3582
|
-
msg = `Order rejected ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3583
|
-
break;
|
|
3584
|
-
}
|
|
3585
|
-
if (msg.length === 0)
|
|
3586
|
-
return null;
|
|
3587
|
-
return {
|
|
3588
|
-
title,
|
|
3589
|
-
msg
|
|
3590
|
-
};
|
|
3591
|
-
}
|
|
3592
3572
|
|
|
3593
3573
|
// src/apis/index.ts
|
|
3594
3574
|
var apis_exports = {};
|
|
@@ -4235,7 +4215,6 @@ exports.OrderStatus = OrderStatus;
|
|
|
4235
4215
|
exports.OrderlyContext = OrderlyContext;
|
|
4236
4216
|
exports.OrderlyProvider = OrderlyProvider;
|
|
4237
4217
|
exports.apis = apis_exports;
|
|
4238
|
-
exports.parseExecutionReportToToastMsg = parseExecutionReportToToastMsg;
|
|
4239
4218
|
exports.useAccount = useAccount;
|
|
4240
4219
|
exports.useAccountInfo = useAccountInfo;
|
|
4241
4220
|
exports.useAccountInstance = useAccountInstance;
|