@yuants/app-virtual-exchange 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credential.js +35 -6
- package/dist/credential.js.map +1 -1
- package/dist/general.js +22 -37
- package/dist/general.js.map +1 -1
- package/lib/credential.d.ts +1 -0
- package/lib/credential.d.ts.map +1 -1
- package/lib/credential.js +37 -7
- package/lib/credential.js.map +1 -1
- package/lib/general.js +21 -36
- package/lib/general.js.map +1 -1
- package/package.json +1 -1
- package/temp/package-deps.json +5 -5
package/dist/credential.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { createCache } from '@yuants/cache';
|
|
1
2
|
import { getCredentialId } from '@yuants/exchange';
|
|
2
3
|
import { Terminal } from '@yuants/protocol';
|
|
3
4
|
import { readSecret, writeSecret } from '@yuants/secret';
|
|
4
5
|
import { escapeSQL, requestSQL } from '@yuants/sql';
|
|
6
|
+
import { newError } from '@yuants/utils';
|
|
5
7
|
import { defer, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';
|
|
6
8
|
const terminal = Terminal.fromNodeEnv();
|
|
7
9
|
const credentialReader = process.env.NODE_UNIT_PUBLIC_KEY || terminal.keyPair.public_key;
|
|
10
|
+
const credentialIdCache = createCache(async (credentialKey) => {
|
|
11
|
+
const credential = JSON.parse(credentialKey);
|
|
12
|
+
const res = await getCredentialId(terminal, credential);
|
|
13
|
+
return res.data;
|
|
14
|
+
});
|
|
8
15
|
export const listAllCredentials = async () => {
|
|
9
16
|
const secrets = await requestSQL(terminal, `select * from secret where tags->>'type' = 'exchange_credential' and reader = ${escapeSQL(credentialReader)}`);
|
|
10
17
|
const results = secrets.map((secret) => ({ secret }));
|
|
@@ -13,9 +20,10 @@ export const listAllCredentials = async () => {
|
|
|
13
20
|
const decrypted = await readSecret(terminal, result.secret);
|
|
14
21
|
const credential = JSON.parse(new TextDecoder().decode(decrypted));
|
|
15
22
|
result.credential = credential;
|
|
16
|
-
const res = await
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
const res = await credentialIdCache.query(JSON.stringify(credential));
|
|
24
|
+
if (res) {
|
|
25
|
+
result.credentialId = res;
|
|
26
|
+
}
|
|
19
27
|
}
|
|
20
28
|
catch (e) {
|
|
21
29
|
result.reason = `${e}`;
|
|
@@ -33,8 +41,8 @@ terminal.server.provideService('VEX/RegisterExchangeCredential', {
|
|
|
33
41
|
}, async (msg) => {
|
|
34
42
|
const credential = msg.req;
|
|
35
43
|
const secretData = new TextEncoder().encode(JSON.stringify(credential));
|
|
36
|
-
await writeSecret(terminal, credentialReader, { type: 'exchange_credential' }, secretData);
|
|
37
|
-
return { res: { code: 0, message: 'OK' } };
|
|
44
|
+
const secret = await writeSecret(terminal, credentialReader, { type: 'exchange_credential' }, secretData);
|
|
45
|
+
return { res: { code: 0, message: 'OK', data: secret } };
|
|
38
46
|
});
|
|
39
47
|
terminal.server.provideService('VEX/ListExchangeCredential', {}, async () => {
|
|
40
48
|
return { res: { code: 0, message: 'OK', data: await listAllCredentials() } };
|
|
@@ -43,8 +51,11 @@ terminal.server.provideService('VEX/ListCredentials', {}, async () => {
|
|
|
43
51
|
const credentials = await firstValueFrom(validCredentials$);
|
|
44
52
|
return { res: { code: 0, message: 'OK', data: [...credentials.keys()] } };
|
|
45
53
|
});
|
|
46
|
-
|
|
54
|
+
const credentialCache = createCache(() => listAllCredentials(), { swrAfter: 10000, expire: 3600000 });
|
|
55
|
+
export const validCredentials$ = defer(() => credentialCache.query('')).pipe(map((x) => {
|
|
47
56
|
const map = new Map();
|
|
57
|
+
if (!x)
|
|
58
|
+
return map;
|
|
48
59
|
for (const xx of x) {
|
|
49
60
|
if (xx.credentialId && xx.credential) {
|
|
50
61
|
map.set(xx.credentialId, xx.credential);
|
|
@@ -63,4 +74,22 @@ export const getCredentialById = async (credential_id) => {
|
|
|
63
74
|
const credentials = await firstValueFrom(validCredentials$);
|
|
64
75
|
return credentials.get(credential_id);
|
|
65
76
|
};
|
|
77
|
+
export const getCredentialBySecretId = async (secret_id) => {
|
|
78
|
+
const allCredentials = await credentialCache.query('');
|
|
79
|
+
const theCredential = allCredentials === null || allCredentials === void 0 ? void 0 : allCredentials.find((x) => x.secret.sign === secret_id);
|
|
80
|
+
if (!theCredential) {
|
|
81
|
+
throw newError('CREDENTIAL_NOT_FOUND', { secret_id });
|
|
82
|
+
}
|
|
83
|
+
if (!theCredential.credential) {
|
|
84
|
+
throw newError('CREDENTIAL_NOT_RESOLVED', { secret_id });
|
|
85
|
+
}
|
|
86
|
+
if (!theCredential.credentialId) {
|
|
87
|
+
throw newError('CREDENTIAL_ID_NOT_RESOLVED', { secret_id });
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
secret: theCredential.secret,
|
|
91
|
+
credential: theCredential.credential,
|
|
92
|
+
credentialId: theCredential.credentialId,
|
|
93
|
+
};
|
|
94
|
+
};
|
|
66
95
|
//# sourceMappingURL=credential.js.map
|
package/dist/credential.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAW,UAAU,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAO9E,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC;AASzF,MAAM,CAAC,M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IACH,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC,CAAC,CACH,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,aAAqB,EAAE,EAAE;IAC/D,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,iBAAiB,CAAC,CAAC;IAC5D,OAAO,WAAW,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAC1C,SAAiB,EAC6E,EAAE;IAChG,MAAM,cAAc,GAAG,MAAM,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAC/E,IAAI,CAAC,aAAa,EAAE;QAClB,MAAM,QAAQ,CAAC,sBAAsB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;KACvD;IACD,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE;QAC7B,MAAM,QAAQ,CAAC,yBAAyB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;KAC1D;IACD,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;QAC/B,MAAM,QAAQ,CAAC,4BAA4B,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;KAC7D;IAED,OAAO;QACL,MAAM,EAAE,aAAa,CAAC,MAAM;QAC5B,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,YAAY,EAAE,aAAa,CAAC,YAAY;KACzC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getCredentialId } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { ISecret, readSecret, writeSecret } from '@yuants/secret';\nimport { escapeSQL, requestSQL } from '@yuants/sql';\nimport { newError } from '@yuants/utils';\nimport { defer, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';\n\nexport interface IExchangeCredential {\n type: string;\n payload: any;\n}\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credentialReader = process.env.NODE_UNIT_PUBLIC_KEY || terminal.keyPair.public_key;\n\ninterface ICredentialResolvedStatus {\n secret: ISecret;\n credential?: IExchangeCredential;\n credentialId?: string;\n reason?: string;\n}\n\nconst credentialIdCache = createCache(async (credentialKey: string) => {\n const credential = JSON.parse(credentialKey) as IExchangeCredential;\n const res = await getCredentialId(terminal, credential);\n return res.data;\n});\n\nexport const listAllCredentials = async () => {\n const secrets = await requestSQL<ISecret[]>(\n terminal,\n `select * from secret where tags->>'type' = 'exchange_credential' and reader = ${escapeSQL(\n credentialReader,\n )}`,\n );\n\n const results = secrets.map((secret): ICredentialResolvedStatus => ({ secret }));\n\n await Promise.all(\n results.map(async (result) => {\n try {\n const decrypted = await readSecret(terminal, result.secret);\n const credential = JSON.parse(new TextDecoder().decode(decrypted)) as IExchangeCredential;\n result.credential = credential;\n\n const res = await credentialIdCache.query(JSON.stringify(credential));\n if (res) {\n result.credentialId = res;\n }\n } catch (e) {\n result.reason = `${e}`;\n }\n }),\n );\n\n return results;\n};\n\nterminal.server.provideService<IExchangeCredential, ISecret>(\n 'VEX/RegisterExchangeCredential',\n {\n type: 'object',\n required: ['type', 'payload'],\n properties: {\n type: { type: 'string' },\n payload: { type: 'object' },\n },\n },\n async (msg) => {\n const credential = msg.req;\n const secretData = new TextEncoder().encode(JSON.stringify(credential));\n const secret = await writeSecret(terminal, credentialReader, { type: 'exchange_credential' }, secretData);\n return { res: { code: 0, message: 'OK', data: secret } };\n },\n);\n\nterminal.server.provideService<void, ICredentialResolvedStatus[]>(\n 'VEX/ListExchangeCredential',\n {},\n async () => {\n return { res: { code: 0, message: 'OK', data: await listAllCredentials() } };\n },\n);\n\nterminal.server.provideService<void, string[]>('VEX/ListCredentials', {}, async () => {\n const credentials = await firstValueFrom(validCredentials$);\n return { res: { code: 0, message: 'OK', data: [...credentials.keys()] } };\n});\n\nconst credentialCache = createCache(() => listAllCredentials(), { swrAfter: 10_000, expire: 3600_000 });\n\nexport const validCredentials$ = defer(() => credentialCache.query('')).pipe(\n map((x) => {\n const map = new Map<string, IExchangeCredential>();\n if (!x) return map;\n for (const xx of x) {\n if (xx.credentialId && xx.credential) {\n map.set(xx.credentialId, xx.credential);\n }\n }\n return map;\n }),\n repeat({ delay: 10000 }),\n retry({ delay: 5000 }),\n shareReplay(1),\n);\n\nexport const validCredentialTypes$ = validCredentials$.pipe(\n map((credentials) => {\n const types = new Set<string>();\n credentials.forEach((credential) => {\n types.add(credential.type);\n });\n return Array.from(types);\n }),\n);\n\nexport const getCredentialById = async (credential_id: string) => {\n const credentials = await firstValueFrom(validCredentials$);\n return credentials.get(credential_id);\n};\n\nexport const getCredentialBySecretId = async (\n secret_id: string,\n): Promise<Required<Pick<ICredentialResolvedStatus, 'secret' | 'credential' | 'credentialId'>>> => {\n const allCredentials = await credentialCache.query('');\n const theCredential = allCredentials?.find((x) => x.secret.sign === secret_id);\n if (!theCredential) {\n throw newError('CREDENTIAL_NOT_FOUND', { secret_id });\n }\n if (!theCredential.credential) {\n throw newError('CREDENTIAL_NOT_RESOLVED', { secret_id });\n }\n if (!theCredential.credentialId) {\n throw newError('CREDENTIAL_ID_NOT_RESOLVED', { secret_id });\n }\n\n return {\n secret: theCredential.secret,\n credential: theCredential.credential,\n credentialId: theCredential.credentialId,\n };\n};\n"]}
|
package/dist/general.js
CHANGED
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
import { cancelOrder, getOrders, getPositions, modifyOrder, submitOrder } from '@yuants/exchange';
|
|
2
2
|
import { Terminal } from '@yuants/protocol';
|
|
3
|
-
import {
|
|
3
|
+
import { getCredentialBySecretId } from './credential';
|
|
4
4
|
const terminal = Terminal.fromNodeEnv();
|
|
5
5
|
terminal.server.provideService('VEX/GetPositions', {
|
|
6
6
|
type: 'object',
|
|
7
|
-
required: ['
|
|
7
|
+
required: ['secret_id'],
|
|
8
8
|
properties: {
|
|
9
|
-
|
|
9
|
+
secret_id: { type: 'string' },
|
|
10
10
|
product_id: { type: 'string' },
|
|
11
11
|
},
|
|
12
12
|
}, async (msg) => {
|
|
13
|
-
const credential = await
|
|
14
|
-
|
|
15
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
16
|
-
}
|
|
17
|
-
const res = await getPositions(terminal, credential, msg.req.product_id);
|
|
13
|
+
const credential = await getCredentialBySecretId(msg.req.secret_id);
|
|
14
|
+
const res = await getPositions(terminal, credential.credential, msg.req.product_id);
|
|
18
15
|
return { res };
|
|
19
16
|
});
|
|
20
17
|
terminal.server.provideService('VEX/GetOrders', {
|
|
21
18
|
type: 'object',
|
|
22
|
-
required: ['
|
|
19
|
+
required: ['secret_id'],
|
|
23
20
|
properties: {
|
|
24
|
-
|
|
21
|
+
secret_id: { type: 'string' },
|
|
25
22
|
product_id: { type: 'string' },
|
|
26
23
|
},
|
|
27
24
|
}, async (msg) => {
|
|
28
25
|
var _a;
|
|
29
|
-
const credential = await
|
|
30
|
-
|
|
31
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
32
|
-
}
|
|
33
|
-
const res = await getOrders(terminal, credential, msg.req.product_id);
|
|
26
|
+
const credential = await getCredentialBySecretId(msg.req.secret_id);
|
|
27
|
+
const res = await getOrders(terminal, credential.credential, msg.req.product_id);
|
|
34
28
|
(_a = res.data) === null || _a === void 0 ? void 0 : _a.forEach((order) => {
|
|
35
|
-
order.account_id =
|
|
29
|
+
order.account_id = credential.credentialId;
|
|
36
30
|
});
|
|
37
31
|
return { res };
|
|
38
32
|
});
|
|
@@ -40,49 +34,40 @@ terminal.server.provideService('VEX/GetOrders', {
|
|
|
40
34
|
// SubmitOrder
|
|
41
35
|
terminal.server.provideService('VEX/SubmitOrder', {
|
|
42
36
|
type: 'object',
|
|
43
|
-
required: ['order', '
|
|
37
|
+
required: ['order', 'secret_id'],
|
|
44
38
|
properties: {
|
|
45
39
|
order: { type: 'object' },
|
|
46
|
-
|
|
40
|
+
secret_id: { type: 'string' },
|
|
47
41
|
},
|
|
48
42
|
}, async (msg) => {
|
|
49
|
-
const credential = await
|
|
50
|
-
|
|
51
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
52
|
-
}
|
|
53
|
-
const res = await submitOrder(terminal, credential, msg.req.order);
|
|
43
|
+
const credential = await getCredentialBySecretId(msg.req.secret_id);
|
|
44
|
+
const res = await submitOrder(terminal, credential.credential, msg.req.order);
|
|
54
45
|
return { res };
|
|
55
46
|
});
|
|
56
47
|
// ModifyOrder
|
|
57
48
|
terminal.server.provideService('VEX/ModifyOrder', {
|
|
58
49
|
type: 'object',
|
|
59
|
-
required: ['order', '
|
|
50
|
+
required: ['order', 'secret_id'],
|
|
60
51
|
properties: {
|
|
61
52
|
order: { type: 'object' },
|
|
62
|
-
|
|
53
|
+
secret_id: { type: 'string' },
|
|
63
54
|
},
|
|
64
55
|
}, async (msg) => {
|
|
65
|
-
const credential = await
|
|
66
|
-
|
|
67
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
68
|
-
}
|
|
69
|
-
const res = await modifyOrder(terminal, credential, msg.req.order);
|
|
56
|
+
const credential = await getCredentialBySecretId(msg.req.secret_id);
|
|
57
|
+
const res = await modifyOrder(terminal, credential.credential, msg.req.order);
|
|
70
58
|
return { res };
|
|
71
59
|
});
|
|
72
60
|
// CancelOrder
|
|
73
61
|
terminal.server.provideService('VEX/CancelOrder', {
|
|
74
62
|
type: 'object',
|
|
75
|
-
required: ['order', '
|
|
63
|
+
required: ['order', 'secret_id'],
|
|
76
64
|
properties: {
|
|
77
65
|
order: { type: 'object' },
|
|
78
|
-
|
|
66
|
+
secret_id: { type: 'string' },
|
|
79
67
|
},
|
|
80
68
|
}, async (msg) => {
|
|
81
|
-
const credential = await
|
|
82
|
-
|
|
83
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
84
|
-
}
|
|
85
|
-
const res = await cancelOrder(terminal, credential, msg.req.order);
|
|
69
|
+
const credential = await getCredentialBySecretId(msg.req.secret_id);
|
|
70
|
+
const res = await cancelOrder(terminal, credential.credential, msg.req.order);
|
|
86
71
|
return { res };
|
|
87
72
|
});
|
|
88
73
|
//# sourceMappingURL=general.js.map
|
package/dist/general.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general.js","sourceRoot":"","sources":["../src/general.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"general.js","sourceRoot":"","sources":["../src/general.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AAEvD,MAAM,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,kBAAkB,EAClB;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,WAAW,CAAC;IACvB,UAAU,EAAE;QACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QAC7B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC/B;CACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;IACZ,MAAM,UAAU,GAAG,MAAM,uBAAuB,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACpE,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,QAAQ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GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9E,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC,CACF,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { cancelOrder, getOrders, getPositions, modifyOrder, submitOrder } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { getCredentialBySecretId } from './credential';\n\nconst terminal = Terminal.fromNodeEnv();\n\nterminal.server.provideService<{ secret_id: string; product_id?: string }, IPosition[]>(\n 'VEX/GetPositions',\n {\n type: 'object',\n required: ['secret_id'],\n properties: {\n secret_id: { type: 'string' },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await getPositions(terminal, credential.credential, msg.req.product_id);\n return { res };\n },\n);\n\nterminal.server.provideService<{ secret_id: string; product_id?: string }, IOrder[]>(\n 'VEX/GetOrders',\n {\n type: 'object',\n required: ['secret_id'],\n properties: {\n secret_id: { type: 'string' },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await getOrders(terminal, credential.credential, msg.req.product_id);\n res.data?.forEach((order) => {\n order.account_id = credential.credentialId;\n });\n return { res };\n },\n);\n\n// 10. Proxy Orders\n// SubmitOrder\nterminal.server.provideService<{ order: IOrder; secret_id: string }, { order_id: string }>(\n 'VEX/SubmitOrder',\n {\n type: 'object',\n required: ['order', 'secret_id'],\n properties: {\n order: { type: 'object' },\n secret_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await submitOrder(terminal, credential.credential, msg.req.order);\n return { res };\n },\n);\n\n// ModifyOrder\nterminal.server.provideService<{ order: IOrder; secret_id: string }, void>(\n 'VEX/ModifyOrder',\n {\n type: 'object',\n required: ['order', 'secret_id'],\n properties: {\n order: { type: 'object' },\n secret_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await modifyOrder(terminal, credential.credential, msg.req.order);\n return { res };\n },\n);\n\n// CancelOrder\nterminal.server.provideService<{ order: IOrder; secret_id: string }, void>(\n 'VEX/CancelOrder',\n {\n type: 'object',\n required: ['order', 'secret_id'],\n properties: {\n order: { type: 'object' },\n secret_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await cancelOrder(terminal, credential.credential, msg.req.order);\n return { res };\n },\n);\n"]}
|
package/lib/credential.d.ts
CHANGED
|
@@ -13,5 +13,6 @@ export declare const listAllCredentials: () => Promise<ICredentialResolvedStatus
|
|
|
13
13
|
export declare const validCredentials$: import("rxjs").Observable<Map<string, IExchangeCredential>>;
|
|
14
14
|
export declare const validCredentialTypes$: import("rxjs").Observable<string[]>;
|
|
15
15
|
export declare const getCredentialById: (credential_id: string) => Promise<IExchangeCredential | undefined>;
|
|
16
|
+
export declare const getCredentialBySecretId: (secret_id: string) => Promise<Required<Pick<ICredentialResolvedStatus, 'secret' | 'credential' | 'credentialId'>>>;
|
|
16
17
|
export {};
|
|
17
18
|
//# sourceMappingURL=credential.d.ts.map
|
package/lib/credential.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAA2B,MAAM,gBAAgB,CAAC;AAKlE,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;CACd;AAMD,UAAU,yBAAyB;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAQD,eAAO,MAAM,kBAAkB,4CA4B9B,CAAC;AAmCF,eAAO,MAAM,iBAAiB,6DAc7B,CAAC;AAEF,eAAO,MAAM,qBAAqB,qCAQjC,CAAC;AAEF,eAAO,MAAM,iBAAiB,kBAAyB,MAAM,6CAG5D,CAAC;AAEF,eAAO,MAAM,uBAAuB,cACvB,MAAM,KAChB,QAAQ,SAAS,KAAK,yBAAyB,EAAE,QAAQ,GAAG,YAAY,GAAG,cAAc,CAAC,CAAC,CAkB7F,CAAC"}
|
package/lib/credential.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCredentialById = exports.validCredentialTypes$ = exports.validCredentials$ = exports.listAllCredentials = void 0;
|
|
3
|
+
exports.getCredentialBySecretId = exports.getCredentialById = exports.validCredentialTypes$ = exports.validCredentials$ = exports.listAllCredentials = void 0;
|
|
4
|
+
const cache_1 = require("@yuants/cache");
|
|
4
5
|
const exchange_1 = require("@yuants/exchange");
|
|
5
6
|
const protocol_1 = require("@yuants/protocol");
|
|
6
7
|
const secret_1 = require("@yuants/secret");
|
|
7
8
|
const sql_1 = require("@yuants/sql");
|
|
9
|
+
const utils_1 = require("@yuants/utils");
|
|
8
10
|
const rxjs_1 = require("rxjs");
|
|
9
11
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
10
12
|
const credentialReader = process.env.NODE_UNIT_PUBLIC_KEY || terminal.keyPair.public_key;
|
|
13
|
+
const credentialIdCache = (0, cache_1.createCache)(async (credentialKey) => {
|
|
14
|
+
const credential = JSON.parse(credentialKey);
|
|
15
|
+
const res = await (0, exchange_1.getCredentialId)(terminal, credential);
|
|
16
|
+
return res.data;
|
|
17
|
+
});
|
|
11
18
|
const listAllCredentials = async () => {
|
|
12
19
|
const secrets = await (0, sql_1.requestSQL)(terminal, `select * from secret where tags->>'type' = 'exchange_credential' and reader = ${(0, sql_1.escapeSQL)(credentialReader)}`);
|
|
13
20
|
const results = secrets.map((secret) => ({ secret }));
|
|
@@ -16,9 +23,10 @@ const listAllCredentials = async () => {
|
|
|
16
23
|
const decrypted = await (0, secret_1.readSecret)(terminal, result.secret);
|
|
17
24
|
const credential = JSON.parse(new TextDecoder().decode(decrypted));
|
|
18
25
|
result.credential = credential;
|
|
19
|
-
const res = await (
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const res = await credentialIdCache.query(JSON.stringify(credential));
|
|
27
|
+
if (res) {
|
|
28
|
+
result.credentialId = res;
|
|
29
|
+
}
|
|
22
30
|
}
|
|
23
31
|
catch (e) {
|
|
24
32
|
result.reason = `${e}`;
|
|
@@ -37,8 +45,8 @@ terminal.server.provideService('VEX/RegisterExchangeCredential', {
|
|
|
37
45
|
}, async (msg) => {
|
|
38
46
|
const credential = msg.req;
|
|
39
47
|
const secretData = new TextEncoder().encode(JSON.stringify(credential));
|
|
40
|
-
await (0, secret_1.writeSecret)(terminal, credentialReader, { type: 'exchange_credential' }, secretData);
|
|
41
|
-
return { res: { code: 0, message: 'OK' } };
|
|
48
|
+
const secret = await (0, secret_1.writeSecret)(terminal, credentialReader, { type: 'exchange_credential' }, secretData);
|
|
49
|
+
return { res: { code: 0, message: 'OK', data: secret } };
|
|
42
50
|
});
|
|
43
51
|
terminal.server.provideService('VEX/ListExchangeCredential', {}, async () => {
|
|
44
52
|
return { res: { code: 0, message: 'OK', data: await (0, exports.listAllCredentials)() } };
|
|
@@ -47,8 +55,11 @@ terminal.server.provideService('VEX/ListCredentials', {}, async () => {
|
|
|
47
55
|
const credentials = await (0, rxjs_1.firstValueFrom)(exports.validCredentials$);
|
|
48
56
|
return { res: { code: 0, message: 'OK', data: [...credentials.keys()] } };
|
|
49
57
|
});
|
|
50
|
-
|
|
58
|
+
const credentialCache = (0, cache_1.createCache)(() => (0, exports.listAllCredentials)(), { swrAfter: 10000, expire: 3600000 });
|
|
59
|
+
exports.validCredentials$ = (0, rxjs_1.defer)(() => credentialCache.query('')).pipe((0, rxjs_1.map)((x) => {
|
|
51
60
|
const map = new Map();
|
|
61
|
+
if (!x)
|
|
62
|
+
return map;
|
|
52
63
|
for (const xx of x) {
|
|
53
64
|
if (xx.credentialId && xx.credential) {
|
|
54
65
|
map.set(xx.credentialId, xx.credential);
|
|
@@ -68,4 +79,23 @@ const getCredentialById = async (credential_id) => {
|
|
|
68
79
|
return credentials.get(credential_id);
|
|
69
80
|
};
|
|
70
81
|
exports.getCredentialById = getCredentialById;
|
|
82
|
+
const getCredentialBySecretId = async (secret_id) => {
|
|
83
|
+
const allCredentials = await credentialCache.query('');
|
|
84
|
+
const theCredential = allCredentials === null || allCredentials === void 0 ? void 0 : allCredentials.find((x) => x.secret.sign === secret_id);
|
|
85
|
+
if (!theCredential) {
|
|
86
|
+
throw (0, utils_1.newError)('CREDENTIAL_NOT_FOUND', { secret_id });
|
|
87
|
+
}
|
|
88
|
+
if (!theCredential.credential) {
|
|
89
|
+
throw (0, utils_1.newError)('CREDENTIAL_NOT_RESOLVED', { secret_id });
|
|
90
|
+
}
|
|
91
|
+
if (!theCredential.credentialId) {
|
|
92
|
+
throw (0, utils_1.newError)('CREDENTIAL_ID_NOT_RESOLVED', { secret_id });
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
secret: theCredential.secret,
|
|
96
|
+
credential: theCredential.credential,
|
|
97
|
+
credentialId: theCredential.credentialId,
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
exports.getCredentialBySecretId = getCredentialBySecretId;
|
|
71
101
|
//# sourceMappingURL=credential.js.map
|
package/lib/credential.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":";;;AAAA,+CAAmD;AACnD,+CAA4C;AAC5C,2CAAkE;AAClE,qCAAoD;AACpD,+BAA8E;AAO9E,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW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AU,EAAE;QAC7B,MAAM,IAAA,gBAAQ,EAAC,yBAAyB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;KAC1D;IACD,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE;QAC/B,MAAM,IAAA,gBAAQ,EAAC,4BAA4B,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;KAC7D;IAED,OAAO;QACL,MAAM,EAAE,aAAa,CAAC,MAAM;QAC5B,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,YAAY,EAAE,aAAa,CAAC,YAAY;KACzC,CAAC;AACJ,CAAC,CAAC;AApBW,QAAA,uBAAuB,2BAoBlC","sourcesContent":["import { createCache } from '@yuants/cache';\nimport { getCredentialId } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { ISecret, readSecret, writeSecret } from '@yuants/secret';\nimport { escapeSQL, requestSQL } from '@yuants/sql';\nimport { newError } from '@yuants/utils';\nimport { defer, firstValueFrom, map, repeat, retry, shareReplay } from 'rxjs';\n\nexport interface IExchangeCredential {\n type: string;\n payload: any;\n}\n\nconst terminal = Terminal.fromNodeEnv();\n\nconst credentialReader = process.env.NODE_UNIT_PUBLIC_KEY || terminal.keyPair.public_key;\n\ninterface ICredentialResolvedStatus {\n secret: ISecret;\n credential?: IExchangeCredential;\n credentialId?: string;\n reason?: string;\n}\n\nconst credentialIdCache = createCache(async (credentialKey: string) => {\n const credential = JSON.parse(credentialKey) as IExchangeCredential;\n const res = await getCredentialId(terminal, credential);\n return res.data;\n});\n\nexport const listAllCredentials = async () => {\n const secrets = await requestSQL<ISecret[]>(\n terminal,\n `select * from secret where tags->>'type' = 'exchange_credential' and reader = ${escapeSQL(\n credentialReader,\n )}`,\n );\n\n const results = secrets.map((secret): ICredentialResolvedStatus => ({ secret }));\n\n await Promise.all(\n results.map(async (result) => {\n try {\n const decrypted = await readSecret(terminal, result.secret);\n const credential = JSON.parse(new TextDecoder().decode(decrypted)) as IExchangeCredential;\n result.credential = credential;\n\n const res = await credentialIdCache.query(JSON.stringify(credential));\n if (res) {\n result.credentialId = res;\n }\n } catch (e) {\n result.reason = `${e}`;\n }\n }),\n );\n\n return results;\n};\n\nterminal.server.provideService<IExchangeCredential, ISecret>(\n 'VEX/RegisterExchangeCredential',\n {\n type: 'object',\n required: ['type', 'payload'],\n properties: {\n type: { type: 'string' },\n payload: { type: 'object' },\n },\n },\n async (msg) => {\n const credential = msg.req;\n const secretData = new TextEncoder().encode(JSON.stringify(credential));\n const secret = await writeSecret(terminal, credentialReader, { type: 'exchange_credential' }, secretData);\n return { res: { code: 0, message: 'OK', data: secret } };\n },\n);\n\nterminal.server.provideService<void, ICredentialResolvedStatus[]>(\n 'VEX/ListExchangeCredential',\n {},\n async () => {\n return { res: { code: 0, message: 'OK', data: await listAllCredentials() } };\n },\n);\n\nterminal.server.provideService<void, string[]>('VEX/ListCredentials', {}, async () => {\n const credentials = await firstValueFrom(validCredentials$);\n return { res: { code: 0, message: 'OK', data: [...credentials.keys()] } };\n});\n\nconst credentialCache = createCache(() => listAllCredentials(), { swrAfter: 10_000, expire: 3600_000 });\n\nexport const validCredentials$ = defer(() => credentialCache.query('')).pipe(\n map((x) => {\n const map = new Map<string, IExchangeCredential>();\n if (!x) return map;\n for (const xx of x) {\n if (xx.credentialId && xx.credential) {\n map.set(xx.credentialId, xx.credential);\n }\n }\n return map;\n }),\n repeat({ delay: 10000 }),\n retry({ delay: 5000 }),\n shareReplay(1),\n);\n\nexport const validCredentialTypes$ = validCredentials$.pipe(\n map((credentials) => {\n const types = new Set<string>();\n credentials.forEach((credential) => {\n types.add(credential.type);\n });\n return Array.from(types);\n }),\n);\n\nexport const getCredentialById = async (credential_id: string) => {\n const credentials = await firstValueFrom(validCredentials$);\n return credentials.get(credential_id);\n};\n\nexport const getCredentialBySecretId = async (\n secret_id: string,\n): Promise<Required<Pick<ICredentialResolvedStatus, 'secret' | 'credential' | 'credentialId'>>> => {\n const allCredentials = await credentialCache.query('');\n const theCredential = allCredentials?.find((x) => x.secret.sign === secret_id);\n if (!theCredential) {\n throw newError('CREDENTIAL_NOT_FOUND', { secret_id });\n }\n if (!theCredential.credential) {\n throw newError('CREDENTIAL_NOT_RESOLVED', { secret_id });\n }\n if (!theCredential.credentialId) {\n throw newError('CREDENTIAL_ID_NOT_RESOLVED', { secret_id });\n }\n\n return {\n secret: theCredential.secret,\n credential: theCredential.credential,\n credentialId: theCredential.credentialId,\n };\n};\n"]}
|
package/lib/general.js
CHANGED
|
@@ -6,35 +6,29 @@ const credential_1 = require("./credential");
|
|
|
6
6
|
const terminal = protocol_1.Terminal.fromNodeEnv();
|
|
7
7
|
terminal.server.provideService('VEX/GetPositions', {
|
|
8
8
|
type: 'object',
|
|
9
|
-
required: ['
|
|
9
|
+
required: ['secret_id'],
|
|
10
10
|
properties: {
|
|
11
|
-
|
|
11
|
+
secret_id: { type: 'string' },
|
|
12
12
|
product_id: { type: 'string' },
|
|
13
13
|
},
|
|
14
14
|
}, async (msg) => {
|
|
15
|
-
const credential = await (0, credential_1.
|
|
16
|
-
|
|
17
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
18
|
-
}
|
|
19
|
-
const res = await (0, exchange_1.getPositions)(terminal, credential, msg.req.product_id);
|
|
15
|
+
const credential = await (0, credential_1.getCredentialBySecretId)(msg.req.secret_id);
|
|
16
|
+
const res = await (0, exchange_1.getPositions)(terminal, credential.credential, msg.req.product_id);
|
|
20
17
|
return { res };
|
|
21
18
|
});
|
|
22
19
|
terminal.server.provideService('VEX/GetOrders', {
|
|
23
20
|
type: 'object',
|
|
24
|
-
required: ['
|
|
21
|
+
required: ['secret_id'],
|
|
25
22
|
properties: {
|
|
26
|
-
|
|
23
|
+
secret_id: { type: 'string' },
|
|
27
24
|
product_id: { type: 'string' },
|
|
28
25
|
},
|
|
29
26
|
}, async (msg) => {
|
|
30
27
|
var _a;
|
|
31
|
-
const credential = await (0, credential_1.
|
|
32
|
-
|
|
33
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
34
|
-
}
|
|
35
|
-
const res = await (0, exchange_1.getOrders)(terminal, credential, msg.req.product_id);
|
|
28
|
+
const credential = await (0, credential_1.getCredentialBySecretId)(msg.req.secret_id);
|
|
29
|
+
const res = await (0, exchange_1.getOrders)(terminal, credential.credential, msg.req.product_id);
|
|
36
30
|
(_a = res.data) === null || _a === void 0 ? void 0 : _a.forEach((order) => {
|
|
37
|
-
order.account_id =
|
|
31
|
+
order.account_id = credential.credentialId;
|
|
38
32
|
});
|
|
39
33
|
return { res };
|
|
40
34
|
});
|
|
@@ -42,49 +36,40 @@ terminal.server.provideService('VEX/GetOrders', {
|
|
|
42
36
|
// SubmitOrder
|
|
43
37
|
terminal.server.provideService('VEX/SubmitOrder', {
|
|
44
38
|
type: 'object',
|
|
45
|
-
required: ['order', '
|
|
39
|
+
required: ['order', 'secret_id'],
|
|
46
40
|
properties: {
|
|
47
41
|
order: { type: 'object' },
|
|
48
|
-
|
|
42
|
+
secret_id: { type: 'string' },
|
|
49
43
|
},
|
|
50
44
|
}, async (msg) => {
|
|
51
|
-
const credential = await (0, credential_1.
|
|
52
|
-
|
|
53
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
54
|
-
}
|
|
55
|
-
const res = await (0, exchange_1.submitOrder)(terminal, credential, msg.req.order);
|
|
45
|
+
const credential = await (0, credential_1.getCredentialBySecretId)(msg.req.secret_id);
|
|
46
|
+
const res = await (0, exchange_1.submitOrder)(terminal, credential.credential, msg.req.order);
|
|
56
47
|
return { res };
|
|
57
48
|
});
|
|
58
49
|
// ModifyOrder
|
|
59
50
|
terminal.server.provideService('VEX/ModifyOrder', {
|
|
60
51
|
type: 'object',
|
|
61
|
-
required: ['order', '
|
|
52
|
+
required: ['order', 'secret_id'],
|
|
62
53
|
properties: {
|
|
63
54
|
order: { type: 'object' },
|
|
64
|
-
|
|
55
|
+
secret_id: { type: 'string' },
|
|
65
56
|
},
|
|
66
57
|
}, async (msg) => {
|
|
67
|
-
const credential = await (0, credential_1.
|
|
68
|
-
|
|
69
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
70
|
-
}
|
|
71
|
-
const res = await (0, exchange_1.modifyOrder)(terminal, credential, msg.req.order);
|
|
58
|
+
const credential = await (0, credential_1.getCredentialBySecretId)(msg.req.secret_id);
|
|
59
|
+
const res = await (0, exchange_1.modifyOrder)(terminal, credential.credential, msg.req.order);
|
|
72
60
|
return { res };
|
|
73
61
|
});
|
|
74
62
|
// CancelOrder
|
|
75
63
|
terminal.server.provideService('VEX/CancelOrder', {
|
|
76
64
|
type: 'object',
|
|
77
|
-
required: ['order', '
|
|
65
|
+
required: ['order', 'secret_id'],
|
|
78
66
|
properties: {
|
|
79
67
|
order: { type: 'object' },
|
|
80
|
-
|
|
68
|
+
secret_id: { type: 'string' },
|
|
81
69
|
},
|
|
82
70
|
}, async (msg) => {
|
|
83
|
-
const credential = await (0, credential_1.
|
|
84
|
-
|
|
85
|
-
return { res: { code: 404, message: 'Credential not found' } };
|
|
86
|
-
}
|
|
87
|
-
const res = await (0, exchange_1.cancelOrder)(terminal, credential, msg.req.order);
|
|
71
|
+
const credential = await (0, credential_1.getCredentialBySecretId)(msg.req.secret_id);
|
|
72
|
+
const res = await (0, exchange_1.cancelOrder)(terminal, credential.credential, msg.req.order);
|
|
88
73
|
return { res };
|
|
89
74
|
});
|
|
90
75
|
//# sourceMappingURL=general.js.map
|
package/lib/general.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general.js","sourceRoot":"","sources":["../src/general.ts"],"names":[],"mappings":";;AAEA,+CAAkG;AAClG,+CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"general.js","sourceRoot":"","sources":["../src/general.ts"],"names":[],"mappings":";;AAEA,+CAAkG;AAClG,+CAA4C;AAC5C,6CAAuD;AAEvD,MAAM,QAAQ,GAAG,mBAAQ,CAAC,WAAW,EAAE,CAAC;AAExC,QAAQ,CAAC,MAAM,CAAC,cAAc,CAC5B,kBAAkB,EAClB;IAC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,EACjB;IACE,IAAI,EAAE,QAAQ;IACd,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,CAAC;IAChC,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;QACzB,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;KAC9B;CACF,EACD,KAAK,EAAE,GAAG,EAAE,EAAE;IACZ,MAAM,UAAU,GAAG,MAAM,IAAA,oCAAuB,EAAC,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACpE,MAAM,GAAG,GAAG,MAAM,IAAA,sBAAW,EAAC,QAAQ,EAAE,UAAU,CAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9E,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC,CACF,CAAC","sourcesContent":["import { IPosition } from '@yuants/data-account';\nimport { IOrder } from '@yuants/data-order';\nimport { cancelOrder, getOrders, getPositions, modifyOrder, submitOrder } from '@yuants/exchange';\nimport { Terminal } from '@yuants/protocol';\nimport { getCredentialBySecretId } from './credential';\n\nconst terminal = Terminal.fromNodeEnv();\n\nterminal.server.provideService<{ secret_id: string; product_id?: string }, IPosition[]>(\n 'VEX/GetPositions',\n {\n type: 'object',\n required: ['secret_id'],\n properties: {\n secret_id: { type: 'string' },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await getPositions(terminal, credential.credential, msg.req.product_id);\n return { res };\n },\n);\n\nterminal.server.provideService<{ secret_id: string; product_id?: string }, IOrder[]>(\n 'VEX/GetOrders',\n {\n type: 'object',\n required: ['secret_id'],\n properties: {\n secret_id: { type: 'string' },\n product_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await getOrders(terminal, credential.credential, msg.req.product_id);\n res.data?.forEach((order) => {\n order.account_id = credential.credentialId;\n });\n return { res };\n },\n);\n\n// 10. Proxy Orders\n// SubmitOrder\nterminal.server.provideService<{ order: IOrder; secret_id: string }, { order_id: string }>(\n 'VEX/SubmitOrder',\n {\n type: 'object',\n required: ['order', 'secret_id'],\n properties: {\n order: { type: 'object' },\n secret_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await submitOrder(terminal, credential.credential, msg.req.order);\n return { res };\n },\n);\n\n// ModifyOrder\nterminal.server.provideService<{ order: IOrder; secret_id: string }, void>(\n 'VEX/ModifyOrder',\n {\n type: 'object',\n required: ['order', 'secret_id'],\n properties: {\n order: { type: 'object' },\n secret_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await modifyOrder(terminal, credential.credential, msg.req.order);\n return { res };\n },\n);\n\n// CancelOrder\nterminal.server.provideService<{ order: IOrder; secret_id: string }, void>(\n 'VEX/CancelOrder',\n {\n type: 'object',\n required: ['order', 'secret_id'],\n properties: {\n order: { type: 'object' },\n secret_id: { type: 'string' },\n },\n },\n async (msg) => {\n const credential = await getCredentialBySecretId(msg.req.secret_id);\n const res = await cancelOrder(terminal, credential.credential, msg.req.order);\n return { res };\n },\n);\n"]}
|
package/package.json
CHANGED
package/temp/package-deps.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
|
-
"apps/virtual-exchange/CHANGELOG.json": "
|
|
3
|
-
"apps/virtual-exchange/CHANGELOG.md": "
|
|
2
|
+
"apps/virtual-exchange/CHANGELOG.json": "ef5ad2bcfa55750d72c0b2b189a96bec372c859c",
|
|
3
|
+
"apps/virtual-exchange/CHANGELOG.md": "400250891aa83c30557a8483fe5b98ce2656b6eb",
|
|
4
4
|
"apps/virtual-exchange/api-extractor.json": "62f4fd324425b9a235f0c117975967aab09ced0c",
|
|
5
5
|
"apps/virtual-exchange/config/jest.config.json": "4bb17bde3ee911163a3edb36a6eb71491d80b1bd",
|
|
6
6
|
"apps/virtual-exchange/config/rig.json": "f6c7b5537dc77a3170ba9f008bae3b6c3ee11956",
|
|
7
7
|
"apps/virtual-exchange/config/typescript.json": "854907e8a821f2050f6533368db160c649c25348",
|
|
8
8
|
"apps/virtual-exchange/etc/app-virtual-exchange.api.md": "6cb40ec1fa2d40a31a7b0dd3f02b8b24a4d7c4de",
|
|
9
|
-
"apps/virtual-exchange/package.json": "
|
|
10
|
-
"apps/virtual-exchange/src/credential.ts": "
|
|
11
|
-
"apps/virtual-exchange/src/general.ts": "
|
|
9
|
+
"apps/virtual-exchange/package.json": "9847730b19aa671e0be997b5bfecf10a04f0fa83",
|
|
10
|
+
"apps/virtual-exchange/src/credential.ts": "f839246750fcbddd9a6a29bf3de54631a92c88b7",
|
|
11
|
+
"apps/virtual-exchange/src/general.ts": "5ffe52c4f30268ef82a285af27f07862bacacebb",
|
|
12
12
|
"apps/virtual-exchange/src/index.ts": "8d7f19a07e6be09c4d8fd4a49ddb3127d3fbf3de",
|
|
13
13
|
"apps/virtual-exchange/src/legacy-services.ts": "08284bbb1d6526c6af15ef1530866f15295554d9",
|
|
14
14
|
"apps/virtual-exchange/src/product-collector.ts": "15ba0a692d694d20b607eaad0287a864577ef30c",
|