@orderly.network/hooks 0.0.28 → 0.0.30
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 +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +39 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -225,7 +225,7 @@ declare const useOrderStream: ({ status, symbol, side, size, }?: {
|
|
|
225
225
|
} | null)[];
|
|
226
226
|
|
|
227
227
|
interface MarketTradeStreamOptions {
|
|
228
|
-
|
|
228
|
+
limit?: number;
|
|
229
229
|
}
|
|
230
230
|
declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
|
|
231
231
|
data: API.Trade[];
|
|
@@ -249,7 +249,10 @@ declare const useCollateral: (options?: Options) => CollateralOutputs;
|
|
|
249
249
|
|
|
250
250
|
declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
|
|
251
251
|
|
|
252
|
-
declare const useMarginRatio: () =>
|
|
252
|
+
declare const useMarginRatio: () => {
|
|
253
|
+
marginRatio: number;
|
|
254
|
+
currentLeverage: number;
|
|
255
|
+
};
|
|
253
256
|
|
|
254
257
|
type inputOptions = {
|
|
255
258
|
filter?: (item: API.Chain) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -225,7 +225,7 @@ declare const useOrderStream: ({ status, symbol, side, size, }?: {
|
|
|
225
225
|
} | null)[];
|
|
226
226
|
|
|
227
227
|
interface MarketTradeStreamOptions {
|
|
228
|
-
|
|
228
|
+
limit?: number;
|
|
229
229
|
}
|
|
230
230
|
declare const useMarketTradeStream: (symbol: string, options?: MarketTradeStreamOptions) => {
|
|
231
231
|
data: API.Trade[];
|
|
@@ -249,7 +249,10 @@ declare const useCollateral: (options?: Options) => CollateralOutputs;
|
|
|
249
249
|
|
|
250
250
|
declare const useMaxQty: (symbol: string, side: OrderSide, reduceOnly?: boolean) => number;
|
|
251
251
|
|
|
252
|
-
declare const useMarginRatio: () =>
|
|
252
|
+
declare const useMarginRatio: () => {
|
|
253
|
+
marginRatio: number;
|
|
254
|
+
currentLeverage: number;
|
|
255
|
+
};
|
|
253
256
|
|
|
254
257
|
type inputOptions = {
|
|
255
258
|
filter?: (item: API.Chain) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -444,7 +444,6 @@ function useLocalStorage(key, initialValue) {
|
|
|
444
444
|
},
|
|
445
445
|
[storedValue]
|
|
446
446
|
);
|
|
447
|
-
console.log("storedValue", storedValue);
|
|
448
447
|
React2.useEffect(() => {
|
|
449
448
|
setStoredValue(readValue());
|
|
450
449
|
}, []);
|
|
@@ -681,6 +680,7 @@ var reduceOrderbook = (depth, level, data) => {
|
|
|
681
680
|
var mergeItems = (data, update) => {
|
|
682
681
|
if (data.length === 0)
|
|
683
682
|
return update;
|
|
683
|
+
data = data.filter(([price]) => !isNaN(price));
|
|
684
684
|
while (update.length > 0) {
|
|
685
685
|
const item = update.shift();
|
|
686
686
|
if (item) {
|
|
@@ -733,6 +733,7 @@ var useOrderbookStream = (symbol, initial = { asks: [], bids: [] }, options) =>
|
|
|
733
733
|
ws.onceSubscribe(
|
|
734
734
|
{
|
|
735
735
|
event: "request",
|
|
736
|
+
id: `${symbol}@orderbook`,
|
|
736
737
|
params: {
|
|
737
738
|
type: "orderbook",
|
|
738
739
|
symbol
|
|
@@ -888,10 +889,10 @@ function quantityInputHandle(inputs) {
|
|
|
888
889
|
price = Number(values.order_price);
|
|
889
890
|
}
|
|
890
891
|
const total = quantity.mul(price);
|
|
891
|
-
|
|
892
|
+
total.dp();
|
|
892
893
|
return [
|
|
893
894
|
__spreadProps(__spreadValues({}, values), {
|
|
894
|
-
total: total.todp(
|
|
895
|
+
total: total.todp(2).toNumber()
|
|
895
896
|
}),
|
|
896
897
|
input,
|
|
897
898
|
value,
|
|
@@ -1808,29 +1809,48 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
1808
1809
|
throw new Error("useTradeStream: symbol is required");
|
|
1809
1810
|
}
|
|
1810
1811
|
const [trades, setTrades] = React2.useState([]);
|
|
1811
|
-
const
|
|
1812
|
-
const {
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1812
|
+
const [isLoading, setIsLoading] = React2.useState(false);
|
|
1813
|
+
const { limit = 50 } = options;
|
|
1814
|
+
const ws = useWS();
|
|
1815
|
+
React2.useEffect(() => {
|
|
1816
|
+
setIsLoading(true);
|
|
1817
|
+
setTrades(() => []);
|
|
1818
|
+
ws.onceSubscribe(
|
|
1819
|
+
{
|
|
1820
|
+
id: `${symbol}@trade`,
|
|
1821
|
+
event: "request",
|
|
1822
|
+
params: {
|
|
1823
|
+
type: "trade",
|
|
1824
|
+
symbol,
|
|
1825
|
+
limit
|
|
1826
|
+
}
|
|
1827
|
+
},
|
|
1828
|
+
{
|
|
1829
|
+
onMessage: (data) => {
|
|
1830
|
+
setIsLoading(false);
|
|
1817
1831
|
setTrades(() => data);
|
|
1818
1832
|
}
|
|
1819
|
-
return data;
|
|
1820
1833
|
}
|
|
1821
|
-
|
|
1822
|
-
);
|
|
1823
|
-
const ws = useWS();
|
|
1834
|
+
);
|
|
1835
|
+
}, [symbol]);
|
|
1824
1836
|
React2.useEffect(() => {
|
|
1837
|
+
if (trades.length <= 0)
|
|
1838
|
+
return;
|
|
1825
1839
|
const unsubscript = ws.subscribe(`@${symbol}/@trade`, {
|
|
1826
1840
|
onMessage: (data) => {
|
|
1827
|
-
|
|
1841
|
+
setTrades((prev) => {
|
|
1842
|
+
const arr = [data, ...prev];
|
|
1843
|
+
if (arr.length > limit) {
|
|
1844
|
+
arr.pop();
|
|
1845
|
+
}
|
|
1846
|
+
return arr;
|
|
1847
|
+
});
|
|
1828
1848
|
}
|
|
1829
1849
|
});
|
|
1830
1850
|
return () => {
|
|
1831
1851
|
unsubscript == null ? void 0 : unsubscript();
|
|
1832
1852
|
};
|
|
1833
|
-
}, []);
|
|
1853
|
+
}, [symbol, trades]);
|
|
1834
1854
|
return { data: trades, isLoading };
|
|
1835
1855
|
};
|
|
1836
1856
|
var useMarginRatio = () => {
|
|
@@ -1838,6 +1858,9 @@ var useMarginRatio = () => {
|
|
|
1838
1858
|
const { data: markPrices } = useMarkPricesStream();
|
|
1839
1859
|
const { totalCollateral } = useCollateral();
|
|
1840
1860
|
const marginRatio = React2.useMemo(() => {
|
|
1861
|
+
if (!rows || !markPrices || !totalCollateral) {
|
|
1862
|
+
return 0;
|
|
1863
|
+
}
|
|
1841
1864
|
const ratio = futures.account.totalMarginRatio({
|
|
1842
1865
|
totalCollateral,
|
|
1843
1866
|
markPrices,
|
|
@@ -1848,7 +1871,7 @@ var useMarginRatio = () => {
|
|
|
1848
1871
|
const currentLeverage = React2.useMemo(() => {
|
|
1849
1872
|
return futures.account.currentLeverage(marginRatio);
|
|
1850
1873
|
}, [marginRatio]);
|
|
1851
|
-
return
|
|
1874
|
+
return { marginRatio, currentLeverage };
|
|
1852
1875
|
};
|
|
1853
1876
|
var useChains = (networkId, options = {}) => {
|
|
1854
1877
|
const _a = options, swrOptions = __objRest(_a, ["filter", "pick"]);
|