@tigeropenapi/tigeropen 0.5.4 → 0.5.7
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 +80 -0
- package/dist/cjs/auth/authentication.js +74 -0
- package/dist/cjs/auth/index.js +24 -0
- package/dist/cjs/auth/oauth2/client-registration.js +44 -0
- package/dist/cjs/auth/oauth2/device-authorization.js +40 -0
- package/dist/cjs/auth/oauth2/errors.js +64 -0
- package/dist/cjs/auth/oauth2/http-utils.js +112 -0
- package/dist/cjs/auth/oauth2/index.js +42 -0
- package/dist/cjs/auth/oauth2/loopback-receiver.js +215 -0
- package/dist/cjs/auth/oauth2/metadata.js +34 -0
- package/dist/cjs/auth/oauth2/oauth2-authentication.js +74 -0
- package/dist/cjs/auth/oauth2/session-manager.js +762 -0
- package/dist/cjs/auth/oauth2/token-store.js +252 -0
- package/dist/cjs/auth/oauth2/token.js +76 -0
- package/dist/cjs/push/index.js +1 -0
- package/dist/cjs/push/pb/Request.js +12 -1
- package/dist/cjs/push/proto-message.js +5 -1
- package/dist/cjs/push/push-client.js +34 -16
- package/dist/cjs/push/tick-util.js +172 -0
- package/dist/cjs/quote/quote-client.js +59 -12
- package/dist/cjs/trade/trade-client.js +55 -6
- package/dist/cjs/version.js +1 -1
- package/dist/esm/auth/authentication.js +68 -0
- package/dist/esm/auth/index.js +3 -0
- package/dist/esm/auth/oauth2/client-registration.js +40 -0
- package/dist/esm/auth/oauth2/device-authorization.js +36 -0
- package/dist/esm/auth/oauth2/errors.js +59 -0
- package/dist/esm/auth/oauth2/http-utils.js +105 -0
- package/dist/esm/auth/oauth2/index.js +11 -0
- package/dist/esm/auth/oauth2/loopback-receiver.js +178 -0
- package/dist/esm/auth/oauth2/metadata.js +30 -0
- package/dist/esm/auth/oauth2/oauth2-authentication.js +70 -0
- package/dist/esm/auth/oauth2/session-manager.js +725 -0
- package/dist/esm/auth/oauth2/token-store.js +214 -0
- package/dist/esm/auth/oauth2/token.js +71 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/push/index.js +1 -0
- package/dist/esm/push/pb/Request.js +12 -1
- package/dist/esm/push/proto-message.js +5 -1
- package/dist/esm/push/push-client.js +34 -16
- package/dist/esm/push/tick-util.js +165 -0
- package/dist/esm/quote/quote-client.js +59 -12
- package/dist/esm/trade/trade-client.js +55 -6
- package/dist/esm/version.js +1 -1
- package/dist/types/auth/authentication.d.ts +98 -0
- package/dist/types/auth/index.d.ts +4 -0
- package/dist/types/auth/oauth2/client-registration.d.ts +32 -0
- package/dist/types/auth/oauth2/device-authorization.d.ts +40 -0
- package/dist/types/auth/oauth2/errors.d.ts +46 -0
- package/dist/types/auth/oauth2/http-utils.d.ts +21 -0
- package/dist/types/auth/oauth2/index.d.ts +16 -0
- package/dist/types/auth/oauth2/loopback-receiver.d.ts +29 -0
- package/dist/types/auth/oauth2/metadata.d.ts +32 -0
- package/dist/types/auth/oauth2/oauth2-authentication.d.ts +31 -0
- package/dist/types/auth/oauth2/session-manager.d.ts +241 -0
- package/dist/types/auth/oauth2/token-store.d.ts +49 -0
- package/dist/types/auth/oauth2/token.d.ts +56 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/model/order.d.ts +62 -11
- package/dist/types/model/quote-requests.d.ts +21 -2
- package/dist/types/model/quote.d.ts +72 -14
- package/dist/types/model/trade-requests.d.ts +17 -4
- package/dist/types/model/trade.d.ts +11 -1
- package/dist/types/push/callbacks.d.ts +3 -7
- package/dist/types/push/index.d.ts +2 -1
- package/dist/types/push/pb/Request.d.ts +1 -0
- package/dist/types/push/proto-message.d.ts +4 -1
- package/dist/types/push/push-client.d.ts +33 -0
- package/dist/types/push/tick-util.d.ts +30 -0
- package/dist/types/quote/quote-client.d.ts +27 -6
- package/dist/types/trade/trade-client.d.ts +27 -3
- package/dist/types/version.d.ts +1 -1
- package/package.json +8 -4
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { OAuth2DeviceAuthorization } from './device-authorization';
|
|
2
|
+
import { OAuth2Token } from './token';
|
|
3
|
+
import { type TokenStore } from './token-store';
|
|
4
|
+
export declare const ENV_ISSUER = "TIGEROPEN_OAUTH2_ISSUER";
|
|
5
|
+
/**
|
|
6
|
+
* Production authorization server. The environment variable or constructor argument
|
|
7
|
+
* overrides this value.
|
|
8
|
+
*/
|
|
9
|
+
export declare const BUILTIN_ISSUER = "https://openapi-oauth2.tigerfintech.com";
|
|
10
|
+
/** How early to refresh an access token. */
|
|
11
|
+
export declare const DEFAULT_REFRESH_AHEAD_MILLIS: number;
|
|
12
|
+
/** Remaining lifetime below which a token is no longer handed out. */
|
|
13
|
+
export declare const MIN_USABLE_REMAINING_MILLIS: number;
|
|
14
|
+
/** How long to wait for the browser callback. */
|
|
15
|
+
export declare const DEFAULT_AUTHORIZE_TIMEOUT_SECONDS: number;
|
|
16
|
+
/**
|
|
17
|
+
* Fixed callback port for a manually configured clientId. Chosen to stay clear of the
|
|
18
|
+
* default Linux ephemeral range (from 32768) and of common dev ports.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_MANUAL_CALLBACK_PORT = 18888;
|
|
21
|
+
/**
|
|
22
|
+
* Application name registered by the SDK itself. Shown on the user's authorization
|
|
23
|
+
* page, so an entry point that registers its own client passes its own name.
|
|
24
|
+
*/
|
|
25
|
+
export declare const CLIENT_NAME = "Tiger TypeScript SDK";
|
|
26
|
+
/** Receives the authorization URL. The SDK does not open a browser itself. */
|
|
27
|
+
export type AuthorizationUrlHandler = (url: string) => void | Promise<void>;
|
|
28
|
+
/** Receives the device authorization so the caller can display it. */
|
|
29
|
+
export type DeviceAuthorizationHandler = (device: OAuth2DeviceAuthorization) => void | Promise<void>;
|
|
30
|
+
export interface OAuth2SessionManagerOptions {
|
|
31
|
+
/** Authorization server; defaults to `TIGEROPEN_OAUTH2_ISSUER` or the built-in issuer */
|
|
32
|
+
issuer?: string;
|
|
33
|
+
/** Manually issued client ID; omit for dynamic registration */
|
|
34
|
+
clientId?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Loopback port; 0 selects a system-assigned port for dynamic registration. Do not
|
|
37
|
+
* pass one in dynamic registration mode: it pins the registered redirect_uri to that
|
|
38
|
+
* port, and later dropping the argument leaves the registration behind.
|
|
39
|
+
*/
|
|
40
|
+
callbackPort?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Storage root; defaults to `TIGEROPEN_HOME` or `~/.tiger/openapi`. Ignored when
|
|
43
|
+
* `store` is provided
|
|
44
|
+
*/
|
|
45
|
+
home?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Persistence provider; when given, it owns its own surface and `surface` is ignored
|
|
48
|
+
*/
|
|
49
|
+
store?: TokenStore;
|
|
50
|
+
/**
|
|
51
|
+
* Entry point owning the dynamic registration, e.g. `sdk-typescript`, `cli`, `mcp`.
|
|
52
|
+
* Each surface registers its own client, so it appears separately on the user's
|
|
53
|
+
* authorization page and can be revoked on its own. Tools built on this SDK must pass
|
|
54
|
+
* their own value
|
|
55
|
+
*/
|
|
56
|
+
surface?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Application name sent with dynamic registration and shown on the user's
|
|
59
|
+
* authorization page. A tool passing its own `surface` passes its own name too, or
|
|
60
|
+
* the user sees the SDK's name where the tool's belongs
|
|
61
|
+
*/
|
|
62
|
+
clientName?: string;
|
|
63
|
+
/** Loopback callback timeout in seconds */
|
|
64
|
+
authorizeTimeoutSeconds?: number;
|
|
65
|
+
}
|
|
66
|
+
/** OAuth 2.0 authorization session manager. */
|
|
67
|
+
export declare class OAuth2SessionManager {
|
|
68
|
+
private readonly _issuer;
|
|
69
|
+
private readonly _callbackPort;
|
|
70
|
+
/** Fixed for the session because it determines storage keys and registration mode. */
|
|
71
|
+
private readonly explicitClientId;
|
|
72
|
+
private readonly authorizeTimeoutSeconds;
|
|
73
|
+
private readonly clientName;
|
|
74
|
+
private readonly store;
|
|
75
|
+
private registeredClientId;
|
|
76
|
+
private metadata;
|
|
77
|
+
private token;
|
|
78
|
+
private resolvedScopes;
|
|
79
|
+
/** In-flight refresh, so concurrent callers share one token request (single-flight). */
|
|
80
|
+
private refreshInFlight;
|
|
81
|
+
/** In-flight metadata discovery, so concurrent callers share one round trip. */
|
|
82
|
+
private metadataInFlight;
|
|
83
|
+
constructor(options?: OAuth2SessionManagerOptions);
|
|
84
|
+
static defaultIssuer(): string;
|
|
85
|
+
get issuer(): string;
|
|
86
|
+
/** Currently known clientId; undefined before registration in dynamic mode. */
|
|
87
|
+
get clientId(): string | undefined;
|
|
88
|
+
get hasExplicitClientId(): boolean;
|
|
89
|
+
get callbackPort(): number;
|
|
90
|
+
/** Scopes requested by this session, space-separated. Fetches metadata. */
|
|
91
|
+
scopes(): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Create a default session and perform browser authorization when required.
|
|
94
|
+
*
|
|
95
|
+
* The callback receives the authorization URL; the SDK does not open a browser.
|
|
96
|
+
*/
|
|
97
|
+
static loginWithDefaults(onAuthorizationUrl: AuthorizationUrlHandler): Promise<OAuth2SessionManager>;
|
|
98
|
+
/** Create a default session and perform device authorization when required. */
|
|
99
|
+
static loginWithDeviceCodeDefaults(onDeviceAuthorization: DeviceAuthorizationHandler): Promise<OAuth2SessionManager>;
|
|
100
|
+
/**
|
|
101
|
+
* Perform browser authorization with a loopback redirect and PKCE.
|
|
102
|
+
*
|
|
103
|
+
* @param onAuthorizationUrl callback receiving the authorization URL
|
|
104
|
+
*/
|
|
105
|
+
login(onAuthorizationUrl: AuthorizationUrlHandler): Promise<OAuth2Token>;
|
|
106
|
+
/**
|
|
107
|
+
* Use the existing local authorization if usable, otherwise run a full loopback +
|
|
108
|
+
* PKCE authorization.
|
|
109
|
+
*/
|
|
110
|
+
loginIfNeeded(onAuthorizationUrl: AuthorizationUrlHandler): Promise<OAuth2Token>;
|
|
111
|
+
/**
|
|
112
|
+
* Reuse local authorization or perform device authorization (RFC 8628).
|
|
113
|
+
*
|
|
114
|
+
* Device authorization supports environments without a local browser. Unlike loopback
|
|
115
|
+
* authorization with PKCE, it has no redirect binding or proof that the initiating and
|
|
116
|
+
* redeeming clients are the same party, increasing phishing risk. Loopback
|
|
117
|
+
* authorization is preferred when a local browser is available.
|
|
118
|
+
*/
|
|
119
|
+
loginWithDeviceCodeIfNeeded(onDeviceAuthorization: DeviceAuthorizationHandler): Promise<OAuth2Token>;
|
|
120
|
+
/**
|
|
121
|
+
* Perform device authorization as defined by RFC 8628.
|
|
122
|
+
*
|
|
123
|
+
* This flow is intended for environments without a local browser and has the security
|
|
124
|
+
* limitations documented by {@link loginWithDeviceCodeIfNeeded}.
|
|
125
|
+
*/
|
|
126
|
+
loginWithDeviceCode(onDeviceAuthorization: DeviceAuthorizationHandler): Promise<OAuth2Token>;
|
|
127
|
+
/**
|
|
128
|
+
* Revoke authorization under RFC 7009 and delete the local token.
|
|
129
|
+
*
|
|
130
|
+
* Dynamic client registration is retained across logout. The local token is deleted
|
|
131
|
+
* even if server-side revocation fails.
|
|
132
|
+
*
|
|
133
|
+
* @returns true when server-side revocation succeeds; false when only local state is
|
|
134
|
+
* cleared and the server credential may remain valid
|
|
135
|
+
*/
|
|
136
|
+
logout(): Promise<boolean>;
|
|
137
|
+
/**
|
|
138
|
+
* Return a usable access token, refreshing near expiry.
|
|
139
|
+
*
|
|
140
|
+
* Throws `ReauthorizationRequired` when no authorization is available. Browser
|
|
141
|
+
* authorization is never started implicitly.
|
|
142
|
+
*
|
|
143
|
+
* A refresh being due does not make the caller wait for one. While the current token
|
|
144
|
+
* still has {@link MIN_USABLE_REMAINING_MILLIS} of life, a refresh already running
|
|
145
|
+
* elsewhere is left to finish and the current token is returned.
|
|
146
|
+
*/
|
|
147
|
+
getAccessToken(): Promise<string>;
|
|
148
|
+
/** The current token, or undefined. Sends no requests and triggers no authorization. */
|
|
149
|
+
status(): OAuth2Token | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* Whether asking for a token now would trigger a refresh. Reads memory only.
|
|
152
|
+
*
|
|
153
|
+
* Exists so no other component needs a refresh-ahead window of its own.
|
|
154
|
+
*/
|
|
155
|
+
shouldRefreshSoon(): boolean;
|
|
156
|
+
isAuthorized(): boolean;
|
|
157
|
+
/** Refresh because the token is close to expiry. */
|
|
158
|
+
refresh(failedAccessToken?: string): Promise<OAuth2Token>;
|
|
159
|
+
/**
|
|
160
|
+
* Refresh after a 401 even when the token is not near expiry.
|
|
161
|
+
*
|
|
162
|
+
* @param failedAccessToken token used by the failed request; comparison with the
|
|
163
|
+
* current token detects rotation completed elsewhere and preserves single-flight
|
|
164
|
+
* refresh behavior
|
|
165
|
+
*/
|
|
166
|
+
refreshAfterUnauthorized(failedAccessToken: string | undefined): Promise<OAuth2Token>;
|
|
167
|
+
/**
|
|
168
|
+
* Single-flight refresh: the first caller performs rotation while others await the
|
|
169
|
+
* same promise.
|
|
170
|
+
*/
|
|
171
|
+
private doRefresh;
|
|
172
|
+
private refreshOnce;
|
|
173
|
+
/**
|
|
174
|
+
* Handle a refresh the authorization server rejected.
|
|
175
|
+
*
|
|
176
|
+
* Refresh tokens rotate, so the rejected value may already have been replaced by
|
|
177
|
+
* another process sharing this store. The store is re-read before any local state is
|
|
178
|
+
* removed, and the authorization is treated as ended only once the newest stored
|
|
179
|
+
* credential is rejected too.
|
|
180
|
+
*/
|
|
181
|
+
private recoverOrGiveUp;
|
|
182
|
+
/** Exchange the given token's refresh token for a new access token and persist it. */
|
|
183
|
+
private exchangeRefreshToken;
|
|
184
|
+
/**
|
|
185
|
+
* Read the stored token from disk, bypassing the in-memory copy.
|
|
186
|
+
*
|
|
187
|
+
* @returns the stored token, or null when there is none or it cannot be read
|
|
188
|
+
*/
|
|
189
|
+
private reloadFromStore;
|
|
190
|
+
/**
|
|
191
|
+
* Remove the local token, and the dynamic registration when that was refused.
|
|
192
|
+
*
|
|
193
|
+
* Only the credential that was refused is removed, and only while it is still the one
|
|
194
|
+
* on disk. Another process sharing the store may have replaced it in the meantime, and
|
|
195
|
+
* that replacement was never refused.
|
|
196
|
+
*/
|
|
197
|
+
private forgetRejectedAuthorization;
|
|
198
|
+
/**
|
|
199
|
+
* Remove a refused dynamic client registration so the next authorization registers a
|
|
200
|
+
* new one. Explicit clientIds are left alone.
|
|
201
|
+
*/
|
|
202
|
+
private forgetRejectedRegistration;
|
|
203
|
+
/**
|
|
204
|
+
* Return a reusable local token, refreshing it when required.
|
|
205
|
+
*
|
|
206
|
+
* @returns undefined when interactive authorization is required
|
|
207
|
+
*/
|
|
208
|
+
private reusableToken;
|
|
209
|
+
private currentToken;
|
|
210
|
+
/**
|
|
211
|
+
* The known clientId, without triggering registration. Manual mode never reads
|
|
212
|
+
* `clients/`.
|
|
213
|
+
*/
|
|
214
|
+
private knownClientId;
|
|
215
|
+
private persist;
|
|
216
|
+
private effectiveCallbackPort;
|
|
217
|
+
private resolveScopes;
|
|
218
|
+
private metadataOf;
|
|
219
|
+
/** Manual clientId > saved registration whose scopes still cover > register. */
|
|
220
|
+
private resolveClientId;
|
|
221
|
+
/**
|
|
222
|
+
* Register a public client under RFC 7591.
|
|
223
|
+
*
|
|
224
|
+
* Registration omits scope. The granted scope set is stored separately so a wider
|
|
225
|
+
* requirement triggers re-registration instead of `invalid_scope`.
|
|
226
|
+
*/
|
|
227
|
+
private register;
|
|
228
|
+
private requestDeviceAuthorization;
|
|
229
|
+
/** Poll the token endpoint according to RFC 8628 response semantics. */
|
|
230
|
+
private pollForDeviceToken;
|
|
231
|
+
private exchange;
|
|
232
|
+
private toToken;
|
|
233
|
+
/**
|
|
234
|
+
* Attempt server-side revocation without throwing.
|
|
235
|
+
*
|
|
236
|
+
* The refresh token is preferred because RFC 7009 §2.1 permits revocation of its
|
|
237
|
+
* associated access tokens. RFC 7009 §2.2 also returns success for unknown or
|
|
238
|
+
* previously revoked tokens.
|
|
239
|
+
*/
|
|
240
|
+
private revoke;
|
|
241
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { OAuth2ClientRegistration } from './client-registration';
|
|
2
|
+
import { OAuth2Token } from './token';
|
|
3
|
+
export declare const ENV_HOME = "TIGEROPEN_HOME";
|
|
4
|
+
/**
|
|
5
|
+
* Entry point owning a registration. Tools built on this SDK must pass their own value,
|
|
6
|
+
* otherwise they would be filed as the TypeScript SDK and share its client. Keep in
|
|
7
|
+
* step with the Java SDK's `sdk-java` and the Python SDK's `sdk-python`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_SURFACE = "sdk-typescript";
|
|
10
|
+
/** Persistence provider contract, so a caller can store tokens somewhere else. */
|
|
11
|
+
export interface TokenStore {
|
|
12
|
+
loadToken(clientId: string, expectedIssuer?: string): OAuth2Token | null;
|
|
13
|
+
saveToken(token: OAuth2Token): void;
|
|
14
|
+
deleteToken(clientId: string): string | null;
|
|
15
|
+
loadClientId(issuer: string): string | null;
|
|
16
|
+
loadClientRegistration(issuer: string): OAuth2ClientRegistration | null;
|
|
17
|
+
saveClientRegistration(registration: OAuth2ClientRegistration): void;
|
|
18
|
+
deleteClientRegistration(issuer: string): void;
|
|
19
|
+
}
|
|
20
|
+
export declare class OAuth2TokenStore implements TokenStore {
|
|
21
|
+
readonly home: string;
|
|
22
|
+
readonly surface: string;
|
|
23
|
+
/**
|
|
24
|
+
* @param home storage root; defaults to `TIGEROPEN_HOME` then `~/.tiger/openapi`
|
|
25
|
+
* @param surface entry point owning the registration, e.g. `sdk-typescript`, `cli`.
|
|
26
|
+
* Lowercase alphanumerics and hyphens only
|
|
27
|
+
*/
|
|
28
|
+
constructor(home?: string, surface?: string);
|
|
29
|
+
/** Load a token, treating a missing file or issuer mismatch as a cache miss. */
|
|
30
|
+
loadToken(clientId: string, expectedIssuer?: string): OAuth2Token | null;
|
|
31
|
+
saveToken(token: OAuth2Token): void;
|
|
32
|
+
/**
|
|
33
|
+
* Delete authorization state while retaining client registration.
|
|
34
|
+
*
|
|
35
|
+
* @returns the path removed, or null when there was nothing to remove. A clientId is
|
|
36
|
+
* not its own file name, so a caller reporting what it deleted has to be told rather
|
|
37
|
+
* than build the path itself
|
|
38
|
+
*/
|
|
39
|
+
deleteToken(clientId: string): string | null;
|
|
40
|
+
loadClientId(issuer: string): string | null;
|
|
41
|
+
loadClientRegistration(issuer: string): OAuth2ClientRegistration | null;
|
|
42
|
+
saveClientRegistration(registration: OAuth2ClientRegistration): void;
|
|
43
|
+
/** Delete registration state after an `invalid_client` response. */
|
|
44
|
+
deleteClientRegistration(issuer: string): void;
|
|
45
|
+
private tokenFile;
|
|
46
|
+
private clientFile;
|
|
47
|
+
}
|
|
48
|
+
/** Return the Java-compatible 32-character SHA-256 issuer file key. */
|
|
49
|
+
export declare function hashIssuer(issuer: string): string;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Persisted OAuth 2.0 authorization state.
|
|
3
|
+
*
|
|
4
|
+
* The `issuer` and `clientId` bind credentials to an authorization server and client,
|
|
5
|
+
* preventing credential reuse across environments. The on-disk field names are
|
|
6
|
+
* snake_case and shared with the Java and Python SDKs.
|
|
7
|
+
*/
|
|
8
|
+
/** On-disk format version. An unrecognised version is an error, not a guess. */
|
|
9
|
+
export declare const TOKEN_SCHEMA_VERSION = 1;
|
|
10
|
+
export declare function currentMillis(): number;
|
|
11
|
+
/** Raw on-disk shape. */
|
|
12
|
+
export interface OAuth2TokenJson {
|
|
13
|
+
schema_version?: number;
|
|
14
|
+
issuer?: string;
|
|
15
|
+
client_id?: string;
|
|
16
|
+
access_token?: string;
|
|
17
|
+
refresh_token?: string;
|
|
18
|
+
token_type?: string;
|
|
19
|
+
scope?: string;
|
|
20
|
+
expires_at?: number;
|
|
21
|
+
}
|
|
22
|
+
/** An access token and its metadata. */
|
|
23
|
+
export declare class OAuth2Token {
|
|
24
|
+
schemaVersion: number;
|
|
25
|
+
issuer?: string;
|
|
26
|
+
clientId?: string;
|
|
27
|
+
accessToken?: string;
|
|
28
|
+
refreshToken?: string;
|
|
29
|
+
tokenType: string;
|
|
30
|
+
scope?: string;
|
|
31
|
+
/** Absolute expiry as epoch millis, not expires_in */
|
|
32
|
+
expiresAt: number;
|
|
33
|
+
constructor(init?: {
|
|
34
|
+
issuer?: string;
|
|
35
|
+
clientId?: string;
|
|
36
|
+
accessToken?: string;
|
|
37
|
+
refreshToken?: string;
|
|
38
|
+
tokenType?: string;
|
|
39
|
+
scope?: string;
|
|
40
|
+
expiresAt?: number;
|
|
41
|
+
schemaVersion?: number;
|
|
42
|
+
});
|
|
43
|
+
/** Time until expiry; negative once already expired. */
|
|
44
|
+
remainingMillis(): number;
|
|
45
|
+
/**
|
|
46
|
+
* @param aheadMillis how early to refresh. The window exists because time passes
|
|
47
|
+
* between sending a request and the server validating it, so using a token right up
|
|
48
|
+
* to its expiry produces intermittent 401s
|
|
49
|
+
*/
|
|
50
|
+
needsRefresh(aheadMillis: number): boolean;
|
|
51
|
+
hasRefreshToken(): boolean;
|
|
52
|
+
toJSON(): OAuth2TokenJson;
|
|
53
|
+
static fromJSON(data: OAuth2TokenJson | null | undefined): OAuth2Token | null;
|
|
54
|
+
/** Prints no token values. */
|
|
55
|
+
toString(): string;
|
|
56
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type { ErrorCategory } from './client';
|
|
|
26
26
|
export { QuoteClient, parseOptionIdentifier } from './quote';
|
|
27
27
|
export { TradeClient } from './trade';
|
|
28
28
|
export { PushClient, ConnectionState, SubjectType } from './push';
|
|
29
|
-
export type { PushClientOptions } from './push';
|
|
29
|
+
export type { PushClientOptions, AccountSubscribeOptions } from './push';
|
|
30
30
|
export type { Order, OrderRequest, ContractLegRequest } from './model/order';
|
|
31
31
|
export { marketOrder, limitOrder, stopOrder, stopLimitOrder } from './model/order-helpers';
|
|
32
32
|
export { normalizeOrderStatus } from './model/order-status';
|
|
@@ -35,5 +35,5 @@ export type { Position } from './model/position';
|
|
|
35
35
|
export type { Asset, AssetSegment, PrimeAsset, PreviewResult, PlaceOrderResult, OrderIdResult, Transaction, ManagedAccount, AnalyticsAsset, AggregateAssets, EstimateTradableQuantity, ForexOrderResult, SegmentFund, SegmentFundAvailableItem, SegmentFundHistoryItem, FundDetails, FundingHistoryItem, PositionTransferRecord, PositionTransferDetail, PositionTransferExternalRecord, OptionExerciseCheckResult, OptionExercisePositionPageResult, OptionExerciseRecordPageResult, } from './model/trade';
|
|
36
36
|
export type { OrdersRequest, GetOrderRequest, OrderTransactionsRequest, PositionsRequest, AssetsRequest, ManagedAccountsRequest, DerivativeContractsRequest, AnalyticsAssetRequest, AggregateAssetsRequest, EstimateTradableQuantityRequest, ForexOrderRequest, SegmentFundRequest, FundDetailsRequest, FundingHistoryRequest, PositionTransferRequest, PositionTransferRecordsRequest, PositionTransferDetailRequest, PositionTransferExternalRecordsRequest, OptionExerciseCheckRequest, OptionExercisePositionRequest, OptionExerciseSubmitRequest, OptionExerciseRecordsRequest, OptionExerciseCancelRequest, } from './model/trade-requests';
|
|
37
37
|
export type { MarketState, Brief, Kline, KlineItem, Timeline, TimelineItem, TradeTick, TradeTickItem, Depth, DepthLevel, OptionExpiration, OptionChain, OptionChainRow, OptionSymbol, OptionChainFilter, OptionChainFilterGreeks, Range, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FutureDepth, FutureTradeTickItem, FutureTradingTime, FinancialDailyItem, FinancialReportItem, CorporateAction, CorporateSymbolChange, CorporateDelisting, CorporateIPO, CapitalFlow, CapitalFlowItem, CapitalDistribution, ScannerResult, ScannerResultItem, QuotePermission, SymbolName, TradeMeta, StockDetail, StockBroker, StockBrokerItem, ShortInterest, StockIndustry, IndustryItem, IndustryStock, WarrantBrief, WarrantFilterResult, FundContractInfo, FundQuote, FundHistoryQuote, QuoteOvernight, KlineQuota, MarketScannerTag, MarketScannerTags, OptionAnalysis, OptionLeg, OptionVolatilityPoint, ExchangeRate, FinancialCurrency, BrokerDetail, TradingCalendarItem, FutureMainContractHistory, } from './model/quote';
|
|
38
|
-
export type { BriefRequest, DepthQuoteRequest, TradeTickRequest, KlineRequest, KlineByPageRequest, FutureBriefRequest, FutureKlineRequest, FutureKlineByPageRequest, FutureTradeTicksRequest, FutureDepthRequest, FutureContractSingleRequest, FutureContinuousContractsRequest, FutureHistoryMainContractRequest, FutureTradingTimesRequest, AllFutureContractsRequest, OptionTradeTicksRequest, OptionTimelineRequest, OptionDepthRequest, OptionSymbolsRequest, OptionAnalysisRequest, OptionQueryItem, ShortInterestRequest, StockBrokerRequest, StockDetailsRequest, StockFundamentalRequest, StockIndustryRequest, StockDelayBriefsRequest, SymbolsRequest, TradeMetasRequest, TradeRankRequest, TimelineHistoryRequest, TradingCalendarRequest, KlineQuotaRequest, QuotePermissionRequest, QuoteOvernightRequest, IndustryListRequest, IndustryStocksRequest, FundSymbolsRequest, FundContractsRequest, FundQuoteRequest, FundHistoryQuoteRequest, WarrantBriefsRequest, WarrantFilterRequest, MarketScannerTagsRequest, FinancialCurrencyRequest, FinancialExchangeRateRequest, } from './model/quote-requests';
|
|
38
|
+
export type { BriefRequest, DepthQuoteRequest, TradeTickRequest, KlineRequest, KlineByPageRequest, TimelineRequest, FutureBriefRequest, FutureKlineRequest, FutureKlineByPageRequest, FutureTradeTicksRequest, FutureDepthRequest, FutureContractSingleRequest, FutureContinuousContractsRequest, FutureHistoryMainContractRequest, FutureTradingTimesRequest, AllFutureContractsRequest, OptionTradeTicksRequest, OptionTimelineRequest, OptionDepthRequest, OptionSymbolsRequest, OptionAnalysisRequest, OptionQueryItem, ShortInterestRequest, StockBrokerRequest, StockDetailsRequest, StockFundamentalRequest, StockIndustryRequest, StockDelayBriefsRequest, SymbolsRequest, TradeMetasRequest, TradeRankRequest, TimelineHistoryRequest, TradingCalendarRequest, KlineQuotaRequest, QuotePermissionRequest, QuoteOvernightRequest, IndustryListRequest, IndustryStocksRequest, FundSymbolsRequest, FundContractsRequest, FundQuoteRequest, FundHistoryQuoteRequest, WarrantBriefsRequest, WarrantFilterRequest, MarketScannerTagsRequest, FinancialCurrencyRequest, FinancialExchangeRateRequest, } from './model/quote-requests';
|
|
39
39
|
export { OrderStatus, SecurityType, OrderType, TimeInForce, Market, Currency, QuoteRight, SegmentType, OrderSortBy, CorporateActionType, IndustryLevel, SortDirection, OptionAnalysisPeriod, FinancialReportPeriod, Language, License, BarPeriod, orderStatusCode, } from './model/enums';
|
|
@@ -12,11 +12,28 @@ export interface OrderLeg {
|
|
|
12
12
|
timeInForce?: string;
|
|
13
13
|
quantity?: number;
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Algo order parameters — response side.
|
|
17
|
+
*
|
|
18
|
+
* The response shape flattens the [{tag, value}, ...] wire form into an
|
|
19
|
+
* object, and the server historically emits `startTime` / `endTime` as
|
|
20
|
+
* epoch-ms numbers (matching what the request side sends). Some legacy
|
|
21
|
+
* paths still return the raw string; accept both.
|
|
22
|
+
*
|
|
23
|
+
* Note: `algoStrategy` on the response side is server-echoed; on the
|
|
24
|
+
* request side it lives on `OrderRequest`, not `AlgoParamsRequest`.
|
|
25
|
+
*/
|
|
16
26
|
export interface AlgoParams {
|
|
17
27
|
algoStrategy?: string;
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
/** Epoch-ms; server may echo as string on legacy paths */
|
|
29
|
+
startTime?: number | string;
|
|
30
|
+
/** Epoch-ms; server may echo as string on legacy paths */
|
|
31
|
+
endTime?: number | string;
|
|
32
|
+
/** Whether to minimize trade count (VWAP) */
|
|
33
|
+
noTakeLiq?: boolean;
|
|
34
|
+
/** Whether to allow completion after end_time (TWAP / VWAP) */
|
|
35
|
+
allowPastEndTime?: boolean;
|
|
36
|
+
/** Participation rate 0.01–0.5 (VWAP only) */
|
|
20
37
|
participationRate?: number;
|
|
21
38
|
}
|
|
22
39
|
/** Order response model (returned by order query methods). */
|
|
@@ -135,10 +152,18 @@ export interface OrderRequest {
|
|
|
135
152
|
checkIntervals?: number;
|
|
136
153
|
/** 冰山单:价格类型(LIMIT_PRICE / ASK_PRICE / BID_PRICE / LATEST_PRICE) */
|
|
137
154
|
priceType?: string;
|
|
138
|
-
/**
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
155
|
+
/**
|
|
156
|
+
* 冰山单:生效开始时间(epoch ms)。
|
|
157
|
+
* Wire note: the gateway accepts both `number` (epoch ms) and `string`
|
|
158
|
+
* (epoch ms as string) for ICEBERG orders; `number | string` keeps
|
|
159
|
+
* TypeScript callers who pass `String(now)` from hitting a compile error.
|
|
160
|
+
*/
|
|
161
|
+
startTime?: number | string;
|
|
162
|
+
/**
|
|
163
|
+
* 冰山单:生效结束时间(epoch ms)。
|
|
164
|
+
* Same dual-type note as `startTime` above.
|
|
165
|
+
*/
|
|
166
|
+
endTime?: number | string;
|
|
142
167
|
/** GTD 到期时间(epoch ms) */
|
|
143
168
|
expireTime?: number;
|
|
144
169
|
/** 盘后委托价格 */
|
|
@@ -180,6 +205,17 @@ export interface OrderRequest {
|
|
|
180
205
|
contractLegs?: ContractLegRequest[];
|
|
181
206
|
/** 组合单类型(如 MLEG) */
|
|
182
207
|
comboType?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Algo strategy name for TWAP / VWAP orders (e.g. `'TWAP'`, `'VWAP'`).
|
|
210
|
+
* Lives on `OrderRequest`, not inside `algoParams` — the Python SDK
|
|
211
|
+
* places it at the top-level order object, and the gateway expects
|
|
212
|
+
* `algo_strategy` as a sibling of `algo_params`.
|
|
213
|
+
*
|
|
214
|
+
* Note: `AlgoParamsRequest` intentionally omits this field (see its
|
|
215
|
+
* doc-comment). Pass `algoStrategy` here and `algoParams` as the
|
|
216
|
+
* companion object.
|
|
217
|
+
*/
|
|
218
|
+
algoStrategy?: string;
|
|
183
219
|
}
|
|
184
220
|
/** Single leg of a multi-leg option order (MLEG) */
|
|
185
221
|
export interface ContractLegRequest {
|
|
@@ -198,10 +234,25 @@ export interface OrderLegRequest {
|
|
|
198
234
|
timeInForce?: string;
|
|
199
235
|
quantity?: number;
|
|
200
236
|
}
|
|
201
|
-
/**
|
|
237
|
+
/**
|
|
238
|
+
* Algo parameters for request side (TWAP / VWAP).
|
|
239
|
+
*
|
|
240
|
+
* Fields match the Python SDK's AlgoParams. On the wire, the SDK marshals
|
|
241
|
+
* this object into the `[{tag, value}, ...]` array shape the gateway
|
|
242
|
+
* expects — callers should just pass the natural object.
|
|
243
|
+
*
|
|
244
|
+
* `algoStrategy` is intentionally not here: it lives on the parent
|
|
245
|
+
* `OrderRequest`, not inside `algoParams`.
|
|
246
|
+
*/
|
|
202
247
|
export interface AlgoParamsRequest {
|
|
203
|
-
|
|
204
|
-
startTime?:
|
|
205
|
-
|
|
248
|
+
/** Epoch-ms start time (TWAP / VWAP only) */
|
|
249
|
+
startTime?: number;
|
|
250
|
+
/** Epoch-ms end time (TWAP / VWAP only) */
|
|
251
|
+
endTime?: number;
|
|
252
|
+
/** Try to minimize trade count (VWAP only) */
|
|
253
|
+
noTakeLiq?: boolean;
|
|
254
|
+
/** Allow completing after end_time (TWAP / VWAP only) */
|
|
255
|
+
allowPastEndTime?: boolean;
|
|
256
|
+
/** Participation rate 0.01–0.5 (VWAP only) */
|
|
206
257
|
participationRate?: number;
|
|
207
258
|
}
|
|
@@ -27,6 +27,7 @@ export interface TradeTickRequest {
|
|
|
27
27
|
beginIndex?: number;
|
|
28
28
|
endIndex?: number;
|
|
29
29
|
limit?: number;
|
|
30
|
+
tradeSession?: string;
|
|
30
31
|
lang?: string;
|
|
31
32
|
}
|
|
32
33
|
/** Real-time futures quotes. wire: future_brief */
|
|
@@ -80,6 +81,7 @@ export interface KlineRequest {
|
|
|
80
81
|
/** K-line client-side pagination wrapper. */
|
|
81
82
|
export interface KlineByPageRequest {
|
|
82
83
|
symbol?: string;
|
|
84
|
+
secType?: string;
|
|
83
85
|
period?: string;
|
|
84
86
|
beginTime?: number;
|
|
85
87
|
endTime?: number;
|
|
@@ -89,6 +91,11 @@ export interface KlineByPageRequest {
|
|
|
89
91
|
lang?: string;
|
|
90
92
|
tradeSession?: string;
|
|
91
93
|
}
|
|
94
|
+
/** Intraday timeline request. wire: timeline */
|
|
95
|
+
export interface TimelineRequest {
|
|
96
|
+
symbols?: string[];
|
|
97
|
+
secType?: string;
|
|
98
|
+
}
|
|
92
99
|
/** Historical intraday timeline. wire: history_timeline */
|
|
93
100
|
export interface TimelineHistoryRequest {
|
|
94
101
|
symbols?: string[];
|
|
@@ -134,7 +141,7 @@ export interface KlineQuotaRequest {
|
|
|
134
141
|
withDetails?: boolean;
|
|
135
142
|
lang?: string;
|
|
136
143
|
}
|
|
137
|
-
/**
|
|
144
|
+
/** Market data permission entry request. wire: get_quote_permission */
|
|
138
145
|
export interface QuotePermissionRequest {
|
|
139
146
|
beginDate?: string;
|
|
140
147
|
endDate?: string;
|
|
@@ -154,9 +161,21 @@ export interface OptionQueryItem {
|
|
|
154
161
|
endIndex?: number;
|
|
155
162
|
pageToken?: string;
|
|
156
163
|
}
|
|
157
|
-
/** Option tick trades. wire: option_trade_tick
|
|
164
|
+
/** Option tick trades. wire: option_trade_tick
|
|
165
|
+
*
|
|
166
|
+
* **Wire contract:** the server expects `biz_content` to be a **top-level
|
|
167
|
+
* JSON array** (`[{symbol, expiry, ...}, ...]`), not `{"contracts": [...]}`.
|
|
168
|
+
* This matches Java (`BatchApiModel.items` serialized directly) and Python
|
|
169
|
+
* (`MultipleContractParams.to_openapi_dict` returns a list).
|
|
170
|
+
*
|
|
171
|
+
* The client unwraps `contracts` before serialization; sending it as an
|
|
172
|
+
* object caused `biz param error(failed to parse parameters in 'biz_content')`.
|
|
173
|
+
* `lang` is retained for API symmetry but is not sent on the wire — the
|
|
174
|
+
* gateway has no `lang` input for this method.
|
|
175
|
+
*/
|
|
158
176
|
export interface OptionTradeTicksRequest {
|
|
159
177
|
contracts?: OptionQueryItem[];
|
|
178
|
+
/** Retained for API symmetry; wire is a top-level array, so `lang` is not sent. */
|
|
160
179
|
lang?: string;
|
|
161
180
|
}
|
|
162
181
|
/** Option intraday timeline. wire: option_timeline */
|