@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.
- package/README.md +475 -104
- package/dist/cjs/client/api-request.js +16 -10
- package/dist/cjs/client/api-response.js +23 -3
- package/dist/cjs/client/case-convert.js +35 -0
- package/dist/cjs/client/http-client.js +46 -20
- package/dist/cjs/client/index.js +6 -2
- package/dist/cjs/config/client-config.js +130 -49
- package/dist/cjs/config/domain.js +21 -2
- package/dist/cjs/config/index.js +3 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/model/contract.js +1 -2
- package/dist/cjs/model/order-helpers.js +9 -9
- package/dist/cjs/model/order.js +5 -2
- package/dist/cjs/model/position.js +1 -2
- package/dist/cjs/model/quote.js +7 -0
- package/dist/cjs/model/trade.js +2 -0
- package/dist/cjs/push/index.js +6 -3
- package/dist/cjs/push/pb/AssetData.js +208 -0
- package/dist/cjs/push/pb/KlineData.js +184 -0
- package/dist/cjs/push/pb/OptionTopData.js +427 -0
- package/dist/cjs/push/pb/OrderStatusData.js +568 -0
- package/dist/cjs/push/pb/OrderTransactionData.js +256 -0
- package/dist/cjs/push/pb/PositionData.js +316 -0
- package/dist/cjs/push/pb/PushData.js +219 -0
- package/dist/cjs/push/pb/QuoteBBOData.js +160 -0
- package/dist/cjs/push/pb/QuoteBasicData.js +329 -0
- package/dist/cjs/push/pb/QuoteData.js +507 -0
- package/dist/cjs/push/pb/QuoteDepthData.js +220 -0
- package/dist/cjs/push/pb/Request.js +278 -0
- package/dist/cjs/push/pb/Response.js +97 -0
- package/dist/cjs/push/pb/SocketCommon.js +86 -0
- package/dist/cjs/push/pb/StockTopData.js +199 -0
- package/dist/cjs/push/pb/TickData.js +202 -0
- package/dist/cjs/push/pb/TradeTickData.js +308 -0
- package/dist/cjs/push/pb/index.js +49 -0
- package/dist/cjs/push/proto-message.js +129 -0
- package/dist/cjs/push/push-client.js +292 -164
- package/dist/cjs/push/push-message.js +4 -60
- package/dist/cjs/push/varint.js +76 -0
- package/dist/cjs/quote/index.js +3 -2
- package/dist/cjs/quote/quote-client.js +128 -94
- package/dist/cjs/signer/signer.js +10 -10
- package/dist/cjs/trade/trade-client.js +56 -62
- package/dist/esm/client/api-request.js +14 -8
- package/dist/esm/client/api-response.js +22 -3
- package/dist/esm/client/case-convert.js +31 -0
- package/dist/esm/client/http-client.js +47 -21
- package/dist/esm/client/index.js +3 -2
- package/dist/esm/config/client-config.js +131 -51
- package/dist/esm/config/domain.js +20 -2
- package/dist/esm/config/index.js +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/model/contract.js +1 -2
- package/dist/esm/model/order-helpers.js +9 -9
- package/dist/esm/model/order.js +5 -2
- package/dist/esm/model/position.js +1 -2
- package/dist/esm/model/quote.js +6 -0
- package/dist/esm/model/trade.js +1 -0
- package/dist/esm/push/index.js +4 -2
- package/dist/esm/push/pb/AssetData.js +205 -0
- package/dist/esm/push/pb/KlineData.js +181 -0
- package/dist/esm/push/pb/OptionTopData.js +424 -0
- package/dist/esm/push/pb/OrderStatusData.js +565 -0
- package/dist/esm/push/pb/OrderTransactionData.js +253 -0
- package/dist/esm/push/pb/PositionData.js +313 -0
- package/dist/esm/push/pb/PushData.js +216 -0
- package/dist/esm/push/pb/QuoteBBOData.js +157 -0
- package/dist/esm/push/pb/QuoteBasicData.js +326 -0
- package/dist/esm/push/pb/QuoteData.js +504 -0
- package/dist/esm/push/pb/QuoteDepthData.js +217 -0
- package/dist/esm/push/pb/Request.js +275 -0
- package/dist/esm/push/pb/Response.js +94 -0
- package/dist/esm/push/pb/SocketCommon.js +83 -0
- package/dist/esm/push/pb/StockTopData.js +196 -0
- package/dist/esm/push/pb/TickData.js +199 -0
- package/dist/esm/push/pb/TradeTickData.js +305 -0
- package/dist/esm/push/pb/index.js +25 -0
- package/dist/esm/push/proto-message.js +121 -0
- package/dist/esm/push/push-client.js +260 -165
- package/dist/esm/push/push-message.js +3 -56
- package/dist/esm/push/varint.js +72 -0
- package/dist/esm/quote/index.js +2 -2
- package/dist/esm/quote/quote-client.js +127 -94
- package/dist/esm/signer/signer.js +10 -10
- package/dist/esm/trade/trade-client.js +56 -62
- package/dist/types/client/api-request.d.ts +12 -11
- package/dist/types/client/api-response.d.ts +15 -7
- package/dist/types/client/case-convert.d.ts +16 -0
- package/dist/types/client/http-client.d.ts +26 -14
- package/dist/types/client/index.d.ts +3 -2
- package/dist/types/config/client-config.d.ts +29 -13
- package/dist/types/config/domain.d.ts +9 -0
- package/dist/types/config/index.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/model/contract.d.ts +13 -29
- package/dist/types/model/order-helpers.d.ts +21 -20
- package/dist/types/model/order.d.ts +101 -55
- package/dist/types/model/position.d.ts +26 -24
- package/dist/types/model/quote.d.ts +311 -0
- package/dist/types/model/trade.d.ts +113 -0
- package/dist/types/push/callbacks.d.ts +32 -51
- package/dist/types/push/index.d.ts +5 -3
- package/dist/types/push/pb/AssetData.d.ts +47 -0
- package/dist/types/push/pb/KlineData.d.ts +43 -0
- package/dist/types/push/pb/OptionTopData.d.ts +76 -0
- package/dist/types/push/pb/OrderStatusData.d.ts +96 -0
- package/dist/types/push/pb/OrderTransactionData.d.ts +51 -0
- package/dist/types/push/pb/PositionData.d.ts +63 -0
- package/dist/types/push/pb/PushData.d.ts +46 -0
- package/dist/types/push/pb/QuoteBBOData.d.ts +35 -0
- package/dist/types/push/pb/QuoteBasicData.d.ts +66 -0
- package/dist/types/push/pb/QuoteData.d.ts +94 -0
- package/dist/types/push/pb/QuoteDepthData.d.ts +37 -0
- package/dist/types/push/pb/Request.d.ts +44 -0
- package/dist/types/push/pb/Response.d.ts +30 -0
- package/dist/types/push/pb/SocketCommon.d.ts +64 -0
- package/dist/types/push/pb/StockTopData.d.ts +37 -0
- package/dist/types/push/pb/TickData.d.ts +44 -0
- package/dist/types/push/pb/TradeTickData.d.ts +53 -0
- package/dist/types/push/pb/index.d.ts +39 -0
- package/dist/types/push/proto-message.d.ts +33 -0
- package/dist/types/push/push-client.d.ts +69 -68
- package/dist/types/push/push-message.d.ts +3 -147
- package/dist/types/push/varint.d.ts +23 -0
- package/dist/types/quote/index.d.ts +2 -2
- package/dist/types/quote/quote-client.d.ts +41 -47
- package/dist/types/signer/signer.d.ts +6 -6
- package/dist/types/trade/trade-client.d.ts +34 -38
- 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
|
-
|
|
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
|
-
*
|
|
21
|
+
* TLS socket interface for test injection
|
|
26
22
|
*/
|
|
27
|
-
export interface
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
/**
|
|
39
|
-
export type
|
|
31
|
+
/** TLS socket factory function type */
|
|
32
|
+
export type TLSSocketFactory = (host: string, port: number) => TLSSocketLike;
|
|
40
33
|
/**
|
|
41
|
-
* PushClient
|
|
34
|
+
* PushClient - TCP + TLS push client (Protobuf protocol)
|
|
42
35
|
*/
|
|
43
36
|
export declare class PushClient {
|
|
44
37
|
private config;
|
|
45
|
-
private
|
|
38
|
+
private pushHost;
|
|
39
|
+
private pushPort;
|
|
46
40
|
private heartbeatInterval;
|
|
47
41
|
private reconnectInterval;
|
|
48
42
|
private autoReconnect;
|
|
49
43
|
private connectTimeout;
|
|
50
|
-
private
|
|
44
|
+
private useFullTick;
|
|
45
|
+
private socket;
|
|
51
46
|
private _state;
|
|
52
47
|
private callbacks;
|
|
53
|
-
/**
|
|
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
|
-
/**
|
|
61
|
-
|
|
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
|
-
/**
|
|
76
|
-
private
|
|
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
|
|
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
|
-
/**
|
|
116
|
+
/** Subscribe to kline data */
|
|
116
117
|
subscribeKline(symbols: string[]): void;
|
|
117
|
-
/**
|
|
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
|
-
*
|
|
5
|
-
*
|
|
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;
|