@orderly.network/hooks 1.1.4 → 1.1.5-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/dataProvider.d.ts +4 -3
- package/esm/dataProvider.d.ts.map +1 -1
- package/esm/dataProvider.js +5 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.d.ts.map +1 -1
- package/esm/index.js +1 -0
- package/esm/orderly/useMaxQty.d.ts.map +1 -1
- package/esm/orderly/useMaxQty.js +12 -26
- package/esm/orderly/useOrderEntry.js +9 -2
- package/esm/orderly/useOrderStream.d.ts +10 -1
- package/esm/orderly/useOrderStream.d.ts.map +1 -1
- package/esm/orderly/useOrderStream.js +16 -25
- package/esm/orderly/useOrderbookStream.d.ts.map +1 -1
- package/esm/orderly/useOrderbookStream.js +10 -6
- package/esm/orderly/usePrivateDataObserver.d.ts.map +1 -1
- package/esm/orderly/usePrivateDataObserver.js +55 -37
- package/esm/services/painter/basePaint.d.ts +5 -1
- package/esm/services/painter/basePaint.d.ts.map +1 -1
- package/esm/services/painter/dataPaint.d.ts.map +1 -1
- package/esm/services/painter/dataPaint.js +40 -17
- package/esm/services/painter/layout.config.js +1 -1
- package/esm/useMutation.d.ts +4 -1
- package/esm/useMutation.d.ts.map +1 -1
- package/esm/useMutation.js +29 -2
- package/esm/usePoster.d.ts +24 -2
- package/esm/usePoster.d.ts.map +1 -1
- package/esm/usePoster.js +88 -20
- package/esm/utils/dev.d.ts +2 -0
- package/esm/utils/dev.d.ts.map +1 -0
- package/esm/utils/dev.js +18 -0
- package/esm/utils/swr.d.ts +10 -0
- package/esm/utils/swr.d.ts.map +1 -0
- package/esm/utils/swr.js +179 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.d.ts.map +1 -1
- package/esm/version.js +2 -2
- package/lib/dataProvider.d.ts +4 -3
- package/lib/dataProvider.d.ts.map +1 -1
- package/lib/dataProvider.js +5 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/orderly/useMaxQty.d.ts.map +1 -1
- package/lib/orderly/useMaxQty.js +12 -26
- package/lib/orderly/useOrderEntry.js +9 -2
- package/lib/orderly/useOrderStream.d.ts +10 -1
- package/lib/orderly/useOrderStream.d.ts.map +1 -1
- package/lib/orderly/useOrderStream.js +16 -25
- package/lib/orderly/useOrderbookStream.d.ts.map +1 -1
- package/lib/orderly/useOrderbookStream.js +10 -6
- package/lib/orderly/usePrivateDataObserver.d.ts.map +1 -1
- package/lib/orderly/usePrivateDataObserver.js +54 -36
- package/lib/services/painter/basePaint.d.ts +5 -1
- package/lib/services/painter/basePaint.d.ts.map +1 -1
- package/lib/services/painter/dataPaint.d.ts.map +1 -1
- package/lib/services/painter/dataPaint.js +40 -17
- package/lib/services/painter/layout.config.js +1 -1
- package/lib/useMutation.d.ts +4 -1
- package/lib/useMutation.d.ts.map +1 -1
- package/lib/useMutation.js +29 -2
- package/lib/usePoster.d.ts +24 -2
- package/lib/usePoster.d.ts.map +1 -1
- package/lib/usePoster.js +87 -19
- package/lib/utils/dev.d.ts +2 -0
- package/lib/utils/dev.d.ts.map +1 -0
- package/lib/utils/dev.js +20 -0
- package/lib/utils/swr.d.ts +10 -0
- package/lib/utils/swr.d.ts.map +1 -0
- package/lib/utils/swr.js +184 -0
- 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
package/esm/dataProvider.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
2
|
export type getKeyFunction = (index: number, prevData: any) => string | null;
|
|
3
|
-
interface
|
|
3
|
+
interface DataCenterContextState {
|
|
4
4
|
regesterKeyHandler: (key: string, handler: getKeyFunction) => void;
|
|
5
|
+
unregisterKeyHandler: (key: string) => void;
|
|
5
6
|
}
|
|
6
|
-
export declare const DataCenterContext: import("react").Context<
|
|
7
|
-
export declare const useDataCenterContext: () =>
|
|
7
|
+
export declare const DataCenterContext: import("react").Context<DataCenterContextState>;
|
|
8
|
+
export declare const useDataCenterContext: () => DataCenterContextState;
|
|
8
9
|
export declare const DataCenterProvider: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element | null;
|
|
9
10
|
export {};
|
|
10
11
|
//# sourceMappingURL=dataProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataProvider.d.ts","sourceRoot":"","sources":["../src/dataProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAqC,MAAM,OAAO,CAAC;AAI7E,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;AAE7E,UAAU,sBAAsB;IAK9B,kBAAkB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"dataProvider.d.ts","sourceRoot":"","sources":["../src/dataProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAqC,MAAM,OAAO,CAAC;AAI7E,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;AAE7E,UAAU,sBAAsB;IAK9B,kBAAkB,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;IACnE,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAED,eAAO,MAAM,iBAAiB,iDAE7B,CAAC;AAEF,eAAO,MAAM,oBAAoB,8BAAsC,CAAC;AAExE,eAAO,MAAM,kBAAkB,iBAAkB,iBAAiB,mDAqCjE,CAAC"}
|
package/esm/dataProvider.js
CHANGED
|
@@ -23,7 +23,12 @@ export const DataCenterProvider = ({ children }) => {
|
|
|
23
23
|
return null;
|
|
24
24
|
return (_jsx(DataCenterContext.Provider, { value: {
|
|
25
25
|
regesterKeyHandler: (key, fun) => {
|
|
26
|
+
console.log("regesterKeyHandler", key);
|
|
26
27
|
getKeyHandlerMapRef.current.set(key, fun);
|
|
27
28
|
},
|
|
29
|
+
unregisterKeyHandler: (key) => {
|
|
30
|
+
console.log("unregisterKeyHandler", key);
|
|
31
|
+
getKeyHandlerMapRef.current.delete(key);
|
|
32
|
+
},
|
|
28
33
|
}, children: children }));
|
|
29
34
|
};
|
package/esm/index.d.ts
CHANGED
package/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AAE/C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,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,MAAM,SAAS,WACZ,MAAM,QACR,SAAS,eACH,OAAO,
|
|
1
|
+
{"version":3,"file":"useMaxQty.d.ts","sourceRoot":"","sources":["../../src/orderly/useMaxQty.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,SAAS,EAAe,MAAM,wBAAwB,CAAC;AAgB1E,eAAO,MAAM,SAAS,WACZ,MAAM,QACR,SAAS,eACH,OAAO,WA0HpB,CAAC"}
|
package/esm/orderly/useMaxQty.js
CHANGED
|
@@ -17,32 +17,6 @@ export const useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
17
17
|
const { totalCollateral } = useCollateral();
|
|
18
18
|
const { data: markPrices } = useMarkPricesStream();
|
|
19
19
|
const [orders] = useOrderStream({ status: OrderStatus.NEW });
|
|
20
|
-
// const {
|
|
21
|
-
// data: orders,
|
|
22
|
-
// error,
|
|
23
|
-
// mutate: updateOrder,
|
|
24
|
-
// } = usePrivateQuery<API.Order[]>(`/v1/orders?status=NEW&size=99`, {
|
|
25
|
-
// formatter: (data) => data.rows,
|
|
26
|
-
// onError: (err) => { },
|
|
27
|
-
// });
|
|
28
|
-
// const ws = useWS();
|
|
29
|
-
// useEffect(() => {
|
|
30
|
-
// const unsubscribe = ws.privateSubscribe(
|
|
31
|
-
// {
|
|
32
|
-
// id: "executionreport_orders",
|
|
33
|
-
// event: "subscribe",
|
|
34
|
-
// topic: "executionreport",
|
|
35
|
-
// ts: Date.now(),
|
|
36
|
-
// },
|
|
37
|
-
// {
|
|
38
|
-
// onMessage: (data: any) => {
|
|
39
|
-
// console.log("refresh orders", data);
|
|
40
|
-
// updateOrder();
|
|
41
|
-
// },
|
|
42
|
-
// }
|
|
43
|
-
// );
|
|
44
|
-
// return () => unsubscribe();
|
|
45
|
-
// }, []);
|
|
46
20
|
const maxQty = useMemo(() => {
|
|
47
21
|
if (!symbol)
|
|
48
22
|
return 0;
|
|
@@ -110,5 +84,17 @@ export const useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
110
84
|
totalCollateral,
|
|
111
85
|
reduceOnly,
|
|
112
86
|
]);
|
|
87
|
+
// debugPrint({
|
|
88
|
+
// maxQty,
|
|
89
|
+
// totalCollateral,
|
|
90
|
+
// side,
|
|
91
|
+
// // reduceOnly,
|
|
92
|
+
// orders: orders?.map((o) => o.quantity),
|
|
93
|
+
// // positionsData,
|
|
94
|
+
// // markPrices,
|
|
95
|
+
// // accountInfo,
|
|
96
|
+
// // symbolInfo,
|
|
97
|
+
// // symbol,
|
|
98
|
+
// });
|
|
113
99
|
return Math.max(maxQty, 0);
|
|
114
100
|
};
|
|
@@ -182,7 +182,7 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
182
182
|
]);
|
|
183
183
|
const isStopOrder = parsedData?.order_type === OrderType.STOP_LIMIT ||
|
|
184
184
|
parsedData?.order_type === OrderType.STOP_MARKET;
|
|
185
|
-
const [doCreateOrder, {
|
|
185
|
+
const [doCreateOrder, { isMutating }] = useMutation(isStopOrder ? "/v1/algo/order" : "/v1/order");
|
|
186
186
|
// const maxQty = 3;
|
|
187
187
|
const createOrder = (values) => {
|
|
188
188
|
if (!values.symbol) {
|
|
@@ -233,9 +233,16 @@ export function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options)
|
|
|
233
233
|
// ...omit(["order_price"], values),
|
|
234
234
|
...data,
|
|
235
235
|
})).then((res) => {
|
|
236
|
-
|
|
236
|
+
console.log("--------------------res::::", res);
|
|
237
237
|
// resolve(res);
|
|
238
238
|
if (res.success) {
|
|
239
|
+
// TODO: remove when the WS service is fixed
|
|
240
|
+
if (Array.isArray(res.data.rows)) {
|
|
241
|
+
ee.emit("algoOrder:cache", {
|
|
242
|
+
...res.data.rows[0],
|
|
243
|
+
trigger_price: data.trigger_price,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
239
246
|
resolve(res.data);
|
|
240
247
|
}
|
|
241
248
|
else {
|
|
@@ -11,7 +11,16 @@ type Params = {
|
|
|
11
11
|
size?: number;
|
|
12
12
|
side?: OrderSide;
|
|
13
13
|
};
|
|
14
|
-
export declare const useOrderStream: (params: Params
|
|
14
|
+
export declare const useOrderStream: (params: Params, options?: {
|
|
15
|
+
/**
|
|
16
|
+
* Keep the state update alive
|
|
17
|
+
*/
|
|
18
|
+
keeplive?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Stop the state update when the component unmount
|
|
21
|
+
*/
|
|
22
|
+
stopOnUnmount?: boolean;
|
|
23
|
+
}) => readonly [any[] | null, {
|
|
15
24
|
readonly total: any;
|
|
16
25
|
readonly isLoading: boolean;
|
|
17
26
|
readonly refresh: import("swr/_internal").KeyedMutator<any[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOrderStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderStream.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,SAAS,EACT,WAAW,EACX,WAAW,EAEZ,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"useOrderStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderStream.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,SAAS,EACT,WAAW,EACX,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAShC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC7B,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;CAC9B;AAID,KAAK,MAAM,GAAG;IACZ,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,cAAc,WAIjB,MAAM,YAEJ;IACR;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;;;;;;oCA4GyC,MAAM,SAAS,WAAW;oCAoD1B,MAAM,WAAW,MAAM;wCA7CnB,MAAM,SAAS,WAAW;wCAoD1B,MAAM,WAAW,MAAM;;;;;;;;;;;;;EAkCtE,CAAC"}
|
|
@@ -5,40 +5,30 @@ import { useMarkPricesStream } from "./useMarkPricesStream";
|
|
|
5
5
|
import { useMutation } from "../useMutation";
|
|
6
6
|
import version from "../version";
|
|
7
7
|
import { useDataCenterContext } from "../dataProvider";
|
|
8
|
-
|
|
8
|
+
import { generateKeyFun } from "../utils/swr";
|
|
9
|
+
export const useOrderStream = (
|
|
10
|
+
/**
|
|
11
|
+
* Orders query params
|
|
12
|
+
*/
|
|
13
|
+
params, options) => {
|
|
9
14
|
const { status, symbol, side, size = 100 } = params;
|
|
10
15
|
const { data: markPrices = {} } = useMarkPricesStream();
|
|
11
|
-
const { regesterKeyHandler } = useDataCenterContext();
|
|
16
|
+
const { regesterKeyHandler, unregisterKeyHandler } = useDataCenterContext();
|
|
12
17
|
const [doCancelOrder, { error: cancelOrderError, isMutating: cancelMutating },] = useMutation("/v1/order", "DELETE");
|
|
13
18
|
const [doUpdateOrder, { error: updateOrderError, isMutating: updateMutating },] = useMutation("/v1/order", "PUT");
|
|
14
19
|
const [doCanceAlgolOrder, { error: cancelAlgoOrderError, isMutating: cancelAlgoMutating },] = useMutation("/v1/algo/order", "DELETE");
|
|
15
20
|
const [doUpdateAlgoOrder, { error: updateAlgoOrderError, isMutating: updateAlgoMutating },] = useMutation("/v1/algo/order", "PUT");
|
|
16
|
-
const getKey = (pageIndex, previousPageData) => {
|
|
17
|
-
// reached the end
|
|
18
|
-
if (previousPageData && !previousPageData.rows?.length)
|
|
19
|
-
return null;
|
|
20
|
-
const search = new URLSearchParams([
|
|
21
|
-
["size", size.toString()],
|
|
22
|
-
["page", `${pageIndex + 1}`],
|
|
23
|
-
["source_type", "ALL"],
|
|
24
|
-
]);
|
|
25
|
-
if (status) {
|
|
26
|
-
search.set(`status`, status);
|
|
27
|
-
}
|
|
28
|
-
if (symbol) {
|
|
29
|
-
search.set(`symbol`, symbol);
|
|
30
|
-
}
|
|
31
|
-
if (side) {
|
|
32
|
-
search.set(`side`, side);
|
|
33
|
-
}
|
|
34
|
-
return `/v1/orders?${search.toString()}`;
|
|
35
|
-
};
|
|
36
21
|
useEffect(() => {
|
|
37
22
|
const formatKey = (value) => (value ? `:${value}` : "");
|
|
38
23
|
const key = `orders${formatKey(status)}${formatKey(symbol)}${formatKey(side)}`;
|
|
39
|
-
regesterKeyHandler(key,
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
regesterKeyHandler?.(key, generateKeyFun({ status, symbol, side, size }));
|
|
25
|
+
return () => {
|
|
26
|
+
if (!options?.stopOnUnmount)
|
|
27
|
+
return;
|
|
28
|
+
unregisterKeyHandler(key);
|
|
29
|
+
};
|
|
30
|
+
}, [status, symbol, side, options?.keeplive]);
|
|
31
|
+
const ordersResponse = usePrivateInfiniteQuery(generateKeyFun({ status, symbol, side, size }), {
|
|
42
32
|
initialSize: 1,
|
|
43
33
|
// revalidateFirstPage: false,
|
|
44
34
|
// onError: (err) => {
|
|
@@ -53,6 +43,7 @@ export const useOrderStream = (params) => {
|
|
|
53
43
|
}
|
|
54
44
|
return ordersResponse.data?.map((item) => item.rows)?.flat();
|
|
55
45
|
}, [ordersResponse.data]);
|
|
46
|
+
// console.log(ordersResponse.data);
|
|
56
47
|
const orders = useMemo(() => {
|
|
57
48
|
if (!flattenOrders) {
|
|
58
49
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useOrderbookStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderbookStream.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,IAAI,EAAE,aAAa,EAAE,CAAC;CACvB,CAAC;AAyFF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UACnB,MAAM,GAAG,SAAS,SAClB,MAAM,WACJ,OAAO,QACV,aAAa,KAClB,
|
|
1
|
+
{"version":3,"file":"useOrderbookStream.d.ts","sourceRoot":"","sources":["../../src/orderly/useOrderbookStream.ts"],"names":[],"mappings":"AAUA,MAAM,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAErC,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,IAAI,EAAE,aAAa,EAAE,CAAC;CACvB,CAAC;AAyFF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,UACnB,MAAM,GAAG,SAAS,SAClB,MAAM,WACJ,OAAO,QACV,aAAa,KAClB,aAyDF,CAAC;AAgCF,eAAO,MAAM,cAAc,SAAU,aAAa,UAAU,aAAa;;;CAWxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAIF;;;GAGG;AACH,eAAO,MAAM,kBAAkB,WACrB,MAAM,YACL,aAAa,YACZ,gBAAgB;;;;;;;;;;;2BA2HgB,MAAM;;;;;;;;;IAmDjD,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -93,22 +93,26 @@ export const reduceOrderbook = (depth, level, padding, data) => {
|
|
|
93
93
|
while (asks.length > 0) {
|
|
94
94
|
const [askPrice, askQty, newQuantity, newAmount] = asks[0];
|
|
95
95
|
if (askPrice <= bidPrice) {
|
|
96
|
-
|
|
96
|
+
console.log("xxxxxxxxxxx reset ask list begin", [...asks], { ...asks[0] });
|
|
97
97
|
asks.shift();
|
|
98
|
-
|
|
98
|
+
let logStr = "";
|
|
99
99
|
for (let index = 0; index < asks.length; index++) {
|
|
100
100
|
if (index === 0) {
|
|
101
101
|
const quantity = asks[index][1] + askQty;
|
|
102
102
|
asks[index][1] = quantity;
|
|
103
103
|
asks[index][2] = quantity;
|
|
104
|
-
asks[index][3] += newAmount;
|
|
104
|
+
// asks[index][3] += newAmount;
|
|
105
|
+
// FIXME: fix this code later
|
|
106
|
+
asks[index][3] = Math.ceil(quantity) * asks[index][0];
|
|
105
107
|
}
|
|
106
108
|
else {
|
|
107
|
-
asks[index][3] += newAmount;
|
|
109
|
+
// asks[index][3] += newAmount;
|
|
110
|
+
// FIXME: fix this code later
|
|
111
|
+
asks[index][3] = asks[index][0] * asks[index][1] + asks[index - 1][3];
|
|
108
112
|
}
|
|
109
|
-
|
|
113
|
+
logStr += `index: ${index} ${asks[index]}\n`;
|
|
110
114
|
}
|
|
111
|
-
|
|
115
|
+
console.log("xxxxxxxxxxx reset ask list end", logStr);
|
|
112
116
|
}
|
|
113
117
|
else {
|
|
114
118
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePrivateDataObserver.d.ts","sourceRoot":"","sources":["../../src/orderly/usePrivateDataObserver.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"usePrivateDataObserver.d.ts","sourceRoot":"","sources":["../../src/orderly/usePrivateDataObserver.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,eAAO,MAAM,sBAAsB;uBAEd,MAAM,KAAK,IAAI,MAAM,EAAE,cAAc,CAAC;UA0K1D,CAAC"}
|
|
@@ -1,41 +1,60 @@
|
|
|
1
|
-
import { useEffect } from "react";
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
2
|
import { useWS } from "../useWS";
|
|
3
|
-
import {
|
|
3
|
+
import { mutate } from "swr";
|
|
4
4
|
import { useAccount } from "../useAccount";
|
|
5
5
|
import { unstable_serialize } from "swr/infinite";
|
|
6
6
|
import { useDebouncedCallback } from "use-debounce";
|
|
7
7
|
import { useEventEmitter } from "../useEventEmitter";
|
|
8
|
-
import {
|
|
8
|
+
import { updateOrdersHandler } from "../utils/swr";
|
|
9
9
|
export const usePrivateDataObserver = (options) => {
|
|
10
10
|
const ws = useWS();
|
|
11
|
-
const { mutate } = useSWRConfig();
|
|
11
|
+
// const { mutate } = useSWRConfig();
|
|
12
12
|
const ee = useEventEmitter();
|
|
13
13
|
const { state } = useAccount();
|
|
14
|
-
|
|
14
|
+
// TODO: remove this when the WS service provides the correct data
|
|
15
|
+
const algoOrderCacheQuneue = useRef([]);
|
|
16
|
+
const updateOrders = useDebouncedCallback((data, isAlgoOrder) => {
|
|
15
17
|
const map = options.getKeysMap("orders");
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
console.log("$$$$$$$$$$$$", data);
|
|
19
|
+
if (isAlgoOrder) {
|
|
20
|
+
/// TODO: remove this when the WS service provides the correct data
|
|
21
|
+
if (algoOrderCacheQuneue.current.length) {
|
|
22
|
+
const index = algoOrderCacheQuneue.current.findIndex((item) => item.order_id === data.algoOrderId);
|
|
23
|
+
console.log({ ...algoOrderCacheQuneue.current[index] });
|
|
24
|
+
if (index > -1) {
|
|
25
|
+
data = {
|
|
26
|
+
...data,
|
|
27
|
+
...algoOrderCacheQuneue.current[index],
|
|
28
|
+
};
|
|
29
|
+
algoOrderCacheQuneue.current.splice(index, 1);
|
|
30
|
+
}
|
|
26
31
|
}
|
|
32
|
+
}
|
|
33
|
+
map.forEach((getKey, key) => {
|
|
34
|
+
mutate(unstable_serialize((index, prevData) => [
|
|
35
|
+
getKey(index, prevData),
|
|
36
|
+
state.accountId,
|
|
37
|
+
]), (prevData) => {
|
|
38
|
+
return updateOrdersHandler(key, data, prevData);
|
|
39
|
+
}, {
|
|
40
|
+
revalidate: false,
|
|
41
|
+
});
|
|
27
42
|
});
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
43
|
+
// emit events;
|
|
44
|
+
ee.emit("orders:changed", {
|
|
45
|
+
...data,
|
|
46
|
+
status: data.status || data.algoStatus,
|
|
47
|
+
});
|
|
48
|
+
}, 50, {
|
|
49
|
+
trailing: true,
|
|
50
|
+
});
|
|
31
51
|
// orders
|
|
32
52
|
useEffect(() => {
|
|
33
53
|
if (!state.accountId)
|
|
34
54
|
return;
|
|
35
55
|
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
36
56
|
onMessage: (data) => {
|
|
37
|
-
updateOrders(data);
|
|
38
|
-
ee.emit("orders:changed", data);
|
|
57
|
+
updateOrders(data, false);
|
|
39
58
|
},
|
|
40
59
|
});
|
|
41
60
|
return () => unsubscribe?.();
|
|
@@ -46,12 +65,15 @@ export const usePrivateDataObserver = (options) => {
|
|
|
46
65
|
return;
|
|
47
66
|
const unsubscribe = ws.privateSubscribe("algoexecutionreport", {
|
|
48
67
|
onMessage: (data) => {
|
|
49
|
-
updateOrders(data);
|
|
50
68
|
if (Array.isArray(data)) {
|
|
51
|
-
data.forEach((item) =>
|
|
69
|
+
data.forEach((item) => {
|
|
70
|
+
updateOrders(item, true);
|
|
71
|
+
// ee.emit("orders:changed", { ...item, status: item.algoStatus });
|
|
72
|
+
});
|
|
52
73
|
}
|
|
53
74
|
else {
|
|
54
|
-
|
|
75
|
+
updateOrders(data, true);
|
|
76
|
+
// ee.emit("orders:changed", { ...data, status: data.algoStatus });
|
|
55
77
|
}
|
|
56
78
|
},
|
|
57
79
|
});
|
|
@@ -109,18 +131,14 @@ export const usePrivateDataObserver = (options) => {
|
|
|
109
131
|
unsubscribe?.();
|
|
110
132
|
};
|
|
111
133
|
}, [state.accountId]);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
console.warn(`Error reading sessionStorage key “${key}”:`, error);
|
|
124
|
-
return initialValue;
|
|
125
|
-
}
|
|
134
|
+
// cache algo orders
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
const handler = (data) => {
|
|
137
|
+
algoOrderCacheQuneue.current.push(data);
|
|
138
|
+
};
|
|
139
|
+
ee.on("algoOrder:cache", handler);
|
|
140
|
+
return () => {
|
|
141
|
+
ee.off("algoOrder:cache", handler);
|
|
142
|
+
};
|
|
143
|
+
}, []);
|
|
126
144
|
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { PosterPainter } from "./painter";
|
|
2
2
|
export type posterDataSource = {
|
|
3
|
+
/**
|
|
4
|
+
* slogan of the poster
|
|
5
|
+
*/
|
|
3
6
|
message?: string;
|
|
4
7
|
position: {
|
|
5
8
|
symbol: string;
|
|
@@ -17,7 +20,7 @@ export type posterDataSource = {
|
|
|
17
20
|
*/
|
|
18
21
|
ROI: number;
|
|
19
22
|
/**
|
|
20
|
-
* The informations of the position, such as open price, opened at, mark price, quantity
|
|
23
|
+
* The informations of the position, such as open price, opened at, mark price, quantity and custom message.
|
|
21
24
|
*/
|
|
22
25
|
informations: {
|
|
23
26
|
title: string;
|
|
@@ -64,6 +67,7 @@ export type drawOptions = {
|
|
|
64
67
|
* Color of common text
|
|
65
68
|
*/
|
|
66
69
|
color?: string;
|
|
70
|
+
fontFamily?: string;
|
|
67
71
|
/**
|
|
68
72
|
* Lose color
|
|
69
73
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basePaint.d.ts","sourceRoot":"","sources":["../../../src/services/painter/basePaint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAA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AAwB;IACvC,SAAS,CAAC,OAAO,EAAE,aAAa;gBADtB,GAAG,EAAE,wBAAwB,EAC7B,OAAO,EAAE,aAAa;IAElC,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CACnD"}
|
|
@@ -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;IAE1C,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;IAE1C,IAAI,CAAC,OAAO,EAAE,WAAW;IA8B/B,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,YAAY;IA0EpB,OAAO,CAAC,iBAAiB;IAwDzB,OAAO,CAAC,gBAAgB;IAsCxB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,SAAS;IAsCjB,OAAO,CAAC,MAAM;CAGf"}
|
|
@@ -9,17 +9,19 @@ export class DataPaint extends BasePaint {
|
|
|
9
9
|
this.DEFAULT_LOSE_COLOR = "rgb(255,103,194)";
|
|
10
10
|
}
|
|
11
11
|
async draw(options) {
|
|
12
|
-
|
|
12
|
+
const needDrawDetails = Array.isArray(options.data?.position?.informations) &&
|
|
13
|
+
(options.data?.position?.informations?.length ?? 0) > 0;
|
|
14
|
+
const offsetTop = 50;
|
|
13
15
|
if (!!options.data?.message) {
|
|
14
16
|
this.drawMessage(options);
|
|
15
17
|
}
|
|
16
18
|
if (!!options.data?.position) {
|
|
17
|
-
this.drawPosition(options);
|
|
19
|
+
this.drawPosition(options, needDrawDetails ? 0 : offsetTop);
|
|
18
20
|
}
|
|
19
|
-
if (
|
|
21
|
+
if (needDrawDetails) {
|
|
20
22
|
this.drawInformations(options);
|
|
21
23
|
}
|
|
22
|
-
this.drawUnrealizedPnL(options);
|
|
24
|
+
this.drawUnrealizedPnL(options, needDrawDetails ? 0 : offsetTop);
|
|
23
25
|
if (!!options.data?.domain) {
|
|
24
26
|
this.drawDomainUrl(options);
|
|
25
27
|
}
|
|
@@ -37,12 +39,14 @@ export class DataPaint extends BasePaint {
|
|
|
37
39
|
top: this._ratio(position.top),
|
|
38
40
|
left: this._ratio(position.left),
|
|
39
41
|
textBaseline: "top",
|
|
42
|
+
fontFamily: options.fontFamily,
|
|
40
43
|
});
|
|
41
44
|
}
|
|
42
|
-
drawPosition(options) {
|
|
45
|
+
drawPosition(options, offsetTop = 0) {
|
|
43
46
|
const layout = path(["layout", "position"], options);
|
|
44
47
|
const { position } = layout;
|
|
45
48
|
let left = this._ratio(position.left);
|
|
49
|
+
let top = position.top + offsetTop;
|
|
46
50
|
let prevElementBoundingBox = {};
|
|
47
51
|
// draw position side;
|
|
48
52
|
if (typeof options.data?.position.side !== "undefined") {
|
|
@@ -51,8 +55,9 @@ export class DataPaint extends BasePaint {
|
|
|
51
55
|
? this.DEFAULT_PROFIT_COLOR
|
|
52
56
|
: this.DEFAULT_LOSE_COLOR,
|
|
53
57
|
left,
|
|
54
|
-
top: this._ratio(
|
|
58
|
+
top: this._ratio(top),
|
|
55
59
|
fontSize: this._ratio(14),
|
|
60
|
+
fontFamily: options.fontFamily,
|
|
56
61
|
});
|
|
57
62
|
}
|
|
58
63
|
if (typeof options.data?.position.symbol !== "undefined") {
|
|
@@ -61,16 +66,18 @@ export class DataPaint extends BasePaint {
|
|
|
61
66
|
prevElementBoundingBox = this._drawText("|", {
|
|
62
67
|
color: "rgba(255,255,255,0.2)",
|
|
63
68
|
left,
|
|
64
|
-
top: this._ratio(
|
|
69
|
+
top: this._ratio(top),
|
|
65
70
|
fontSize: this._ratio(12),
|
|
71
|
+
fontFamily: options.fontFamily,
|
|
66
72
|
});
|
|
67
73
|
}
|
|
68
74
|
left += (prevElementBoundingBox.width ?? 0) + this._ratio(7);
|
|
69
75
|
prevElementBoundingBox = this._drawText(options.data?.position.symbol, {
|
|
70
76
|
color: "rgba(255,255,255,0.98)",
|
|
71
77
|
left: left,
|
|
72
|
-
top: this._ratio(
|
|
78
|
+
top: this._ratio(top),
|
|
73
79
|
fontSize: this._ratio(12),
|
|
80
|
+
fontFamily: options.fontFamily,
|
|
74
81
|
});
|
|
75
82
|
}
|
|
76
83
|
if (typeof options.data?.position.leverage !== "undefined") {
|
|
@@ -79,25 +86,28 @@ export class DataPaint extends BasePaint {
|
|
|
79
86
|
prevElementBoundingBox = this._drawText("|", {
|
|
80
87
|
color: "rgba(255,255,255,0.2)",
|
|
81
88
|
left,
|
|
82
|
-
top: this._ratio(
|
|
89
|
+
top: this._ratio(top),
|
|
83
90
|
fontSize: this._ratio(12),
|
|
91
|
+
fontFamily: options.fontFamily,
|
|
84
92
|
});
|
|
85
93
|
}
|
|
86
94
|
left += (prevElementBoundingBox.width ?? 0) + this._ratio(7);
|
|
87
95
|
prevElementBoundingBox = this._drawText(`${options.data?.position.leverage}X`, {
|
|
88
96
|
color: "rgba(255,255,255,0.98)",
|
|
89
97
|
left,
|
|
90
|
-
top: this._ratio(
|
|
98
|
+
top: this._ratio(top),
|
|
91
99
|
fontSize: this._ratio(12),
|
|
100
|
+
fontFamily: options.fontFamily,
|
|
92
101
|
});
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
|
-
drawUnrealizedPnL(options) {
|
|
104
|
+
drawUnrealizedPnL(options, offsetTop = 0) {
|
|
96
105
|
// reset left value;
|
|
97
106
|
const layout = path(["layout", "unrealizedPnl"], options);
|
|
98
107
|
const { position } = layout;
|
|
99
108
|
let left = this._ratio(position.left);
|
|
100
109
|
let prevElementBoundingBox = {};
|
|
110
|
+
const top = (position.top ?? 0) + offsetTop;
|
|
101
111
|
// ROI
|
|
102
112
|
if (typeof options.data?.position.ROI !== "undefined") {
|
|
103
113
|
const prefix = options.data?.position.ROI > 0 ? "+" : "";
|
|
@@ -106,9 +116,10 @@ export class DataPaint extends BasePaint {
|
|
|
106
116
|
? options.profitColor || this.DEFAULT_PROFIT_COLOR
|
|
107
117
|
: options.loseColor || this.DEFAULT_LOSE_COLOR,
|
|
108
118
|
left,
|
|
109
|
-
top: this._ratio(
|
|
119
|
+
top: this._ratio(top),
|
|
110
120
|
fontSize: this._ratio(layout.fontSize),
|
|
111
121
|
fontWeight: 700,
|
|
122
|
+
fontFamily: options.fontFamily,
|
|
112
123
|
});
|
|
113
124
|
}
|
|
114
125
|
// unrelPnL
|
|
@@ -125,30 +136,39 @@ export class DataPaint extends BasePaint {
|
|
|
125
136
|
prevElementBoundingBox = this._drawText(text, {
|
|
126
137
|
color: "rgba(255,255,255,0.5)",
|
|
127
138
|
left,
|
|
128
|
-
top: this._ratio(
|
|
139
|
+
top: this._ratio(top),
|
|
129
140
|
fontSize: this._ratio(layout.fontSize * 0.6),
|
|
130
141
|
fontWeight: 600,
|
|
142
|
+
fontFamily: options.fontFamily,
|
|
131
143
|
});
|
|
132
144
|
}
|
|
133
145
|
}
|
|
134
146
|
drawInformations(options) {
|
|
135
147
|
const layout = path(["layout", "informations"], options);
|
|
136
148
|
const { position } = layout;
|
|
149
|
+
const isVertical = (options.data?.position.informations.length ?? 0) === 2;
|
|
137
150
|
options.data?.position.informations.forEach((info, index) => {
|
|
138
|
-
|
|
139
|
-
|
|
151
|
+
// let cellWidth = this.positionInfoCellWidth;
|
|
152
|
+
let left = position.left + this.positionInfoCellWidth * Math.floor(index / 2);
|
|
153
|
+
let top = position.top + (index % 2) * 40;
|
|
154
|
+
// if (isVertical && index === 1) {
|
|
155
|
+
// left = position.left!;
|
|
156
|
+
// top = (position.top as number) + index * 40;
|
|
157
|
+
// }
|
|
140
158
|
this._drawText(info.title, {
|
|
141
159
|
left: this._ratio(left),
|
|
142
160
|
top: this._ratio(top),
|
|
143
161
|
fontSize: this._ratio(10),
|
|
144
162
|
color: "rgba(255,255,255,0.2)",
|
|
163
|
+
fontFamily: options.fontFamily,
|
|
145
164
|
});
|
|
146
165
|
this._drawText(info.value, {
|
|
147
|
-
left: this._ratio(
|
|
166
|
+
left: this._ratio(left),
|
|
148
167
|
top: this._ratio(top + 17),
|
|
149
168
|
fontSize: this._ratio(layout.fontSize),
|
|
150
169
|
fontWeight: 500,
|
|
151
170
|
color: layout.color,
|
|
171
|
+
fontFamily: options.fontFamily,
|
|
152
172
|
});
|
|
153
173
|
});
|
|
154
174
|
}
|
|
@@ -161,6 +181,7 @@ export class DataPaint extends BasePaint {
|
|
|
161
181
|
top: this._ratio(top),
|
|
162
182
|
fontSize: this._ratio(layout.fontSize),
|
|
163
183
|
color: options.brandColor ?? this.DEFAULT_PROFIT_COLOR,
|
|
184
|
+
fontFamily: options.fontFamily,
|
|
164
185
|
});
|
|
165
186
|
}
|
|
166
187
|
drawPositionTime(options) {
|
|
@@ -174,13 +195,15 @@ export class DataPaint extends BasePaint {
|
|
|
174
195
|
fontSize: this._ratio(layout.fontSize),
|
|
175
196
|
color: layout.color,
|
|
176
197
|
textAlign: "end",
|
|
198
|
+
fontFamily: options.fontFamily,
|
|
177
199
|
});
|
|
178
200
|
}
|
|
179
201
|
_drawText(str, options) {
|
|
180
202
|
let boundingBox;
|
|
181
203
|
const { left = 30, top = 30, fontSize = 13, fontWeight = 500, color = "black", textBaseline = "middle", textAlign = "start", } = options ?? {};
|
|
182
204
|
this.ctx.save();
|
|
183
|
-
|
|
205
|
+
// "Nunito Sans",-apple-system,"San Francisco",BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Helvetica,Arial,sans-serif
|
|
206
|
+
this.ctx.font = `${fontWeight} ${fontSize}px ${options?.fontFamily}`;
|
|
184
207
|
this.ctx.fillStyle = color;
|
|
185
208
|
this.ctx.textBaseline = textBaseline;
|
|
186
209
|
this.ctx.textAlign = textAlign;
|