@orderly.network/hooks 0.0.32 → 0.0.34
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -177,7 +177,8 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
177
177
|
const { apiBaseUrl } = useContext(OrderlyContext);
|
|
178
178
|
return (key, fetcher4, config) => {
|
|
179
179
|
try {
|
|
180
|
-
const extendedFetcher = (
|
|
180
|
+
const extendedFetcher = (args) => __async(void 0, null, function* () {
|
|
181
|
+
let url = Array.isArray(args) ? args[0] : args;
|
|
181
182
|
let account5 = SimpleDI.get("account");
|
|
182
183
|
let fullUrl = `${apiBaseUrl}${url}`;
|
|
183
184
|
const signer = account5.signer;
|
|
@@ -271,7 +272,7 @@ var usePrivateQuery = (query, options) => {
|
|
|
271
272
|
const account5 = useAccount();
|
|
272
273
|
const middleware = Array.isArray(options == null ? void 0 : options.use) ? (_b = options == null ? void 0 : options.use) != null ? _b : [] : [];
|
|
273
274
|
return useSWR(
|
|
274
|
-
() => account5.state.status >= AccountStatusEnum.EnableTrading ? query : null,
|
|
275
|
+
() => account5.state.status >= AccountStatusEnum.EnableTrading ? [query, account5.state.accountId] : null,
|
|
275
276
|
// query,
|
|
276
277
|
(url, init) => {
|
|
277
278
|
return fetcher(url, init, { formatter });
|
|
@@ -678,6 +679,8 @@ var mergeItems = (data, update) => {
|
|
|
678
679
|
const [price, quantity] = item;
|
|
679
680
|
const index = data.findIndex(([p], index2) => p === price);
|
|
680
681
|
if (index === -1) {
|
|
682
|
+
if (quantity === 0)
|
|
683
|
+
continue;
|
|
681
684
|
data.push(item);
|
|
682
685
|
} else {
|
|
683
686
|
if (quantity === 0) {
|
|
@@ -1011,6 +1014,7 @@ var parseHolding = (holding, markPrices) => {
|
|
|
1011
1014
|
var usePositionStream = (symbol, options) => {
|
|
1012
1015
|
var _a;
|
|
1013
1016
|
const symbolInfo = useSymbolsInfo();
|
|
1017
|
+
useAccount();
|
|
1014
1018
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1015
1019
|
const { data: holding } = usePrivateQuery(
|
|
1016
1020
|
"/v1/client/holding",
|
|
@@ -1024,7 +1028,9 @@ var usePositionStream = (symbol, options) => {
|
|
|
1024
1028
|
const { data, error } = usePrivateQuery(`/v1/positions`, __spreadProps(__spreadValues({
|
|
1025
1029
|
// revalidateOnFocus: false,
|
|
1026
1030
|
// revalidateOnReconnect: false,
|
|
1027
|
-
dedupingInterval: 5e3
|
|
1031
|
+
dedupingInterval: 5e3,
|
|
1032
|
+
keepPreviousData: false,
|
|
1033
|
+
revalidateIfStale: true
|
|
1028
1034
|
}, options), {
|
|
1029
1035
|
formatter: (data2) => data2,
|
|
1030
1036
|
onError: (err) => {
|
|
@@ -1035,10 +1041,8 @@ var usePositionStream = (symbol, options) => {
|
|
|
1035
1041
|
const formatedPositions = useMemo(() => {
|
|
1036
1042
|
if (!(data == null ? void 0 : data.rows) || !symbolInfo || !accountInfo)
|
|
1037
1043
|
return null;
|
|
1038
|
-
const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows.filter((item) => {
|
|
1039
|
-
return item.
|
|
1040
|
-
}) : data.rows.filter((item) => {
|
|
1041
|
-
return item.symbol === symbol && item.position_qty !== 0;
|
|
1044
|
+
const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows : data.rows.filter((item) => {
|
|
1045
|
+
return item.symbol === symbol;
|
|
1042
1046
|
});
|
|
1043
1047
|
let unrealPnL_total = zero, notional_total = zero, unsettlementPnL_total = zero;
|
|
1044
1048
|
const formatted = filteredData.map((item) => {
|
|
@@ -1114,7 +1118,7 @@ var usePositionStream = (symbol, options) => {
|
|
|
1114
1118
|
if (!symbolInfo || !accountInfo)
|
|
1115
1119
|
return formatedPositions[0];
|
|
1116
1120
|
const total = totalCollateral.toNumber();
|
|
1117
|
-
return formatedPositions[0].map((item) => {
|
|
1121
|
+
return formatedPositions[0].filter((item) => item.position_qty !== 0).map((item) => {
|
|
1118
1122
|
const info = symbolInfo == null ? void 0 : symbolInfo[item.symbol];
|
|
1119
1123
|
const MMR = positions.MMR({
|
|
1120
1124
|
baseMMR: info("base_mmr"),
|