@tigeropenapi/tigeropen 0.1.0 → 0.4.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 +47 -21
- 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/enums.js +89 -7
- package/dist/cjs/model/order-helpers.js +9 -9
- package/dist/cjs/model/order-status.js +46 -0
- package/dist/cjs/model/order.js +5 -2
- package/dist/cjs/model/position.js +1 -2
- package/dist/cjs/model/quote-requests.js +11 -0
- package/dist/cjs/model/quote.js +7 -0
- package/dist/cjs/model/trade-requests.js +13 -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 +592 -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 +135 -0
- package/dist/cjs/push/push-client.js +361 -163
- package/dist/cjs/push/push-message.js +8 -60
- package/dist/cjs/push/varint.js +76 -0
- package/dist/cjs/quote/index.js +3 -2
- package/dist/cjs/quote/quote-client.js +440 -94
- package/dist/cjs/signer/signer.js +10 -10
- package/dist/cjs/trade/trade-client.js +197 -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 +48 -22
- 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/enums.js +87 -6
- package/dist/esm/model/order-helpers.js +9 -9
- package/dist/esm/model/order-status.js +43 -0
- package/dist/esm/model/order.js +5 -2
- package/dist/esm/model/position.js +1 -2
- package/dist/esm/model/quote-requests.js +10 -0
- package/dist/esm/model/quote.js +6 -0
- package/dist/esm/model/trade-requests.js +12 -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 +589 -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 +127 -0
- package/dist/esm/push/push-client.js +329 -164
- package/dist/esm/push/push-message.js +7 -56
- package/dist/esm/push/varint.js +72 -0
- package/dist/esm/quote/index.js +2 -2
- package/dist/esm/quote/quote-client.js +439 -94
- package/dist/esm/signer/signer.js +10 -10
- package/dist/esm/trade/trade-client.js +197 -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/enums.d.ts +60 -6
- package/dist/types/model/order-helpers.d.ts +21 -20
- package/dist/types/model/order-status.d.ts +14 -0
- package/dist/types/model/order.d.ts +101 -55
- package/dist/types/model/position.d.ts +26 -24
- package/dist/types/model/quote-requests.d.ts +344 -0
- package/dist/types/model/quote.d.ts +572 -0
- package/dist/types/model/trade-requests.d.ts +195 -0
- package/dist/types/model/trade.d.ts +235 -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 +100 -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 +100 -68
- package/dist/types/push/push-message.d.ts +7 -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 +154 -47
- package/dist/types/signer/signer.d.ts +6 -6
- package/dist/types/trade/trade-client.d.ts +106 -38
- package/package.json +11 -6
|
@@ -1,58 +1,125 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ClientConfig -
|
|
2
|
+
* ClientConfig - Client configuration management
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
4
|
+
* Aggregates all configuration parameters with support for:
|
|
5
|
+
* - Direct code configuration
|
|
6
|
+
* - Properties file loading (explicit path or auto-discovery)
|
|
7
|
+
* - Environment variable overrides
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* Priority: environment variables > code options (incl. config file) > defaults
|
|
10
10
|
*/
|
|
11
|
-
import { readFileSync } from 'fs';
|
|
11
|
+
import { readFileSync, existsSync } from 'fs';
|
|
12
|
+
import { join } from 'path';
|
|
13
|
+
import { homedir, networkInterfaces } from 'os';
|
|
12
14
|
import { parsePropertiesString } from './config-parser';
|
|
13
|
-
import { queryDomains, resolveDynamicServerUrl } from './domain';
|
|
14
|
-
/**
|
|
15
|
+
import { queryDomains, resolveDynamicServerUrl, resolveDynamicQuoteServerUrl } from './domain';
|
|
16
|
+
/** Default config file name */
|
|
17
|
+
const CONFIG_FILE_NAME = 'tiger_openapi_config.properties';
|
|
18
|
+
/** Defaults */
|
|
15
19
|
const DEFAULT_LANGUAGE = 'zh_CN';
|
|
16
20
|
const DEFAULT_TIMEOUT = 15;
|
|
17
21
|
const DEFAULT_SERVER_URL = 'https://openapi.tigerfintech.com/gateway';
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
/** Tiger public key for response signature verification (Base64-encoded) */
|
|
23
|
+
const TIGER_PUBLIC_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDNF3G8SoEcCZh2rshUbayDgLLrj6rKgzNMxDL2HSnKcB0+GPOsndqSv+a4IBu9+I3fyBp5hkyMMG2+AXugd9pMpy6VxJxlNjhX1MYbNTZJUT4nudki4uh+LMOkIBHOceGNXjgB+cXqmlUnjlqha/HgboeHSnSgpM3dKSJQlIOsDwIDAQAB';
|
|
24
|
+
/** Environment variable names */
|
|
20
25
|
const ENV_TIGER_ID = 'TIGEROPEN_TIGER_ID';
|
|
21
26
|
const ENV_PRIVATE_KEY = 'TIGEROPEN_PRIVATE_KEY';
|
|
22
27
|
const ENV_ACCOUNT = 'TIGEROPEN_ACCOUNT';
|
|
28
|
+
const ENV_TOKEN = 'TIGEROPEN_TOKEN';
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
30
|
+
* Load and parse a Java-style properties file.
|
|
25
31
|
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
32
|
+
* @param filePath - Absolute or relative path to the properties file
|
|
33
|
+
* @returns Parsed key-value pairs, or empty object if the file cannot be read
|
|
34
|
+
*/
|
|
35
|
+
export function loadPropertiesFile(filePath) {
|
|
36
|
+
try {
|
|
37
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
38
|
+
return parsePropertiesString(content);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Discover the config file by searching well-known locations.
|
|
46
|
+
*
|
|
47
|
+
* Search order:
|
|
48
|
+
* 1. `./tiger_openapi_config.properties` (current working directory)
|
|
49
|
+
* 2. `~/.tigeropen/tiger_openapi_config.properties` (home directory)
|
|
50
|
+
*
|
|
51
|
+
* @returns The resolved file path, or `undefined` if not found
|
|
52
|
+
*/
|
|
53
|
+
function discoverConfigFile() {
|
|
54
|
+
const candidates = [
|
|
55
|
+
join(process.cwd(), CONFIG_FILE_NAME),
|
|
56
|
+
join(homedir(), '.tigeropen', CONFIG_FILE_NAME),
|
|
57
|
+
];
|
|
58
|
+
for (const candidate of candidates) {
|
|
59
|
+
if (existsSync(candidate)) {
|
|
60
|
+
return candidate;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Auto-detect device identifier from the first non-internal MAC address.
|
|
28
67
|
*
|
|
29
|
-
* @
|
|
30
|
-
|
|
31
|
-
|
|
68
|
+
* @returns MAC address string, or empty string if none found
|
|
69
|
+
*/
|
|
70
|
+
function detectDeviceId() {
|
|
71
|
+
const interfaces = networkInterfaces();
|
|
72
|
+
for (const [, addrs] of Object.entries(interfaces)) {
|
|
73
|
+
if (!addrs)
|
|
74
|
+
continue;
|
|
75
|
+
for (const addr of addrs) {
|
|
76
|
+
if (!addr.internal && addr.mac && addr.mac !== '00:00:00:00:00:00') {
|
|
77
|
+
return addr.mac;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a client configuration.
|
|
85
|
+
*
|
|
86
|
+
* When called with no arguments (or without `propertiesFilePath`), the function
|
|
87
|
+
* automatically searches for `tiger_openapi_config.properties` in the current
|
|
88
|
+
* directory and `~/.tigeropen/`. Discovered values serve as defaults; explicit
|
|
89
|
+
* options and environment variables take precedence.
|
|
90
|
+
*
|
|
91
|
+
* Priority: environment variables > code options > config file > defaults
|
|
92
|
+
*
|
|
93
|
+
* @param options - Configuration options (optional)
|
|
94
|
+
* @returns Complete client configuration object
|
|
95
|
+
* @throws When tigerId or privateKey is empty after all resolution
|
|
32
96
|
*/
|
|
33
97
|
export function createClientConfig(options) {
|
|
34
|
-
|
|
98
|
+
const opts = options ?? {};
|
|
99
|
+
// Load properties: explicit path > auto-discovery
|
|
35
100
|
let fileProps = {};
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
101
|
+
if (opts.propertiesFilePath) {
|
|
102
|
+
fileProps = loadPropertiesFile(opts.propertiesFilePath);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
const discovered = discoverConfigFile();
|
|
106
|
+
if (discovered) {
|
|
107
|
+
fileProps = loadPropertiesFile(discovered);
|
|
43
108
|
}
|
|
44
109
|
}
|
|
45
|
-
//
|
|
46
|
-
let tigerId =
|
|
47
|
-
let privateKey =
|
|
48
|
-
let account =
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
110
|
+
// Merge values (code options override config file)
|
|
111
|
+
let tigerId = opts.tigerId || fileProps['tiger_id'] || '';
|
|
112
|
+
let privateKey = opts.privateKey || resolvePrivateKey(fileProps) || '';
|
|
113
|
+
let account = opts.account || fileProps['account'] || '';
|
|
114
|
+
let token = opts.token || fileProps['token'];
|
|
115
|
+
const license = opts.license || fileProps['license'];
|
|
116
|
+
const language = opts.language || fileProps['language'] || DEFAULT_LANGUAGE;
|
|
117
|
+
const timezone = opts.timezone || fileProps['timezone'];
|
|
118
|
+
// Environment variables override everything
|
|
53
119
|
const envTigerId = process.env[ENV_TIGER_ID];
|
|
54
120
|
const envPrivateKey = process.env[ENV_PRIVATE_KEY];
|
|
55
121
|
const envAccount = process.env[ENV_ACCOUNT];
|
|
122
|
+
const envToken = process.env[ENV_TOKEN];
|
|
56
123
|
if (envTigerId) {
|
|
57
124
|
tigerId = envTigerId;
|
|
58
125
|
}
|
|
@@ -62,25 +129,24 @@ export function createClientConfig(options) {
|
|
|
62
129
|
if (envAccount) {
|
|
63
130
|
account = envAccount;
|
|
64
131
|
}
|
|
65
|
-
|
|
132
|
+
if (envToken) {
|
|
133
|
+
token = envToken;
|
|
134
|
+
}
|
|
135
|
+
// Validate required fields
|
|
66
136
|
if (!tigerId) {
|
|
67
|
-
throw new Error(`tigerId
|
|
137
|
+
throw new Error(`tigerId is required. Set it via options.tigerId, a config file, or the ${ENV_TIGER_ID} environment variable.`);
|
|
68
138
|
}
|
|
69
139
|
if (!privateKey) {
|
|
70
|
-
throw new Error(`privateKey
|
|
140
|
+
throw new Error(`privateKey is required. Set it via options.privateKey, a config file, or the ${ENV_PRIVATE_KEY} environment variable.`);
|
|
71
141
|
}
|
|
72
|
-
//
|
|
73
|
-
const
|
|
74
|
-
const enableDynamicDomain = options.enableDynamicDomain ?? true;
|
|
142
|
+
// Resolve server URL: explicit > dynamic domain > default
|
|
143
|
+
const enableDynamicDomain = opts.enableDynamicDomain ?? true;
|
|
75
144
|
let serverUrl;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
else if (options.serverUrl) {
|
|
80
|
-
serverUrl = options.serverUrl;
|
|
145
|
+
let quoteServerUrl;
|
|
146
|
+
if (opts.serverUrl) {
|
|
147
|
+
serverUrl = opts.serverUrl;
|
|
81
148
|
}
|
|
82
149
|
else {
|
|
83
|
-
// 尝试动态域名获取
|
|
84
150
|
let dynamicUrl = '';
|
|
85
151
|
if (enableDynamicDomain) {
|
|
86
152
|
const domainConf = queryDomains(license);
|
|
@@ -88,6 +154,18 @@ export function createClientConfig(options) {
|
|
|
88
154
|
}
|
|
89
155
|
serverUrl = dynamicUrl || DEFAULT_SERVER_URL;
|
|
90
156
|
}
|
|
157
|
+
// Resolve quote server URL: explicit > dynamic domain > serverUrl fallback
|
|
158
|
+
if (opts.quoteServerUrl) {
|
|
159
|
+
quoteServerUrl = opts.quoteServerUrl;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
let dynamicQuoteUrl = '';
|
|
163
|
+
if (enableDynamicDomain) {
|
|
164
|
+
const domainConf = queryDomains(license);
|
|
165
|
+
dynamicQuoteUrl = resolveDynamicQuoteServerUrl(domainConf, license);
|
|
166
|
+
}
|
|
167
|
+
quoteServerUrl = dynamicQuoteUrl || serverUrl;
|
|
168
|
+
}
|
|
91
169
|
return {
|
|
92
170
|
tigerId,
|
|
93
171
|
privateKey,
|
|
@@ -95,16 +173,18 @@ export function createClientConfig(options) {
|
|
|
95
173
|
license,
|
|
96
174
|
language,
|
|
97
175
|
timezone,
|
|
98
|
-
timeout:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
tokenRefreshDuration: options.tokenRefreshDuration,
|
|
176
|
+
timeout: opts.timeout ?? DEFAULT_TIMEOUT,
|
|
177
|
+
token,
|
|
178
|
+
tokenRefreshDuration: opts.tokenRefreshDuration,
|
|
102
179
|
serverUrl,
|
|
180
|
+
quoteServerUrl,
|
|
181
|
+
deviceId: detectDeviceId(),
|
|
182
|
+
tigerPublicKey: TIGER_PUBLIC_KEY,
|
|
103
183
|
};
|
|
104
184
|
}
|
|
105
185
|
/**
|
|
106
|
-
*
|
|
107
|
-
*
|
|
186
|
+
* Resolve private key from properties.
|
|
187
|
+
* Priority: private_key > private_key_pk8 > private_key_pk1
|
|
108
188
|
*/
|
|
109
189
|
function resolvePrivateKey(props) {
|
|
110
190
|
return props['private_key'] || props['private_key_pk8'] || props['private_key_pk1'] || '';
|
|
@@ -63,8 +63,26 @@ export function resolveDynamicServerUrl(domainConf, license) {
|
|
|
63
63
|
return '';
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
66
|
+
* Resolve the quote server URL from dynamic domain configuration.
|
|
67
|
+
* Uses the `{LICENSE}-QUOTE` key, falling back to empty string.
|
|
68
|
+
*
|
|
69
|
+
* @param domainConf - Domain configuration map from queryDomains
|
|
70
|
+
* @param license - License type (e.g. "TBNZ")
|
|
71
|
+
* @returns Quote server URL with gateway suffix, or empty string
|
|
72
|
+
*/
|
|
73
|
+
export function resolveDynamicQuoteServerUrl(domainConf, license) {
|
|
74
|
+
if (!domainConf || Object.keys(domainConf).length === 0) {
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
const key = license ? `${license}-QUOTE` : `${DOMAIN_KEY_COMMON}-QUOTE`;
|
|
78
|
+
if (typeof domainConf[key] === 'string') {
|
|
79
|
+
return domainConf[key] + GATEWAY_SUFFIX;
|
|
80
|
+
}
|
|
81
|
+
return '';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Synchronous HTTP GET request (Node.js environment).
|
|
85
|
+
* Uses child_process.execSync for synchronous requests with fast timeout.
|
|
68
86
|
*/
|
|
69
87
|
function syncHttpGet(url, timeoutMs) {
|
|
70
88
|
try {
|
package/dist/esm/config/index.js
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* 配置层导出
|
|
3
3
|
*/
|
|
4
4
|
export { parsePropertiesFile, parsePropertiesString } from './config-parser';
|
|
5
|
-
export { createClientConfig } from './client-config';
|
|
6
|
-
export { queryDomains, resolveDynamicServerUrl } from './domain';
|
|
5
|
+
export { createClientConfig, loadPropertiesFile } from './client-config';
|
|
6
|
+
export { queryDomains, resolveDynamicServerUrl, resolveDynamicQuoteServerUrl } from './domain';
|
package/dist/esm/index.js
CHANGED
package/dist/esm/model/enums.js
CHANGED
|
@@ -48,19 +48,49 @@ export var OrderType;
|
|
|
48
48
|
OrderType["VWAP"] = "VWAP";
|
|
49
49
|
OrderType["OCA"] = "OCA";
|
|
50
50
|
})(OrderType || (OrderType = {}));
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* 订单状态枚举。对齐 Java SDK OrderStatus 定义。
|
|
53
|
+
*
|
|
54
|
+
* 服务端 wire 返回的值同时可能是:
|
|
55
|
+
* - 数字: -2 / -1 / 3 / 4 / 5 / 6 / 7 / 8
|
|
56
|
+
* - 字符串: "Invalid" / "Initial" / "PendingCancel" / "Cancelled" /
|
|
57
|
+
* "Submitted" / "Filled" / "Inactive" / "PendingSubmit"
|
|
58
|
+
*
|
|
59
|
+
* Client 层通过 normalizeOrderStatus() 做数字→字符串归一,不做跨别名合并。
|
|
60
|
+
*/
|
|
52
61
|
export var OrderStatus;
|
|
53
62
|
(function (OrderStatus) {
|
|
54
|
-
OrderStatus["
|
|
63
|
+
OrderStatus["Invalid"] = "Invalid";
|
|
55
64
|
OrderStatus["Initial"] = "Initial";
|
|
65
|
+
OrderStatus["PendingCancel"] = "PendingCancel";
|
|
66
|
+
OrderStatus["Cancelled"] = "Cancelled";
|
|
56
67
|
OrderStatus["Submitted"] = "Submitted";
|
|
57
|
-
OrderStatus["PartiallyFilled"] = "PartiallyFilled";
|
|
58
68
|
OrderStatus["Filled"] = "Filled";
|
|
59
|
-
OrderStatus["Cancelled"] = "Cancelled";
|
|
60
|
-
OrderStatus["PendingCancel"] = "PendingCancel";
|
|
61
69
|
OrderStatus["Inactive"] = "Inactive";
|
|
62
|
-
OrderStatus["
|
|
70
|
+
OrderStatus["PendingSubmit"] = "PendingSubmit";
|
|
63
71
|
})(OrderStatus || (OrderStatus = {}));
|
|
72
|
+
/** 返回订单状态对应的服务端数字码,未知返回 0。 */
|
|
73
|
+
export function orderStatusCode(status) {
|
|
74
|
+
switch (status) {
|
|
75
|
+
case OrderStatus.Invalid:
|
|
76
|
+
return -2;
|
|
77
|
+
case OrderStatus.Initial:
|
|
78
|
+
return -1;
|
|
79
|
+
case OrderStatus.PendingCancel:
|
|
80
|
+
return 3;
|
|
81
|
+
case OrderStatus.Cancelled:
|
|
82
|
+
return 4;
|
|
83
|
+
case OrderStatus.Submitted:
|
|
84
|
+
return 5;
|
|
85
|
+
case OrderStatus.Filled:
|
|
86
|
+
return 6;
|
|
87
|
+
case OrderStatus.Inactive:
|
|
88
|
+
return 7;
|
|
89
|
+
case OrderStatus.PendingSubmit:
|
|
90
|
+
return 8;
|
|
91
|
+
}
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
64
94
|
/** K 线周期枚举 */
|
|
65
95
|
export var BarPeriod;
|
|
66
96
|
(function (BarPeriod) {
|
|
@@ -105,3 +135,54 @@ export var TimeInForce;
|
|
|
105
135
|
TimeInForce["GTC"] = "GTC";
|
|
106
136
|
TimeInForce["OPG"] = "OPG";
|
|
107
137
|
})(TimeInForce || (TimeInForce = {}));
|
|
138
|
+
/** 订单排序字段 */
|
|
139
|
+
export var OrderSortBy;
|
|
140
|
+
(function (OrderSortBy) {
|
|
141
|
+
OrderSortBy["LatestCreated"] = "LATEST_CREATED";
|
|
142
|
+
OrderSortBy["LatestStatusUpdated"] = "LATEST_STATUS_UPDATED";
|
|
143
|
+
})(OrderSortBy || (OrderSortBy = {}));
|
|
144
|
+
/** 账户分部类型 */
|
|
145
|
+
export var SegmentType;
|
|
146
|
+
(function (SegmentType) {
|
|
147
|
+
SegmentType["All"] = "ALL";
|
|
148
|
+
SegmentType["Sec"] = "SEC";
|
|
149
|
+
SegmentType["Fut"] = "FUT";
|
|
150
|
+
SegmentType["Fund"] = "FUND";
|
|
151
|
+
})(SegmentType || (SegmentType = {}));
|
|
152
|
+
/** 公司行动类型 */
|
|
153
|
+
export var CorporateActionType;
|
|
154
|
+
(function (CorporateActionType) {
|
|
155
|
+
CorporateActionType["Split"] = "split";
|
|
156
|
+
CorporateActionType["Dividend"] = "dividend";
|
|
157
|
+
CorporateActionType["Earning"] = "earning";
|
|
158
|
+
})(CorporateActionType || (CorporateActionType = {}));
|
|
159
|
+
/** 行业级别 (1~4 级) */
|
|
160
|
+
export var IndustryLevel;
|
|
161
|
+
(function (IndustryLevel) {
|
|
162
|
+
IndustryLevel["GSector"] = "GSECTOR";
|
|
163
|
+
IndustryLevel["GGroup"] = "GGROUP";
|
|
164
|
+
IndustryLevel["GInd"] = "GIND";
|
|
165
|
+
IndustryLevel["GSubInd"] = "GSUBIND";
|
|
166
|
+
})(IndustryLevel || (IndustryLevel = {}));
|
|
167
|
+
/** 排序方向 */
|
|
168
|
+
export var SortDirection;
|
|
169
|
+
(function (SortDirection) {
|
|
170
|
+
SortDirection["No"] = "SortDir_No";
|
|
171
|
+
SortDirection["Ascend"] = "SortDir_Ascend";
|
|
172
|
+
SortDirection["Descend"] = "SortDir_Descend";
|
|
173
|
+
})(SortDirection || (SortDirection = {}));
|
|
174
|
+
/** 期权分析周期 */
|
|
175
|
+
export var OptionAnalysisPeriod;
|
|
176
|
+
(function (OptionAnalysisPeriod) {
|
|
177
|
+
OptionAnalysisPeriod["ThreeYear"] = "3year";
|
|
178
|
+
OptionAnalysisPeriod["FiftyTwoWeek"] = "52week";
|
|
179
|
+
OptionAnalysisPeriod["TwentySixWeek"] = "26week";
|
|
180
|
+
OptionAnalysisPeriod["ThirteenWeek"] = "13week";
|
|
181
|
+
})(OptionAnalysisPeriod || (OptionAnalysisPeriod = {}));
|
|
182
|
+
/** 财报类型 */
|
|
183
|
+
export var FinancialReportPeriod;
|
|
184
|
+
(function (FinancialReportPeriod) {
|
|
185
|
+
FinancialReportPeriod["Annual"] = "Annual";
|
|
186
|
+
FinancialReportPeriod["Quarterly"] = "Quarterly";
|
|
187
|
+
FinancialReportPeriod["LTM"] = "LTM";
|
|
188
|
+
})(FinancialReportPeriod || (FinancialReportPeriod = {}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OrderType, TimeInForce } from './enums';
|
|
2
|
-
/**
|
|
2
|
+
/** Market order */
|
|
3
3
|
export function marketOrder(account, symbol, secType, action, quantity) {
|
|
4
4
|
return {
|
|
5
5
|
account, symbol, secType, action,
|
|
@@ -9,7 +9,7 @@ export function marketOrder(account, symbol, secType, action, quantity) {
|
|
|
9
9
|
outsideRth: false,
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
/**
|
|
12
|
+
/** Limit order */
|
|
13
13
|
export function limitOrder(account, symbol, secType, action, quantity, limitPrice) {
|
|
14
14
|
return {
|
|
15
15
|
account, symbol, secType, action,
|
|
@@ -20,7 +20,7 @@ export function limitOrder(account, symbol, secType, action, quantity, limitPric
|
|
|
20
20
|
outsideRth: false,
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
23
|
+
/** Stop order */
|
|
24
24
|
export function stopOrder(account, symbol, secType, action, quantity, auxPrice) {
|
|
25
25
|
return {
|
|
26
26
|
account, symbol, secType, action,
|
|
@@ -31,7 +31,7 @@ export function stopOrder(account, symbol, secType, action, quantity, auxPrice)
|
|
|
31
31
|
outsideRth: false,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
34
|
+
/** Stop limit order */
|
|
35
35
|
export function stopLimitOrder(account, symbol, secType, action, quantity, limitPrice, auxPrice) {
|
|
36
36
|
return {
|
|
37
37
|
account, symbol, secType, action,
|
|
@@ -43,7 +43,7 @@ export function stopLimitOrder(account, symbol, secType, action, quantity, limit
|
|
|
43
43
|
outsideRth: false,
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
-
/**
|
|
46
|
+
/** Trailing stop order */
|
|
47
47
|
export function trailOrder(account, symbol, secType, action, quantity, trailingPercent) {
|
|
48
48
|
return {
|
|
49
49
|
account, symbol, secType, action,
|
|
@@ -54,7 +54,7 @@ export function trailOrder(account, symbol, secType, action, quantity, trailingP
|
|
|
54
54
|
outsideRth: false,
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
/**
|
|
57
|
+
/** Auction limit order */
|
|
58
58
|
export function auctionLimitOrder(account, symbol, secType, action, quantity, limitPrice) {
|
|
59
59
|
return {
|
|
60
60
|
account, symbol, secType, action,
|
|
@@ -65,7 +65,7 @@ export function auctionLimitOrder(account, symbol, secType, action, quantity, li
|
|
|
65
65
|
outsideRth: false,
|
|
66
66
|
};
|
|
67
67
|
}
|
|
68
|
-
/**
|
|
68
|
+
/** Auction market order */
|
|
69
69
|
export function auctionMarketOrder(account, symbol, secType, action, quantity) {
|
|
70
70
|
return {
|
|
71
71
|
account, symbol, secType, action,
|
|
@@ -75,7 +75,7 @@ export function auctionMarketOrder(account, symbol, secType, action, quantity) {
|
|
|
75
75
|
outsideRth: false,
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
|
-
/**
|
|
78
|
+
/** Algo order (TWAP / VWAP) */
|
|
79
79
|
export function algoOrder(account, symbol, secType, action, quantity, limitPrice, algoType, params) {
|
|
80
80
|
return {
|
|
81
81
|
account, symbol, secType, action,
|
|
@@ -87,7 +87,7 @@ export function algoOrder(account, symbol, secType, action, quantity, limitPrice
|
|
|
87
87
|
outsideRth: false,
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
-
/**
|
|
90
|
+
/** Attached profit / loss leg */
|
|
91
91
|
export function orderLeg(legType, price, timeInForce) {
|
|
92
92
|
return { legType, price, timeInForce };
|
|
93
93
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Order status normalization.
|
|
3
|
+
*
|
|
4
|
+
* 服务端返回的订单状态有时是整数(-2/-1/3/4/5/6/7/8),有时是字符串
|
|
5
|
+
* ("Invalid"/"Submitted"/...)。本模块把二者统一为 Java SDK OrderStatus 的
|
|
6
|
+
* 字符串值。不做跨别名合并。
|
|
7
|
+
*
|
|
8
|
+
* 对齐 Java SDK OrderStatus.java。
|
|
9
|
+
*/
|
|
10
|
+
import { OrderStatus } from './enums';
|
|
11
|
+
/** 把数字状态码映射到字符串,未识别返回空串。 */
|
|
12
|
+
function statusIntToString(n) {
|
|
13
|
+
switch (n) {
|
|
14
|
+
case -2:
|
|
15
|
+
return OrderStatus.Invalid;
|
|
16
|
+
case -1:
|
|
17
|
+
return OrderStatus.Initial;
|
|
18
|
+
case 3:
|
|
19
|
+
return OrderStatus.PendingCancel;
|
|
20
|
+
case 4:
|
|
21
|
+
return OrderStatus.Cancelled;
|
|
22
|
+
case 5:
|
|
23
|
+
return OrderStatus.Submitted;
|
|
24
|
+
case 6:
|
|
25
|
+
return OrderStatus.Filled;
|
|
26
|
+
case 7:
|
|
27
|
+
return OrderStatus.Inactive;
|
|
28
|
+
case 8:
|
|
29
|
+
return OrderStatus.PendingSubmit;
|
|
30
|
+
}
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 把服务端可能返回的 string/number 订单状态归一为字符串。
|
|
35
|
+
* 字符串原样透传;数字按映射表转换;其他输入返回空串。
|
|
36
|
+
*/
|
|
37
|
+
export function normalizeOrderStatus(raw) {
|
|
38
|
+
if (typeof raw === 'string')
|
|
39
|
+
return raw;
|
|
40
|
+
if (typeof raw === 'number')
|
|
41
|
+
return statusIntToString(raw);
|
|
42
|
+
return '';
|
|
43
|
+
}
|
package/dist/esm/model/order.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Order
|
|
3
|
-
*
|
|
2
|
+
* Order response / request models.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript uses camelCase field names idiomatically. The client layer
|
|
5
|
+
* transparently converts request camelCase to snake_case before sending;
|
|
6
|
+
* server responses are already camelCase so they decode directly.
|
|
4
7
|
*/
|
|
5
8
|
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Quote request interfaces (v0.4.0).
|
|
3
|
+
*
|
|
4
|
+
* 所有字段可选(用户调用时传一个空对象即可);字段名用 camelCase,
|
|
5
|
+
* client 层通过 keysToSnakeCase 转成服务端 wire 真名的 snake_case。
|
|
6
|
+
* **字段名设计规则:camelCase → snake_case 后必须等于服务端 wire 真名。**
|
|
7
|
+
*
|
|
8
|
+
* 参考 Go SDK model/quote_requests.go。
|
|
9
|
+
*/
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trade request interfaces (v0.4.0).
|
|
3
|
+
*
|
|
4
|
+
* 所有字段可选(用户调用时传一个空对象即可);字段名用 camelCase,
|
|
5
|
+
* client 层通过 keysToSnakeCase 转成服务端 wire 真名的 snake_case。
|
|
6
|
+
* **字段名设计规则:camelCase → snake_case 后必须等于服务端 wire 真名。**
|
|
7
|
+
* 比如 Trade 用 `startDate`/`endDate`(wire `start_date`/`end_date`),
|
|
8
|
+
* 不用 `startTime`/`endTime`(会被转成 `start_time`/`end_time`,与 wire 不符)。
|
|
9
|
+
*
|
|
10
|
+
* 参考 Go SDK model/trade_requests.go。
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/push/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Push module exports
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export { SubjectType } from './push-message';
|
|
5
5
|
export * from './callbacks';
|
|
6
|
+
export * from './varint';
|
|
7
|
+
export * from './proto-message';
|
|
6
8
|
export { PushClient, ConnectionState } from './push-client';
|