@orderly.network/hooks 1.1.8 → 1.2.0-alpha.0
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/orderbook.service.d.ts +33 -0
- package/esm/orderly/orderbook.service.d.ts.map +1 -0
- package/esm/orderly/orderbook.service.js +118 -0
- 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 +8 -6
- package/esm/orderly/useOrderbookStream.d.ts.map +1 -1
- package/esm/orderly/useOrderbookStream.js +52 -71
- 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/services/painter/dataPaint.d.ts.map +1 -1
- package/esm/services/painter/dataPaint.js +11 -5
- package/esm/services/painter/layout.config.js +4 -4
- 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/createOrder.d.ts.map +1 -1
- package/esm/utils/createOrder.js +11 -1
- package/esm/utils/swr.js +1 -1
- package/esm/version.d.ts +1 -1
- package/esm/version.d.ts.map +1 -1
- package/esm/version.js +2 -2
- package/lib/orderly/orderbook.service.d.ts +33 -0
- package/lib/orderly/orderbook.service.d.ts.map +1 -0
- package/lib/orderly/orderbook.service.js +121 -0
- 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 +8 -6
- package/lib/orderly/useOrderbookStream.d.ts.map +1 -1
- package/lib/orderly/useOrderbookStream.js +55 -71
- 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/services/painter/dataPaint.d.ts.map +1 -1
- package/lib/services/painter/dataPaint.js +11 -5
- package/lib/services/painter/layout.config.js +4 -4
- 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/createOrder.d.ts.map +1 -1
- package/lib/utils/createOrder.js +11 -1
- package/lib/utils/swr.js +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.d.ts.map +1 -1
- package/lib/version.js +2 -2
- package/package.json +8 -8
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface RawOrderBook {
|
|
2
|
+
asks: [number, number][];
|
|
3
|
+
bids: [number, number][];
|
|
4
|
+
ts: number;
|
|
5
|
+
}
|
|
6
|
+
export interface RawOrderBookUpdate {
|
|
7
|
+
asks: [number, number][];
|
|
8
|
+
bids: [number, number][];
|
|
9
|
+
prevTs: number;
|
|
10
|
+
ts: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const defaultRawOrderBook: RawOrderBook;
|
|
13
|
+
declare class OrderbookService {
|
|
14
|
+
private static instance;
|
|
15
|
+
private bufferedOrderBookUpdates;
|
|
16
|
+
private rawOrderBook;
|
|
17
|
+
constructor();
|
|
18
|
+
static getInstance(): OrderbookService;
|
|
19
|
+
private sortBufferedOrderBookUpdates;
|
|
20
|
+
private applyUpdateToRawOrderBook;
|
|
21
|
+
private applyBufferedUpdatesToRawOrderBooks;
|
|
22
|
+
private deleteBufferedOrderBookUpdates;
|
|
23
|
+
private commitOrderBook;
|
|
24
|
+
private pushUpdateToBuffer;
|
|
25
|
+
private isValidFullOrderBook;
|
|
26
|
+
setFullOrderbook(symbol: string, rawOrderbook: RawOrderBook): void;
|
|
27
|
+
updateOrderbook(symbol: string, update: RawOrderBookUpdate, callback: () => void): void;
|
|
28
|
+
getRawOrderbook(symbol: string): RawOrderBook;
|
|
29
|
+
resetOrderBook(symbol: string): void;
|
|
30
|
+
}
|
|
31
|
+
declare const orderBookService: OrderbookService;
|
|
32
|
+
export default orderBookService;
|
|
33
|
+
//# sourceMappingURL=orderbook.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orderbook.service.d.ts","sourceRoot":"","sources":["../../src/orderly/orderbook.service.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,EAAE,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,mBAAmB,EAAE,YAIjC,CAAC;AAEF,cAAM,gBAAgB;IAClB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAC1C,OAAO,CAAC,wBAAwB,CAAkD;IAClF,OAAO,CAAC,YAAY,CAA0C;;IAK9D,MAAM,CAAC,WAAW;IAOlB,OAAO,CAAC,4BAA4B;IAIpC,OAAO,CAAC,yBAAyB;IAqBjC,OAAO,CAAC,mCAAmC;IAI3C,OAAO,CAAC,8BAA8B;IAItC,OAAO,CAAC,eAAe;IAsBvB,OAAO,CAAC,kBAAkB;IAgB1B,OAAO,CAAC,oBAAoB;IAU5B,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IAY3D,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,IAAI;IAwBhF,eAAe,CAAC,MAAM,EAAE,MAAM;IAIvB,cAAc,CAAC,MAAM,EAAE,MAAM;CAOvC;AAED,QAAA,MAAM,gBAAgB,kBAAiC,CAAC;AAExD,eAAe,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export const defaultRawOrderBook = {
|
|
2
|
+
asks: [],
|
|
3
|
+
bids: [],
|
|
4
|
+
ts: 0,
|
|
5
|
+
};
|
|
6
|
+
class OrderbookService {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.bufferedOrderBookUpdates = {};
|
|
9
|
+
this.rawOrderBook = {};
|
|
10
|
+
}
|
|
11
|
+
static getInstance() {
|
|
12
|
+
if (!this.instance) {
|
|
13
|
+
this.instance = new OrderbookService();
|
|
14
|
+
}
|
|
15
|
+
return this.instance;
|
|
16
|
+
}
|
|
17
|
+
sortBufferedOrderBookUpdates(symbol) {
|
|
18
|
+
this.bufferedOrderBookUpdates[symbol]?.sort((a, b) => a.ts - b.ts);
|
|
19
|
+
}
|
|
20
|
+
applyUpdateToRawOrderBook(symbol, update) {
|
|
21
|
+
const rawOrderBook = this.rawOrderBook[symbol];
|
|
22
|
+
if (!rawOrderBook || rawOrderBook.ts > update.prevTs) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const askMap = new Map();
|
|
26
|
+
const bidMap = new Map();
|
|
27
|
+
rawOrderBook.asks.forEach((ask) => askMap.set(ask[0], ask[1]));
|
|
28
|
+
rawOrderBook.bids.forEach((bid) => bidMap.set(bid[0], bid[1]));
|
|
29
|
+
update.asks.forEach((ask) => (ask[1] === 0 ? askMap.delete(ask[0]) : askMap.set(ask[0], ask[1])));
|
|
30
|
+
update.bids.forEach((bid) => (bid[1] === 0 ? bidMap.delete(bid[0]) : bidMap.set(bid[0], bid[1])));
|
|
31
|
+
rawOrderBook.asks = Array.from(askMap.entries()).sort((a, b) => a[0] - b[0]);
|
|
32
|
+
rawOrderBook.bids = Array.from(bidMap.entries()).sort((a, b) => b[0] - a[0]);
|
|
33
|
+
rawOrderBook.ts = update.ts;
|
|
34
|
+
}
|
|
35
|
+
applyBufferedUpdatesToRawOrderBooks(symbol) {
|
|
36
|
+
this.bufferedOrderBookUpdates[symbol]?.forEach((update) => this.applyUpdateToRawOrderBook(symbol, update));
|
|
37
|
+
}
|
|
38
|
+
deleteBufferedOrderBookUpdates(symbol) {
|
|
39
|
+
delete this.bufferedOrderBookUpdates[symbol];
|
|
40
|
+
}
|
|
41
|
+
commitOrderBook(symbol) {
|
|
42
|
+
const rawOrderBook = this.rawOrderBook[symbol];
|
|
43
|
+
if (!rawOrderBook) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// const orderbook = this.prepareOrderBookStore(rawOrderBook);
|
|
47
|
+
// if (orderbook.firstAskPrice <= orderbook.firstBidPrice) {
|
|
48
|
+
// console.error(SERVICE_PREFIX, 'Orderbook crossing error', { crossedAsks: orderbook.asks, crossedBids: orderbook.bids });
|
|
49
|
+
//
|
|
50
|
+
// this.rawOrderBook[symbol] = {
|
|
51
|
+
// ...defaultRawOrderBook,
|
|
52
|
+
// ts: -1, // must be -1 because it needs to cause Orderbook version error in public websocket
|
|
53
|
+
// };
|
|
54
|
+
// } else {
|
|
55
|
+
// orderBookStore.update(symbol, orderbook);
|
|
56
|
+
// depthChartService.commitDepthChart(symbol);
|
|
57
|
+
// }
|
|
58
|
+
}
|
|
59
|
+
pushUpdateToBuffer(symbol, update) {
|
|
60
|
+
if (this.bufferedOrderBookUpdates[symbol] === undefined) {
|
|
61
|
+
this.bufferedOrderBookUpdates[symbol] = [];
|
|
62
|
+
}
|
|
63
|
+
const buffer = this.bufferedOrderBookUpdates[symbol];
|
|
64
|
+
if (buffer.length > 0) {
|
|
65
|
+
const lastUpdate = buffer[buffer.length - 1];
|
|
66
|
+
if (lastUpdate.ts !== update.prevTs) {
|
|
67
|
+
this.bufferedOrderBookUpdates[symbol] = [];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
this.bufferedOrderBookUpdates[symbol].push(update);
|
|
71
|
+
}
|
|
72
|
+
isValidFullOrderBook(symbol, currentTs) {
|
|
73
|
+
if ((this.bufferedOrderBookUpdates[symbol]?.length ?? 0) !== 0) {
|
|
74
|
+
const earliestUpdates = this.bufferedOrderBookUpdates[symbol][0];
|
|
75
|
+
// Incoming full orderbook is invalid if the timestamp is less than all of our buffered diff orderbook updates.
|
|
76
|
+
return earliestUpdates.prevTs <= currentTs;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
setFullOrderbook(symbol, rawOrderbook) {
|
|
81
|
+
const { ts } = rawOrderbook;
|
|
82
|
+
this.rawOrderBook[symbol] = rawOrderbook;
|
|
83
|
+
this.sortBufferedOrderBookUpdates(symbol);
|
|
84
|
+
if (this.isValidFullOrderBook(symbol, ts)) {
|
|
85
|
+
this.applyBufferedUpdatesToRawOrderBooks(symbol);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
;
|
|
89
|
+
updateOrderbook(symbol, update, callback) {
|
|
90
|
+
const { asks, bids, prevTs, ts } = update;
|
|
91
|
+
const rawOrderBook = this.rawOrderBook[symbol];
|
|
92
|
+
if (!rawOrderBook) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const currentTs = rawOrderBook.ts;
|
|
96
|
+
if (currentTs === 0) {
|
|
97
|
+
this.pushUpdateToBuffer(symbol, { asks, bids, prevTs, ts });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (prevTs !== currentTs) {
|
|
101
|
+
this.pushUpdateToBuffer(symbol, { asks, bids, prevTs, ts });
|
|
102
|
+
if (callback) {
|
|
103
|
+
callback();
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.applyUpdateToRawOrderBook(symbol, update);
|
|
108
|
+
this.deleteBufferedOrderBookUpdates(symbol);
|
|
109
|
+
}
|
|
110
|
+
getRawOrderbook(symbol) {
|
|
111
|
+
return this.rawOrderBook[symbol];
|
|
112
|
+
}
|
|
113
|
+
resetOrderBook(symbol) {
|
|
114
|
+
this.rawOrderBook[symbol] = defaultRawOrderBook;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const orderBookService = OrderbookService.getInstance();
|
|
118
|
+
export default orderBookService;
|
|
@@ -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,17 +327,20 @@ 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,
|
|
340
341
|
formattedOrder.total,
|
|
341
342
|
formattedOrder.trigger_price,
|
|
343
|
+
formattedOrder.order_type,
|
|
342
344
|
markPrice,
|
|
343
345
|
]);
|
|
344
346
|
//====== update orderbook ask0/bid0 ======
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOrderbookStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderbookStream.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useOrderbookStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderbookStream.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,MAAM,aAAa,GAAG;IACxB,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,IAAI,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAyFF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UACjB,MAAM,GAAG,SAAS,SAClB,MAAM,WACJ,OAAO,QACV,aAAa,KACpB,aAyDF,CAAC;AAgCF,eAAO,MAAM,cAAc,SAAU,aAAa,UAAU,aAAa;;;CAWxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,WACnB,MAAM,YACL,aAAa,YACZ,gBAAgB;;;;;;;;;;;2BA8GgB,MAAM;;;;;;;;;IAmDnD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -7,6 +7,7 @@ import { useSymbolsInfo } from "./useSymbolsInfo";
|
|
|
7
7
|
import { Decimal } from "@orderly.network/utils";
|
|
8
8
|
import { min } from "ramda";
|
|
9
9
|
import { SDKError } from "@orderly.network/types";
|
|
10
|
+
import orderbooksService from './orderbook.service';
|
|
10
11
|
const paddingFn = (len) => Array(len).fill([Number.NaN, Number.NaN, Number.NaN, Number.NaN]);
|
|
11
12
|
const asksSortFn = (a, b) => a[0] - b[0];
|
|
12
13
|
const bidsSortFn = (a, b) => b[0] - a[0];
|
|
@@ -202,74 +203,54 @@ export const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
202
203
|
const eventEmitter = useEventEmitter();
|
|
203
204
|
// const orderbookRequest =
|
|
204
205
|
useEffect(() => {
|
|
206
|
+
let needRequestFullOrderbook = true;
|
|
205
207
|
setIsLoading(true);
|
|
206
|
-
let
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
type: "orderbook",
|
|
212
|
-
symbol: symbol,
|
|
213
|
-
},
|
|
208
|
+
let orderBookUpdateSub;
|
|
209
|
+
let fullOrderBookUpdateSub;
|
|
210
|
+
orderBookUpdateSub = ws.subscribe({
|
|
211
|
+
event: "subscribe",
|
|
212
|
+
topic: `${symbol}@orderbookupdate`,
|
|
214
213
|
}, {
|
|
214
|
+
formatter: (message) => message,
|
|
215
215
|
onMessage: (message) => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
bids = bids.filter((item) => !isNaN(item[0]) && item[1] > 0);
|
|
223
|
-
let asks = [...message.asks.sort(asksSortFn)];
|
|
224
|
-
asks = asks.filter((item) => !isNaN(item[0]) && item[1] > 0);
|
|
225
|
-
// const reduceOrderbookData = reduceOrderbook(depth, level, {
|
|
226
|
-
// bids: bids,
|
|
227
|
-
// asks: asks,
|
|
228
|
-
// });
|
|
229
|
-
setRequestData({ bids: bids, asks: asks });
|
|
230
|
-
setData({ bids: [...bids], asks: [...asks] });
|
|
231
|
-
}
|
|
232
|
-
setIsLoading(false);
|
|
233
|
-
},
|
|
216
|
+
const { data: wsData, ts } = message;
|
|
217
|
+
const { asks, bids, prevTs } = wsData;
|
|
218
|
+
orderbooksService.updateOrderbook(symbol, { asks, bids, ts, prevTs }, () => needRequestFullOrderbook = true);
|
|
219
|
+
const data = orderbooksService.getRawOrderbook(symbol);
|
|
220
|
+
setData({ bids: data.bids, asks: data.asks });
|
|
221
|
+
}
|
|
234
222
|
});
|
|
223
|
+
if (needRequestFullOrderbook) {
|
|
224
|
+
setIsLoading(true);
|
|
225
|
+
fullOrderBookUpdateSub = ws.onceSubscribe({
|
|
226
|
+
event: "request",
|
|
227
|
+
id: `${symbol}@orderbook`,
|
|
228
|
+
params: {
|
|
229
|
+
type: "orderbook",
|
|
230
|
+
symbol: symbol,
|
|
231
|
+
},
|
|
232
|
+
}, {
|
|
233
|
+
formatter: (message) => message,
|
|
234
|
+
onMessage: (message) => {
|
|
235
|
+
const { symbol, asks, bids, ts } = message.data;
|
|
236
|
+
orderbooksService.setFullOrderbook(symbol, { asks, bids, ts });
|
|
237
|
+
const data = orderbooksService.getRawOrderbook(symbol);
|
|
238
|
+
setData({ bids: data.bids, asks: data.asks });
|
|
239
|
+
setIsLoading(false);
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
needRequestFullOrderbook = false;
|
|
243
|
+
}
|
|
235
244
|
return () => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
245
|
+
// unsubscribe
|
|
246
|
+
orderBookUpdateSub?.();
|
|
247
|
+
fullOrderBookUpdateSub?.();
|
|
248
|
+
orderbooksService.resetOrderBook(symbol);
|
|
239
249
|
setData(INIT_DATA);
|
|
240
|
-
prevMiddlePrice.current = 0;
|
|
241
250
|
};
|
|
242
251
|
}, [symbol]);
|
|
243
252
|
// const {data:markPrices} = useMarkPricesStream();
|
|
244
253
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
245
|
-
useEffect(() => {
|
|
246
|
-
if (!requestData)
|
|
247
|
-
return;
|
|
248
|
-
let ignore = false;
|
|
249
|
-
const subscription = ws.subscribe({
|
|
250
|
-
event: "subscribe",
|
|
251
|
-
topic: `${symbol}@orderbookupdate`,
|
|
252
|
-
}, {
|
|
253
|
-
onMessage: (message) => {
|
|
254
|
-
//
|
|
255
|
-
if (ignore)
|
|
256
|
-
return;
|
|
257
|
-
setData((data) => {
|
|
258
|
-
const mergedData = !message.asks && !message.bids
|
|
259
|
-
? data
|
|
260
|
-
: mergeOrderbook(data, message);
|
|
261
|
-
return mergedData;
|
|
262
|
-
// const reducedData = reduceOrderbook(depth, level, mergedData);
|
|
263
|
-
// return reducedData;
|
|
264
|
-
});
|
|
265
|
-
},
|
|
266
|
-
});
|
|
267
|
-
return () => {
|
|
268
|
-
ignore = true;
|
|
269
|
-
prevMiddlePrice.current = 0;
|
|
270
|
-
subscription?.(); //unsubscribe
|
|
271
|
-
};
|
|
272
|
-
}, [symbol, requestData]);
|
|
273
254
|
const onItemClick = useCallback((item) => {
|
|
274
255
|
eventEmitter.emit("orderbook:item:click", item);
|
|
275
256
|
}, []);
|
|
@@ -277,10 +258,22 @@ export const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
277
258
|
//
|
|
278
259
|
setDepth(() => depth);
|
|
279
260
|
}, []);
|
|
261
|
+
const reducedData = reduceOrderbook(depth, level, padding, {
|
|
262
|
+
asks: [...data.asks],
|
|
263
|
+
bids: [...data.bids],
|
|
264
|
+
});
|
|
265
|
+
// emit the asks0 and bids0
|
|
266
|
+
useEffect(() => {
|
|
267
|
+
const updateData = [
|
|
268
|
+
reducedData.asks?.[reducedData.asks.length - 1]?.[0],
|
|
269
|
+
reducedData.bids?.[0]?.[0]
|
|
270
|
+
];
|
|
271
|
+
eventEmitter.emit("orderbook:update", updateData);
|
|
272
|
+
}, [reducedData.asks?.[reducedData.asks.length - 1]?.[0], reducedData.bids?.[0]?.[0]]);
|
|
280
273
|
const middlePrice = useMemo(() => {
|
|
281
274
|
let asksFrist = 0, bidsFirst = 0;
|
|
282
275
|
if (data.asks.length > 0) {
|
|
283
|
-
asksFrist =
|
|
276
|
+
asksFrist = reducedData.asks?.[reducedData.asks.length - 1]?.[0];
|
|
284
277
|
}
|
|
285
278
|
if (data.bids.length > 0) {
|
|
286
279
|
bidsFirst = data.bids[0][0];
|
|
@@ -292,18 +285,6 @@ export const useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
292
285
|
useEffect(() => {
|
|
293
286
|
prevMiddlePrice.current = middlePrice;
|
|
294
287
|
}, [middlePrice]);
|
|
295
|
-
const reducedData = reduceOrderbook(depth, level, padding, {
|
|
296
|
-
asks: [...data.asks],
|
|
297
|
-
bids: [...data.bids],
|
|
298
|
-
});
|
|
299
|
-
// emit the asks0 and bids0
|
|
300
|
-
useEffect(() => {
|
|
301
|
-
const updateData = [
|
|
302
|
-
reducedData.asks?.[reducedData.asks.length - 1]?.[0],
|
|
303
|
-
reducedData.bids?.[0]?.[0]
|
|
304
|
-
];
|
|
305
|
-
eventEmitter.emit("orderbook:update", updateData);
|
|
306
|
-
}, [reducedData.asks?.[reducedData.asks.length - 1]?.[0], reducedData.bids?.[0]?.[0]]);
|
|
307
288
|
return [
|
|
308
289
|
{
|
|
309
290
|
asks: reducedData.asks.slice(-level),
|
|
@@ -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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataPaint.d.ts","sourceRoot":"","sources":["../../../src/services/painter/dataPaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAGjE,qBAAa,SAAU,SAAQ,SAAS;IACtC,OAAO,CAAC,qBAAqB,CAAO;IAEpC,OAAO,CAAC,oBAAoB,CAAoB;IAChD,OAAO,CAAC,kBAAkB,CAAsB;IAEhD,OAAO,CAAC,YAAY,CAAK;IAEnB,IAAI,CAAC,OAAO,EAAE,WAAW;
|
|
1
|
+
{"version":3,"file":"dataPaint.d.ts","sourceRoot":"","sources":["../../../src/services/painter/dataPaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAc,MAAM,aAAa,CAAC;AAGjE,qBAAa,SAAU,SAAQ,SAAS;IACtC,OAAO,CAAC,qBAAqB,CAAO;IAEpC,OAAO,CAAC,oBAAoB,CAAoB;IAChD,OAAO,CAAC,kBAAkB,CAAsB;IAEhD,OAAO,CAAC,YAAY,CAAK;IAEnB,IAAI,CAAC,OAAO,EAAE,WAAW;IAsC/B,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,YAAY;IA2EpB,OAAO,CAAC,iBAAiB;IAyEzB,OAAO,CAAC,gBAAgB;IAuCxB,OAAO,CAAC,aAAa;IAmBrB,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,SAAS;IAuCjB,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -12,10 +12,12 @@ export class DataPaint extends BasePaint {
|
|
|
12
12
|
async draw(options) {
|
|
13
13
|
const needDrawDetails = Array.isArray(options.data?.position?.informations) &&
|
|
14
14
|
(options.data?.position?.informations?.length ?? 0) > 0;
|
|
15
|
-
const hasMessage = !!options.data?.message;
|
|
15
|
+
// const hasMessage = !!options.data?.message;
|
|
16
|
+
const hasMessage = true;
|
|
16
17
|
this.transformTop = hasMessage ? 0 : needDrawDetails ? -40 : -150;
|
|
17
18
|
// If position details are not displayed, the position PNL information will be margin
|
|
18
|
-
const offsetTop = hasMessage ? 50 : 100;
|
|
19
|
+
// const offsetTop = hasMessage ? 50 : 100;
|
|
20
|
+
const offsetTop = 100;
|
|
19
21
|
// const offsetMessage = hasMessage ? 0 : -50;
|
|
20
22
|
if (!!options.data?.message) {
|
|
21
23
|
this.drawMessage(options);
|
|
@@ -164,8 +166,11 @@ export class DataPaint extends BasePaint {
|
|
|
164
166
|
const isVertical = (options.data?.position.informations.length ?? 0) === 2;
|
|
165
167
|
options.data?.position.informations.forEach((info, index) => {
|
|
166
168
|
// let cellWidth = this.positionInfoCellWidth;
|
|
167
|
-
let left = position.left +
|
|
168
|
-
let top = position.top + (index
|
|
169
|
+
let left = position.left + (index % 2) * this.positionInfoCellWidth;
|
|
170
|
+
// let top = (position.top as number) + (index / 2) * 38 + this.transformTop;
|
|
171
|
+
let top = position.top +
|
|
172
|
+
Math.floor(index / 2) * 38 +
|
|
173
|
+
this.transformTop;
|
|
169
174
|
this._drawText(info.title, {
|
|
170
175
|
left: this._ratio(left),
|
|
171
176
|
top: this._ratio(top),
|
|
@@ -201,7 +206,8 @@ export class DataPaint extends BasePaint {
|
|
|
201
206
|
const layout = path(["layout", "updateTime"], options);
|
|
202
207
|
const { position } = layout;
|
|
203
208
|
const top = this.painter.height - position.bottom;
|
|
204
|
-
const left =
|
|
209
|
+
const left = position.left;
|
|
210
|
+
console.log("*******", left, top, options.data?.updateTime);
|
|
205
211
|
this._drawText(options.data?.updateTime, {
|
|
206
212
|
left: this._ratio(left),
|
|
207
213
|
top: this._ratio(top),
|
|
@@ -5,7 +5,7 @@ export const DefaultLayoutConfig = {
|
|
|
5
5
|
textBaseline: "bottom",
|
|
6
6
|
position: {
|
|
7
7
|
left: 20,
|
|
8
|
-
bottom:
|
|
8
|
+
bottom: 32,
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
11
|
message: {
|
|
@@ -46,11 +46,11 @@ export const DefaultLayoutConfig = {
|
|
|
46
46
|
},
|
|
47
47
|
updateTime: {
|
|
48
48
|
fontSize: 10,
|
|
49
|
-
color: "rgba(255,255,255,0.
|
|
50
|
-
textAlign: "end",
|
|
49
|
+
color: "rgba(255,255,255,0.3)",
|
|
50
|
+
// textAlign: "end",
|
|
51
51
|
textBaseline: "bottom",
|
|
52
52
|
position: {
|
|
53
|
-
|
|
53
|
+
left: 20,
|
|
54
54
|
bottom: 17,
|
|
55
55
|
},
|
|
56
56
|
},
|
|
@@ -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) =>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