@alphaio/quote-client 0.2.0 → 0.2.2
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/README.md +10 -5
- package/dist/client.d.ts +1 -2
- package/dist/curve-helpers.d.ts +1 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -13
- package/examples/README.md +26 -0
- package/examples/demo-fenshi-vol.mjs +53 -0
- package/examples/demo-fenshi.mjs +53 -0
- package/examples/demo-l2.mjs +49 -0
- package/examples/demo-mf-range.mjs +62 -0
- package/examples/demo-order.mjs +45 -0
- package/examples/demo-trans.mjs +45 -0
- package/package.json +11 -3
- package/dist/cli.d.ts +0 -2
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -118
- package/dist/cli.js.map +0 -1
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -311
- package/dist/client.js.map +0 -1
- package/dist/curve-helpers.d.ts.map +0 -1
- package/dist/curve-helpers.js +0 -152
- package/dist/curve-helpers.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/load-test.d.ts +0 -2
- package/dist/load-test.d.ts.map +0 -1
- package/dist/load-test.js +0 -150
- package/dist/load-test.js.map +0 -1
package/README.md
CHANGED
|
@@ -63,12 +63,17 @@ await client.subscribe(['l2.600519', 'mf_range.600519']);
|
|
|
63
63
|
const d = diffMfRangePoints(leftPoint, rightPoint); // 右 − 左
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
## Demo
|
|
66
|
+
## Demo(库级依赖)
|
|
67
|
+
|
|
68
|
+
包内 [`examples/`](./examples/) 全部 `import '@alphaio/quote-client'`:
|
|
67
69
|
|
|
68
70
|
```bash
|
|
69
|
-
|
|
70
|
-
yarn workspace @alphaio/quote-client demo
|
|
71
|
-
|
|
71
|
+
export QUOTE_ACTIVATION_KEY='…'
|
|
72
|
+
yarn workspace @alphaio/quote-client demo:l2
|
|
73
|
+
yarn workspace @alphaio/quote-client demo:mf-range
|
|
74
|
+
# 或:node node_modules/@alphaio/quote-client/examples/demo-l2.mjs
|
|
72
75
|
```
|
|
73
76
|
|
|
74
|
-
|
|
77
|
+
综合板:`yarn workspace @alphaio/quote-client demo`(`src/cli.ts`,需本地/联调 relay)。
|
|
78
|
+
|
|
79
|
+
Python 版见 [`packages/client-sdk-python`](../client-sdk-python)。发布:[docs/PUBLISH_SDKS.md](../../docs/PUBLISH_SDKS.md)。
|
package/dist/client.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type QuoteClientOptions = {
|
|
|
9
9
|
clientVersion?: string;
|
|
10
10
|
};
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* 类型化事件映射:`on('quote', q => …)` 可收窄 `q` 的类型。
|
|
13
13
|
* 按 topic 监听请用 `quote:${topic}` / `curve:${topic}`,或
|
|
14
14
|
* {@link QuoteClient.onTopic} / {@link QuoteClient.onCurveTopic}。
|
|
15
15
|
*/
|
|
@@ -67,4 +67,3 @@ export declare class QuoteClient extends EventEmitter {
|
|
|
67
67
|
close(): Promise<void>;
|
|
68
68
|
}
|
|
69
69
|
export {};
|
|
70
|
-
//# sourceMappingURL=client.d.ts.map
|
package/dist/curve-helpers.d.ts
CHANGED
|
@@ -53,8 +53,7 @@ export declare function narrowCurveDelta(delta: CurveDeltaPayload): NarrowedCurv
|
|
|
53
53
|
/** 区间主力序列末点(开盘→此刻累计);非 mf_range 或空序列返回 null。 */
|
|
54
54
|
export declare function lastMfRangePoint(snapOrItems: CurveSnapPayload | CurveDeltaPayload | readonly CurvePoint[], topicHint?: string): MfRangePoint | null;
|
|
55
55
|
/**
|
|
56
|
-
* 区间差分:右端 −
|
|
56
|
+
* 区间差分:右端 − 左端(客户端滑杆选两点时用)。
|
|
57
57
|
* 传入同一序列上的两点(开盘累计水位)。
|
|
58
58
|
*/
|
|
59
59
|
export declare function diffMfRangePoints(left: MfRangePoint, right: MfRangePoint): MfRangePoint;
|
|
60
|
-
//# sourceMappingURL=curve-helpers.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -9,4 +9,3 @@ export { curveKindOf, diffMfRangePoints, isFenshiPricePoint, isFenshiVolPoint, i
|
|
|
9
9
|
export { encodeFrame, encodeQuoteFrame, FrameReader, HEADER_SIZE, isKnownFrameType, MAX_FRAME_BYTES, tryDecodeFrame, type UnencodedQuoteKeys, } from '@alphaio/quote-protocol';
|
|
10
10
|
export { type CurveQuoteStreamKind, deliveryShapeOf, formatQuoteTopic, isCurveQuoteStreamKind, isNatsQuoteStreamKind, isQuoteStreamKind, isTickQuoteStreamKind, type NatsQuoteStreamKind, natsSubjectForQuoteTopic, type ParsedQuoteTopic, parseQuoteTopic, PRODUCTS, QUOTE_STREAM_KINDS, type QuoteStreamKind, type QuoteStreamQuotaKey, type QuoteStreamQuotas, STREAM_QUOTA_FIELD, streamQuotaCap, type TickQuoteStreamKind, } from '@alphaio/quote-protocol';
|
|
11
11
|
export { type AuthFailPayload, type AuthOkPayload, type AuthPayload, type CurveDeltaPayload, type CurvePoint, type CurveSnapPayload, type DecodedFrame, DEFAULT_HEARTBEAT_INTERVAL_SEC, DEFAULT_IDLE_MISS_LIMIT, type DeliveryShape, type ErrorCode, type ErrorPayload, type FenshiPricePoint, type FenshiVolPoint, type FramePayloadByType, FrameType, type FrameTypeCode, type KickPayload, type KickReason, type MfRangePoint, type PingPayload, type PongPayload, PROTOCOL_VERSION, type QuoteBatchPayload, type QuotePayload, type QuoteSnapPayload, type SessionState, SHAPE_FRAMES, type SubAckPayload, type SubPayload, TOPIC_RE, type UnsubAckPayload, type UnsubPayload, } from '@alphaio/quote-protocol';
|
|
12
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* `@alphaio/quote-client` — 用户端完整入口。
|
|
3
|
-
*
|
|
4
|
-
* 只需安装本包即可:TCP 客户端 + 协议类型 / 产品登记 / 曲线收窄工具
|
|
5
|
-
* 均从此入口导出(protocol 为运行时依赖,会随本包安装)。
|
|
6
|
-
*/
|
|
7
|
-
export { QuoteClient, } from './client.js';
|
|
8
|
-
export { curveKindOf, diffMfRangePoints, isFenshiPricePoint, isFenshiVolPoint, isMfRangePoint, lastMfRangePoint, narrowCurveDelta, narrowCurveSnap, } from './curve-helpers.js';
|
|
9
|
-
// —— 协议面(与 @alphaio/quote-protocol 对齐,避免用户再装一份)——
|
|
10
|
-
export { encodeFrame, encodeQuoteFrame, FrameReader, HEADER_SIZE, isKnownFrameType, MAX_FRAME_BYTES, tryDecodeFrame, } from '@alphaio/quote-protocol';
|
|
11
|
-
export { deliveryShapeOf, formatQuoteTopic, isCurveQuoteStreamKind, isNatsQuoteStreamKind, isQuoteStreamKind, isTickQuoteStreamKind, natsSubjectForQuoteTopic, parseQuoteTopic, PRODUCTS, QUOTE_STREAM_KINDS, STREAM_QUOTA_FIELD, streamQuotaCap, } from '@alphaio/quote-protocol';
|
|
12
|
-
export { DEFAULT_HEARTBEAT_INTERVAL_SEC, DEFAULT_IDLE_MISS_LIMIT, FrameType, PROTOCOL_VERSION, SHAPE_FRAMES, TOPIC_RE, } from '@alphaio/quote-protocol';
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import{EventEmitter as f}from"node:events";import{connect as S}from"node:net";import{DEFAULT_HEARTBEAT_INTERVAL_SEC as C,DEFAULT_IDLE_MISS_LIMIT as k,encodeFrame as E,FrameReader as g,FrameType as a,PROTOCOL_VERSION as b}from"@alphaio/quote-protocol";var l=class extends f{constructor(e){super();this.state="closed";this.topics=new Set;this.#e=null;this.#l=new g;this.#s=0;this.#u=0;this.#a=!1;this.#r=[];this.#i=e}#i;#e;#l;#n;#s;#u;#a;#r;on(e,t){return super.on(e,t)}once(e,t){return super.once(e,t)}off(e,t){return super.off(e,t)}emit(e,...t){return super.emit(e,...t)}async connect(){return this.#a=!1,this.#p()}async subscribe(e,t){this.#P();let n={topics:e,...t?.withSnap!==void 0?{withSnap:t.withSnap}:{}};return new Promise((u,r)=>{let s=c=>{this.off("subAck",s),u(c)};this.on("subAck",s),this.#o(a.SUB,n),setTimeout(()=>{this.off("subAck",s),r(new Error("SUB_ACK timeout"))},1e4)})}unsubscribe(e){this.#P(),this.#o(a.UNSUB,{topics:e})}onTopic(e,t){let n=`quote:${e}`;return this.on(n,t),()=>{this.off(n,t)}}onCurveTopic(e,t){let n=`curve:${e}`;return this.on(n,t),()=>{this.off(n,t)}}async close(){this.#a=!0,this.#d();let e=this.#e;this.#e=null,this.#t("closed"),e?.destroy(),this.emit("close")}async#p(){let e=this.#i.host??process.env.RELAY_HOST??"127.0.0.1",t=this.#i.port??Number(process.env.RELAY_LISTEN_PORT||17010);this.#t("connecting"),this.#l.reset();let n=await new Promise((r,s)=>{let c=S({host:e,port:t},()=>r(c));c.once("error",s)});this.#e=n,n.setNoDelay(!0),n.on("data",r=>this.#m(r)),n.on("error",r=>this.emit("error",r)),n.on("close",()=>this.#f()),this.#t("authenticating");let u=new Promise((r,s)=>{this.#r.push({resolve:r,reject:s})});return this.#y(),u}#y(){this.#o(a.AUTH,{...this.#i.auth,clientVersion:this.#i.clientVersion??b})}#m(e){let t;try{t=this.#l.push(e)}catch(n){this.emit("error",n instanceof Error?n:new Error("frame decode error")),this.close();return}for(let n of t)this.#v(n)}#v(e){switch(this.#s=0,e.type){case a.AUTH_OK:{this.lease=e.payload,this.#t("ready"),this.#u=0,this.#S(e.payload.heartbeatIntervalSec);for(let t of this.#r.splice(0))t.resolve(e.payload);this.emit("authOk",e.payload);break}case a.AUTH_FAIL:{if(this.emit("authFail",e.payload),e.payload.retryable){let n=Math.max(0,e.payload.retryAfterMs??2e3);setTimeout(()=>{this.state==="authenticating"&&this.#e&&this.#y()},n).unref?.();break}let t=new Error(`${e.payload.code}: ${e.payload.message}`);for(let n of this.#r.splice(0))n.reject(t);this.close();break}case a.SUB_ACK:{for(let t of e.payload.accepted)this.topics.add(t);this.#t(this.topics.size>0?"subscribed":"ready"),this.emit("subAck",e.payload);break}case a.UNSUB_ACK:{for(let t of e.payload.topics)this.topics.delete(t);this.#t(this.topics.size>0?"subscribed":"ready");break}case a.QUOTE:{this.#c(e.payload);break}case a.QUOTE_SNAP:{this.emit("quoteSnap",e.payload);for(let t of e.payload.items)this.#c(t);break}case a.QUOTE_BATCH:{for(let t of e.payload.items)this.#c(t);break}case a.CURVE_SNAP:{this.#h("curveSnap",e.payload);break}case a.CURVE_DELTA:{this.#h("curveDelta",e.payload);break}case a.PING:this.#o(a.PONG,{ts:e.payload.ts??Date.now()});break;case a.PONG:break;case a.KICK:this.emit("kick",e.payload),this.close();break;case a.ERROR:this.emit("error",new Error(`${e.payload.code}: ${e.payload.message}`));break;default:break}}#c(e){this.emit("quote",e),this.emit(`quote:${e.topic}`,e)}#h(e,t){e==="curveSnap"?this.emit("curveSnap",t):this.emit("curveDelta",t),this.emit(`curve:${t.topic}`,t)}#f(){this.#d(),this.#e=null;let e=this.#r.splice(0);for(let t of e)t.reject(new Error("connection closed during AUTH"));if(this.#t("closed"),this.emit("close"),!this.#a&&this.#i.autoReconnect!==!1){let t=Math.min(1e4,500*2**this.#u);this.#u+=1,setTimeout(()=>{this.#a||this.#p().then(async n=>(this.topics.size>0&&await this.subscribe([...this.topics]),n)).catch(n=>this.emit("error",n instanceof Error?n:new Error(String(n))))},t)}}#S(e=C){this.#d();let t=Math.max(5,e)*1e3;this.#n=setInterval(()=>{if(this.#s+=1,this.#s>=k){this.emit("error",new Error("IDLE_TIMEOUT")),this.#e?.destroy();return}this.#o(a.PING,{ts:Date.now()})},t)}#d(){this.#n&&(clearInterval(this.#n),this.#n=void 0)}#o(e,t){!this.#e||this.#e.destroyed||this.#e.write(E(e,t))}#t(e){this.state=e,this.emit("state",e)}#P(){if(this.state!=="ready"&&this.state!=="subscribed")throw new Error(`not ready (state=${this.state})`)}};import{isCurveQuoteStreamKind as A,parseQuoteTopic as T}from"@alphaio/quote-protocol";function d(i){let o=T(i);return!o||!A(o.kind)?null:o.kind}function Q(i){return"price"in i&&typeof i.price=="number"}function R(i){return!("price"in i)&&!("mainNet"in i)&&!("mainBuy"in i)}function m(i){return"mainNet"in i&&typeof i.mainNet=="number"&&typeof i.mainBuy=="number"&&typeof i.mainSell=="number"}function v(i,o){switch(i){case"fenshi":return o;case"fenshi_vol":return o;case"mf_range":return o}}function F(i){let o=d(i.topic);if(!o)return{kind:"unknown",topic:i.topic,items:i.items,...i.total!==void 0?{total:i.total}:{}};let e={topic:i.topic,items:v(o,i.items),...i.total!==void 0?{total:i.total}:{}};return o==="fenshi"?{kind:o,topic:e.topic,items:e.items,...e.total!==void 0?{total:e.total}:{}}:o==="fenshi_vol"?{kind:o,topic:e.topic,items:e.items,...e.total!==void 0?{total:e.total}:{}}:{kind:o,topic:e.topic,items:e.items,...e.total!==void 0?{total:e.total}:{}}}function K(i){let o=d(i.topic);if(!o)return{kind:"unknown",topic:i.topic,items:i.items};let e=v(o,i.items);return o==="fenshi"?{kind:o,topic:i.topic,items:e}:o==="fenshi_vol"?{kind:o,topic:i.topic,items:e}:{kind:o,topic:i.topic,items:e}}function w(i,o){let e=o??(Array.isArray(i)?void 0:i.topic);if(e&&d(e)!=="mf_range")return null;let t=Array.isArray(i)?i:i.items;if(!t.length)return null;let n=t[t.length-1];return n?(m(n),n):null}function _(i,o){let e=(h,P)=>{if(!(h===void 0&&P===void 0))return(h??0)-(P??0)},t={ts:o.ts,mainBuy:o.mainBuy-i.mainBuy,mainSell:o.mainSell-i.mainSell,mainNet:o.mainNet-i.mainNet},n=e(o.turnover,i.turnover);n!==void 0&&(t.turnover=n);let u=e(o.turnoverRatio,i.turnoverRatio);u!==void 0&&(t.turnoverRatio=u);let r=e(o.changCount,i.changCount);r!==void 0&&(t.changCount=Math.trunc(r));let s=e(o.chipLarge,i.chipLarge);s!==void 0&&(t.chipLarge=s);let c=e(o.chipMiddle,i.chipMiddle);c!==void 0&&(t.chipMiddle=c);let p=e(o.chipSmall,i.chipSmall);p!==void 0&&(t.chipSmall=p);let y=e(o.chipSmallest,i.chipSmallest);return y!==void 0&&(t.chipSmallest=y),t}import{encodeFrame as $,encodeQuoteFrame as q,FrameReader as H,HEADER_SIZE as j,isKnownFrameType as G,MAX_FRAME_BYTES as z,tryDecodeFrame as Y}from"@alphaio/quote-protocol";import{deliveryShapeOf as W,formatQuoteTopic as X,isCurveQuoteStreamKind as Z,isNatsQuoteStreamKind as ee,isQuoteStreamKind as te,isTickQuoteStreamKind as ie,natsSubjectForQuoteTopic as oe,parseQuoteTopic as ne,PRODUCTS as ae,QUOTE_STREAM_KINDS as re,STREAM_QUOTA_FIELD as se,streamQuotaCap as ue}from"@alphaio/quote-protocol";import{DEFAULT_HEARTBEAT_INTERVAL_SEC as de,DEFAULT_IDLE_MISS_LIMIT as le,FrameType as pe,PROTOCOL_VERSION as ye,SHAPE_FRAMES as he,TOPIC_RE as Pe}from"@alphaio/quote-protocol";export{de as DEFAULT_HEARTBEAT_INTERVAL_SEC,le as DEFAULT_IDLE_MISS_LIMIT,H as FrameReader,pe as FrameType,j as HEADER_SIZE,z as MAX_FRAME_BYTES,ae as PRODUCTS,ye as PROTOCOL_VERSION,re as QUOTE_STREAM_KINDS,l as QuoteClient,he as SHAPE_FRAMES,se as STREAM_QUOTA_FIELD,Pe as TOPIC_RE,d as curveKindOf,W as deliveryShapeOf,_ as diffMfRangePoints,$ as encodeFrame,q as encodeQuoteFrame,X as formatQuoteTopic,Z as isCurveQuoteStreamKind,Q as isFenshiPricePoint,R as isFenshiVolPoint,G as isKnownFrameType,m as isMfRangePoint,ee as isNatsQuoteStreamKind,te as isQuoteStreamKind,ie as isTickQuoteStreamKind,w as lastMfRangePoint,K as narrowCurveDelta,F as narrowCurveSnap,oe as natsSubjectForQuoteTopic,ne as parseQuoteTopic,ue as streamQuotaCap,Y as tryDecodeFrame};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Examples(库级依赖)
|
|
2
|
+
|
|
3
|
+
全部 Demo **只** `import` 已发布包 `@alphaio/quote-client`,不再粘贴 SDK 源码。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i @alphaio/quote-client
|
|
7
|
+
export QUOTE_ACTIVATION_KEY='…'
|
|
8
|
+
node node_modules/@alphaio/quote-client/examples/demo-l2.mjs
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
仓库内:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
export QUOTE_ACTIVATION_KEY='…' # 或默认本地 relay 的 dev key
|
|
15
|
+
yarn workspace @alphaio/quote-client demo:l2
|
|
16
|
+
yarn workspace @alphaio/quote-client demo:mf-range
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
| 文件 | topic |
|
|
20
|
+
| --------------------- | -------------- |
|
|
21
|
+
| `demo-l2.mjs` | `l2.*` |
|
|
22
|
+
| `demo-trans.mjs` | `trans.*` |
|
|
23
|
+
| `demo-order.mjs` | `order.*` |
|
|
24
|
+
| `demo-fenshi.mjs` | `fenshi.*` |
|
|
25
|
+
| `demo-fenshi-vol.mjs` | `fenshi_vol.*` |
|
|
26
|
+
| `demo-mf-range.mjs` | `mf_range.*` |
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 分时量额 Demo — `import` from `@alphaio/quote-client`
|
|
3
|
+
*
|
|
4
|
+
* export QUOTE_ACTIVATION_KEY='…'
|
|
5
|
+
* yarn workspace @alphaio/quote-client demo:fenshi-vol
|
|
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-fenshi-vol-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
|
+
|
|
25
|
+
const curve = new Map();
|
|
26
|
+
client.on('curveSnap', (s) => {
|
|
27
|
+
curve.clear();
|
|
28
|
+
for (const p of s.items ?? []) curve.set(p.ts, p);
|
|
29
|
+
console.log(
|
|
30
|
+
`[FENSHI_VOL SNAP] ${s.topic} total=${s.total ?? '—'} loaded=${curve.size}`
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
client.on('curveDelta', (d) => {
|
|
34
|
+
for (const p of d.items ?? []) curve.set(p.ts, p);
|
|
35
|
+
const last = d.items?.[d.items.length - 1];
|
|
36
|
+
console.log(
|
|
37
|
+
`[FENSHI_VOL Δ] ${d.topic} +${d.items?.length ?? 0} last ts=${last?.ts} vol=${last?.volume} amount=${last?.amount} size=${curve.size}`
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const lease = await client.connect();
|
|
42
|
+
console.log(
|
|
43
|
+
`AUTH_OK fenshiVolQuota=${lease.streamQuotas?.fenshiVol} until=${lease.validUntil}`
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const topic = process.env.QUOTE_TOPIC || 'fenshi_vol.600519';
|
|
47
|
+
const ack = await client.subscribe([topic]);
|
|
48
|
+
console.log('accepted', ack.accepted);
|
|
49
|
+
console.log('rejected', ack.rejected);
|
|
50
|
+
|
|
51
|
+
process.on('SIGINT', () => {
|
|
52
|
+
void client.close().then(() => process.exit(0));
|
|
53
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 分时价格 Demo — `import` from `@alphaio/quote-client`
|
|
3
|
+
*
|
|
4
|
+
* export QUOTE_ACTIVATION_KEY='…'
|
|
5
|
+
* yarn workspace @alphaio/quote-client demo:fenshi
|
|
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-fenshi-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
|
+
|
|
25
|
+
const curve = new Map();
|
|
26
|
+
client.on('curveSnap', (s) => {
|
|
27
|
+
curve.clear();
|
|
28
|
+
for (const p of s.items ?? []) curve.set(p.ts, p);
|
|
29
|
+
console.log(
|
|
30
|
+
`[FENSHI SNAP] ${s.topic} total=${s.total ?? '—'} loaded=${curve.size}`
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
client.on('curveDelta', (d) => {
|
|
34
|
+
for (const p of d.items ?? []) curve.set(p.ts, p);
|
|
35
|
+
const last = d.items?.[d.items.length - 1];
|
|
36
|
+
console.log(
|
|
37
|
+
`[FENSHI Δ] ${d.topic} +${d.items?.length ?? 0} last ts=${last?.ts} price=${last?.price} avg=${last?.avg} size=${curve.size}`
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const lease = await client.connect();
|
|
42
|
+
console.log(
|
|
43
|
+
`AUTH_OK fenshiQuota=${lease.streamQuotas?.fenshi} until=${lease.validUntil}`
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const topic = process.env.QUOTE_TOPIC || 'fenshi.600519';
|
|
47
|
+
const ack = await client.subscribe([topic]);
|
|
48
|
+
console.log('accepted', ack.accepted);
|
|
49
|
+
console.log('rejected', ack.rejected);
|
|
50
|
+
|
|
51
|
+
process.on('SIGINT', () => {
|
|
52
|
+
void client.close().then(() => process.exit(0));
|
|
53
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 十档 L2 Demo — 依赖已发布包 `@alphaio/quote-client`
|
|
3
|
+
*
|
|
4
|
+
* npm i @alphaio/quote-client
|
|
5
|
+
* export QUOTE_ACTIVATION_KEY='…'
|
|
6
|
+
* node node_modules/@alphaio/quote-client/examples/demo-l2.mjs
|
|
7
|
+
* # 或仓库内:yarn workspace @alphaio/quote-client demo:l2
|
|
8
|
+
*/
|
|
9
|
+
import { QuoteClient } from '@alphaio/quote-client';
|
|
10
|
+
|
|
11
|
+
const client = new QuoteClient({
|
|
12
|
+
host: process.env.RELAY_HOST ?? 's1.diancha.vip',
|
|
13
|
+
port: Number(process.env.RELAY_LISTEN_PORT || 17010),
|
|
14
|
+
auth: {
|
|
15
|
+
activationKey: process.env.QUOTE_ACTIVATION_KEY,
|
|
16
|
+
deviceId: process.env.QUOTE_DEVICE_ID ?? 'demo-l2-node',
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
client.on('authFail', (f) => {
|
|
21
|
+
console.error('[AUTH_FAIL]', f.code, f.message);
|
|
22
|
+
void client.close();
|
|
23
|
+
});
|
|
24
|
+
client.on('kick', (k) => console.warn('[KICK]', k.reason, k.message ?? ''));
|
|
25
|
+
client.on('error', (e) => console.error('[error]', e.message));
|
|
26
|
+
client.on('quote', (q) => {
|
|
27
|
+
const b1 = q.bid_price?.[0] ?? q.bid;
|
|
28
|
+
const a1 = q.ask_price?.[0] ?? q.ask;
|
|
29
|
+
console.log(
|
|
30
|
+
`[L2] ${q.topic} last=${q.last} bid1=${b1} ask1=${a1} phase=${q.trading_phase} time=${q.time}`
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
client.on('quoteSnap', (s) =>
|
|
34
|
+
console.log(`[L2 SNAP] ${s.topic} items=${s.items.length}`)
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const lease = await client.connect();
|
|
38
|
+
console.log(
|
|
39
|
+
`AUTH_OK l2Quota=${lease.streamQuotas?.l2} until=${lease.validUntil}`
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const topic = process.env.QUOTE_TOPIC || 'l2.600519';
|
|
43
|
+
const ack = await client.subscribe([topic]);
|
|
44
|
+
console.log('accepted', ack.accepted);
|
|
45
|
+
console.log('rejected', ack.rejected);
|
|
46
|
+
|
|
47
|
+
process.on('SIGINT', () => {
|
|
48
|
+
void client.close().then(() => process.exit(0));
|
|
49
|
+
});
|
|
@@ -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,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alphaio/quote-client",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Thin TCP client for AlphaIO quote-relay.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -29,13 +29,20 @@
|
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
30
30
|
"files": [
|
|
31
31
|
"./dist/",
|
|
32
|
+
"./examples/",
|
|
32
33
|
"README.md",
|
|
33
34
|
"LICENSE"
|
|
34
35
|
],
|
|
35
36
|
"scripts": {
|
|
36
|
-
"build": "
|
|
37
|
+
"build": "yarn clean && node ../../scripts/build-sdk-package.mjs --external=@alphaio/quote-protocol",
|
|
37
38
|
"clean": "rimraf --no-glob ./dist ./coverage ./.eslintcache ./tsconfig.tsbuildinfo",
|
|
38
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",
|
|
39
46
|
"fix-all-files": "eslint . --fix",
|
|
40
47
|
"load-test": "node --import=@hyperse/ts-node/register ./src/load-test.ts",
|
|
41
48
|
"lint": "eslint .",
|
|
@@ -44,12 +51,13 @@
|
|
|
44
51
|
"typecheck": "tsc -p ./tsconfig.json --noEmit"
|
|
45
52
|
},
|
|
46
53
|
"dependencies": {
|
|
47
|
-
"@alphaio/quote-protocol": "^0.2.
|
|
54
|
+
"@alphaio/quote-protocol": "^0.2.2"
|
|
48
55
|
},
|
|
49
56
|
"devDependencies": {
|
|
50
57
|
"@hyperse/eslint-config-hyperse": "^2.1.0",
|
|
51
58
|
"@hyperse/ts-node": "^1.2.0",
|
|
52
59
|
"@types/node": "^26.6.11",
|
|
60
|
+
"esbuild": "^0.28.2",
|
|
53
61
|
"eslint": "^10.16.0",
|
|
54
62
|
"prettier": "^3.10.1",
|
|
55
63
|
"rimraf": "^6.1.4",
|
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { PROTOCOL_VERSION } from '@alphaio/quote-protocol';
|
|
2
|
-
import { QuoteClient } from './client.js';
|
|
3
|
-
const host = process.env.RELAY_HOST ?? '127.0.0.1';
|
|
4
|
-
const port = Number(process.env.RELAY_LISTEN_PORT || 17010);
|
|
5
|
-
const topics = (process.env.QUOTE_TOPICS ??
|
|
6
|
-
'l2.600519,trans.600519,order.600519,fenshi.600519,fenshi_vol.600519,mf_range.600519')
|
|
7
|
-
.split(',')
|
|
8
|
-
.map((s) => s.trim())
|
|
9
|
-
.filter(Boolean);
|
|
10
|
-
const quiet = process.env.QUOTE_DEMO_QUIET === '1';
|
|
11
|
-
const summaryEveryMs = Number(process.env.QUOTE_DEMO_SUMMARY_MS || 5_000);
|
|
12
|
-
const client = new QuoteClient({
|
|
13
|
-
host,
|
|
14
|
-
port,
|
|
15
|
-
auth: {
|
|
16
|
-
activationKey: process.env.QUOTE_ACTIVATION_KEY ?? 'dev-all-streams',
|
|
17
|
-
deviceId: process.env.QUOTE_DEVICE_ID ?? 'board-demo-device-1',
|
|
18
|
-
},
|
|
19
|
-
autoReconnect: true,
|
|
20
|
-
});
|
|
21
|
-
const counts = {
|
|
22
|
-
quote: 0,
|
|
23
|
-
quoteSnap: 0,
|
|
24
|
-
curveSnap: 0,
|
|
25
|
-
curveDelta: 0,
|
|
26
|
-
byTopic: new Map(),
|
|
27
|
-
};
|
|
28
|
-
function bump(topic) {
|
|
29
|
-
counts.byTopic.set(topic, (counts.byTopic.get(topic) ?? 0) + 1);
|
|
30
|
-
}
|
|
31
|
-
/** topic 前缀即产品:l2 / trans / order / fenshi / fenshi_vol / mf_range */
|
|
32
|
-
function productOf(topic) {
|
|
33
|
-
return topic.split('.')[0] || '?';
|
|
34
|
-
}
|
|
35
|
-
function mfRangeTail(items) {
|
|
36
|
-
const last = items[items.length - 1];
|
|
37
|
-
if (!last || typeof last.mainNet !== 'number') {
|
|
38
|
-
return '';
|
|
39
|
-
}
|
|
40
|
-
return ` lastNet=${last.mainNet} buy=${last.mainBuy ?? '—'} sell=${last.mainSell ?? '—'} ts=${last.ts ?? '—'}`;
|
|
41
|
-
}
|
|
42
|
-
// 连接状态机:idle → connecting → authed → closed 等(与产品无关)
|
|
43
|
-
client.on('state', (s) => console.log(`[sdk] state → ${s}`));
|
|
44
|
-
// 服务端主动踢线(配额/鉴权/慢消费等),需处理重连或换凭证
|
|
45
|
-
client.on('kick', (k) => console.warn(`[sdk] KICK ${k.reason} ${k.message ?? ''}`));
|
|
46
|
-
// 传输层/协议错误(断线、解码失败等)
|
|
47
|
-
client.on('error', (e) => console.error(`[sdk] error`, e.message));
|
|
48
|
-
// —— 产品 → 事件 ——
|
|
49
|
-
// l2.* / trans.* / order.* → tick:quote + quoteSnap
|
|
50
|
-
// fenshi.* → 分时价:curveSnap + curveDelta
|
|
51
|
-
// fenshi_vol.* → 分时量:curveSnap + curveDelta
|
|
52
|
-
// mf_range.* → 区间主力:curveSnap + curveDelta(开盘累计;末点≈区间统计屏)
|
|
53
|
-
// tick 实时推送:产品 l2 / trans / order,看 q.topic 区分
|
|
54
|
-
client.on('quote', (q) => {
|
|
55
|
-
counts.quote += 1;
|
|
56
|
-
bump(q.topic);
|
|
57
|
-
if (!quiet) {
|
|
58
|
-
const depth = q.bid_price && q.ask_price
|
|
59
|
-
? ` bid1=${q.bid_price[0]} ask1=${q.ask_price[0]} levels=${q.bid_price.length}`
|
|
60
|
-
: ` bid=${q.bid} ask=${q.ask}`;
|
|
61
|
-
console.log(`[sdk] QUOTE [${productOf(q.topic)}] ${q.topic} last=${q.last}${depth} ts=${q.ts}`);
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
// tick 快照补洞:刚 SUB l2/trans/order 时下发近期缓存,避免空白开局
|
|
65
|
-
client.on('quoteSnap', (snap) => {
|
|
66
|
-
counts.quoteSnap += 1;
|
|
67
|
-
bump(snap.topic);
|
|
68
|
-
if (!quiet) {
|
|
69
|
-
const head = snap.items[0];
|
|
70
|
-
const depth = head?.bid_price && head?.ask_price
|
|
71
|
-
? ` bid1=${head.bid_price[0]} ask1=${head.ask_price[0]}`
|
|
72
|
-
: '';
|
|
73
|
-
console.log(`[sdk] QUOTE_SNAP [${productOf(snap.topic)}] ${snap.topic} items=${snap.items.length}${depth}`);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
// 曲线快照:刚 SUB fenshi / fenshi_vol / mf_range 时下发缓冲历史点
|
|
77
|
-
client.on('curveSnap', (snap) => {
|
|
78
|
-
counts.curveSnap += 1;
|
|
79
|
-
bump(snap.topic);
|
|
80
|
-
const product = productOf(snap.topic);
|
|
81
|
-
const extra = product === 'mf_range'
|
|
82
|
-
? mfRangeTail(snap.items)
|
|
83
|
-
: '';
|
|
84
|
-
console.log(`[sdk] CURVE_SNAP [${product}] ${snap.topic} items=${snap.items.length} total=${snap.total ?? '—'}${extra}`);
|
|
85
|
-
});
|
|
86
|
-
// 曲线增量:盘中新点或尾部修正(含 mf_range 分钟累计)
|
|
87
|
-
client.on('curveDelta', (delta) => {
|
|
88
|
-
counts.curveDelta += 1;
|
|
89
|
-
bump(delta.topic);
|
|
90
|
-
if (!quiet) {
|
|
91
|
-
const product = productOf(delta.topic);
|
|
92
|
-
const extra = product === 'mf_range'
|
|
93
|
-
? mfRangeTail(delta.items)
|
|
94
|
-
: '';
|
|
95
|
-
console.log(`[sdk] CURVE_DELTA [${product}] ${delta.topic} items=${delta.items.length}${extra}`);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
console.log(`[sdk] PROTOCOL ${PROTOCOL_VERSION} → ${host}:${port} topics=${topics.join(',')}`);
|
|
99
|
-
const lease = await client.connect();
|
|
100
|
-
console.log(`[sdk] AUTH_OK lease=${lease.leaseId} quotas=${JSON.stringify(lease.streamQuotas)} until=${lease.validUntil}`);
|
|
101
|
-
const ack = await client.subscribe(topics);
|
|
102
|
-
console.log(`[sdk] SUB_ACK accepted=${ack.accepted.join(',') || '—'} rejected=${ack.rejected.length}`);
|
|
103
|
-
for (const r of ack.rejected) {
|
|
104
|
-
console.warn(`[sdk] REJECTED ${r.topic} ${r.code}: ${r.message}`);
|
|
105
|
-
}
|
|
106
|
-
const summaryTimer = setInterval(() => {
|
|
107
|
-
const topicLine = [...counts.byTopic.entries()]
|
|
108
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
109
|
-
.map(([t, n]) => `${t}=${n}`)
|
|
110
|
-
.join(' ');
|
|
111
|
-
console.log(`[sdk] summary quote=${counts.quote} quoteSnap=${counts.quoteSnap} curveSnap=${counts.curveSnap} curveDelta=${counts.curveDelta}${topicLine ? ` | ${topicLine}` : ''}`);
|
|
112
|
-
}, Math.max(1_000, summaryEveryMs));
|
|
113
|
-
summaryTimer.unref?.();
|
|
114
|
-
process.on('SIGINT', () => {
|
|
115
|
-
clearInterval(summaryTimer);
|
|
116
|
-
void client.close().then(() => process.exit(0));
|
|
117
|
-
});
|
|
118
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;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