@orderly.network/hooks 1.0.28-alpha.19 → 1.0.28-alpha.20
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 +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +56 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -24,7 +24,7 @@ declare global {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
declare const _default: "1.0.28-alpha.
|
|
27
|
+
declare const _default: "1.0.28-alpha.20";
|
|
28
28
|
|
|
29
29
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
30
30
|
formatter?: (data: any) => T;
|
|
@@ -326,10 +326,12 @@ declare const useCollateral: (options?: Options) => CollateralOutputs;
|
|
|
326
326
|
|
|
327
327
|
declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
type MarginRatioReturn = {
|
|
330
330
|
marginRatio: number;
|
|
331
331
|
currentLeverage: number;
|
|
332
|
+
mmr: number | null;
|
|
332
333
|
};
|
|
334
|
+
declare const useMarginRatio: () => MarginRatioReturn;
|
|
333
335
|
|
|
334
336
|
type inputOptions = {
|
|
335
337
|
filter?: (item: API.Chain) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ declare global {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
declare const _default: "1.0.28-alpha.
|
|
27
|
+
declare const _default: "1.0.28-alpha.20";
|
|
28
28
|
|
|
29
29
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
30
30
|
formatter?: (data: any) => T;
|
|
@@ -326,10 +326,12 @@ declare const useCollateral: (options?: Options) => CollateralOutputs;
|
|
|
326
326
|
|
|
327
327
|
declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
|
|
328
328
|
|
|
329
|
-
|
|
329
|
+
type MarginRatioReturn = {
|
|
330
330
|
marginRatio: number;
|
|
331
331
|
currentLeverage: number;
|
|
332
|
+
mmr: number | null;
|
|
332
333
|
};
|
|
334
|
+
declare const useMarginRatio: () => MarginRatioReturn;
|
|
333
335
|
|
|
334
336
|
type inputOptions = {
|
|
335
337
|
filter?: (item: API.Chain) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -28,9 +28,9 @@ var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscriptio
|
|
|
28
28
|
// src/version.ts
|
|
29
29
|
if (typeof window !== "undefined") {
|
|
30
30
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
31
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.0.28-alpha.
|
|
31
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.0.28-alpha.20";
|
|
32
32
|
}
|
|
33
|
-
var version_default = "1.0.28-alpha.
|
|
33
|
+
var version_default = "1.0.28-alpha.20";
|
|
34
34
|
var fetcher = (url, init = {}, queryOptions) => net.get(url, init, queryOptions?.formatter);
|
|
35
35
|
var OrderlyContext = React.createContext({
|
|
36
36
|
// configStore: new MemoryConfigStore(),
|
|
@@ -789,7 +789,7 @@ var reduceItems = (depth, level, data, asks = false) => {
|
|
|
789
789
|
const result = [];
|
|
790
790
|
if (typeof depth !== "undefined") {
|
|
791
791
|
const prices = /* @__PURE__ */ new Map();
|
|
792
|
-
for (let i = 0; i < data.length; i++) {
|
|
792
|
+
for (let i = 0; i < ramda.min(level, data.length); i++) {
|
|
793
793
|
const [price, quantity] = data[i];
|
|
794
794
|
if (isNaN(price) || isNaN(quantity))
|
|
795
795
|
continue;
|
|
@@ -824,7 +824,8 @@ var reduceItems = (depth, level, data, asks = false) => {
|
|
|
824
824
|
if (isNaN(price) || isNaN(quantity))
|
|
825
825
|
continue;
|
|
826
826
|
const newQuantity = new utils.Decimal(quantity).add(result.length > 0 ? result[result.length - 1][2] : 0).toNumber();
|
|
827
|
-
|
|
827
|
+
const newAmount = new utils.Decimal(quantity * price).add(result.length > 0 ? result[result.length - 1][3] : 0).toNumber();
|
|
828
|
+
result.push([price, quantity, newQuantity, newAmount]);
|
|
828
829
|
}
|
|
829
830
|
return result;
|
|
830
831
|
};
|
|
@@ -855,9 +856,11 @@ var reduceOrderbook = (depth, level, data) => {
|
|
|
855
856
|
}
|
|
856
857
|
}
|
|
857
858
|
asks = asks.reverse();
|
|
859
|
+
asks = asks.length < level ? paddingFn(level - asks.length).concat(asks) : asks;
|
|
860
|
+
bids = bids.length < level ? bids.concat(paddingFn(level - bids.length)) : bids;
|
|
858
861
|
return {
|
|
859
|
-
asks
|
|
860
|
-
bids
|
|
862
|
+
asks,
|
|
863
|
+
bids
|
|
861
864
|
};
|
|
862
865
|
};
|
|
863
866
|
var mergeItems = (data, update) => {
|
|
@@ -1649,7 +1652,7 @@ var positionsPath = ramda.pathOr([], [0, "rows"]);
|
|
|
1649
1652
|
ramda.pathOr(0, [0, "totalCollateral"]);
|
|
1650
1653
|
var useCollateral = (options = { dp: 6 }) => {
|
|
1651
1654
|
const { dp } = options;
|
|
1652
|
-
const
|
|
1655
|
+
const positions3 = usePositionStream();
|
|
1653
1656
|
const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
|
|
1654
1657
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1655
1658
|
const symbolInfo = useSymbolsInfo();
|
|
@@ -1657,23 +1660,23 @@ var useCollateral = (options = { dp: 6 }) => {
|
|
|
1657
1660
|
const { usdc } = useHoldingStream();
|
|
1658
1661
|
const [totalCollateral, totalValue] = React.useMemo(() => {
|
|
1659
1662
|
return [
|
|
1660
|
-
ramda.pathOr(utils.zero, [0, "totalCollateral"],
|
|
1661
|
-
ramda.pathOr(utils.zero, [0, "totalValue"],
|
|
1663
|
+
ramda.pathOr(utils.zero, [0, "totalCollateral"], positions3),
|
|
1664
|
+
ramda.pathOr(utils.zero, [0, "totalValue"], positions3)
|
|
1662
1665
|
];
|
|
1663
|
-
}, [
|
|
1666
|
+
}, [positions3, markPrices]);
|
|
1664
1667
|
const totalInitialMarginWithOrders = React.useMemo(() => {
|
|
1665
1668
|
if (!accountInfo || !symbolInfo || !markPrices) {
|
|
1666
1669
|
return 0;
|
|
1667
1670
|
}
|
|
1668
1671
|
return perp.account.totalInitialMarginWithOrders({
|
|
1669
|
-
positions: positionsPath(
|
|
1672
|
+
positions: positionsPath(positions3),
|
|
1670
1673
|
orders: orders ?? [],
|
|
1671
1674
|
markPrices,
|
|
1672
1675
|
IMR_Factors: accountInfo.imr_factor,
|
|
1673
1676
|
maxLeverage: accountInfo.max_leverage,
|
|
1674
1677
|
symbolInfo
|
|
1675
1678
|
});
|
|
1676
|
-
}, [
|
|
1679
|
+
}, [positions3, orders, markPrices, accountInfo, symbolInfo]);
|
|
1677
1680
|
const freeCollateral = React.useMemo(() => {
|
|
1678
1681
|
return perp.account.freeCollateral({
|
|
1679
1682
|
totalCollateral,
|
|
@@ -1683,15 +1686,15 @@ var useCollateral = (options = { dp: 6 }) => {
|
|
|
1683
1686
|
const availableBalance = React.useMemo(() => {
|
|
1684
1687
|
return perp.account.availableBalance({
|
|
1685
1688
|
USDCHolding: usdc?.holding ?? 0,
|
|
1686
|
-
unsettlementPnL: pathOr_unsettledPnLPathOr(
|
|
1689
|
+
unsettlementPnL: pathOr_unsettledPnLPathOr(positions3)
|
|
1687
1690
|
});
|
|
1688
|
-
}, [usdc, pathOr_unsettledPnLPathOr(
|
|
1691
|
+
}, [usdc, pathOr_unsettledPnLPathOr(positions3)]);
|
|
1689
1692
|
return {
|
|
1690
1693
|
totalCollateral: totalCollateral.toDecimalPlaces(dp).toNumber(),
|
|
1691
1694
|
freeCollateral: freeCollateral.toDecimalPlaces(dp).toNumber(),
|
|
1692
1695
|
totalValue: totalValue.toDecimalPlaces(dp).toNumber(),
|
|
1693
1696
|
availableBalance,
|
|
1694
|
-
unsettledPnL: pathOr_unsettledPnLPathOr(
|
|
1697
|
+
unsettledPnL: pathOr_unsettledPnLPathOr(positions3)
|
|
1695
1698
|
};
|
|
1696
1699
|
};
|
|
1697
1700
|
var positionsPath2 = ramda.pathOr([], [0, "rows"]);
|
|
@@ -1705,8 +1708,8 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1705
1708
|
const maxQty = React.useMemo(() => {
|
|
1706
1709
|
if (!symbol)
|
|
1707
1710
|
return 0;
|
|
1708
|
-
const
|
|
1709
|
-
const positionQty = perp.account.getQtyFromPositions(
|
|
1711
|
+
const positions3 = positionsPath2(positionsData);
|
|
1712
|
+
const positionQty = perp.account.getQtyFromPositions(positions3, symbol);
|
|
1710
1713
|
if (reduceOnly) {
|
|
1711
1714
|
if (positionQty > 0) {
|
|
1712
1715
|
if (side === types.OrderSide.BUY) {
|
|
@@ -1737,7 +1740,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1737
1740
|
symbol,
|
|
1738
1741
|
types.OrderSide.SELL
|
|
1739
1742
|
);
|
|
1740
|
-
const otherPositions =
|
|
1743
|
+
const otherPositions = positions3.filter(
|
|
1741
1744
|
(item) => item.symbol !== symbol
|
|
1742
1745
|
);
|
|
1743
1746
|
const otherOrders = orders.filter(
|
|
@@ -1954,13 +1957,20 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1954
1957
|
);
|
|
1955
1958
|
const onSubmit = (values) => {
|
|
1956
1959
|
if (!values || typeof values.order_type === "undefined" || values.order_type !== types.OrderType.MARKET && values.order_type !== types.OrderType.LIMIT) {
|
|
1957
|
-
throw new
|
|
1960
|
+
throw new types.SDKError("order_type is error");
|
|
1958
1961
|
}
|
|
1959
1962
|
const orderCreator = OrderFactory.create(
|
|
1960
1963
|
!!values.order_type_ext ? values.order_type_ext : values.order_type
|
|
1961
1964
|
);
|
|
1962
1965
|
if (!orderCreator) {
|
|
1963
|
-
return Promise.reject(new
|
|
1966
|
+
return Promise.reject(new types.SDKError("orderCreator is null"));
|
|
1967
|
+
}
|
|
1968
|
+
if (reduceOnly && !values.reduce_only) {
|
|
1969
|
+
return Promise.reject(
|
|
1970
|
+
new types.SDKError(
|
|
1971
|
+
"The reduceOny parameter of hook does not match your order data"
|
|
1972
|
+
)
|
|
1973
|
+
);
|
|
1964
1974
|
}
|
|
1965
1975
|
return orderCreator?.validate(values, {
|
|
1966
1976
|
symbol: symbolInfo[symbol](),
|
|
@@ -1969,10 +1979,10 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1969
1979
|
markPrice
|
|
1970
1980
|
}).then(() => {
|
|
1971
1981
|
if (!orderCreator) {
|
|
1972
|
-
throw new
|
|
1982
|
+
throw new types.SDKError("orderCreator is null");
|
|
1973
1983
|
}
|
|
1974
1984
|
if (!symbol) {
|
|
1975
|
-
throw new
|
|
1985
|
+
throw new types.SDKError("symbol is null");
|
|
1976
1986
|
}
|
|
1977
1987
|
const data2 = orderCreator.create(values);
|
|
1978
1988
|
return doCreateOrder({
|
|
@@ -2031,6 +2041,7 @@ var useMarkets = (type) => {
|
|
|
2031
2041
|
const marketsKey = "markets";
|
|
2032
2042
|
const { data } = useMarketsStream();
|
|
2033
2043
|
const { configStore } = React.useContext(OrderlyContext);
|
|
2044
|
+
const publicInfo = useSymbolsInfo();
|
|
2034
2045
|
if (!configStore.get(marketsKey)) {
|
|
2035
2046
|
const jsonStr = localStorage.getItem(marketsKey);
|
|
2036
2047
|
if (jsonStr) {
|
|
@@ -2167,11 +2178,16 @@ var useMarkets = (type) => {
|
|
|
2167
2178
|
const isFavorite = type2 == 0 /* FAVORITES */ ? true : favoriteKeys.includes(element.symbol);
|
|
2168
2179
|
const fIndex = favoritesData.findIndex((item) => item.name === element.symbol);
|
|
2169
2180
|
const tabs2 = fIndex === -1 ? [] : favoritesData[fIndex].tabs;
|
|
2181
|
+
let imr = void 0;
|
|
2182
|
+
if (publicInfo) {
|
|
2183
|
+
imr = publicInfo?.[element.symbol]("base_imr");
|
|
2184
|
+
}
|
|
2170
2185
|
filter[index] = {
|
|
2171
2186
|
...filter[index],
|
|
2172
2187
|
// @ts-ignore
|
|
2173
2188
|
isFavorite,
|
|
2174
|
-
tabs: tabs2
|
|
2189
|
+
tabs: tabs2,
|
|
2190
|
+
leverage: imr ? 1 / imr : void 0
|
|
2175
2191
|
};
|
|
2176
2192
|
}
|
|
2177
2193
|
}
|
|
@@ -2346,7 +2362,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
2346
2362
|
return { data: trades, isLoading };
|
|
2347
2363
|
};
|
|
2348
2364
|
var useMarginRatio = () => {
|
|
2349
|
-
const [{ rows }] = usePositionStream();
|
|
2365
|
+
const [{ rows, aggregated }] = usePositionStream();
|
|
2350
2366
|
const { data: markPrices } = useMarkPricesStream();
|
|
2351
2367
|
const { totalCollateral } = useCollateral();
|
|
2352
2368
|
const marginRatio = React.useMemo(() => {
|
|
@@ -2363,7 +2379,20 @@ var useMarginRatio = () => {
|
|
|
2363
2379
|
const currentLeverage = React.useMemo(() => {
|
|
2364
2380
|
return perp.account.currentLeverage(marginRatio);
|
|
2365
2381
|
}, [marginRatio]);
|
|
2366
|
-
|
|
2382
|
+
const mmr = React.useMemo(() => {
|
|
2383
|
+
if (!rows)
|
|
2384
|
+
return 0;
|
|
2385
|
+
let positionsMM = utils.zero;
|
|
2386
|
+
for (let index = 0; index < rows.length; index++) {
|
|
2387
|
+
const item = rows[index];
|
|
2388
|
+
positionsMM = positionsMM.add(item.mm);
|
|
2389
|
+
}
|
|
2390
|
+
return perp.account.MMR({
|
|
2391
|
+
positionsMMR: positionsMM.toNumber(),
|
|
2392
|
+
positionsNotional: aggregated.notional
|
|
2393
|
+
});
|
|
2394
|
+
}, [rows, aggregated]);
|
|
2395
|
+
return { marginRatio, currentLeverage, mmr };
|
|
2367
2396
|
};
|
|
2368
2397
|
|
|
2369
2398
|
// src/woo/constants.ts
|
|
@@ -3782,7 +3811,7 @@ var useDeposit = (options) => {
|
|
|
3782
3811
|
dst.symbol
|
|
3783
3812
|
]);
|
|
3784
3813
|
const approve = React.useCallback(
|
|
3785
|
-
async (amount
|
|
3814
|
+
async (amount) => {
|
|
3786
3815
|
if (!options?.address) {
|
|
3787
3816
|
throw new Error("address is required");
|
|
3788
3817
|
}
|
|
@@ -3796,7 +3825,7 @@ var useDeposit = (options) => {
|
|
|
3796
3825
|
return result;
|
|
3797
3826
|
});
|
|
3798
3827
|
},
|
|
3799
|
-
[account5, getAllowance, options?.address
|
|
3828
|
+
[account5, getAllowance, options?.address]
|
|
3800
3829
|
);
|
|
3801
3830
|
const deposit = React.useCallback(async () => {
|
|
3802
3831
|
return account5.assetsManager.deposit(quantity, depositFee).then((res) => {
|