@tigeropenapi/tigeropen 0.1.0 → 0.3.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.
Files changed (129) hide show
  1. package/README.md +475 -104
  2. package/dist/cjs/client/api-request.js +16 -10
  3. package/dist/cjs/client/api-response.js +23 -3
  4. package/dist/cjs/client/case-convert.js +35 -0
  5. package/dist/cjs/client/http-client.js +46 -20
  6. package/dist/cjs/client/index.js +6 -2
  7. package/dist/cjs/config/client-config.js +130 -49
  8. package/dist/cjs/config/domain.js +21 -2
  9. package/dist/cjs/config/index.js +3 -1
  10. package/dist/cjs/index.js +1 -1
  11. package/dist/cjs/model/contract.js +1 -2
  12. package/dist/cjs/model/order-helpers.js +9 -9
  13. package/dist/cjs/model/order.js +5 -2
  14. package/dist/cjs/model/position.js +1 -2
  15. package/dist/cjs/model/quote.js +7 -0
  16. package/dist/cjs/model/trade.js +2 -0
  17. package/dist/cjs/push/index.js +6 -3
  18. package/dist/cjs/push/pb/AssetData.js +208 -0
  19. package/dist/cjs/push/pb/KlineData.js +184 -0
  20. package/dist/cjs/push/pb/OptionTopData.js +427 -0
  21. package/dist/cjs/push/pb/OrderStatusData.js +568 -0
  22. package/dist/cjs/push/pb/OrderTransactionData.js +256 -0
  23. package/dist/cjs/push/pb/PositionData.js +316 -0
  24. package/dist/cjs/push/pb/PushData.js +219 -0
  25. package/dist/cjs/push/pb/QuoteBBOData.js +160 -0
  26. package/dist/cjs/push/pb/QuoteBasicData.js +329 -0
  27. package/dist/cjs/push/pb/QuoteData.js +507 -0
  28. package/dist/cjs/push/pb/QuoteDepthData.js +220 -0
  29. package/dist/cjs/push/pb/Request.js +278 -0
  30. package/dist/cjs/push/pb/Response.js +97 -0
  31. package/dist/cjs/push/pb/SocketCommon.js +86 -0
  32. package/dist/cjs/push/pb/StockTopData.js +199 -0
  33. package/dist/cjs/push/pb/TickData.js +202 -0
  34. package/dist/cjs/push/pb/TradeTickData.js +308 -0
  35. package/dist/cjs/push/pb/index.js +49 -0
  36. package/dist/cjs/push/proto-message.js +129 -0
  37. package/dist/cjs/push/push-client.js +292 -164
  38. package/dist/cjs/push/push-message.js +4 -60
  39. package/dist/cjs/push/varint.js +76 -0
  40. package/dist/cjs/quote/index.js +3 -2
  41. package/dist/cjs/quote/quote-client.js +128 -94
  42. package/dist/cjs/signer/signer.js +10 -10
  43. package/dist/cjs/trade/trade-client.js +56 -62
  44. package/dist/esm/client/api-request.js +14 -8
  45. package/dist/esm/client/api-response.js +22 -3
  46. package/dist/esm/client/case-convert.js +31 -0
  47. package/dist/esm/client/http-client.js +47 -21
  48. package/dist/esm/client/index.js +3 -2
  49. package/dist/esm/config/client-config.js +131 -51
  50. package/dist/esm/config/domain.js +20 -2
  51. package/dist/esm/config/index.js +2 -2
  52. package/dist/esm/index.js +1 -1
  53. package/dist/esm/model/contract.js +1 -2
  54. package/dist/esm/model/order-helpers.js +9 -9
  55. package/dist/esm/model/order.js +5 -2
  56. package/dist/esm/model/position.js +1 -2
  57. package/dist/esm/model/quote.js +6 -0
  58. package/dist/esm/model/trade.js +1 -0
  59. package/dist/esm/push/index.js +4 -2
  60. package/dist/esm/push/pb/AssetData.js +205 -0
  61. package/dist/esm/push/pb/KlineData.js +181 -0
  62. package/dist/esm/push/pb/OptionTopData.js +424 -0
  63. package/dist/esm/push/pb/OrderStatusData.js +565 -0
  64. package/dist/esm/push/pb/OrderTransactionData.js +253 -0
  65. package/dist/esm/push/pb/PositionData.js +313 -0
  66. package/dist/esm/push/pb/PushData.js +216 -0
  67. package/dist/esm/push/pb/QuoteBBOData.js +157 -0
  68. package/dist/esm/push/pb/QuoteBasicData.js +326 -0
  69. package/dist/esm/push/pb/QuoteData.js +504 -0
  70. package/dist/esm/push/pb/QuoteDepthData.js +217 -0
  71. package/dist/esm/push/pb/Request.js +275 -0
  72. package/dist/esm/push/pb/Response.js +94 -0
  73. package/dist/esm/push/pb/SocketCommon.js +83 -0
  74. package/dist/esm/push/pb/StockTopData.js +196 -0
  75. package/dist/esm/push/pb/TickData.js +199 -0
  76. package/dist/esm/push/pb/TradeTickData.js +305 -0
  77. package/dist/esm/push/pb/index.js +25 -0
  78. package/dist/esm/push/proto-message.js +121 -0
  79. package/dist/esm/push/push-client.js +260 -165
  80. package/dist/esm/push/push-message.js +3 -56
  81. package/dist/esm/push/varint.js +72 -0
  82. package/dist/esm/quote/index.js +2 -2
  83. package/dist/esm/quote/quote-client.js +127 -94
  84. package/dist/esm/signer/signer.js +10 -10
  85. package/dist/esm/trade/trade-client.js +56 -62
  86. package/dist/types/client/api-request.d.ts +12 -11
  87. package/dist/types/client/api-response.d.ts +15 -7
  88. package/dist/types/client/case-convert.d.ts +16 -0
  89. package/dist/types/client/http-client.d.ts +26 -14
  90. package/dist/types/client/index.d.ts +3 -2
  91. package/dist/types/config/client-config.d.ts +29 -13
  92. package/dist/types/config/domain.d.ts +9 -0
  93. package/dist/types/config/index.d.ts +2 -2
  94. package/dist/types/index.d.ts +1 -1
  95. package/dist/types/model/contract.d.ts +13 -29
  96. package/dist/types/model/order-helpers.d.ts +21 -20
  97. package/dist/types/model/order.d.ts +101 -55
  98. package/dist/types/model/position.d.ts +26 -24
  99. package/dist/types/model/quote.d.ts +311 -0
  100. package/dist/types/model/trade.d.ts +113 -0
  101. package/dist/types/push/callbacks.d.ts +32 -51
  102. package/dist/types/push/index.d.ts +5 -3
  103. package/dist/types/push/pb/AssetData.d.ts +47 -0
  104. package/dist/types/push/pb/KlineData.d.ts +43 -0
  105. package/dist/types/push/pb/OptionTopData.d.ts +76 -0
  106. package/dist/types/push/pb/OrderStatusData.d.ts +96 -0
  107. package/dist/types/push/pb/OrderTransactionData.d.ts +51 -0
  108. package/dist/types/push/pb/PositionData.d.ts +63 -0
  109. package/dist/types/push/pb/PushData.d.ts +46 -0
  110. package/dist/types/push/pb/QuoteBBOData.d.ts +35 -0
  111. package/dist/types/push/pb/QuoteBasicData.d.ts +66 -0
  112. package/dist/types/push/pb/QuoteData.d.ts +94 -0
  113. package/dist/types/push/pb/QuoteDepthData.d.ts +37 -0
  114. package/dist/types/push/pb/Request.d.ts +44 -0
  115. package/dist/types/push/pb/Response.d.ts +30 -0
  116. package/dist/types/push/pb/SocketCommon.d.ts +64 -0
  117. package/dist/types/push/pb/StockTopData.d.ts +37 -0
  118. package/dist/types/push/pb/TickData.d.ts +44 -0
  119. package/dist/types/push/pb/TradeTickData.d.ts +53 -0
  120. package/dist/types/push/pb/index.d.ts +39 -0
  121. package/dist/types/push/proto-message.d.ts +33 -0
  122. package/dist/types/push/push-client.d.ts +69 -68
  123. package/dist/types/push/push-message.d.ts +3 -147
  124. package/dist/types/push/varint.d.ts +23 -0
  125. package/dist/types/quote/index.d.ts +2 -2
  126. package/dist/types/quote/quote-client.d.ts +41 -47
  127. package/dist/types/signer/signer.d.ts +6 -6
  128. package/dist/types/trade/trade-client.d.ts +34 -38
  129. package/package.json +11 -6
@@ -0,0 +1,44 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ export declare const protobufPackage = "com.tigerbrokers.stock.openapi.client.socket.data.pb";
3
+ export interface TickData {
4
+ symbol: string;
5
+ ticks: TickData_Tick[];
6
+ timestamp: number;
7
+ /** data source (Optional) */
8
+ source: string;
9
+ }
10
+ export interface TickData_Tick {
11
+ /** The order in which upstream data arrives, for reference only. */
12
+ sn: number;
13
+ /** Execution time of transaction. 13-digit timestamp */
14
+ time: number;
15
+ /** Transaction price. */
16
+ price: number;
17
+ /** Transaction volume. */
18
+ volume: number;
19
+ /** buy/sell direction. Active buy(+); Active sell(-); Neutral transaction(*) */
20
+ type: string;
21
+ /** The trade condition for irregular transaction. (Optional) */
22
+ cond: string;
23
+ /** The market participant reports the transaction. (Optional) */
24
+ partCode: string;
25
+ }
26
+ export declare const TickData: MessageFns<TickData>;
27
+ export declare const TickData_Tick: MessageFns<TickData_Tick>;
28
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
29
+ export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
30
+ [K in keyof T]?: DeepPartial<T[K]>;
31
+ } : Partial<T>;
32
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
33
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
34
+ [K in keyof P]: Exact<P[K], I[K]>;
35
+ } & {
36
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
37
+ };
38
+ export interface MessageFns<T> {
39
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
40
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
41
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
42
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
43
+ }
44
+ export {};
@@ -0,0 +1,53 @@
1
+ import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
2
+ export declare const protobufPackage = "com.tigerbrokers.stock.openapi.client.socket.data.pb";
3
+ export interface TradeTickData {
4
+ symbol: string;
5
+ /** buy/sell direction. Active buy(+); Active sell(-); Neutral transaction(*).Futures are not supported */
6
+ type: string;
7
+ /** The trade condition for irregular transaction.(Futures are not supported) */
8
+ cond: string;
9
+ /** serial number */
10
+ sn: number;
11
+ priceBase: number;
12
+ priceOffset: number;
13
+ /** The compressed transaction time is restored to the original time: time[i] = time[i] + time[i-1] */
14
+ time: number[];
15
+ /** The compressed transaction price is restored to the original price: price[i] = (priceBase + price[i]) / 10^priceOffset */
16
+ price: number[];
17
+ /** volume */
18
+ volume: number[];
19
+ /** The market participant reports the transaction,Usually a ~ z characters.(Futures are not supported) */
20
+ partCode: string[];
21
+ /** (Futures are not supported) */
22
+ quoteLevel: string;
23
+ timestamp: number;
24
+ /** STK Stocks, FUT Futures */
25
+ secType: string;
26
+ /** Original number of merges(Only futures are supported) */
27
+ mergedVols: TradeTickData_MergedVol[];
28
+ }
29
+ export interface TradeTickData_MergedVol {
30
+ /** Original number of merges */
31
+ mergeTimes: number;
32
+ /** original trading volume */
33
+ vol: number[];
34
+ }
35
+ export declare const TradeTickData: MessageFns<TradeTickData>;
36
+ export declare const TradeTickData_MergedVol: MessageFns<TradeTickData_MergedVol>;
37
+ type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
38
+ export type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
39
+ [K in keyof T]?: DeepPartial<T[K]>;
40
+ } : Partial<T>;
41
+ type KeysOfUnion<T> = T extends T ? keyof T : never;
42
+ export type Exact<P, I extends P> = P extends Builtin ? P : P & {
43
+ [K in keyof P]: Exact<P[K], I[K]>;
44
+ } & {
45
+ [K in Exclude<keyof I, KeysOfUnion<P>>]: never;
46
+ };
47
+ export interface MessageFns<T> {
48
+ encode(message: T, writer?: BinaryWriter): BinaryWriter;
49
+ decode(input: BinaryReader | Uint8Array, length?: number): T;
50
+ create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
51
+ fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
52
+ }
53
+ export {};
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Protobuf 生成代码统一导出
3
+ *
4
+ * 由 ts-proto 从 proto 文件生成的所有类型、枚举和编解码函数
5
+ */
6
+ export { SocketCommon_Command, SocketCommon_DataType, SocketCommon_QuoteType, } from './SocketCommon';
7
+ export type { SocketCommon } from './SocketCommon';
8
+ export { Request, Request_Connect, Request_Subscribe } from './Request';
9
+ export type { Request as RequestType, Request_Connect as RequestConnectType, Request_Subscribe as RequestSubscribeType, } from './Request';
10
+ export { Response } from './Response';
11
+ export type { Response as ResponseType } from './Response';
12
+ export { PushData } from './PushData';
13
+ export type { PushData as PushDataType } from './PushData';
14
+ export { QuoteData } from './QuoteData';
15
+ export type { QuoteData as QuoteDataType, QuoteData_Minute } from './QuoteData';
16
+ export { QuoteBasicData } from './QuoteBasicData';
17
+ export type { QuoteBasicData as QuoteBasicDataType } from './QuoteBasicData';
18
+ export { QuoteBBOData } from './QuoteBBOData';
19
+ export type { QuoteBBOData as QuoteBBODataType } from './QuoteBBOData';
20
+ export { QuoteDepthData } from './QuoteDepthData';
21
+ export type { QuoteDepthData as QuoteDepthDataType, QuoteDepthData_OrderBook } from './QuoteDepthData';
22
+ export { TradeTickData } from './TradeTickData';
23
+ export type { TradeTickData as TradeTickDataType, TradeTickData_MergedVol } from './TradeTickData';
24
+ export { TickData } from './TickData';
25
+ export type { TickData as TickDataType, TickData_Tick } from './TickData';
26
+ export { AssetData } from './AssetData';
27
+ export type { AssetData as AssetDataType } from './AssetData';
28
+ export { PositionData } from './PositionData';
29
+ export type { PositionData as PositionDataType } from './PositionData';
30
+ export { OrderStatusData } from './OrderStatusData';
31
+ export type { OrderStatusData as OrderStatusDataType } from './OrderStatusData';
32
+ export { OrderTransactionData } from './OrderTransactionData';
33
+ export type { OrderTransactionData as OrderTransactionDataType } from './OrderTransactionData';
34
+ export { StockTopData } from './StockTopData';
35
+ export type { StockTopData as StockTopDataType, StockTopData_TopData, StockTopData_StockItem, } from './StockTopData';
36
+ export { OptionTopData } from './OptionTopData';
37
+ export type { OptionTopData as OptionTopDataType, OptionTopData_TopData, OptionTopData_BigOrder, OptionTopData_OptionItem, } from './OptionTopData';
38
+ export { KlineData } from './KlineData';
39
+ export type { KlineData as KlineDataType } from './KlineData';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Protobuf 消息构建器
3
+ *
4
+ * 对齐 Java SDK 的 ProtoMessageUtil,提供构建各种 Request 消息的工具函数。
5
+ * 所有构建函数共享一个递增的 requestId 计数器。
6
+ */
7
+ import { Request } from './pb/Request';
8
+ import { SocketCommon_DataType } from './pb/SocketCommon';
9
+ import { SubjectType } from './push-message';
10
+ /**
11
+ * 构建 CONNECT 请求消息
12
+ */
13
+ export declare function buildConnectMessage(tigerId: string, sign: string, sdkVersion: string, acceptVersion: string, sendInterval: number, receiveInterval: number, useFullTick: boolean): Request;
14
+ /**
15
+ * 构建 HEARTBEAT 请求消息
16
+ */
17
+ export declare function buildHeartBeatMessage(): Request;
18
+ /**
19
+ * 构建 SUBSCRIBE 请求消息
20
+ */
21
+ export declare function buildSubscribeMessage(dataType: SocketCommon_DataType, symbols?: string, account?: string, market?: string): Request;
22
+ /**
23
+ * 构建 UNSUBSCRIBE 请求消息
24
+ */
25
+ export declare function buildUnSubscribeMessage(dataType: SocketCommon_DataType, symbols?: string, account?: string, market?: string): Request;
26
+ /**
27
+ * 构建 DISCONNECT 请求消息
28
+ */
29
+ export declare function buildDisconnectMessage(): Request;
30
+ /**
31
+ * 将 SubjectType 映射到 SocketCommon_DataType
32
+ */
33
+ export declare function subjectToDataType(subject: SubjectType): SocketCommon_DataType;
@@ -1,139 +1,140 @@
1
- /**
2
- * PushClient - WebSocket 推送客户端
3
- *
4
- * 通过 WebSocket 长连接接收实时行情和账户推送。
5
- * 支持连接认证、订阅/退订、回调机制、心跳保活和自动重连。
6
- */
7
1
  import type { ClientConfig } from '../config/client-config';
8
2
  import type { Callbacks } from './callbacks';
9
3
  import { SubjectType } from './push-message';
10
- /** 连接状态 */
4
+ /** Connection state */
11
5
  export declare enum ConnectionState {
12
6
  Disconnected = 0,
13
7
  Connecting = 1,
14
8
  Connected = 2
15
9
  }
16
- /** PushClient 配置选项 */
10
+ /** PushClient configuration options */
17
11
  export interface PushClientOptions {
18
- pushUrl?: string;
12
+ pushHost?: string;
13
+ pushPort?: number;
19
14
  heartbeatInterval?: number;
20
15
  reconnectInterval?: number;
21
16
  autoReconnect?: boolean;
22
17
  connectTimeout?: number;
18
+ useFullTick?: boolean;
23
19
  }
24
20
  /**
25
- * WebSocket 接口,方便测试注入
21
+ * TLS socket interface for test injection
26
22
  */
27
- export interface WebSocketLike {
28
- readonly readyState: number;
29
- send(data: string): void;
30
- close(): void;
31
- onopen: ((ev: unknown) => void) | null;
32
- onmessage: ((ev: {
33
- data: unknown;
34
- }) => void) | null;
35
- onclose: ((ev: unknown) => void) | null;
36
- onerror: ((ev: unknown) => void) | null;
23
+ export interface TLSSocketLike {
24
+ write(data: Uint8Array): boolean;
25
+ destroy(): void;
26
+ on(event: 'data', listener: (chunk: Buffer) => void): this;
27
+ on(event: 'error', listener: (err: Error) => void): this;
28
+ on(event: 'close', listener: () => void): this;
29
+ on(event: 'connect', listener: () => void): this;
37
30
  }
38
- /** WebSocket 工厂函数类型 */
39
- export type WebSocketFactory = (url: string) => WebSocketLike;
31
+ /** TLS socket factory function type */
32
+ export type TLSSocketFactory = (host: string, port: number) => TLSSocketLike;
40
33
  /**
41
- * PushClient WebSocket 推送客户端
34
+ * PushClient - TCP + TLS push client (Protobuf protocol)
42
35
  */
43
36
  export declare class PushClient {
44
37
  private config;
45
- private pushUrl;
38
+ private pushHost;
39
+ private pushPort;
46
40
  private heartbeatInterval;
47
41
  private reconnectInterval;
48
42
  private autoReconnect;
49
43
  private connectTimeout;
50
- private ws;
44
+ private useFullTick;
45
+ private socket;
51
46
  private _state;
52
47
  private callbacks;
53
- /** 订阅状态管理:subject -> Set<symbol> */
48
+ /** Subscription state: subject -> Set<symbol> */
54
49
  private subscriptions;
55
- /** 账户级别订阅 */
50
+ /** Account-level subscriptions */
56
51
  private accountSubs;
57
52
  private heartbeatTimer;
58
53
  private reconnectTimer;
59
54
  private stopped;
60
- /** 可注入的 WebSocket 工厂(用于测试) */
61
- wsFactory: WebSocketFactory | null;
55
+ /** TCP stream receive buffer */
56
+ private recvBuffer;
57
+ /** Injectable TLS socket factory (for testing) */
58
+ socketFactory: TLSSocketFactory | null;
62
59
  constructor(config: ClientConfig, options?: PushClientOptions);
63
- /** 获取当前连接状态 */
60
+ /** Get current connection state */
64
61
  get state(): ConnectionState;
65
- /** 设置回调函数集合 */
62
+ /** Set callback functions */
66
63
  setCallbacks(cb: Callbacks): void;
67
- /** 连接到推送服务器并进行认证 */
64
+ /** Connect to the push server and authenticate */
68
65
  connect(): Promise<void>;
69
- /** 断开连接 */
66
+ /** Disconnect from the push server */
70
67
  disconnect(): void;
71
- /** 发送认证消息 */
68
+ /** Send authentication message */
72
69
  private authenticate;
73
- /** 发送消息 */
70
+ /** Send a Protobuf Request message (varint32 length prefix + binary) */
74
71
  private sendMessage;
75
- /** 创建 WebSocket 实例 */
76
- private createWebSocket;
77
- /** 心跳保活 */
72
+ /** Create a TLS socket instance */
73
+ private createSocket;
74
+ /** Handle incoming TCP data: buffer + decode varint32 frames */
75
+ private handleData;
76
+ /** Handle a decoded Response message */
77
+ private handleResponse;
78
+ /** Heartbeat keep-alive */
78
79
  private startHeartbeat;
79
80
  private stopHeartbeat;
80
- /** 自动重连 */
81
+ /** Auto reconnect with exponential backoff */
81
82
  private scheduleReconnect;
82
83
  private clearReconnectTimer;
83
- /** 重连后恢复订阅 */
84
+ /** Resubscribe after reconnection */
84
85
  private resubscribe;
85
- /** 处理收到的消息 */
86
- private handleMessage;
87
- /** 内部订阅方法 */
86
+ /** Dispatch push data to the appropriate callback based on dataType */
87
+ private dispatchPushData;
88
+ /** Internal subscribe method */
88
89
  private doSubscribe;
89
- /** 内部退订方法 */
90
+ /** Internal unsubscribe method */
90
91
  private doUnsubscribe;
91
- /** 添加订阅记录 */
92
+ /** Add subscription record */
92
93
  private addSubscription;
93
- /** 移除订阅记录 */
94
+ /** Remove subscription record */
94
95
  private removeSubscription;
95
- /** 订阅行情 */
96
+ /** Subscribe to quotes */
96
97
  subscribeQuote(symbols: string[]): void;
97
- /** 退订行情 */
98
+ /** Unsubscribe from quotes */
98
99
  unsubscribeQuote(symbols?: string[]): void;
99
- /** 订阅逐笔成交 */
100
+ /** Subscribe to trade ticks */
100
101
  subscribeTick(symbols: string[]): void;
101
- /** 退订逐笔成交 */
102
+ /** Unsubscribe from trade ticks */
102
103
  unsubscribeTick(symbols?: string[]): void;
103
- /** 订阅深度行情 */
104
+ /** Subscribe to depth data */
104
105
  subscribeDepth(symbols: string[]): void;
105
- /** 退订深度行情 */
106
+ /** Unsubscribe from depth data */
106
107
  unsubscribeDepth(symbols?: string[]): void;
107
- /** 订阅期权行情 */
108
+ /** Subscribe to option quotes */
108
109
  subscribeOption(symbols: string[]): void;
109
- /** 退订期权行情 */
110
+ /** Unsubscribe from option quotes */
110
111
  unsubscribeOption(symbols?: string[]): void;
111
- /** 订阅期货行情 */
112
+ /** Subscribe to futures quotes */
112
113
  subscribeFuture(symbols: string[]): void;
113
- /** 退订期货行情 */
114
+ /** Unsubscribe from futures quotes */
114
115
  unsubscribeFuture(symbols?: string[]): void;
115
- /** 订阅 K 线 */
116
+ /** Subscribe to kline data */
116
117
  subscribeKline(symbols: string[]): void;
117
- /** 退订 K 线 */
118
+ /** Unsubscribe from kline data */
118
119
  unsubscribeKline(symbols?: string[]): void;
119
- /** 订阅资产变动 */
120
+ /** Subscribe to asset changes */
120
121
  subscribeAsset(account?: string): void;
121
- /** 退订资产变动 */
122
+ /** Unsubscribe from asset changes */
122
123
  unsubscribeAsset(): void;
123
- /** 订阅持仓变动 */
124
+ /** Subscribe to position changes */
124
125
  subscribePosition(account?: string): void;
125
- /** 退订持仓变动 */
126
+ /** Unsubscribe from position changes */
126
127
  unsubscribePosition(): void;
127
- /** 订阅订单状态 */
128
+ /** Subscribe to order status */
128
129
  subscribeOrder(account?: string): void;
129
- /** 退订订单状态 */
130
+ /** Unsubscribe from order status */
130
131
  unsubscribeOrder(): void;
131
- /** 订阅成交明细 */
132
+ /** Subscribe to transaction details */
132
133
  subscribeTransaction(account?: string): void;
133
- /** 退订成交明细 */
134
+ /** Unsubscribe from transaction details */
134
135
  unsubscribeTransaction(): void;
135
- /** 获取当前行情订阅状态 */
136
+ /** Get current market data subscriptions */
136
137
  getSubscriptions(): Map<SubjectType, string[]>;
137
- /** 获取账户级别订阅状态 */
138
+ /** Get account-level subscriptions */
138
139
  getAccountSubscriptions(): SubjectType[];
139
140
  }
@@ -1,34 +1,9 @@
1
1
  /**
2
- * 推送消息类型定义和数据结构
2
+ * 推送消息类型定义
3
3
  *
4
- * 定义 WebSocket 推送消息的类型、主题和数据结构,
5
- * 使用 JSON 序列化/反序列化(简化替代 Protobuf)。
4
+ * 仅保留 SubjectType 枚举,用于订阅/退订 API。
5
+ * JSON 消息类型定义和序列化函数已移除,改用 Protobuf 协议。
6
6
  */
7
- /** 推送消息类型 */
8
- export declare enum MessageType {
9
- Connect = "connect",
10
- Connected = "connected",
11
- Disconnect = "disconnect",
12
- Heartbeat = "heartbeat",
13
- Kickout = "kickout",
14
- Error = "error",
15
- Subscribe = "subscribe",
16
- Unsubscribe = "unsubscribe",
17
- Quote = "quote",
18
- Tick = "tick",
19
- Depth = "depth",
20
- Option = "option",
21
- Future = "future",
22
- Kline = "kline",
23
- StockTop = "stock_top",
24
- OptionTop = "option_top",
25
- FullTick = "full_tick",
26
- QuoteBBO = "quote_bbo",
27
- Asset = "asset",
28
- Position = "position",
29
- Order = "order",
30
- Transaction = "transaction"
31
- }
32
7
  /** 订阅主题类型 */
33
8
  export declare enum SubjectType {
34
9
  Quote = "quote",
@@ -46,122 +21,3 @@ export declare enum SubjectType {
46
21
  Order = "order",
47
22
  Transaction = "transaction"
48
23
  }
49
- /** 推送消息通用结构 */
50
- export interface PushMessage {
51
- type: MessageType;
52
- subject?: SubjectType | string;
53
- data?: unknown;
54
- }
55
- /** 连接认证请求 */
56
- export interface ConnectRequest {
57
- tigerId: string;
58
- sign: string;
59
- timestamp: string;
60
- version: string;
61
- }
62
- /** 订阅/退订请求 */
63
- export interface SubscribeRequest {
64
- subject: SubjectType;
65
- symbols?: string[];
66
- account?: string;
67
- market?: string;
68
- }
69
- /** 行情推送数据 */
70
- export interface QuoteData {
71
- symbol: string;
72
- latestPrice?: number;
73
- preClose?: number;
74
- open?: number;
75
- high?: number;
76
- low?: number;
77
- volume?: number;
78
- amount?: number;
79
- timestamp?: number;
80
- }
81
- /** 逐笔成交推送数据 */
82
- export interface TickData {
83
- symbol: string;
84
- price: number;
85
- volume: number;
86
- type?: string;
87
- timestamp?: number;
88
- }
89
- /** 价格档位 */
90
- export interface PriceLevel {
91
- price: number;
92
- volume: number;
93
- count?: number;
94
- }
95
- /** 深度行情推送数据 */
96
- export interface DepthData {
97
- symbol: string;
98
- asks?: PriceLevel[];
99
- bids?: PriceLevel[];
100
- }
101
- /** K 线推送数据 */
102
- export interface KlineData {
103
- symbol: string;
104
- open: number;
105
- high: number;
106
- low: number;
107
- close: number;
108
- volume: number;
109
- timestamp?: number;
110
- }
111
- /** 资产推送数据 */
112
- export interface AssetData {
113
- account: string;
114
- netLiquidation?: number;
115
- equityWithLoan?: number;
116
- cashBalance?: number;
117
- buyingPower?: number;
118
- currency?: string;
119
- }
120
- /** 持仓推送数据 */
121
- export interface PositionData {
122
- account: string;
123
- symbol: string;
124
- secType?: string;
125
- quantity: number;
126
- averageCost?: number;
127
- marketPrice?: number;
128
- marketValue?: number;
129
- unrealizedPnl?: number;
130
- }
131
- /** 订单推送数据 */
132
- export interface OrderData {
133
- account: string;
134
- id?: number;
135
- orderId?: number;
136
- symbol: string;
137
- action?: string;
138
- orderType?: string;
139
- quantity?: number;
140
- limitPrice?: number;
141
- status?: string;
142
- filled?: number;
143
- avgFillPrice?: number;
144
- }
145
- /** 成交推送数据 */
146
- export interface TransactionData {
147
- account: string;
148
- id?: number;
149
- orderId?: number;
150
- symbol: string;
151
- action?: string;
152
- price?: number;
153
- quantity?: number;
154
- timestamp?: number;
155
- }
156
- /**
157
- * 创建推送消息
158
- */
159
- export declare function createPushMessage(type: MessageType, subject?: SubjectType | string, data?: unknown): PushMessage;
160
- /**
161
- * 序列化推送消息为 JSON 字符串
162
- */
163
- export declare function serializeMessage(msg: PushMessage): string;
164
- /**
165
- * 反序列化 JSON 字符串为推送消息
166
- */
167
- export declare function deserializeMessage(data: string): PushMessage;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Varint32 帧编解码器
3
+ *
4
+ * 兼容 Netty 的 ProtobufVarint32FrameDecoder / ProtobufVarint32LengthFieldPrepender。
5
+ * 每个字节低 7 位存数据,最高位为延续标志(1=后续还有字节,0=最后一个字节),最大 5 字节。
6
+ */
7
+ /**
8
+ * 在 protobuf 字节前添加 varint32 长度前缀
9
+ *
10
+ * @param data - 待编码的 protobuf 二进制数据
11
+ * @returns varint32 长度前缀 + 原始数据
12
+ */
13
+ export declare function encodeVarint32(data: Uint8Array): Uint8Array;
14
+ /**
15
+ * 从缓冲区解码一个 varint32 帧
16
+ *
17
+ * @param buffer - 包含 varint32 长度前缀 + protobuf 数据的缓冲区
18
+ * @returns 解码结果 `{ message, remaining }`,数据不足时返回 `null`
19
+ */
20
+ export declare function decodeVarint32(buffer: Uint8Array): {
21
+ message: Uint8Array;
22
+ remaining: Uint8Array;
23
+ } | null;
@@ -1,4 +1,4 @@
1
1
  /**
2
- * 行情模块导出
2
+ * Quote module exports
3
3
  */
4
- export { QuoteClient } from './quote-client';
4
+ export { QuoteClient, parseOptionIdentifier } from './quote-client';