@orderly.network/hooks 1.0.5 → 1.0.7
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.js +68 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1100,8 +1100,8 @@ var usePositionStream = (symbol, options) => {
|
|
|
1100
1100
|
const fundingRates = useFundingRates();
|
|
1101
1101
|
const {
|
|
1102
1102
|
data,
|
|
1103
|
-
error
|
|
1104
|
-
|
|
1103
|
+
error,
|
|
1104
|
+
mutate: updatePositions
|
|
1105
1105
|
} = usePrivateQuery(`/v1/positions`, {
|
|
1106
1106
|
// revalidateOnFocus: false,
|
|
1107
1107
|
// revalidateOnReconnect: false,
|
|
@@ -1113,6 +1113,10 @@ var usePositionStream = (symbol, options) => {
|
|
|
1113
1113
|
onError: (err) => {
|
|
1114
1114
|
}
|
|
1115
1115
|
});
|
|
1116
|
+
usePositionUpdateStream((positions2) => {
|
|
1117
|
+
console.log("position message", positions2);
|
|
1118
|
+
updatePositions();
|
|
1119
|
+
});
|
|
1116
1120
|
const { data: markPrices } = useMarkPricesStream();
|
|
1117
1121
|
const formatedPositions = React.useMemo(() => {
|
|
1118
1122
|
if (!data?.rows || !symbolInfo || !accountInfo)
|
|
@@ -1261,6 +1265,41 @@ var pathOr_unsettledPnLPathOr = ramda.pathOr(0, [
|
|
|
1261
1265
|
"aggregated",
|
|
1262
1266
|
"unsettledPnL"
|
|
1263
1267
|
]);
|
|
1268
|
+
var usePositionUpdateStream = (callback) => {
|
|
1269
|
+
const ws = useWS();
|
|
1270
|
+
const positionList = React.useRef({});
|
|
1271
|
+
return useSWRSubscription__default.default("positionUpdate", (key, { next }) => {
|
|
1272
|
+
const unsubscribe = ws.privateSubscribe(
|
|
1273
|
+
// { event: "subscribe", topic: "markprices" },
|
|
1274
|
+
"position",
|
|
1275
|
+
{
|
|
1276
|
+
onMessage: (message) => {
|
|
1277
|
+
const { positions: positions2 } = message;
|
|
1278
|
+
let update = false;
|
|
1279
|
+
for (const p in positions2) {
|
|
1280
|
+
const { symbol, positionQty } = positions2[p];
|
|
1281
|
+
if (positionList.current[symbol] !== positionQty) {
|
|
1282
|
+
update = true;
|
|
1283
|
+
positionList.current[symbol] = positionQty;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
if (update) {
|
|
1287
|
+
callback(positions2.current);
|
|
1288
|
+
}
|
|
1289
|
+
next(null, positionList);
|
|
1290
|
+
},
|
|
1291
|
+
// onUnsubscribe: () => {
|
|
1292
|
+
// return "markprices";
|
|
1293
|
+
// },
|
|
1294
|
+
onError: (error) => {
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
);
|
|
1298
|
+
return () => {
|
|
1299
|
+
unsubscribe?.();
|
|
1300
|
+
};
|
|
1301
|
+
});
|
|
1302
|
+
};
|
|
1264
1303
|
var useHoldingStream = () => {
|
|
1265
1304
|
const ws = useWS();
|
|
1266
1305
|
const { data, isLoading, mutate: mutate2 } = usePrivateQuery(
|
|
@@ -1537,11 +1576,37 @@ var useCollateral = (options = { dp: 6 }) => {
|
|
|
1537
1576
|
var positionsPath2 = ramda.pathOr([], [0, "rows"]);
|
|
1538
1577
|
var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
1539
1578
|
const positionsData = usePositionStream();
|
|
1540
|
-
const [orders] = useOrderStream({ status: types.OrderStatus.NEW });
|
|
1541
1579
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1542
1580
|
const symbolInfo = useSymbolsInfo();
|
|
1543
1581
|
const { totalCollateral } = useCollateral();
|
|
1544
1582
|
const { data: markPrices } = useMarkPricesStream();
|
|
1583
|
+
const {
|
|
1584
|
+
data: orders,
|
|
1585
|
+
error,
|
|
1586
|
+
mutate: updateOrder
|
|
1587
|
+
} = usePrivateQuery(`/v1/orders?status=NEW&size=99`, {
|
|
1588
|
+
formatter: (data) => data.rows,
|
|
1589
|
+
onError: (err) => {
|
|
1590
|
+
}
|
|
1591
|
+
});
|
|
1592
|
+
const ws = useWS();
|
|
1593
|
+
React.useEffect(() => {
|
|
1594
|
+
const unsubscribe = ws.privateSubscribe(
|
|
1595
|
+
{
|
|
1596
|
+
id: "executionreport_orders",
|
|
1597
|
+
event: "subscribe",
|
|
1598
|
+
topic: "executionreport",
|
|
1599
|
+
ts: Date.now()
|
|
1600
|
+
},
|
|
1601
|
+
{
|
|
1602
|
+
onMessage: (data) => {
|
|
1603
|
+
console.log("refresh orders", data);
|
|
1604
|
+
updateOrder();
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
);
|
|
1608
|
+
return () => unsubscribe();
|
|
1609
|
+
}, []);
|
|
1545
1610
|
const maxQty = React.useMemo(() => {
|
|
1546
1611
|
if (!symbol)
|
|
1547
1612
|
return 0;
|