@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/useMutation.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type SWRMutationConfiguration } from "swr/mutation";
|
|
2
2
|
type HTTP_METHOD = "POST" | "PUT" | "DELETE";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* This hook is used to execute API requests for data mutation, such as POST, DELETE, PUT, etc.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useMutation: <T, E>(url: string, method?: HTTP_METHOD, options?: SWRMutationConfiguration<T, E> | undefined) => readonly [(data: Record<string, any> | null, params?: Record<string, any>, options?: SWRMutationConfiguration<T, E> | undefined) => Promise<any>, {
|
|
4
7
|
readonly data: any;
|
|
5
8
|
readonly error: E | undefined;
|
|
6
9
|
readonly reset: () => void;
|
package/esm/useMutation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../src/useMutation.ts"],"names":[],"mappings":"AAAA,OAAuB,EAErB,KAAK,wBAAwB,EAE9B,MAAM,cAAc,CAAC;AAStB,KAAK,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAmC7C,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../src/useMutation.ts"],"names":[],"mappings":"AAAA,OAAuB,EAErB,KAAK,wBAAwB,EAE9B,MAAM,cAAc,CAAC;AAStB,KAAK,WAAW,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAmC7C;;GAEG;AACH,eAAO,MAAM,WAAW,cAKjB,MAAM,WAIH,WAAW,4EA6BX,OAAO,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,WAIvB,OAAO,MAAM,EAAE,GAAG,CAAC,2DAE3B,QAAQ,GAAG,CAAC;;;;;EAsChB,CAAC"}
|
package/esm/useMutation.js
CHANGED
|
@@ -19,7 +19,26 @@ const fetcher = (url, options) => {
|
|
|
19
19
|
}
|
|
20
20
|
return mutate(url, init);
|
|
21
21
|
};
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* This hook is used to execute API requests for data mutation, such as POST, DELETE, PUT, etc.
|
|
24
|
+
*/
|
|
25
|
+
export const useMutation = (
|
|
26
|
+
/**
|
|
27
|
+
* The URL to send the request to. If the URL does not start with "http",
|
|
28
|
+
* it will be prefixed with the API base URL.
|
|
29
|
+
*/
|
|
30
|
+
url,
|
|
31
|
+
/**
|
|
32
|
+
* The HTTP method to use for the request. Defaults to "POST".
|
|
33
|
+
*/
|
|
34
|
+
method = "POST",
|
|
35
|
+
/**
|
|
36
|
+
* The configuration object for the mutation.
|
|
37
|
+
* @see [useSWRMutation](https://swr.vercel.app/docs/mutation#api)
|
|
38
|
+
*
|
|
39
|
+
* @link https://swr.vercel.app/docs/mutation#api
|
|
40
|
+
*/
|
|
41
|
+
options) => {
|
|
23
42
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
24
43
|
let fullUrl = url;
|
|
25
44
|
if (!url.startsWith("http")) {
|
|
@@ -30,7 +49,15 @@ export const useMutation = (url, method = "POST", options) => {
|
|
|
30
49
|
const { trigger, data, error, reset, isMutating } = useSWRMutation(fullUrl,
|
|
31
50
|
// method === "POST" ? fetcher : deleteFetcher,
|
|
32
51
|
fetcher, options);
|
|
33
|
-
const mutation = async (
|
|
52
|
+
const mutation = async (
|
|
53
|
+
/**
|
|
54
|
+
* The data to send with the request.
|
|
55
|
+
*/
|
|
56
|
+
data,
|
|
57
|
+
/**
|
|
58
|
+
* The query parameters to send with the request.
|
|
59
|
+
*/
|
|
60
|
+
params, options) => {
|
|
34
61
|
let newUrl = url;
|
|
35
62
|
if (typeof params === "object" && Object.keys(params).length) {
|
|
36
63
|
let search = new URLSearchParams(params);
|
package/esm/usePoster.d.ts
CHANGED
|
@@ -2,13 +2,35 @@ import { type drawOptions } from "./services/painter/basePaint";
|
|
|
2
2
|
export { type drawOptions } from "./services/painter/basePaint";
|
|
3
3
|
/**
|
|
4
4
|
* Generates a poster image based on position information. You can set the size, background color, font color, font size, and content position of the poster.
|
|
5
|
-
* @
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const { ref, toDataURL, toBlob, download, copy } = usePoster({
|
|
8
|
+
* backgroundColor: "#0b8c70",
|
|
9
|
+
* backgroundImg: "/images/poster_bg.png",
|
|
10
|
+
* color: "rgba(255, 255, 255, 0.98)",
|
|
11
|
+
* profitColor: "rgb(0,181,159)",
|
|
12
|
+
* ...
|
|
13
|
+
* });
|
|
6
14
|
*/
|
|
7
|
-
export declare const usePoster: (
|
|
15
|
+
export declare const usePoster: (options: drawOptions) => {
|
|
8
16
|
readonly error: Error | null;
|
|
17
|
+
readonly ref: (ref: HTMLCanvasElement | null) => void;
|
|
9
18
|
/**
|
|
10
19
|
* Converts the poster to a data URL
|
|
11
20
|
*/
|
|
12
21
|
readonly toDataURL: (type?: string, encoderOptions?: number) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Converts the poster to a blob
|
|
24
|
+
*/
|
|
25
|
+
readonly toBlob: (type?: string, encoderOptions?: number) => Promise<Blob | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Downloads the poster as an image
|
|
28
|
+
*/
|
|
29
|
+
readonly download: (filename: string, type?: string, encoderOptions?: number) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Browser if supports copy image to clipboard
|
|
32
|
+
*/
|
|
33
|
+
readonly canCopy: boolean;
|
|
34
|
+
readonly copy: () => Promise<void>;
|
|
13
35
|
};
|
|
14
36
|
//# sourceMappingURL=usePoster.d.ts.map
|
package/esm/usePoster.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePoster.d.ts","sourceRoot":"","sources":["../src/usePoster.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"usePoster.d.ts","sourceRoot":"","sources":["../src/usePoster.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAIhE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,SAAS,YAIX,WAAW;;wBAuDF,iBAAiB,GAAG,IAAI;IAkDxC;;OAEG;gCA3EqB,MAAM,mBAAmB,MAAM;IA6EvD;;OAEG;6BApEK,MAAM,mBAAmB,MAAM,KAAG,QAAQ,IAAI,GAAG,IAAI,CAAC;IAsE9D;;OAEG;kCAjDQ,MAAM,SAAQ,MAAM,mBAAiC,MAAM;IAmDtE;;OAEG;;;CAIN,CAAC"}
|
package/esm/usePoster.js
CHANGED
|
@@ -1,52 +1,120 @@
|
|
|
1
|
-
import { useEffect, useRef, useState } from "react";
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
2
|
import { mergeDeepRight } from "ramda";
|
|
3
3
|
import { PosterPainter } from "./services/painter/painter";
|
|
4
4
|
import { defaultLayoutConfig } from "./services/painter/layout.config";
|
|
5
|
+
import { SDKError } from "@orderly.network/types";
|
|
5
6
|
/**
|
|
6
7
|
* Generates a poster image based on position information. You can set the size, background color, font color, font size, and content position of the poster.
|
|
7
|
-
* @
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const { ref, toDataURL, toBlob, download, copy } = usePoster({
|
|
11
|
+
* backgroundColor: "#0b8c70",
|
|
12
|
+
* backgroundImg: "/images/poster_bg.png",
|
|
13
|
+
* color: "rgba(255, 255, 255, 0.98)",
|
|
14
|
+
* profitColor: "rgb(0,181,159)",
|
|
15
|
+
* ...
|
|
16
|
+
* });
|
|
8
17
|
*/
|
|
9
18
|
export const usePoster = (
|
|
10
|
-
/**
|
|
11
|
-
* The canvas element to draw the poster on
|
|
12
|
-
*/
|
|
13
|
-
trage,
|
|
14
19
|
/**
|
|
15
20
|
* The options to draw the poster
|
|
16
21
|
*/
|
|
17
22
|
options) => {
|
|
18
23
|
const [error, setError] = useState(null);
|
|
24
|
+
const [canCopy, setCanCopy] = useState(() => typeof navigator.clipboard !== "undefined");
|
|
19
25
|
const painterRef = useRef(null);
|
|
26
|
+
const [target, setTarget] = useState(null);
|
|
20
27
|
useEffect(() => {
|
|
21
28
|
// Create the painter instance
|
|
22
|
-
if (
|
|
23
|
-
painterRef.current = new PosterPainter(
|
|
24
|
-
painterRef.current.draw(mergeDeepRight({ layout: defaultLayoutConfig }, options));
|
|
29
|
+
if (target && !painterRef.current) {
|
|
30
|
+
painterRef.current = new PosterPainter(target);
|
|
31
|
+
painterRef.current.draw(mergeDeepRight({ layout: defaultLayoutConfig, fontFamily: "Manrope" }, options));
|
|
25
32
|
}
|
|
26
|
-
}, [
|
|
33
|
+
}, [target]);
|
|
27
34
|
useEffect(() => {
|
|
28
35
|
if (painterRef.current) {
|
|
29
36
|
painterRef.current.draw(mergeDeepRight({ layout: defaultLayoutConfig }, options));
|
|
30
37
|
}
|
|
31
38
|
}, [options]);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
type = "image/png",
|
|
39
|
+
const toDataURL = (type, encoderOptions) => {
|
|
40
|
+
if (!target) {
|
|
41
|
+
throw new SDKError("The ref must be a canvas element");
|
|
42
|
+
}
|
|
43
|
+
return target.toDataURL(type, encoderOptions);
|
|
44
|
+
};
|
|
39
45
|
/**
|
|
40
|
-
*
|
|
46
|
+
* Converts the poster to a blob
|
|
41
47
|
*/
|
|
42
|
-
|
|
43
|
-
return
|
|
48
|
+
const toBlob = useCallback((type, encoderOptions) => {
|
|
49
|
+
return new Promise((resolve) => {
|
|
50
|
+
if (!target) {
|
|
51
|
+
resolve(null);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
target.toBlob(resolve, type, encoderOptions);
|
|
55
|
+
});
|
|
56
|
+
}, [target]);
|
|
57
|
+
const ref = (ref) => {
|
|
58
|
+
if (!ref)
|
|
59
|
+
return;
|
|
60
|
+
if (ref.tagName.toUpperCase() !== "CANVAS") {
|
|
61
|
+
// throw new Error("The ref must be a canvas element");
|
|
62
|
+
setError(new SDKError("The ref must be a canvas element"));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
setTarget(ref);
|
|
44
66
|
};
|
|
67
|
+
const download = useCallback((filename, type = "image/png", encoderOptions) => {
|
|
68
|
+
if (!target) {
|
|
69
|
+
throw new SDKError("The ref must be a canvas element");
|
|
70
|
+
}
|
|
71
|
+
const img = new Image();
|
|
72
|
+
img.src = target.toDataURL(type, encoderOptions);
|
|
73
|
+
const link = document.createElement("a");
|
|
74
|
+
link.href = img.src;
|
|
75
|
+
link.download = filename;
|
|
76
|
+
link.click();
|
|
77
|
+
}, [target]);
|
|
78
|
+
const copy = useCallback(() => {
|
|
79
|
+
if (!target) {
|
|
80
|
+
throw new SDKError("The ref must be a canvas element");
|
|
81
|
+
}
|
|
82
|
+
// copy image to clipboard
|
|
83
|
+
return new Promise((resolve, reject) => {
|
|
84
|
+
if (!navigator.clipboard) {
|
|
85
|
+
reject(new SDKError("Clipboard API is not supported"));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
target.toBlob((blob) => {
|
|
89
|
+
if (!blob) {
|
|
90
|
+
reject(new SDKError("Failed to create blob"));
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return navigator.clipboard
|
|
94
|
+
.write([new ClipboardItem({ [blob.type]: blob })])
|
|
95
|
+
.then(resolve, reject);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
}, [target]);
|
|
45
99
|
return {
|
|
46
100
|
error,
|
|
101
|
+
ref,
|
|
47
102
|
/**
|
|
48
103
|
* Converts the poster to a data URL
|
|
49
104
|
*/
|
|
50
105
|
toDataURL,
|
|
106
|
+
/**
|
|
107
|
+
* Converts the poster to a blob
|
|
108
|
+
*/
|
|
109
|
+
toBlob,
|
|
110
|
+
/**
|
|
111
|
+
* Downloads the poster as an image
|
|
112
|
+
*/
|
|
113
|
+
download,
|
|
114
|
+
/**
|
|
115
|
+
* Browser if supports copy image to clipboard
|
|
116
|
+
*/
|
|
117
|
+
canCopy,
|
|
118
|
+
copy,
|
|
51
119
|
};
|
|
52
120
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../src/utils/dev.ts"],"names":[],"mappings":""}
|
package/esm/utils/dev.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SimpleDI } from "@orderly.network/core";
|
|
2
|
+
const __ORDERLY__DEBUGER_TAG = "__ORDERLY__DEBUGER";
|
|
3
|
+
function debugPrint(msg, tag) {
|
|
4
|
+
tag = `${__ORDERLY__DEBUGER_TAG}:${tag} `;
|
|
5
|
+
if (!window.__ORDERLY__DEBUGER) {
|
|
6
|
+
console.log("${tag}${msg}");
|
|
7
|
+
// console.info(
|
|
8
|
+
// "You can add `DebugPrinter` component to see the data in your UI"
|
|
9
|
+
// );
|
|
10
|
+
}
|
|
11
|
+
let ee = SimpleDI.get("EE");
|
|
12
|
+
if (ee && msg) {
|
|
13
|
+
ee.emit("print:data", msg);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
if (typeof window !== "undefined") {
|
|
17
|
+
window.debugPrint = debugPrint;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { API } from "@orderly.network/types";
|
|
2
|
+
import { WSMessage } from "@orderly.network/types";
|
|
3
|
+
export declare const generateKeyFun: (args: {
|
|
4
|
+
status?: string;
|
|
5
|
+
symbol?: string;
|
|
6
|
+
side?: string;
|
|
7
|
+
size?: number;
|
|
8
|
+
}) => (pageIndex: number, previousPageData: any) => string | null;
|
|
9
|
+
export declare const updateOrdersHandler: (key: string, updatedOrder: WSMessage.AlgoOrder | WSMessage.Order, orders?: API.OrderResponse[]) => unknown[] | undefined;
|
|
10
|
+
//# sourceMappingURL=swr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swr.d.ts","sourceRoot":"","sources":["../../src/utils/swr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAInD,eAAO,MAAM,cAAc,SAClB;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,iBAC7D,MAAM,oBAAoB,GAAG,KAAG,MAAM,GAAG,IAyBpD,CAAC;AAEJ,eAAO,MAAM,mBAAmB,QACzB,MAAM,gBACG,UAAU,SAAS,GAAG,UAAU,KAAK,WAC1C,IAAI,aAAa,EAAE,0BAyG7B,CAAC"}
|
package/esm/utils/swr.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { camelCaseToUnderscoreCase } from "@orderly.network/utils";
|
|
2
|
+
import { lensIndex, over } from "ramda";
|
|
3
|
+
export const generateKeyFun = (args) => (pageIndex, previousPageData) => {
|
|
4
|
+
// reached the end
|
|
5
|
+
if (previousPageData && !previousPageData.rows?.length)
|
|
6
|
+
return null;
|
|
7
|
+
const { status, symbol, side, size = 100 } = args;
|
|
8
|
+
const search = new URLSearchParams([
|
|
9
|
+
["size", size.toString()],
|
|
10
|
+
["page", `${pageIndex + 1}`],
|
|
11
|
+
["source_type", "ALL"],
|
|
12
|
+
]);
|
|
13
|
+
if (status) {
|
|
14
|
+
search.set(`status`, status);
|
|
15
|
+
}
|
|
16
|
+
if (symbol) {
|
|
17
|
+
search.set(`symbol`, symbol);
|
|
18
|
+
}
|
|
19
|
+
if (side) {
|
|
20
|
+
search.set(`side`, side);
|
|
21
|
+
}
|
|
22
|
+
return `/v1/orders?${search.toString()}`;
|
|
23
|
+
};
|
|
24
|
+
export const updateOrdersHandler = (key, updatedOrder, orders) => {
|
|
25
|
+
if (!orders) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
// console.log(key);
|
|
29
|
+
const isAlgoOrder = "algoOrderId" in updatedOrder;
|
|
30
|
+
let formattedOrder = {
|
|
31
|
+
...object2underscore(updatedOrder),
|
|
32
|
+
created_time: updatedOrder.timestamp,
|
|
33
|
+
};
|
|
34
|
+
if (isAlgoOrder) {
|
|
35
|
+
if (typeof updatedOrder.triggerTradePrice !== "undefined") {
|
|
36
|
+
formattedOrder.trigger_price = updatedOrder.triggerTradePrice;
|
|
37
|
+
}
|
|
38
|
+
if (updatedOrder.type === "MARKET_ORDER") {
|
|
39
|
+
formattedOrder.price = undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// formattedOrder.created_time = updatedOrder.timestamp;
|
|
44
|
+
}
|
|
45
|
+
// const index = lensIndex(0);
|
|
46
|
+
const orderId = updatedOrder.orderId ||
|
|
47
|
+
updatedOrder.algoOrderId;
|
|
48
|
+
const isExisting = orderIsExisting(orders, orderId);
|
|
49
|
+
const status = updatedOrder.status ||
|
|
50
|
+
updatedOrder.rootAlgoStatus;
|
|
51
|
+
switch (status) {
|
|
52
|
+
case "NEW": {
|
|
53
|
+
// chceck if the order is already in the list
|
|
54
|
+
if (isExisting ||
|
|
55
|
+
key.startsWith("orders:CANCELLED") ||
|
|
56
|
+
key.startsWith("orders:FILLED") ||
|
|
57
|
+
key.startsWith("orders:REJECTED")) {
|
|
58
|
+
return orders;
|
|
59
|
+
}
|
|
60
|
+
return insertOrders(orders, formattedOrder);
|
|
61
|
+
}
|
|
62
|
+
case "CANCELLED": {
|
|
63
|
+
if (key.startsWith("orders:FILLED") ||
|
|
64
|
+
key.startsWith("orders:REJECTED")) {
|
|
65
|
+
return orders;
|
|
66
|
+
}
|
|
67
|
+
if (key.startsWith("orders:NEW") || key.startsWith("orders:INCOMPLETE")) {
|
|
68
|
+
return removeOrderIfExisting(orders, orderId);
|
|
69
|
+
}
|
|
70
|
+
if (key.startsWith("orders:CANCELLED")) {
|
|
71
|
+
return insertOrders(orders, formattedOrder);
|
|
72
|
+
}
|
|
73
|
+
return updateOrders(orders, formattedOrder);
|
|
74
|
+
}
|
|
75
|
+
case "REPLACED":
|
|
76
|
+
return updateOrders(orders, formattedOrder);
|
|
77
|
+
case "FILLED": {
|
|
78
|
+
if (isExisting) {
|
|
79
|
+
// for new list, remove the order if it exists
|
|
80
|
+
if (key.startsWith("orders:INCOMPLETE") ||
|
|
81
|
+
key.startsWith("orders:NEW")) {
|
|
82
|
+
// if fullfilled, remove from the list
|
|
83
|
+
if (updatedOrder.totalExecutedQuantity === updatedOrder.quantity) {
|
|
84
|
+
return removeOrderIfExisting(orders, orderId);
|
|
85
|
+
}
|
|
86
|
+
// update
|
|
87
|
+
return updateOrders(orders, formattedOrder);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// for filled list, insert the order if it doesn't exist
|
|
92
|
+
if (key.startsWith("orders:CANCELLED") ||
|
|
93
|
+
key.startsWith("orders:INCOMPLETE") ||
|
|
94
|
+
key.startsWith("orders:NEW")) {
|
|
95
|
+
return orders;
|
|
96
|
+
}
|
|
97
|
+
// if filled/history list:
|
|
98
|
+
return insertOrders(orders, formattedOrder);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
default:
|
|
102
|
+
return orders;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
function updateOrders(orders, formattedOrder) {
|
|
106
|
+
return orders.map((item) => {
|
|
107
|
+
return {
|
|
108
|
+
// ...item,
|
|
109
|
+
meta: item.meta,
|
|
110
|
+
rows: item.rows.map((order) => {
|
|
111
|
+
const isAlgoOrder = "algo_order_id" in order;
|
|
112
|
+
const updatedOrderId = isAlgoOrder
|
|
113
|
+
? formattedOrder.algo_order_id
|
|
114
|
+
: formattedOrder.order_id;
|
|
115
|
+
if (order.algo_order_id === updatedOrderId ||
|
|
116
|
+
order.order_id === updatedOrderId) {
|
|
117
|
+
return { ...order, ...formattedOrder };
|
|
118
|
+
}
|
|
119
|
+
return order;
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function insertOrders(orders, formattedOrder) {
|
|
125
|
+
const index = lensIndex(0);
|
|
126
|
+
return over(index, (item) => ({
|
|
127
|
+
meta: {
|
|
128
|
+
...item.meta,
|
|
129
|
+
total: item.meta.total + 1,
|
|
130
|
+
},
|
|
131
|
+
rows: [formattedOrder, ...item.rows],
|
|
132
|
+
}), orders);
|
|
133
|
+
}
|
|
134
|
+
function removeOrderIfExisting(orders, orderId) {
|
|
135
|
+
const isExisting = orderIsExisting(orders, orderId);
|
|
136
|
+
if (!isExisting)
|
|
137
|
+
return orders;
|
|
138
|
+
return orders.map((item) => {
|
|
139
|
+
return {
|
|
140
|
+
meta: { ...item.meta, total: item.meta.total - 1 },
|
|
141
|
+
rows: item.rows.filter((order) => {
|
|
142
|
+
const isAlgoOrder = "algo_order_id" in order;
|
|
143
|
+
return isAlgoOrder
|
|
144
|
+
? order.algo_order_id !== orderId
|
|
145
|
+
: order.order_id !== orderId;
|
|
146
|
+
}),
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
function findOrderIndex(orders, orderId) {
|
|
151
|
+
let index = 0;
|
|
152
|
+
let index2;
|
|
153
|
+
for (let idx = 0; idx < orders.length; idx++) {
|
|
154
|
+
index = idx;
|
|
155
|
+
const item = orders[idx];
|
|
156
|
+
for (let idx2 = 0; idx2 < item.rows.length; idx2++) {
|
|
157
|
+
const element = item.rows[idx2];
|
|
158
|
+
if (element.algo_order_id === orderId ||
|
|
159
|
+
element.order_id === orderId) {
|
|
160
|
+
index2 = idx2;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (typeof index2 === "undefined") {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
return [index, index2];
|
|
169
|
+
}
|
|
170
|
+
function orderIsExisting(orders, orderId) {
|
|
171
|
+
const index = findOrderIndex(orders, orderId);
|
|
172
|
+
return Array.isArray(index);
|
|
173
|
+
}
|
|
174
|
+
function object2underscore(obj) {
|
|
175
|
+
return Object.keys(obj).reduce((acc, key) => {
|
|
176
|
+
acc[camelCaseToUnderscoreCase(key)] = obj[key];
|
|
177
|
+
return acc;
|
|
178
|
+
}, {});
|
|
179
|
+
}
|
package/esm/version.d.ts
CHANGED
package/esm/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,mBAAmB,CAAC,EAAE;YAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACzB,CAAC;KACL;CACJ;;AAMD,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,mBAAmB,CAAC,EAAE;YAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;SACzB,CAAC;KACL;CACJ;;AAMD,wBAA+B"}
|
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.5-alpha.0";
|
|
4
4
|
}
|
|
5
5
|
;
|
|
6
|
-
export default "1.1.
|
|
6
|
+
export default "1.1.5-alpha.0";
|
package/lib/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/lib/dataProvider.js
CHANGED
|
@@ -27,8 +27,13 @@ const DataCenterProvider = ({ children }) => {
|
|
|
27
27
|
return null;
|
|
28
28
|
return ((0, jsx_runtime_1.jsx)(exports.DataCenterContext.Provider, { value: {
|
|
29
29
|
regesterKeyHandler: (key, fun) => {
|
|
30
|
+
console.log("regesterKeyHandler", key);
|
|
30
31
|
getKeyHandlerMapRef.current.set(key, fun);
|
|
31
32
|
},
|
|
33
|
+
unregisterKeyHandler: (key) => {
|
|
34
|
+
console.log("unregisterKeyHandler", key);
|
|
35
|
+
getKeyHandlerMapRef.current.delete(key);
|
|
36
|
+
},
|
|
32
37
|
}, children: children }));
|
|
33
38
|
};
|
|
34
39
|
exports.DataCenterProvider = DataCenterProvider;
|
package/lib/index.d.ts
CHANGED
package/lib/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,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EACL,sBAAsB,EACtB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAElC,cAAc,wBAAwB,CAAC;AAGvC,OAAO,MAAM,EAAE,EAAE,KAAK,gBAAgB,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AAE/D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,gBAAgB,EAAE,CAAC;AAEpD,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1D,cAAc,wBAAwB,CAAC;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAE5D,YAAY,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -30,6 +30,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
30
30
|
};
|
|
31
31
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
32
|
exports.cleanStringStyle = exports.usePoster = exports.useMediaQuery = exports.SWRConfig = exports.useSWR = exports.useWalletConnector = exports.WalletConnectorContext = exports.OrderlyConfigProvider = exports.WsNetworkStatus = exports.useWsStatus = exports.useConfig = exports.useWS = exports.useConstant = exports.parseJSON = exports.useLocalStorage = exports.useSessionStorage = exports.useEventEmitter = exports.usePreLoadData = exports.useAccountInstance = exports.useAccount = exports.useBoolean = exports.usePrivateInfiniteQuery = exports.usePrivateQuery = exports.useMutation = exports.useLazyQuery = exports.useQuery = exports.version = void 0;
|
|
33
|
+
require("./utils/dev");
|
|
33
34
|
var version_1 = require("./version");
|
|
34
35
|
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return __importDefault(version_1).default; } });
|
|
35
36
|
var useQuery_1 = require("./useQuery");
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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/lib/orderly/useMaxQty.js
CHANGED
|
@@ -20,32 +20,6 @@ const useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
20
20
|
const { totalCollateral } = (0, useCollateral_1.useCollateral)();
|
|
21
21
|
const { data: markPrices } = (0, useMarkPricesStream_1.useMarkPricesStream)();
|
|
22
22
|
const [orders] = (0, useOrderStream_1.useOrderStream)({ status: types_1.OrderStatus.NEW });
|
|
23
|
-
// const {
|
|
24
|
-
// data: orders,
|
|
25
|
-
// error,
|
|
26
|
-
// mutate: updateOrder,
|
|
27
|
-
// } = usePrivateQuery<API.Order[]>(`/v1/orders?status=NEW&size=99`, {
|
|
28
|
-
// formatter: (data) => data.rows,
|
|
29
|
-
// onError: (err) => { },
|
|
30
|
-
// });
|
|
31
|
-
// const ws = useWS();
|
|
32
|
-
// useEffect(() => {
|
|
33
|
-
// const unsubscribe = ws.privateSubscribe(
|
|
34
|
-
// {
|
|
35
|
-
// id: "executionreport_orders",
|
|
36
|
-
// event: "subscribe",
|
|
37
|
-
// topic: "executionreport",
|
|
38
|
-
// ts: Date.now(),
|
|
39
|
-
// },
|
|
40
|
-
// {
|
|
41
|
-
// onMessage: (data: any) => {
|
|
42
|
-
// console.log("refresh orders", data);
|
|
43
|
-
// updateOrder();
|
|
44
|
-
// },
|
|
45
|
-
// }
|
|
46
|
-
// );
|
|
47
|
-
// return () => unsubscribe();
|
|
48
|
-
// }, []);
|
|
49
23
|
const maxQty = (0, react_1.useMemo)(() => {
|
|
50
24
|
if (!symbol)
|
|
51
25
|
return 0;
|
|
@@ -113,6 +87,18 @@ const useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
113
87
|
totalCollateral,
|
|
114
88
|
reduceOnly,
|
|
115
89
|
]);
|
|
90
|
+
// debugPrint({
|
|
91
|
+
// maxQty,
|
|
92
|
+
// totalCollateral,
|
|
93
|
+
// side,
|
|
94
|
+
// // reduceOnly,
|
|
95
|
+
// orders: orders?.map((o) => o.quantity),
|
|
96
|
+
// // positionsData,
|
|
97
|
+
// // markPrices,
|
|
98
|
+
// // accountInfo,
|
|
99
|
+
// // symbolInfo,
|
|
100
|
+
// // symbol,
|
|
101
|
+
// });
|
|
116
102
|
return Math.max(maxQty, 0);
|
|
117
103
|
};
|
|
118
104
|
exports.useMaxQty = useMaxQty;
|
|
@@ -185,7 +185,7 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
185
185
|
]);
|
|
186
186
|
const isStopOrder = parsedData?.order_type === types_1.OrderType.STOP_LIMIT ||
|
|
187
187
|
parsedData?.order_type === types_1.OrderType.STOP_MARKET;
|
|
188
|
-
const [doCreateOrder, {
|
|
188
|
+
const [doCreateOrder, { isMutating }] = (0, useMutation_1.useMutation)(isStopOrder ? "/v1/algo/order" : "/v1/order");
|
|
189
189
|
// const maxQty = 3;
|
|
190
190
|
const createOrder = (values) => {
|
|
191
191
|
if (!values.symbol) {
|
|
@@ -236,9 +236,16 @@ function useOrderEntry(symbolOrOrder, sideOrOptions, reduceOnly, options) {
|
|
|
236
236
|
// ...omit(["order_price"], values),
|
|
237
237
|
...data,
|
|
238
238
|
})).then((res) => {
|
|
239
|
-
|
|
239
|
+
console.log("--------------------res::::", res);
|
|
240
240
|
// resolve(res);
|
|
241
241
|
if (res.success) {
|
|
242
|
+
// TODO: remove when the WS service is fixed
|
|
243
|
+
if (Array.isArray(res.data.rows)) {
|
|
244
|
+
ee.emit("algoOrder:cache", {
|
|
245
|
+
...res.data.rows[0],
|
|
246
|
+
trigger_price: data.trigger_price,
|
|
247
|
+
});
|
|
248
|
+
}
|
|
242
249
|
resolve(res.data);
|
|
243
250
|
}
|
|
244
251
|
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[]>;
|