@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.d.mts
CHANGED
|
@@ -355,7 +355,11 @@ declare const useBalance: () => any;
|
|
|
355
355
|
|
|
356
356
|
declare const usePrivateDataObserver: () => void;
|
|
357
357
|
|
|
358
|
-
declare const useExecutionReport: (
|
|
358
|
+
declare const useExecutionReport: (options?: {
|
|
359
|
+
onMessage?: ((data: any) => void) | undefined;
|
|
360
|
+
} | undefined) => any;
|
|
361
|
+
|
|
362
|
+
declare function parseExecutionReportToToastMsg(data: any, symbolsInfo: any): any | null;
|
|
359
363
|
|
|
360
364
|
interface Info {
|
|
361
365
|
symbol: string;
|
|
@@ -486,4 +490,4 @@ declare const useSwap: () => {
|
|
|
486
490
|
status: WS_WalletStatusEnum;
|
|
487
491
|
};
|
|
488
492
|
|
|
489
|
-
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 };
|
|
493
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -355,7 +355,11 @@ declare const useBalance: () => any;
|
|
|
355
355
|
|
|
356
356
|
declare const usePrivateDataObserver: () => void;
|
|
357
357
|
|
|
358
|
-
declare const useExecutionReport: (
|
|
358
|
+
declare const useExecutionReport: (options?: {
|
|
359
|
+
onMessage?: ((data: any) => void) | undefined;
|
|
360
|
+
} | undefined) => any;
|
|
361
|
+
|
|
362
|
+
declare function parseExecutionReportToToastMsg(data: any, symbolsInfo: any): any | null;
|
|
359
363
|
|
|
360
364
|
interface Info {
|
|
361
365
|
symbol: string;
|
|
@@ -486,4 +490,4 @@ declare const useSwap: () => {
|
|
|
486
490
|
status: WS_WalletStatusEnum;
|
|
487
491
|
};
|
|
488
492
|
|
|
489
|
-
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 };
|
|
493
|
+
export { AppStateErrors, DataSourceProvider, OrderStatus, OrderlyAppConfig, OrderlyContext, OrderlyContextState, OrderlyProvider, index 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 };
|
package/dist/index.js
CHANGED
|
@@ -1037,7 +1037,6 @@ var parseHolding = (holding, markPrices) => {
|
|
|
1037
1037
|
};
|
|
1038
1038
|
var usePositionStream = (symbol, options) => {
|
|
1039
1039
|
const symbolInfo = useSymbolsInfo();
|
|
1040
|
-
useEventEmitter();
|
|
1041
1040
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1042
1041
|
const { data: holding } = usePrivateQuery(
|
|
1043
1042
|
"/v1/client/holding",
|
|
@@ -1077,12 +1076,27 @@ var usePositionStream = (symbol, options) => {
|
|
|
1077
1076
|
item.symbol,
|
|
1078
1077
|
markPrices
|
|
1079
1078
|
);
|
|
1079
|
+
const info = symbolInfo?.[item.symbol];
|
|
1080
1080
|
const notional = futures.positions.notional(item.position_qty, price);
|
|
1081
1081
|
const unrealPnl = futures.positions.unrealizedPnL({
|
|
1082
1082
|
qty: item.position_qty,
|
|
1083
1083
|
openPrice: item.average_open_price,
|
|
1084
1084
|
markPrice: price
|
|
1085
1085
|
});
|
|
1086
|
+
const imr = futures.account.IMR({
|
|
1087
|
+
maxLeverage: accountInfo.max_leverage,
|
|
1088
|
+
baseIMR: info("base_imr"),
|
|
1089
|
+
IMR_Factor: accountInfo.imr_factor[item.symbol],
|
|
1090
|
+
positionNotional: notional,
|
|
1091
|
+
ordersNotional: 0,
|
|
1092
|
+
IMR_factor_power: 4 / 5
|
|
1093
|
+
});
|
|
1094
|
+
const unrealPnlROI = futures.positions.unrealizedPnLROI({
|
|
1095
|
+
positionQty: item.position_qty,
|
|
1096
|
+
openPrice: item.average_open_price,
|
|
1097
|
+
IMR: imr,
|
|
1098
|
+
unrealizedPnL: unrealPnl
|
|
1099
|
+
});
|
|
1086
1100
|
const unsettlementPnL = futures.positions.unsettlementPnL({
|
|
1087
1101
|
positionQty: item.position_qty,
|
|
1088
1102
|
markPrice: price,
|
|
@@ -1102,7 +1116,8 @@ var usePositionStream = (symbol, options) => {
|
|
|
1102
1116
|
mm: 0,
|
|
1103
1117
|
notional,
|
|
1104
1118
|
unsettlement_pnl: unsettlementPnL,
|
|
1105
|
-
unrealized_pnl: unrealPnl
|
|
1119
|
+
unrealized_pnl: unrealPnl,
|
|
1120
|
+
unsettled_pnl_ROI: unrealPnlROI
|
|
1106
1121
|
};
|
|
1107
1122
|
});
|
|
1108
1123
|
return [
|
|
@@ -1457,7 +1472,7 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
1457
1472
|
}
|
|
1458
1473
|
validate(values, config) {
|
|
1459
1474
|
return this.baseValidate(values, config).then((errors) => {
|
|
1460
|
-
const { order_price } = values;
|
|
1475
|
+
const { order_price, side } = values;
|
|
1461
1476
|
if (!order_price) {
|
|
1462
1477
|
errors.order_price = {
|
|
1463
1478
|
type: "required",
|
|
@@ -1469,20 +1484,21 @@ var LimitOrderCreator = class extends BaseOrderCreator {
|
|
|
1469
1484
|
const { price_range } = symbol;
|
|
1470
1485
|
const maxPriceNumber = maxPrice(config.markPrice, price_range);
|
|
1471
1486
|
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)) {
|
|
1487
|
+
console.log(`side: ${side} value:`, values);
|
|
1488
|
+
if (side === "BUY" && price.gt(maxPriceNumber)) {
|
|
1480
1489
|
errors.order_price = {
|
|
1481
1490
|
type: "max",
|
|
1482
1491
|
message: `price must be less than ${new utils.Decimal(
|
|
1483
1492
|
maxPriceNumber
|
|
1484
1493
|
).todp(symbol.quote_dp)}`
|
|
1485
1494
|
};
|
|
1495
|
+
} else if (side === "SELL" && price.lt(minPriceNumber)) {
|
|
1496
|
+
errors.order_price = {
|
|
1497
|
+
type: "min",
|
|
1498
|
+
message: `price must be greater than ${new utils.Decimal(
|
|
1499
|
+
minPriceNumber
|
|
1500
|
+
).todp(symbol.quote_dp)}`
|
|
1501
|
+
};
|
|
1486
1502
|
}
|
|
1487
1503
|
}
|
|
1488
1504
|
return errors;
|
|
@@ -3531,17 +3547,64 @@ var usePrivateDataObserver = () => {
|
|
|
3531
3547
|
};
|
|
3532
3548
|
}, [state.accountId]);
|
|
3533
3549
|
};
|
|
3534
|
-
var useExecutionReport = () => {
|
|
3550
|
+
var useExecutionReport = (options) => {
|
|
3535
3551
|
const ws = useWS();
|
|
3536
3552
|
const { data } = useSWRSubscription__default.default("executionreport", (_, { next }) => {
|
|
3537
|
-
const unsubscribe = ws.privateSubscribe(
|
|
3553
|
+
const unsubscribe = ws.privateSubscribe({
|
|
3554
|
+
id: "executionreport",
|
|
3555
|
+
event: "subscribe",
|
|
3556
|
+
topic: "executionreport",
|
|
3557
|
+
ts: Date.now()
|
|
3558
|
+
}, {
|
|
3538
3559
|
onMessage: (data2) => {
|
|
3560
|
+
options?.onMessage?.(data2);
|
|
3561
|
+
next(data2);
|
|
3539
3562
|
}
|
|
3540
3563
|
});
|
|
3541
3564
|
return () => unsubscribe();
|
|
3542
3565
|
});
|
|
3543
3566
|
return data;
|
|
3544
3567
|
};
|
|
3568
|
+
function parseExecutionReportToToastMsg(data, symbolsInfo) {
|
|
3569
|
+
const { symbol } = data;
|
|
3570
|
+
const getSymbolInfo = symbolsInfo[symbol];
|
|
3571
|
+
const baseTick = getSymbolInfo("base_dp");
|
|
3572
|
+
const { status } = data;
|
|
3573
|
+
const { side } = data;
|
|
3574
|
+
const { quantity } = data;
|
|
3575
|
+
const displaySide = utils.capitalizeString(side);
|
|
3576
|
+
const displaySymbol = utils.transSymbolformString(symbol);
|
|
3577
|
+
const displayQuantity = baseTick === void 0 ? quantity : quantity.toFixed(baseTick);
|
|
3578
|
+
let msg = "";
|
|
3579
|
+
let title = "";
|
|
3580
|
+
switch (status) {
|
|
3581
|
+
case "NEW":
|
|
3582
|
+
title = "Order opened";
|
|
3583
|
+
msg = `Order opened ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3584
|
+
break;
|
|
3585
|
+
case "FILLED":
|
|
3586
|
+
case "PARTIAL_FILLED":
|
|
3587
|
+
const { totalExecutedQuantity } = data;
|
|
3588
|
+
const displayTotalExecutedQuantity = baseTick === void 0 ? totalExecutedQuantity : totalExecutedQuantity.toFixed(baseTick);
|
|
3589
|
+
title = "Order filled";
|
|
3590
|
+
msg = `Order filled ${displaySide} ${displaySymbol} ${displayTotalExecutedQuantity} / ${displayQuantity}`;
|
|
3591
|
+
break;
|
|
3592
|
+
case "CANCELLED":
|
|
3593
|
+
title = "Order cancelled";
|
|
3594
|
+
msg = `Order cancelled ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3595
|
+
break;
|
|
3596
|
+
case "REJECTED":
|
|
3597
|
+
title = "Order rejected";
|
|
3598
|
+
msg = `Order rejected ${displaySide} ${displaySymbol} ${displayQuantity}`;
|
|
3599
|
+
break;
|
|
3600
|
+
}
|
|
3601
|
+
if (msg.length === 0)
|
|
3602
|
+
return null;
|
|
3603
|
+
return {
|
|
3604
|
+
title,
|
|
3605
|
+
msg
|
|
3606
|
+
};
|
|
3607
|
+
}
|
|
3545
3608
|
|
|
3546
3609
|
// src/apis/index.ts
|
|
3547
3610
|
var apis_exports = {};
|
|
@@ -4188,6 +4251,7 @@ exports.OrderStatus = OrderStatus;
|
|
|
4188
4251
|
exports.OrderlyContext = OrderlyContext;
|
|
4189
4252
|
exports.OrderlyProvider = OrderlyProvider;
|
|
4190
4253
|
exports.apis = apis_exports;
|
|
4254
|
+
exports.parseExecutionReportToToastMsg = parseExecutionReportToToastMsg;
|
|
4191
4255
|
exports.useAccount = useAccount;
|
|
4192
4256
|
exports.useAccountInfo = useAccountInfo;
|
|
4193
4257
|
exports.useAccountInstance = useAccountInstance;
|