@orderly.network/hooks 1.1.8 → 1.1.9
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/esm/orderly/useFundingRates.d.ts +6 -1
- package/esm/orderly/useFundingRates.d.ts.map +1 -1
- package/esm/orderly/useFundingRates.js +0 -1
- package/esm/orderly/useOrderEntry.js +7 -6
- package/esm/orderly/usePositionStream.d.ts +14 -1
- package/esm/orderly/usePositionStream.d.ts.map +1 -1
- package/esm/orderly/usePositionStream.js +4 -3
- package/esm/orderly/useSymbolsInfo.d.ts +6 -1
- package/esm/orderly/useSymbolsInfo.d.ts.map +1 -1
- package/esm/orderly/useSymbolsInfo.js +1 -1
- package/esm/unuse/useTokenInfo.d.ts +6 -1
- package/esm/unuse/useTokenInfo.d.ts.map +1 -1
- package/esm/utils/createGetter.d.ts +8 -1
- package/esm/utils/createGetter.d.ts.map +1 -1
- package/esm/utils/createGetter.js +5 -0
- package/esm/utils/swr.js +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.js +2 -2
- package/lib/orderly/useFundingRates.d.ts +6 -1
- package/lib/orderly/useFundingRates.d.ts.map +1 -1
- package/lib/orderly/useFundingRates.js +0 -1
- package/lib/orderly/useOrderEntry.js +7 -6
- package/lib/orderly/usePositionStream.d.ts +14 -1
- package/lib/orderly/usePositionStream.d.ts.map +1 -1
- package/lib/orderly/usePositionStream.js +4 -3
- package/lib/orderly/useSymbolsInfo.d.ts +6 -1
- package/lib/orderly/useSymbolsInfo.d.ts.map +1 -1
- package/lib/orderly/useSymbolsInfo.js +1 -1
- package/lib/unuse/useTokenInfo.d.ts +6 -1
- package/lib/unuse/useTokenInfo.d.ts.map +1 -1
- package/lib/utils/createGetter.d.ts +8 -1
- package/lib/utils/createGetter.d.ts.map +1 -1
- package/lib/utils/createGetter.js +5 -0
- package/lib/utils/swr.js +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +2 -2
- package/package.json +8 -8
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type API } from "@orderly.network/types";
|
|
2
|
+
export declare const useFundingRates: () => {
|
|
3
|
+
[x: string]: (key?: keyof API.FundingRate | undefined, defaultValue?: (string | number) | undefined) => any;
|
|
4
|
+
} & {
|
|
5
|
+
isNil: boolean;
|
|
6
|
+
};
|
|
2
7
|
//# sourceMappingURL=useFundingRates.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFundingRates.d.ts","sourceRoot":"","sources":["../../src/orderly/useFundingRates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFundingRates.d.ts","sourceRoot":"","sources":["../../src/orderly/useFundingRates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAGlD,eAAO,MAAM,eAAe;;;;CAuB3B,CAAC"}
|
|
@@ -76,8 +76,8 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
76
76
|
const quoteDP = useMemo(() => {
|
|
77
77
|
return getPrecisionByNumber(symbolInfo[symbol]("quote_tick", 0));
|
|
78
78
|
}, [symbolInfo]);
|
|
79
|
-
const baseIMR = useMemo(() => symbolInfo[symbol]("base_imr"), [symbolInfo]);
|
|
80
|
-
const baseMMR = useMemo(() => symbolInfo[symbol]("base_mmr"), [symbolInfo]);
|
|
79
|
+
const baseIMR = useMemo(() => symbolInfo[symbol]("base_imr", 0), [symbolInfo]);
|
|
80
|
+
const baseMMR = useMemo(() => symbolInfo[symbol]("base_mmr", 0), [symbolInfo]);
|
|
81
81
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
82
82
|
// const markPrice = 1;
|
|
83
83
|
const diffOrderEntry = (prev, current) => {
|
|
@@ -233,7 +233,6 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
233
233
|
// ...omit(["order_price"], values),
|
|
234
234
|
...data,
|
|
235
235
|
})).then((res) => {
|
|
236
|
-
console.log("--------------------res::::", res);
|
|
237
236
|
// resolve(res);
|
|
238
237
|
if (res.success) {
|
|
239
238
|
// TODO: remove when the WS service is fixed
|
|
@@ -328,12 +327,14 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
328
327
|
}, [parsedData, markPrice]);
|
|
329
328
|
/// validator order info
|
|
330
329
|
useEffect(() => {
|
|
331
|
-
if (!markPrice)
|
|
330
|
+
if (!markPrice || symbolInfo.isNil)
|
|
332
331
|
return;
|
|
333
332
|
// validate order data;
|
|
334
|
-
validator(formattedOrder)
|
|
333
|
+
validator(formattedOrder)
|
|
334
|
+
?.then((err) => {
|
|
335
335
|
setErrors(err);
|
|
336
|
-
})
|
|
336
|
+
})
|
|
337
|
+
.catch((err) => { });
|
|
337
338
|
}, [
|
|
338
339
|
formattedOrder.broker_id,
|
|
339
340
|
formattedOrder.order_quantity,
|
|
@@ -15,7 +15,20 @@ export declare const usePositionStream: (symbol?: string, options?: SWRConfigura
|
|
|
15
15
|
readonly totalCollateral: Decimal;
|
|
16
16
|
readonly totalValue: Decimal;
|
|
17
17
|
readonly totalUnrealizedROI: number;
|
|
18
|
-
},
|
|
18
|
+
}, {
|
|
19
|
+
margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
20
|
+
initial_margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
21
|
+
maintenance_margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
22
|
+
open_margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
23
|
+
current_margin_ratio_with_orders: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
24
|
+
initial_margin_ratio_with_orders: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
25
|
+
maintenance_margin_ratio_with_orders: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
26
|
+
total_collateral_value: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
27
|
+
free_collateral: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
28
|
+
total_pnl_24_h: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
29
|
+
} & {
|
|
30
|
+
isNil: boolean;
|
|
31
|
+
}, {
|
|
19
32
|
readonly loading: false;
|
|
20
33
|
readonly error: any;
|
|
21
34
|
readonly refresh: import("swr/_internal").KeyedMutator<API.PositionInfo>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePositionStream.d.ts","sourceRoot":"","sources":["../../src/orderly/usePositionStream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAI5C,OAAO,EAAE,KAAK,GAAG,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAK/D,OAAO,EAAE,OAAO,EAAQ,MAAM,wBAAwB,CAAC;AAIvD,KAAK,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CACL,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC,KAC5D,IAAI,CAAC;CACX;AAED,eAAO,MAAM,iBAAiB,YAInB,MAAM,YACL,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE
|
|
1
|
+
{"version":3,"file":"usePositionStream.d.ts","sourceRoot":"","sources":["../../src/orderly/usePositionStream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAI5C,OAAO,EAAE,KAAK,GAAG,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAK/D,OAAO,EAAE,OAAO,EAAQ,MAAM,wBAAwB,CAAC;AAIvD,KAAK,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CACL,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC,KAC5D,IAAI,CAAC;CACX;AAED,eAAO,MAAM,iBAAiB,YAInB,MAAM,YACL,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;EAsRtD,CAAC;AAEF,eAAO,MAAM,yBAAyB,sBAIpC,CAAC"}
|
|
@@ -51,7 +51,7 @@ symbol, options) => {
|
|
|
51
51
|
return data;
|
|
52
52
|
}, [tickers]);
|
|
53
53
|
const formatedPositions = useMemo(() => {
|
|
54
|
-
if (!data?.rows ||
|
|
54
|
+
if (!data?.rows || symbolInfo.isNil || !accountInfo)
|
|
55
55
|
return null;
|
|
56
56
|
const filteredData = typeof symbol === "undefined" || symbol === ""
|
|
57
57
|
? data.rows
|
|
@@ -63,7 +63,7 @@ symbol, options) => {
|
|
|
63
63
|
// const price = (markPrices as any)[item.symbol] ?? item.mark_price;
|
|
64
64
|
const unRealizedPrice = propOr(item.mark_price, item.symbol, priceMode === "markPrice" ? markPrices : tickerPrices);
|
|
65
65
|
const price = propOr(item.mark_price, item.symbol, markPrices);
|
|
66
|
-
const info = symbolInfo
|
|
66
|
+
const info = symbolInfo[item.symbol];
|
|
67
67
|
//
|
|
68
68
|
const notional = positions.notional(item.position_qty, price);
|
|
69
69
|
const unrealPnl = positions.unrealizedPnL({
|
|
@@ -203,6 +203,7 @@ symbol, options) => {
|
|
|
203
203
|
// updatePositions();
|
|
204
204
|
// });
|
|
205
205
|
// }, []);
|
|
206
|
+
const positionInfoGetter = createGetter(data, 1);
|
|
206
207
|
return [
|
|
207
208
|
{
|
|
208
209
|
rows: positionsRows,
|
|
@@ -214,7 +215,7 @@ symbol, options) => {
|
|
|
214
215
|
totalValue,
|
|
215
216
|
totalUnrealizedROI,
|
|
216
217
|
},
|
|
217
|
-
|
|
218
|
+
positionInfoGetter,
|
|
218
219
|
{
|
|
219
220
|
// close: onClosePosition,
|
|
220
221
|
loading: false,
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type API } from "@orderly.network/types";
|
|
2
|
+
export declare const useSymbolsInfo: () => {
|
|
3
|
+
[x: string]: (key?: keyof API.SymbolExt | undefined, defaultValue?: (string | number) | undefined) => any;
|
|
4
|
+
} & {
|
|
5
|
+
isNil: boolean;
|
|
6
|
+
};
|
|
2
7
|
//# sourceMappingURL=useSymbolsInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSymbolsInfo.d.ts","sourceRoot":"","sources":["../../src/orderly/useSymbolsInfo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSymbolsInfo.d.ts","sourceRoot":"","sources":["../../src/orderly/useSymbolsInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAIlD,eAAO,MAAM,cAAc;;;;CAgC1B,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { useQuery } from "../useQuery";
|
|
|
2
2
|
import { createGetter } from "../utils/createGetter";
|
|
3
3
|
import { getPrecisionByNumber } from "@orderly.network/utils";
|
|
4
4
|
export const useSymbolsInfo = () => {
|
|
5
|
-
const { data
|
|
5
|
+
const { data } = useQuery(`/v1/public/info`, {
|
|
6
6
|
focusThrottleInterval: 1000 * 60 * 60 * 24,
|
|
7
7
|
dedupingInterval: 1000 * 60 * 60 * 24,
|
|
8
8
|
revalidateOnFocus: false,
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type API } from "@orderly.network/types";
|
|
2
|
+
export declare const useTokenInfo: () => {
|
|
3
|
+
[x: string]: (key?: keyof API.TokenInfo | undefined, defaultValue?: (string | number) | undefined) => any;
|
|
4
|
+
} & {
|
|
5
|
+
isNil: boolean;
|
|
6
|
+
};
|
|
2
7
|
//# sourceMappingURL=useTokenInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTokenInfo.d.ts","sourceRoot":"","sources":["../../src/unuse/useTokenInfo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTokenInfo.d.ts","sourceRoot":"","sources":["../../src/unuse/useTokenInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAGlD,eAAO,MAAM,YAAY;;;;CAwBxB,CAAC"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
type objectDepth = 1 | 2;
|
|
2
|
-
|
|
2
|
+
type ValueOf<T> = T[keyof T];
|
|
3
|
+
export declare function createGetter<T extends any, K extends string = string, Key = keyof T>(data: Record<string, T> | null | undefined, depth?: objectDepth): (typeof depth extends 1 ? {
|
|
4
|
+
[P in K]: (defaultValue?: any) => any;
|
|
5
|
+
} : {
|
|
6
|
+
[P in K]: (key?: Key, defaultValue?: ValueOf<T>) => any;
|
|
7
|
+
}) & {
|
|
8
|
+
isNil: boolean;
|
|
9
|
+
};
|
|
3
10
|
export {};
|
|
4
11
|
//# sourceMappingURL=createGetter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGetter.d.ts","sourceRoot":"","sources":["../../src/utils/createGetter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createGetter.d.ts","sourceRoot":"","sources":["../../src/utils/createGetter.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG,CAAC,GAAG,CAAC,CAAC;AASzB,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAG7B,wBAAgB,YAAY,CAC1B,CAAC,SAAS,GAAG,EACb,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,GAAG,GAAG,MAAM,CAAC,EAEb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC1C,KAAK,GAAE,WAAe,GACrB,CAAC,OAAO,KAAK,SAAS,CAAC,GACtB;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,GAAG;CAAE,GACzC;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;CAAE,CAAC,GAAG;IACjE,KAAK,EAAE,OAAO,CAAC;CAChB,CAyBA"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { isNil } from "ramda";
|
|
2
|
+
// export function createGetter<T extends Record<string, any>, K extends keyof T>(
|
|
1
3
|
export function createGetter(data, depth = 2) {
|
|
2
4
|
return new Proxy(data || {}, {
|
|
3
5
|
get(target, property, receiver) {
|
|
6
|
+
if (property === "isNil") {
|
|
7
|
+
return isNil(data);
|
|
8
|
+
}
|
|
4
9
|
if (depth === 1) {
|
|
5
10
|
return (defaultValue) => {
|
|
6
11
|
if (!target)
|
package/esm/utils/swr.js
CHANGED
|
@@ -31,7 +31,7 @@ export const updateOrdersHandler = (key, updatedOrder, orders) => {
|
|
|
31
31
|
let formattedOrder = {
|
|
32
32
|
...underscoreOrder,
|
|
33
33
|
updated_time: updatedOrder.timestamp,
|
|
34
|
-
type: updatedOrder.type.replace("_ORDER", ""),
|
|
34
|
+
type: typeof underscoreOrder.type === 'string' ? updatedOrder.type.replace("_ORDER", "") : updatedOrder.type,
|
|
35
35
|
//@ts-ignore
|
|
36
36
|
// visible_quantity: updatedOrder.visibleQuantity || updatedOrder.visible,
|
|
37
37
|
};
|
package/esm/version.d.ts
CHANGED
package/esm/version.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
if (typeof window !== 'undefined') {
|
|
2
2
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
3
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.
|
|
3
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.9";
|
|
4
4
|
}
|
|
5
5
|
;
|
|
6
|
-
export default "1.1.
|
|
6
|
+
export default "1.1.9";
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type API } from "@orderly.network/types";
|
|
2
|
+
export declare const useFundingRates: () => {
|
|
3
|
+
[x: string]: (key?: keyof API.FundingRate | undefined, defaultValue?: (string | number) | undefined) => any;
|
|
4
|
+
} & {
|
|
5
|
+
isNil: boolean;
|
|
6
|
+
};
|
|
2
7
|
//# sourceMappingURL=useFundingRates.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFundingRates.d.ts","sourceRoot":"","sources":["../../src/orderly/useFundingRates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFundingRates.d.ts","sourceRoot":"","sources":["../../src/orderly/useFundingRates.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAGlD,eAAO,MAAM,eAAe;;;;CAuB3B,CAAC"}
|
|
@@ -79,8 +79,8 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
79
79
|
const quoteDP = (0, react_1.useMemo)(() => {
|
|
80
80
|
return (0, utils_1.getPrecisionByNumber)(symbolInfo[symbol]("quote_tick", 0));
|
|
81
81
|
}, [symbolInfo]);
|
|
82
|
-
const baseIMR = (0, react_1.useMemo)(() => symbolInfo[symbol]("base_imr"), [symbolInfo]);
|
|
83
|
-
const baseMMR = (0, react_1.useMemo)(() => symbolInfo[symbol]("base_mmr"), [symbolInfo]);
|
|
82
|
+
const baseIMR = (0, react_1.useMemo)(() => symbolInfo[symbol]("base_imr", 0), [symbolInfo]);
|
|
83
|
+
const baseMMR = (0, react_1.useMemo)(() => symbolInfo[symbol]("base_mmr", 0), [symbolInfo]);
|
|
84
84
|
const { data: markPrice } = (0, useMarkPrice_1.useMarkPrice)(symbol);
|
|
85
85
|
// const markPrice = 1;
|
|
86
86
|
const diffOrderEntry = (prev, current) => {
|
|
@@ -236,7 +236,6 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
236
236
|
// ...omit(["order_price"], values),
|
|
237
237
|
...data,
|
|
238
238
|
})).then((res) => {
|
|
239
|
-
console.log("--------------------res::::", res);
|
|
240
239
|
// resolve(res);
|
|
241
240
|
if (res.success) {
|
|
242
241
|
// TODO: remove when the WS service is fixed
|
|
@@ -331,12 +330,14 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
331
330
|
}, [parsedData, markPrice]);
|
|
332
331
|
/// validator order info
|
|
333
332
|
(0, react_1.useEffect)(() => {
|
|
334
|
-
if (!markPrice)
|
|
333
|
+
if (!markPrice || symbolInfo.isNil)
|
|
335
334
|
return;
|
|
336
335
|
// validate order data;
|
|
337
|
-
validator(formattedOrder)
|
|
336
|
+
validator(formattedOrder)
|
|
337
|
+
?.then((err) => {
|
|
338
338
|
setErrors(err);
|
|
339
|
-
})
|
|
339
|
+
})
|
|
340
|
+
.catch((err) => { });
|
|
340
341
|
}, [
|
|
341
342
|
formattedOrder.broker_id,
|
|
342
343
|
formattedOrder.order_quantity,
|
|
@@ -15,7 +15,20 @@ export declare const usePositionStream: (symbol?: string, options?: SWRConfigura
|
|
|
15
15
|
readonly totalCollateral: Decimal;
|
|
16
16
|
readonly totalValue: Decimal;
|
|
17
17
|
readonly totalUnrealizedROI: number;
|
|
18
|
-
},
|
|
18
|
+
}, {
|
|
19
|
+
margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
20
|
+
initial_margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
21
|
+
maintenance_margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
22
|
+
open_margin_ratio: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
23
|
+
current_margin_ratio_with_orders: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
24
|
+
initial_margin_ratio_with_orders: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
25
|
+
maintenance_margin_ratio_with_orders: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
26
|
+
total_collateral_value: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
27
|
+
free_collateral: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
28
|
+
total_pnl_24_h: (key?: "margin_ratio" | "initial_margin_ratio" | "maintenance_margin_ratio" | "open_margin_ratio" | "current_margin_ratio_with_orders" | "initial_margin_ratio_with_orders" | "maintenance_margin_ratio_with_orders" | "total_collateral_value" | "free_collateral" | "total_pnl_24_h" | undefined, defaultValue?: number | undefined) => any;
|
|
29
|
+
} & {
|
|
30
|
+
isNil: boolean;
|
|
31
|
+
}, {
|
|
19
32
|
readonly loading: false;
|
|
20
33
|
readonly error: any;
|
|
21
34
|
readonly refresh: import("swr/_internal").KeyedMutator<API.PositionInfo>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePositionStream.d.ts","sourceRoot":"","sources":["../../src/orderly/usePositionStream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAI5C,OAAO,EAAE,KAAK,GAAG,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAK/D,OAAO,EAAE,OAAO,EAAQ,MAAM,wBAAwB,CAAC;AAIvD,KAAK,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CACL,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC,KAC5D,IAAI,CAAC;CACX;AAED,eAAO,MAAM,iBAAiB,YAInB,MAAM,YACL,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE
|
|
1
|
+
{"version":3,"file":"usePositionStream.d.ts","sourceRoot":"","sources":["../../src/orderly/usePositionStream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,KAAK,CAAC;AAI5C,OAAO,EAAE,KAAK,GAAG,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAK/D,OAAO,EAAE,OAAO,EAAQ,MAAM,wBAAwB,CAAC;AAIvD,KAAK,SAAS,GAAG,WAAW,GAAG,WAAW,CAAC;AAE3C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,CACL,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,CAAC,KAC5D,IAAI,CAAC;CACX;AAED,eAAO,MAAM,iBAAiB,YAInB,MAAM,YACL,gBAAgB,GAAG;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;EAsRtD,CAAC;AAEF,eAAO,MAAM,yBAAyB,sBAIpC,CAAC"}
|
|
@@ -54,7 +54,7 @@ symbol, options) => {
|
|
|
54
54
|
return data;
|
|
55
55
|
}, [tickers]);
|
|
56
56
|
const formatedPositions = (0, react_1.useMemo)(() => {
|
|
57
|
-
if (!data?.rows ||
|
|
57
|
+
if (!data?.rows || symbolInfo.isNil || !accountInfo)
|
|
58
58
|
return null;
|
|
59
59
|
const filteredData = typeof symbol === "undefined" || symbol === ""
|
|
60
60
|
? data.rows
|
|
@@ -66,7 +66,7 @@ symbol, options) => {
|
|
|
66
66
|
// const price = (markPrices as any)[item.symbol] ?? item.mark_price;
|
|
67
67
|
const unRealizedPrice = (0, ramda_1.propOr)(item.mark_price, item.symbol, priceMode === "markPrice" ? markPrices : tickerPrices);
|
|
68
68
|
const price = (0, ramda_1.propOr)(item.mark_price, item.symbol, markPrices);
|
|
69
|
-
const info = symbolInfo
|
|
69
|
+
const info = symbolInfo[item.symbol];
|
|
70
70
|
//
|
|
71
71
|
const notional = perp_1.positions.notional(item.position_qty, price);
|
|
72
72
|
const unrealPnl = perp_1.positions.unrealizedPnL({
|
|
@@ -206,6 +206,7 @@ symbol, options) => {
|
|
|
206
206
|
// updatePositions();
|
|
207
207
|
// });
|
|
208
208
|
// }, []);
|
|
209
|
+
const positionInfoGetter = (0, createGetter_1.createGetter)(data, 1);
|
|
209
210
|
return [
|
|
210
211
|
{
|
|
211
212
|
rows: positionsRows,
|
|
@@ -217,7 +218,7 @@ symbol, options) => {
|
|
|
217
218
|
totalValue,
|
|
218
219
|
totalUnrealizedROI,
|
|
219
220
|
},
|
|
220
|
-
|
|
221
|
+
positionInfoGetter,
|
|
221
222
|
{
|
|
222
223
|
// close: onClosePosition,
|
|
223
224
|
loading: false,
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type API } from "@orderly.network/types";
|
|
2
|
+
export declare const useSymbolsInfo: () => {
|
|
3
|
+
[x: string]: (key?: keyof API.SymbolExt | undefined, defaultValue?: (string | number) | undefined) => any;
|
|
4
|
+
} & {
|
|
5
|
+
isNil: boolean;
|
|
6
|
+
};
|
|
2
7
|
//# sourceMappingURL=useSymbolsInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSymbolsInfo.d.ts","sourceRoot":"","sources":["../../src/orderly/useSymbolsInfo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSymbolsInfo.d.ts","sourceRoot":"","sources":["../../src/orderly/useSymbolsInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAIlD,eAAO,MAAM,cAAc;;;;CAgC1B,CAAC"}
|
|
@@ -5,7 +5,7 @@ const useQuery_1 = require("../useQuery");
|
|
|
5
5
|
const createGetter_1 = require("../utils/createGetter");
|
|
6
6
|
const utils_1 = require("@orderly.network/utils");
|
|
7
7
|
const useSymbolsInfo = () => {
|
|
8
|
-
const { data
|
|
8
|
+
const { data } = (0, useQuery_1.useQuery)(`/v1/public/info`, {
|
|
9
9
|
focusThrottleInterval: 1000 * 60 * 60 * 24,
|
|
10
10
|
dedupingInterval: 1000 * 60 * 60 * 24,
|
|
11
11
|
revalidateOnFocus: false,
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { type API } from "@orderly.network/types";
|
|
2
|
+
export declare const useTokenInfo: () => {
|
|
3
|
+
[x: string]: (key?: keyof API.TokenInfo | undefined, defaultValue?: (string | number) | undefined) => any;
|
|
4
|
+
} & {
|
|
5
|
+
isNil: boolean;
|
|
6
|
+
};
|
|
2
7
|
//# sourceMappingURL=useTokenInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTokenInfo.d.ts","sourceRoot":"","sources":["../../src/unuse/useTokenInfo.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTokenInfo.d.ts","sourceRoot":"","sources":["../../src/unuse/useTokenInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAGlD,eAAO,MAAM,YAAY;;;;CAwBxB,CAAC"}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
type objectDepth = 1 | 2;
|
|
2
|
-
|
|
2
|
+
type ValueOf<T> = T[keyof T];
|
|
3
|
+
export declare function createGetter<T extends any, K extends string = string, Key = keyof T>(data: Record<string, T> | null | undefined, depth?: objectDepth): (typeof depth extends 1 ? {
|
|
4
|
+
[P in K]: (defaultValue?: any) => any;
|
|
5
|
+
} : {
|
|
6
|
+
[P in K]: (key?: Key, defaultValue?: ValueOf<T>) => any;
|
|
7
|
+
}) & {
|
|
8
|
+
isNil: boolean;
|
|
9
|
+
};
|
|
3
10
|
export {};
|
|
4
11
|
//# sourceMappingURL=createGetter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createGetter.d.ts","sourceRoot":"","sources":["../../src/utils/createGetter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createGetter.d.ts","sourceRoot":"","sources":["../../src/utils/createGetter.ts"],"names":[],"mappings":"AAGA,KAAK,WAAW,GAAG,CAAC,GAAG,CAAC,CAAC;AASzB,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAG7B,wBAAgB,YAAY,CAC1B,CAAC,SAAS,GAAG,EACb,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,GAAG,GAAG,MAAM,CAAC,EAEb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EAC1C,KAAK,GAAE,WAAe,GACrB,CAAC,OAAO,KAAK,SAAS,CAAC,GACtB;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,GAAG,KAAK,GAAG;CAAE,GACzC;KAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,YAAY,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;CAAE,CAAC,GAAG;IACjE,KAAK,EAAE,OAAO,CAAC;CAChB,CAyBA"}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createGetter = void 0;
|
|
4
|
+
const ramda_1 = require("ramda");
|
|
5
|
+
// export function createGetter<T extends Record<string, any>, K extends keyof T>(
|
|
4
6
|
function createGetter(data, depth = 2) {
|
|
5
7
|
return new Proxy(data || {}, {
|
|
6
8
|
get(target, property, receiver) {
|
|
9
|
+
if (property === "isNil") {
|
|
10
|
+
return (0, ramda_1.isNil)(data);
|
|
11
|
+
}
|
|
7
12
|
if (depth === 1) {
|
|
8
13
|
return (defaultValue) => {
|
|
9
14
|
if (!target)
|
package/lib/utils/swr.js
CHANGED
|
@@ -35,7 +35,7 @@ const updateOrdersHandler = (key, updatedOrder, orders) => {
|
|
|
35
35
|
let formattedOrder = {
|
|
36
36
|
...underscoreOrder,
|
|
37
37
|
updated_time: updatedOrder.timestamp,
|
|
38
|
-
type: updatedOrder.type.replace("_ORDER", ""),
|
|
38
|
+
type: typeof underscoreOrder.type === 'string' ? updatedOrder.type.replace("_ORDER", "") : updatedOrder.type,
|
|
39
39
|
//@ts-ignore
|
|
40
40
|
// visible_quantity: updatedOrder.visibleQuantity || updatedOrder.visible,
|
|
41
41
|
};
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
if (typeof window !== 'undefined') {
|
|
4
4
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
5
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.
|
|
5
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "1.1.9";
|
|
6
6
|
}
|
|
7
7
|
;
|
|
8
|
-
exports.default = "1.1.
|
|
8
|
+
exports.default = "1.1.9";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orderly.network/hooks",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -20,25 +20,25 @@
|
|
|
20
20
|
"@types/jest": "^29.5.3",
|
|
21
21
|
"@types/ramda": "^0.29.3",
|
|
22
22
|
"@types/react": "^18.2.38",
|
|
23
|
-
"react": "^18.2.0",
|
|
24
23
|
"jest": "^29.6.1",
|
|
24
|
+
"react": "^18.2.0",
|
|
25
25
|
"react-test-renderer": "^18.2.0",
|
|
26
26
|
"rimraf": "^5.0.5",
|
|
27
27
|
"tsup": "^7.1.0",
|
|
28
28
|
"typedoc": "^0.24.8",
|
|
29
29
|
"typescript": "^5.1.6",
|
|
30
|
-
"tsconfig": "0.1.
|
|
30
|
+
"tsconfig": "0.1.8"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"ramda": "^0.29.0",
|
|
34
34
|
"swr": "^2.2.4",
|
|
35
35
|
"use-constant": "^1.1.1",
|
|
36
36
|
"use-debounce": "^9.0.4",
|
|
37
|
-
"@orderly.network/
|
|
38
|
-
"@orderly.network/net": "1.1.
|
|
39
|
-
"@orderly.network/perp": "2.0.
|
|
40
|
-
"@orderly.network/types": "0.2.
|
|
41
|
-
"@orderly.network/
|
|
37
|
+
"@orderly.network/core": "0.2.8",
|
|
38
|
+
"@orderly.network/net": "1.1.8",
|
|
39
|
+
"@orderly.network/perp": "2.0.8",
|
|
40
|
+
"@orderly.network/types": "0.2.8",
|
|
41
|
+
"@orderly.network/utils": "0.1.8"
|
|
42
42
|
},
|
|
43
43
|
"publishConfig": {
|
|
44
44
|
"access": "public"
|