@orderly.network/hooks 1.1.4-alpha.3 → 1.1.4-alpha.5
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 +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +35 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -20,9 +20,9 @@ import { createClient } from '@layerzerolabs/scan-client';
|
|
|
20
20
|
// src/version.ts
|
|
21
21
|
if (typeof window !== "undefined") {
|
|
22
22
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
23
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.4-alpha.
|
|
23
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.4-alpha.5";
|
|
24
24
|
}
|
|
25
|
-
var version_default = "1.1.4-alpha.
|
|
25
|
+
var version_default = "1.1.4-alpha.5";
|
|
26
26
|
var fetcher = (url, init = {}, queryOptions) => get(url, init, queryOptions?.formatter);
|
|
27
27
|
var OrderlyContext = createContext({
|
|
28
28
|
// configStore: new MemoryConfigStore(),
|
|
@@ -438,6 +438,8 @@ var useWS = () => {
|
|
|
438
438
|
account5.on("change:status", (nextState) => {
|
|
439
439
|
if (nextState.status === AccountStatusEnum.EnableTrading && nextState.accountId) {
|
|
440
440
|
websocketClient.openPrivate(nextState.accountId);
|
|
441
|
+
} else {
|
|
442
|
+
websocketClient.closePrivate();
|
|
441
443
|
}
|
|
442
444
|
});
|
|
443
445
|
if (typeof window !== "undefined") {
|
|
@@ -962,20 +964,24 @@ var reduceOrderbook = (depth, level, data) => {
|
|
|
962
964
|
let bids = reduceItems(depth, level, data.bids);
|
|
963
965
|
if (asks.length !== 0 && bids.length !== 0 && asks[0][0] <= bids[0][0]) {
|
|
964
966
|
if (asks.length === 1) {
|
|
965
|
-
const [price, qty, newQuantity] = asks[0];
|
|
967
|
+
const [price, qty, newQuantity, newAmount] = asks[0];
|
|
966
968
|
asks.shift();
|
|
967
|
-
asks.push([price + (depth === void 0 ? 0 : depth), qty, newQuantity]);
|
|
969
|
+
asks.push([price + (depth === void 0 ? 0 : depth), qty, newQuantity, newAmount]);
|
|
968
970
|
} else {
|
|
969
971
|
const [bidPrice] = bids[0];
|
|
970
972
|
while (asks.length > 0) {
|
|
971
|
-
const [askPrice, askQty, newQuantity] = asks[0];
|
|
973
|
+
const [askPrice, askQty, newQuantity, newAmount] = asks[0];
|
|
972
974
|
if (askPrice <= bidPrice) {
|
|
973
975
|
asks.shift();
|
|
974
976
|
for (let index = 0; index < asks.length; index++) {
|
|
975
977
|
if (index === 0) {
|
|
976
|
-
asks[index][1]
|
|
978
|
+
const quantity = asks[index][1] + askQty;
|
|
979
|
+
asks[index][1] = quantity;
|
|
980
|
+
asks[index][2] = quantity;
|
|
981
|
+
asks[index][3] += newAmount;
|
|
982
|
+
} else {
|
|
983
|
+
asks[index][3] += newAmount;
|
|
977
984
|
}
|
|
978
|
-
asks[index][2] += newQuantity;
|
|
979
985
|
}
|
|
980
986
|
} else {
|
|
981
987
|
break;
|
|
@@ -2320,7 +2326,9 @@ var OrderFactory = class {
|
|
|
2320
2326
|
}
|
|
2321
2327
|
};
|
|
2322
2328
|
function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
2329
|
+
let isNewVersion = false;
|
|
2323
2330
|
if (typeof symbolOrOrder === "object") {
|
|
2331
|
+
isNewVersion = true;
|
|
2324
2332
|
if (!symbolOrOrder.symbol) {
|
|
2325
2333
|
throw new SDKError("symbol is required");
|
|
2326
2334
|
}
|
|
@@ -2461,7 +2469,8 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
2461
2469
|
needParse?.order_type_ext,
|
|
2462
2470
|
needParse?.symbol,
|
|
2463
2471
|
needParse?.reduce_only,
|
|
2464
|
-
needParse?.side
|
|
2472
|
+
needParse?.side,
|
|
2473
|
+
needParse?.visible_quantity
|
|
2465
2474
|
]);
|
|
2466
2475
|
const createOrder = (values) => {
|
|
2467
2476
|
if (!values.symbol) {
|
|
@@ -2599,8 +2608,17 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
2599
2608
|
markPrice
|
|
2600
2609
|
]);
|
|
2601
2610
|
useEffect(() => {
|
|
2602
|
-
if (
|
|
2603
|
-
|
|
2611
|
+
if (isNewVersion) {
|
|
2612
|
+
if (!optionsValue?.watchOrderbook) {
|
|
2613
|
+
throw new SDKError(
|
|
2614
|
+
"In order to calculate the estimated liquidation price, the `options.watchOrderbook` parameter must be set to true."
|
|
2615
|
+
);
|
|
2616
|
+
}
|
|
2617
|
+
} else {
|
|
2618
|
+
if (!optionsValue?.watchOrderbook) {
|
|
2619
|
+
return;
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2604
2622
|
ee.on("orderbook:update", onOrderbookUpdate);
|
|
2605
2623
|
return () => {
|
|
2606
2624
|
ee.off("orderbook_update", onOrderbookUpdate);
|
|
@@ -2612,8 +2630,14 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
2612
2630
|
const getPriceAndQty = (symbolOrOrder2) => {
|
|
2613
2631
|
let quantity = Number(symbolOrOrder2.order_quantity);
|
|
2614
2632
|
const orderPrice = Number(symbolOrOrder2.order_price);
|
|
2615
|
-
if (isNaN(quantity) || quantity <= 0
|
|
2633
|
+
if (isNaN(quantity) || quantity <= 0) {
|
|
2616
2634
|
return null;
|
|
2635
|
+
}
|
|
2636
|
+
if (!!options?.watchOrderbook && askAndBid.current.length === 0) {
|
|
2637
|
+
throw new SDKError(
|
|
2638
|
+
"Please check if you are using the `useOrderbookStream` hook or if the orderBook has data."
|
|
2639
|
+
);
|
|
2640
|
+
}
|
|
2617
2641
|
if ((symbolOrOrder2.order_type === OrderType.LIMIT || symbolOrOrder2.order_type === OrderType.STOP_LIMIT) && isNaN(orderPrice))
|
|
2618
2642
|
return null;
|
|
2619
2643
|
let price;
|