@alphaio/quote-client 0.0.0-stage → 0.2.1

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.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * 区间主力 Demo — `import` from `@alphaio/quote-client`
3
+ *
4
+ * export QUOTE_ACTIVATION_KEY='…'
5
+ * yarn workspace @alphaio/quote-client demo:mf-range
6
+ */
7
+ import {
8
+ lastMfRangePoint,
9
+ narrowCurveSnap,
10
+ QuoteClient,
11
+ } from '@alphaio/quote-client';
12
+
13
+ const topic = process.env.QUOTE_TOPIC ?? 'mf_range.600519';
14
+ const client = new QuoteClient({
15
+ host: process.env.RELAY_HOST ?? 's1.diancha.vip',
16
+ port: Number(process.env.RELAY_LISTEN_PORT || 17010),
17
+ auth: {
18
+ activationKey: process.env.QUOTE_ACTIVATION_KEY ?? 'dev-mf-range-only',
19
+ deviceId: process.env.QUOTE_DEVICE_ID ?? 'demo-mf-range-node',
20
+ },
21
+ });
22
+
23
+ client.on('authFail', (f) => {
24
+ console.error('[AUTH_FAIL]', f.code, f.message);
25
+ void client.close();
26
+ });
27
+ client.on('kick', (k) => console.warn('[KICK]', k.reason, k.message ?? ''));
28
+ client.on('error', (e) => console.error('[error]', e.message));
29
+
30
+ client.on('curveSnap', (snap) => {
31
+ const n = narrowCurveSnap(snap);
32
+ if (n.kind !== 'mf_range') return;
33
+ const last = lastMfRangePoint(n.items);
34
+ console.log(
35
+ 'CURVE_SNAP',
36
+ snap.topic,
37
+ 'items',
38
+ n.items.length,
39
+ 'lastNet',
40
+ last?.mainNet
41
+ );
42
+ });
43
+ client.on('curveDelta', (delta) => {
44
+ const last = lastMfRangePoint(delta);
45
+ console.log(
46
+ 'CURVE_DELTA',
47
+ delta.topic,
48
+ 'items',
49
+ delta.items.length,
50
+ 'lastNet',
51
+ last?.mainNet
52
+ );
53
+ });
54
+
55
+ const lease = await client.connect();
56
+ console.log('AUTH_OK mfRange', lease.streamQuotas.mfRange);
57
+ const ack = await client.subscribe([topic]);
58
+ console.log('SUB_ACK', ack.accepted, ack.rejected);
59
+
60
+ process.on('SIGINT', () => {
61
+ void client.close().then(() => process.exit(0));
62
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 逐笔委托 Demo — `import` from `@alphaio/quote-client`
3
+ *
4
+ * export QUOTE_ACTIVATION_KEY='…'
5
+ * yarn workspace @alphaio/quote-client demo:order
6
+ */
7
+ import { QuoteClient } from '@alphaio/quote-client';
8
+
9
+ const client = new QuoteClient({
10
+ host: process.env.RELAY_HOST ?? 's1.diancha.vip',
11
+ port: Number(process.env.RELAY_LISTEN_PORT || 17010),
12
+ auth: {
13
+ activationKey: process.env.QUOTE_ACTIVATION_KEY,
14
+ deviceId: process.env.QUOTE_DEVICE_ID ?? 'demo-order-node',
15
+ },
16
+ });
17
+
18
+ client.on('authFail', (f) => {
19
+ console.error('[AUTH_FAIL]', f.code, f.message);
20
+ void client.close();
21
+ });
22
+ client.on('kick', (k) => console.warn('[KICK]', k.reason, k.message ?? ''));
23
+ client.on('error', (e) => console.error('[error]', e.message));
24
+ client.on('quote', (q) => {
25
+ console.log(
26
+ `[ORDER] ${q.topic} price=${q.price} vol=${q.volume} side=${q.side ?? q.bs_flag} time=${q.time}`
27
+ );
28
+ });
29
+ client.on('quoteSnap', (s) =>
30
+ console.log(`[ORDER SNAP] ${s.topic} items=${s.items.length}`)
31
+ );
32
+
33
+ const lease = await client.connect();
34
+ console.log(
35
+ `AUTH_OK orderQuota=${lease.streamQuotas?.order} until=${lease.validUntil}`
36
+ );
37
+
38
+ const topic = process.env.QUOTE_TOPIC || 'order.600519';
39
+ const ack = await client.subscribe([topic]);
40
+ console.log('accepted', ack.accepted);
41
+ console.log('rejected', ack.rejected);
42
+
43
+ process.on('SIGINT', () => {
44
+ void client.close().then(() => process.exit(0));
45
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 逐笔成交 Demo — `import` from `@alphaio/quote-client`
3
+ *
4
+ * export QUOTE_ACTIVATION_KEY='…'
5
+ * yarn workspace @alphaio/quote-client demo:trans
6
+ */
7
+ import { QuoteClient } from '@alphaio/quote-client';
8
+
9
+ const client = new QuoteClient({
10
+ host: process.env.RELAY_HOST ?? 's1.diancha.vip',
11
+ port: Number(process.env.RELAY_LISTEN_PORT || 17010),
12
+ auth: {
13
+ activationKey: process.env.QUOTE_ACTIVATION_KEY,
14
+ deviceId: process.env.QUOTE_DEVICE_ID ?? 'demo-trans-node',
15
+ },
16
+ });
17
+
18
+ client.on('authFail', (f) => {
19
+ console.error('[AUTH_FAIL]', f.code, f.message);
20
+ void client.close();
21
+ });
22
+ client.on('kick', (k) => console.warn('[KICK]', k.reason, k.message ?? ''));
23
+ client.on('error', (e) => console.error('[error]', e.message));
24
+ client.on('quote', (q) => {
25
+ console.log(
26
+ `[TRANS] ${q.topic} price=${q.price} vol=${q.volume} bs=${q.bs_flag} time=${q.time}`
27
+ );
28
+ });
29
+ client.on('quoteSnap', (s) =>
30
+ console.log(`[TRANS SNAP] ${s.topic} items=${s.items.length}`)
31
+ );
32
+
33
+ const lease = await client.connect();
34
+ console.log(
35
+ `AUTH_OK transQuota=${lease.streamQuotas?.trans} until=${lease.validUntil}`
36
+ );
37
+
38
+ const topic = process.env.QUOTE_TOPIC || 'trans.600519';
39
+ const ack = await client.subscribe([topic]);
40
+ console.log('accepted', ack.accepted);
41
+ console.log('rejected', ack.rejected);
42
+
43
+ process.on('SIGINT', () => {
44
+ void client.close().then(() => process.exit(0));
45
+ });
package/package.json CHANGED
@@ -1,6 +1,70 @@
1
1
  {
2
2
  "name": "@alphaio/quote-client",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.1",
4
+ "description": "Thin TCP client for AlphaIO quote-relay.",
5
+ "license": "MIT",
6
+ "author": {
7
+ "name": "AlphaIO",
8
+ "url": "https://github.com/alphaio"
9
+ },
10
+ "homepage": "https://www.npmjs.com/package/@alphaio/quote-client",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/hyperse-internal/hps-quote-relay.git",
14
+ "directory": "packages/client-sdk"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "registry": "https://registry.npmjs.org/"
19
+ },
20
+ "type": "module",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js",
25
+ "default": "./dist/index.js"
26
+ },
27
+ "./package.json": "./package.json"
28
+ },
29
+ "types": "./dist/index.d.ts",
30
+ "files": [
31
+ "./dist/",
32
+ "./examples/",
33
+ "README.md",
34
+ "LICENSE"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsc -p ./tsconfig.json",
38
+ "clean": "rimraf --no-glob ./dist ./coverage ./.eslintcache ./tsconfig.tsbuildinfo",
39
+ "demo": "node --import=@hyperse/ts-node/register ./src/cli.ts",
40
+ "demo:l2": "node ./examples/demo-l2.mjs",
41
+ "demo:trans": "node ./examples/demo-trans.mjs",
42
+ "demo:order": "node ./examples/demo-order.mjs",
43
+ "demo:fenshi": "node ./examples/demo-fenshi.mjs",
44
+ "demo:fenshi-vol": "node ./examples/demo-fenshi-vol.mjs",
45
+ "demo:mf-range": "node ./examples/demo-mf-range.mjs",
46
+ "fix-all-files": "eslint . --fix",
47
+ "load-test": "node --import=@hyperse/ts-node/register ./src/load-test.ts",
48
+ "lint": "eslint .",
49
+ "prepublishOnly": "yarn workspace @alphaio/quote-protocol build && yarn build",
50
+ "test": "vitest run",
51
+ "typecheck": "tsc -p ./tsconfig.json --noEmit"
52
+ },
53
+ "dependencies": {
54
+ "@alphaio/quote-protocol": "^0.2.1"
55
+ },
56
+ "devDependencies": {
57
+ "@hyperse/eslint-config-hyperse": "^2.1.0",
58
+ "@hyperse/ts-node": "^1.2.0",
59
+ "@types/node": "^26.6.11",
60
+ "eslint": "^10.16.0",
61
+ "prettier": "^3.10.1",
62
+ "rimraf": "^6.1.4",
63
+ "typescript": "^7.0.2",
64
+ "vite": "^8.4.1",
65
+ "vitest": "^5.1.2"
66
+ },
67
+ "engines": {
68
+ "node": ">=20.19.0"
69
+ }
6
70
  }