@finatic/client 0.0.131
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 +489 -0
- package/dist/index.d.ts +2037 -0
- package/dist/index.js +4815 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4787 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types/client/ApiClient.d.ts +234 -0
- package/dist/types/client/FinaticConnect.d.ts +307 -0
- package/dist/types/index.d.ts +17 -0
- package/dist/types/mocks/MockApiClient.d.ts +228 -0
- package/dist/types/mocks/MockDataProvider.d.ts +132 -0
- package/dist/types/mocks/MockFactory.d.ts +53 -0
- package/dist/types/mocks/index.d.ts +5 -0
- package/dist/types/mocks/utils.d.ts +29 -0
- package/dist/types/portal/PortalUI.d.ts +38 -0
- package/dist/types/security/ApiSecurity.d.ts +24 -0
- package/dist/types/security/RuntimeSecurity.d.ts +28 -0
- package/dist/types/security/SecurityUtils.d.ts +21 -0
- package/dist/types/security/index.d.ts +2 -0
- package/dist/types/services/AnalyticsService.d.ts +18 -0
- package/dist/types/services/ApiClient.d.ts +121 -0
- package/dist/types/services/PortalService.d.ts +24 -0
- package/dist/types/services/TradingService.d.ts +55 -0
- package/dist/types/services/api.d.ts +23 -0
- package/dist/types/services/auth.d.ts +9 -0
- package/dist/types/services/index.d.ts +4 -0
- package/dist/types/services/portfolio.d.ts +10 -0
- package/dist/types/services/trading.d.ts +10 -0
- package/dist/types/shared/index.d.ts +2 -0
- package/dist/types/shared/themes/index.d.ts +2 -0
- package/dist/types/shared/themes/portalPresets.d.ts +8 -0
- package/dist/types/shared/themes/presets.d.ts +3 -0
- package/dist/types/shared/themes/system.d.ts +2 -0
- package/dist/types/shared/types/index.d.ts +110 -0
- package/dist/types/types/api.d.ts +486 -0
- package/dist/types/types/config.d.ts +12 -0
- package/dist/types/types/connect.d.ts +51 -0
- package/dist/types/types/errors.d.ts +47 -0
- package/dist/types/types/portal.d.ts +75 -0
- package/dist/types/types/security.d.ts +35 -0
- package/dist/types/types/shared.d.ts +50 -0
- package/dist/types/types/theme.d.ts +101 -0
- package/dist/types/types.d.ts +157 -0
- package/dist/types/utils/errors.d.ts +42 -0
- package/dist/types/utils/events.d.ts +12 -0
- package/dist/types/utils/themeUtils.d.ts +34 -0
- package/package.json +56 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2037 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API-related types for Finatic Connect SDK
|
|
3
|
+
*/
|
|
4
|
+
interface SessionInitResponse {
|
|
5
|
+
success: boolean;
|
|
6
|
+
message: string;
|
|
7
|
+
data: {
|
|
8
|
+
one_time_token: string;
|
|
9
|
+
expires_at: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
interface SessionResponseData {
|
|
13
|
+
session_id: string;
|
|
14
|
+
company_id: string;
|
|
15
|
+
status: 'pending';
|
|
16
|
+
expires_at: string;
|
|
17
|
+
}
|
|
18
|
+
interface SessionStartResponse {
|
|
19
|
+
data: SessionResponseData;
|
|
20
|
+
message: 'Session started successfully';
|
|
21
|
+
}
|
|
22
|
+
interface OtpRequestResponse {
|
|
23
|
+
success: boolean;
|
|
24
|
+
message: string;
|
|
25
|
+
data: boolean;
|
|
26
|
+
}
|
|
27
|
+
interface OtpVerifyResponse {
|
|
28
|
+
success: boolean;
|
|
29
|
+
message: string;
|
|
30
|
+
data: {
|
|
31
|
+
access_token: string;
|
|
32
|
+
refresh_token: string;
|
|
33
|
+
user_id: string;
|
|
34
|
+
expires_in: number;
|
|
35
|
+
scope: string;
|
|
36
|
+
token_type: 'Bearer';
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface PortalUrlResponse {
|
|
40
|
+
success: boolean;
|
|
41
|
+
message: string;
|
|
42
|
+
data: {
|
|
43
|
+
portal_url: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
interface UserToken {
|
|
47
|
+
accessToken: string;
|
|
48
|
+
refreshToken: string;
|
|
49
|
+
expiresIn: number;
|
|
50
|
+
user_id: string;
|
|
51
|
+
tokenType: string;
|
|
52
|
+
scope: string;
|
|
53
|
+
}
|
|
54
|
+
interface ApiConfig {
|
|
55
|
+
baseUrl: string;
|
|
56
|
+
apiKey?: string;
|
|
57
|
+
sandbox?: boolean;
|
|
58
|
+
}
|
|
59
|
+
interface RequestHeaders {
|
|
60
|
+
'Content-Type': string;
|
|
61
|
+
'X-API-Key'?: string;
|
|
62
|
+
Authorization?: string;
|
|
63
|
+
'X-CSRF-Token'?: string;
|
|
64
|
+
token?: string;
|
|
65
|
+
'User-Agent'?: string;
|
|
66
|
+
'X-Device-Info'?: string;
|
|
67
|
+
'X-Request-ID'?: string;
|
|
68
|
+
'X-Request-Timestamp'?: string;
|
|
69
|
+
'X-Request-Signature'?: string;
|
|
70
|
+
[key: string]: string | undefined;
|
|
71
|
+
}
|
|
72
|
+
declare enum SessionState {
|
|
73
|
+
PENDING = "PENDING",
|
|
74
|
+
AUTHENTICATING = "AUTHENTICATING",
|
|
75
|
+
ACTIVE = "ACTIVE",
|
|
76
|
+
COMPLETED = "COMPLETED",
|
|
77
|
+
EXPIRED = "EXPIRED"
|
|
78
|
+
}
|
|
79
|
+
type SessionStatus = SessionState;
|
|
80
|
+
interface ApiResponse<T> {
|
|
81
|
+
data: T;
|
|
82
|
+
error?: string;
|
|
83
|
+
status: number;
|
|
84
|
+
}
|
|
85
|
+
interface Order {
|
|
86
|
+
symbol: string;
|
|
87
|
+
side: 'buy' | 'sell';
|
|
88
|
+
quantity: number;
|
|
89
|
+
type_: 'market' | 'limit' | 'stop' | 'stop_limit';
|
|
90
|
+
price?: number;
|
|
91
|
+
stopPrice?: number;
|
|
92
|
+
timeInForce: 'day' | 'gtc' | 'opg' | 'cls' | 'ioc' | 'fok';
|
|
93
|
+
}
|
|
94
|
+
interface OptionsOrder extends Order {
|
|
95
|
+
optionType: 'call' | 'put';
|
|
96
|
+
strikePrice: number;
|
|
97
|
+
expirationDate: string;
|
|
98
|
+
}
|
|
99
|
+
interface BrokerAccount {
|
|
100
|
+
id: string;
|
|
101
|
+
user_broker_connection_id: string;
|
|
102
|
+
broker_provided_account_id: string;
|
|
103
|
+
account_name: string;
|
|
104
|
+
account_type: string;
|
|
105
|
+
currency: string;
|
|
106
|
+
cash_balance: number;
|
|
107
|
+
buying_power: number;
|
|
108
|
+
status: string;
|
|
109
|
+
/** ISO 8601 timestamp with timezone information */
|
|
110
|
+
created_at: string;
|
|
111
|
+
/** ISO 8601 timestamp with timezone information */
|
|
112
|
+
updated_at: string;
|
|
113
|
+
/** ISO 8601 timestamp with timezone information */
|
|
114
|
+
last_synced_at: string;
|
|
115
|
+
}
|
|
116
|
+
interface BrokerOrder {
|
|
117
|
+
id: string;
|
|
118
|
+
user_broker_connection_id: string;
|
|
119
|
+
broker_provided_account_id: string;
|
|
120
|
+
order_id: string;
|
|
121
|
+
symbol: string;
|
|
122
|
+
order_type: string;
|
|
123
|
+
side: 'buy' | 'sell';
|
|
124
|
+
quantity: number;
|
|
125
|
+
price: number;
|
|
126
|
+
status: string;
|
|
127
|
+
/** ISO 8601 timestamp with timezone information */
|
|
128
|
+
created_at: string;
|
|
129
|
+
/** ISO 8601 timestamp with timezone information */
|
|
130
|
+
updated_at: string;
|
|
131
|
+
/** ISO 8601 timestamp with timezone information, null if not filled */
|
|
132
|
+
filled_at: string | null;
|
|
133
|
+
filled_quantity: number;
|
|
134
|
+
filled_avg_price: number;
|
|
135
|
+
}
|
|
136
|
+
interface BrokerPosition {
|
|
137
|
+
id: string;
|
|
138
|
+
user_broker_connection_id: string;
|
|
139
|
+
broker_provided_account_id: string;
|
|
140
|
+
symbol: string;
|
|
141
|
+
asset_type: string;
|
|
142
|
+
quantity: number;
|
|
143
|
+
average_price: number;
|
|
144
|
+
market_value: number;
|
|
145
|
+
cost_basis: number;
|
|
146
|
+
unrealized_gain_loss: number;
|
|
147
|
+
unrealized_gain_loss_percent: number;
|
|
148
|
+
current_price: number;
|
|
149
|
+
last_price: number;
|
|
150
|
+
/** ISO 8601 timestamp with timezone information */
|
|
151
|
+
last_price_updated_at: string;
|
|
152
|
+
/** ISO 8601 timestamp with timezone information */
|
|
153
|
+
created_at: string;
|
|
154
|
+
/** ISO 8601 timestamp with timezone information */
|
|
155
|
+
updated_at: string;
|
|
156
|
+
}
|
|
157
|
+
interface BrokerDataOptions {
|
|
158
|
+
broker_name?: string;
|
|
159
|
+
account_id?: string;
|
|
160
|
+
symbol?: string;
|
|
161
|
+
}
|
|
162
|
+
interface PortfolioSnapshot {
|
|
163
|
+
timestamp: string;
|
|
164
|
+
totalValue: number;
|
|
165
|
+
cash: number;
|
|
166
|
+
equity: number;
|
|
167
|
+
positions: {
|
|
168
|
+
symbol: string;
|
|
169
|
+
quantity: number;
|
|
170
|
+
averagePrice: number;
|
|
171
|
+
currentPrice: number;
|
|
172
|
+
marketValue: number;
|
|
173
|
+
unrealizedPnL: number;
|
|
174
|
+
}[];
|
|
175
|
+
}
|
|
176
|
+
interface PerformanceMetrics {
|
|
177
|
+
totalReturn: number;
|
|
178
|
+
dailyReturn: number;
|
|
179
|
+
weeklyReturn: number;
|
|
180
|
+
monthlyReturn: number;
|
|
181
|
+
yearlyReturn: number;
|
|
182
|
+
maxDrawdown: number;
|
|
183
|
+
sharpeRatio: number;
|
|
184
|
+
beta: number;
|
|
185
|
+
alpha: number;
|
|
186
|
+
}
|
|
187
|
+
interface Holding {
|
|
188
|
+
symbol: string;
|
|
189
|
+
quantity: number;
|
|
190
|
+
averagePrice: number;
|
|
191
|
+
currentPrice: number;
|
|
192
|
+
marketValue: number;
|
|
193
|
+
unrealizedPnL: number;
|
|
194
|
+
realizedPnL: number;
|
|
195
|
+
costBasis: number;
|
|
196
|
+
currency: string;
|
|
197
|
+
}
|
|
198
|
+
interface Portfolio {
|
|
199
|
+
id: string;
|
|
200
|
+
name: string;
|
|
201
|
+
type: string;
|
|
202
|
+
status: string;
|
|
203
|
+
cash: number;
|
|
204
|
+
buyingPower: number;
|
|
205
|
+
equity: number;
|
|
206
|
+
longMarketValue: number;
|
|
207
|
+
shortMarketValue: number;
|
|
208
|
+
initialMargin: number;
|
|
209
|
+
maintenanceMargin: number;
|
|
210
|
+
lastEquity: number;
|
|
211
|
+
positions: Holding[];
|
|
212
|
+
performance: PerformanceMetrics;
|
|
213
|
+
}
|
|
214
|
+
interface PortalResponse {
|
|
215
|
+
portalUrl: string;
|
|
216
|
+
token: string;
|
|
217
|
+
expiresIn: number;
|
|
218
|
+
}
|
|
219
|
+
interface SessionValidationResponse {
|
|
220
|
+
valid: boolean;
|
|
221
|
+
company_id: string;
|
|
222
|
+
status: string;
|
|
223
|
+
}
|
|
224
|
+
interface SessionAuthenticateResponse {
|
|
225
|
+
success: boolean;
|
|
226
|
+
message: string;
|
|
227
|
+
data: {
|
|
228
|
+
access_token: string;
|
|
229
|
+
refresh_token: string;
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
interface RefreshTokenRequest {
|
|
233
|
+
refresh_token: string;
|
|
234
|
+
}
|
|
235
|
+
interface RefreshTokenResponse {
|
|
236
|
+
success: boolean;
|
|
237
|
+
response_data: {
|
|
238
|
+
access_token: string;
|
|
239
|
+
refresh_token: string;
|
|
240
|
+
expires_at: string;
|
|
241
|
+
company_id: string;
|
|
242
|
+
company_name: string;
|
|
243
|
+
email_verified: boolean;
|
|
244
|
+
};
|
|
245
|
+
message: string;
|
|
246
|
+
}
|
|
247
|
+
interface TokenInfo {
|
|
248
|
+
accessToken: string;
|
|
249
|
+
refreshToken: string;
|
|
250
|
+
expiresAt: string;
|
|
251
|
+
userId?: string;
|
|
252
|
+
}
|
|
253
|
+
interface SessionResponse {
|
|
254
|
+
data: {
|
|
255
|
+
session_id: string;
|
|
256
|
+
state: SessionState;
|
|
257
|
+
device_info?: Record<string, string>;
|
|
258
|
+
company_id?: string;
|
|
259
|
+
status?: string;
|
|
260
|
+
expires_at?: string;
|
|
261
|
+
user_id?: string | null;
|
|
262
|
+
auto_login?: boolean;
|
|
263
|
+
access_token?: string;
|
|
264
|
+
refresh_token?: string;
|
|
265
|
+
expires_in?: number;
|
|
266
|
+
token_type?: string;
|
|
267
|
+
scope?: string;
|
|
268
|
+
};
|
|
269
|
+
message: string;
|
|
270
|
+
}
|
|
271
|
+
interface BrokerInfo {
|
|
272
|
+
id: string;
|
|
273
|
+
name: string;
|
|
274
|
+
display_name: string;
|
|
275
|
+
description: string;
|
|
276
|
+
website: string;
|
|
277
|
+
features: string[];
|
|
278
|
+
auth_type: 'oauth' | 'api_key';
|
|
279
|
+
logo_path: string;
|
|
280
|
+
is_active: boolean;
|
|
281
|
+
}
|
|
282
|
+
interface DeviceInfo$1 {
|
|
283
|
+
ip_address: string;
|
|
284
|
+
user_agent: string;
|
|
285
|
+
fingerprint: string;
|
|
286
|
+
}
|
|
287
|
+
interface BrokerOrderParams {
|
|
288
|
+
broker: 'robinhood' | 'tasty_trade' | 'ninja_trader';
|
|
289
|
+
accountNumber: string;
|
|
290
|
+
symbol: string;
|
|
291
|
+
orderQty: number;
|
|
292
|
+
action: 'Buy' | 'Sell';
|
|
293
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
|
|
294
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
295
|
+
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
296
|
+
price?: number;
|
|
297
|
+
stopPrice?: number;
|
|
298
|
+
}
|
|
299
|
+
interface BrokerExtras {
|
|
300
|
+
robinhood?: {
|
|
301
|
+
extendedHours?: boolean;
|
|
302
|
+
marketHours?: 'regular_hours' | 'extended_hours';
|
|
303
|
+
trailType?: 'percentage' | 'amount';
|
|
304
|
+
};
|
|
305
|
+
ninjaTrader?: {
|
|
306
|
+
accountSpec?: string;
|
|
307
|
+
isAutomated?: boolean;
|
|
308
|
+
activationTime?: string;
|
|
309
|
+
text?: string;
|
|
310
|
+
pegDifference?: number;
|
|
311
|
+
expireTime?: string;
|
|
312
|
+
};
|
|
313
|
+
tastyTrade?: {
|
|
314
|
+
automatedSource?: boolean;
|
|
315
|
+
priceEffect?: 'Debit' | 'Credit';
|
|
316
|
+
externalIdentifier?: string;
|
|
317
|
+
partitionKey?: string;
|
|
318
|
+
preflightId?: string;
|
|
319
|
+
source?: string;
|
|
320
|
+
valueEffect?: 'Debit' | 'Credit';
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
interface CryptoOrderOptions {
|
|
324
|
+
quantity?: number;
|
|
325
|
+
notional?: number;
|
|
326
|
+
}
|
|
327
|
+
interface OptionsOrderOptions {
|
|
328
|
+
strikePrice: number;
|
|
329
|
+
expirationDate: string;
|
|
330
|
+
optionType: 'call' | 'put';
|
|
331
|
+
contractSize?: number;
|
|
332
|
+
}
|
|
333
|
+
interface OrderResponse {
|
|
334
|
+
success: boolean;
|
|
335
|
+
response_data: {
|
|
336
|
+
orderId: string;
|
|
337
|
+
status: string;
|
|
338
|
+
broker?: string;
|
|
339
|
+
accountNumber?: string;
|
|
340
|
+
};
|
|
341
|
+
message: string;
|
|
342
|
+
status_code: number;
|
|
343
|
+
}
|
|
344
|
+
interface TradingContext {
|
|
345
|
+
broker?: string;
|
|
346
|
+
accountNumber?: string;
|
|
347
|
+
accountId?: string;
|
|
348
|
+
}
|
|
349
|
+
interface BrokerConnection {
|
|
350
|
+
id: string;
|
|
351
|
+
broker_id: string;
|
|
352
|
+
user_id: string;
|
|
353
|
+
company_id: string;
|
|
354
|
+
status: 'connected' | 'disconnected' | 'error';
|
|
355
|
+
connected_at: string;
|
|
356
|
+
last_synced_at: string | null;
|
|
357
|
+
permissions: {
|
|
358
|
+
read: boolean;
|
|
359
|
+
write: boolean;
|
|
360
|
+
};
|
|
361
|
+
metadata: {
|
|
362
|
+
nickname?: string;
|
|
363
|
+
[key: string]: any;
|
|
364
|
+
};
|
|
365
|
+
needs_reauth: boolean;
|
|
366
|
+
}
|
|
367
|
+
interface OrdersFilter {
|
|
368
|
+
broker_id?: string;
|
|
369
|
+
connection_id?: string;
|
|
370
|
+
account_id?: string;
|
|
371
|
+
symbol?: string;
|
|
372
|
+
status?: 'filled' | 'pending' | 'cancelled' | 'rejected' | 'partially_filled';
|
|
373
|
+
side?: 'buy' | 'sell';
|
|
374
|
+
asset_type?: 'stock' | 'option' | 'crypto' | 'future';
|
|
375
|
+
limit?: number;
|
|
376
|
+
offset?: number;
|
|
377
|
+
created_after?: string;
|
|
378
|
+
created_before?: string;
|
|
379
|
+
with_metadata?: boolean;
|
|
380
|
+
}
|
|
381
|
+
interface PositionsFilter {
|
|
382
|
+
broker_id?: string;
|
|
383
|
+
connection_id?: string;
|
|
384
|
+
account_id?: string;
|
|
385
|
+
symbol?: string;
|
|
386
|
+
side?: 'long' | 'short';
|
|
387
|
+
asset_type?: 'stock' | 'option' | 'crypto' | 'future';
|
|
388
|
+
position_status?: 'open' | 'closed';
|
|
389
|
+
limit?: number;
|
|
390
|
+
offset?: number;
|
|
391
|
+
updated_after?: string;
|
|
392
|
+
updated_before?: string;
|
|
393
|
+
with_metadata?: boolean;
|
|
394
|
+
}
|
|
395
|
+
interface AccountsFilter {
|
|
396
|
+
broker_id?: string;
|
|
397
|
+
connection_id?: string;
|
|
398
|
+
account_type?: 'margin' | 'cash' | 'crypto_wallet' | 'live' | 'sim';
|
|
399
|
+
status?: 'active' | 'inactive';
|
|
400
|
+
currency?: string;
|
|
401
|
+
limit?: number;
|
|
402
|
+
offset?: number;
|
|
403
|
+
with_metadata?: boolean;
|
|
404
|
+
}
|
|
405
|
+
interface BrokerDataOrder {
|
|
406
|
+
id: string;
|
|
407
|
+
broker_id: string;
|
|
408
|
+
connection_id: string;
|
|
409
|
+
account_id: string;
|
|
410
|
+
order_id: string;
|
|
411
|
+
symbol: string;
|
|
412
|
+
order_type: string;
|
|
413
|
+
side: 'buy' | 'sell';
|
|
414
|
+
quantity: number;
|
|
415
|
+
price: number;
|
|
416
|
+
status: 'filled' | 'pending' | 'cancelled' | 'rejected' | 'partially_filled';
|
|
417
|
+
asset_type: 'stock' | 'option' | 'crypto' | 'future';
|
|
418
|
+
created_at: string;
|
|
419
|
+
updated_at: string;
|
|
420
|
+
filled_at?: string;
|
|
421
|
+
filled_quantity: number;
|
|
422
|
+
filled_avg_price: number;
|
|
423
|
+
metadata?: Record<string, any>;
|
|
424
|
+
}
|
|
425
|
+
interface BrokerDataPosition {
|
|
426
|
+
id: string;
|
|
427
|
+
broker_id: string;
|
|
428
|
+
connection_id: string;
|
|
429
|
+
account_id: string;
|
|
430
|
+
symbol: string;
|
|
431
|
+
asset_type: 'stock' | 'option' | 'crypto' | 'future';
|
|
432
|
+
side: 'long' | 'short';
|
|
433
|
+
quantity: number;
|
|
434
|
+
average_price: number;
|
|
435
|
+
market_value: number;
|
|
436
|
+
cost_basis: number;
|
|
437
|
+
unrealized_gain_loss: number;
|
|
438
|
+
unrealized_gain_loss_percent: number;
|
|
439
|
+
current_price: number;
|
|
440
|
+
last_price: number;
|
|
441
|
+
last_price_updated_at: string;
|
|
442
|
+
position_status: 'open' | 'closed';
|
|
443
|
+
created_at: string;
|
|
444
|
+
updated_at: string;
|
|
445
|
+
metadata?: Record<string, any>;
|
|
446
|
+
}
|
|
447
|
+
interface BrokerDataAccount {
|
|
448
|
+
id: string;
|
|
449
|
+
broker_id: string;
|
|
450
|
+
connection_id: string;
|
|
451
|
+
account_id: string;
|
|
452
|
+
account_name: string;
|
|
453
|
+
account_type: 'margin' | 'cash' | 'crypto_wallet' | 'live' | 'sim';
|
|
454
|
+
status: 'active' | 'inactive';
|
|
455
|
+
currency: string;
|
|
456
|
+
cash_balance: number;
|
|
457
|
+
buying_power: number;
|
|
458
|
+
equity: number;
|
|
459
|
+
created_at: string;
|
|
460
|
+
updated_at: string;
|
|
461
|
+
last_synced_at: string;
|
|
462
|
+
metadata?: Record<string, any>;
|
|
463
|
+
}
|
|
464
|
+
interface FilteredOrdersResponse {
|
|
465
|
+
orders: BrokerDataOrder[];
|
|
466
|
+
total: number;
|
|
467
|
+
limit: number;
|
|
468
|
+
offset: number;
|
|
469
|
+
}
|
|
470
|
+
interface FilteredPositionsResponse {
|
|
471
|
+
positions: BrokerDataPosition[];
|
|
472
|
+
total: number;
|
|
473
|
+
limit: number;
|
|
474
|
+
offset: number;
|
|
475
|
+
}
|
|
476
|
+
interface FilteredAccountsResponse {
|
|
477
|
+
accounts: BrokerDataAccount[];
|
|
478
|
+
total: number;
|
|
479
|
+
limit: number;
|
|
480
|
+
offset: number;
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
interface Theme {
|
|
484
|
+
mode: 'light' | 'dark';
|
|
485
|
+
primaryColor: string;
|
|
486
|
+
colors: {
|
|
487
|
+
primary: string;
|
|
488
|
+
secondary: string;
|
|
489
|
+
background: {
|
|
490
|
+
primary: string;
|
|
491
|
+
secondary: string;
|
|
492
|
+
tertiary: string;
|
|
493
|
+
};
|
|
494
|
+
text: {
|
|
495
|
+
primary: string;
|
|
496
|
+
secondary: string;
|
|
497
|
+
disabled: string;
|
|
498
|
+
error: string;
|
|
499
|
+
success: string;
|
|
500
|
+
warning: string;
|
|
501
|
+
};
|
|
502
|
+
border: {
|
|
503
|
+
light: string;
|
|
504
|
+
medium: string;
|
|
505
|
+
dark: string;
|
|
506
|
+
};
|
|
507
|
+
status: {
|
|
508
|
+
active: string;
|
|
509
|
+
inactive: string;
|
|
510
|
+
pending: string;
|
|
511
|
+
error: string;
|
|
512
|
+
success: string;
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
typography: {
|
|
516
|
+
fontFamily: string;
|
|
517
|
+
fontSize: {
|
|
518
|
+
xs: string;
|
|
519
|
+
sm: string;
|
|
520
|
+
base: string;
|
|
521
|
+
lg: string;
|
|
522
|
+
xl: string;
|
|
523
|
+
'2xl': string;
|
|
524
|
+
};
|
|
525
|
+
fontWeight: {
|
|
526
|
+
light: number;
|
|
527
|
+
normal: number;
|
|
528
|
+
medium: number;
|
|
529
|
+
semibold: number;
|
|
530
|
+
bold: number;
|
|
531
|
+
};
|
|
532
|
+
lineHeight: {
|
|
533
|
+
none: number;
|
|
534
|
+
tight: number;
|
|
535
|
+
normal: number;
|
|
536
|
+
relaxed: number;
|
|
537
|
+
};
|
|
538
|
+
};
|
|
539
|
+
spacing: {
|
|
540
|
+
xs: string;
|
|
541
|
+
sm: string;
|
|
542
|
+
md: string;
|
|
543
|
+
lg: string;
|
|
544
|
+
xl: string;
|
|
545
|
+
'2xl': string;
|
|
546
|
+
};
|
|
547
|
+
animation: {
|
|
548
|
+
duration: {
|
|
549
|
+
fast: string;
|
|
550
|
+
normal: string;
|
|
551
|
+
slow: string;
|
|
552
|
+
};
|
|
553
|
+
easing: {
|
|
554
|
+
linear: string;
|
|
555
|
+
easeIn: string;
|
|
556
|
+
easeOut: string;
|
|
557
|
+
easeInOut: string;
|
|
558
|
+
};
|
|
559
|
+
};
|
|
560
|
+
components: {
|
|
561
|
+
button: {
|
|
562
|
+
borderRadius: string;
|
|
563
|
+
padding: string;
|
|
564
|
+
fontSize: string;
|
|
565
|
+
fontWeight: number;
|
|
566
|
+
};
|
|
567
|
+
input: {
|
|
568
|
+
borderRadius: string;
|
|
569
|
+
padding: string;
|
|
570
|
+
fontSize: string;
|
|
571
|
+
};
|
|
572
|
+
card: {
|
|
573
|
+
borderRadius: string;
|
|
574
|
+
padding: string;
|
|
575
|
+
shadow: string;
|
|
576
|
+
};
|
|
577
|
+
modal: {
|
|
578
|
+
borderRadius: string;
|
|
579
|
+
padding: string;
|
|
580
|
+
backdrop: string;
|
|
581
|
+
};
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
interface SDKConfig {
|
|
586
|
+
token: string;
|
|
587
|
+
theme?: Theme;
|
|
588
|
+
sandbox?: boolean;
|
|
589
|
+
}
|
|
590
|
+
interface PortalConfig$1 {
|
|
591
|
+
companyId: string;
|
|
592
|
+
theme?: Theme;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
interface PortalConfig {
|
|
596
|
+
width?: string;
|
|
597
|
+
height?: string;
|
|
598
|
+
position?: 'center' | 'top' | 'bottom';
|
|
599
|
+
zIndex?: number;
|
|
600
|
+
}
|
|
601
|
+
interface PortalThemeConfig {
|
|
602
|
+
mode: 'dark' | 'light' | 'auto';
|
|
603
|
+
colors: {
|
|
604
|
+
background: {
|
|
605
|
+
primary: string;
|
|
606
|
+
secondary: string;
|
|
607
|
+
tertiary: string;
|
|
608
|
+
accent: string;
|
|
609
|
+
glass: string;
|
|
610
|
+
};
|
|
611
|
+
status: {
|
|
612
|
+
connected: string;
|
|
613
|
+
disconnected: string;
|
|
614
|
+
warning: string;
|
|
615
|
+
pending: string;
|
|
616
|
+
error: string;
|
|
617
|
+
success: string;
|
|
618
|
+
};
|
|
619
|
+
text: {
|
|
620
|
+
primary: string;
|
|
621
|
+
secondary: string;
|
|
622
|
+
muted: string;
|
|
623
|
+
inverse: string;
|
|
624
|
+
};
|
|
625
|
+
border: {
|
|
626
|
+
primary: string;
|
|
627
|
+
secondary: string;
|
|
628
|
+
hover: string;
|
|
629
|
+
focus: string;
|
|
630
|
+
accent: string;
|
|
631
|
+
};
|
|
632
|
+
input: {
|
|
633
|
+
background: string;
|
|
634
|
+
border: string;
|
|
635
|
+
borderFocus: string;
|
|
636
|
+
text: string;
|
|
637
|
+
placeholder: string;
|
|
638
|
+
};
|
|
639
|
+
button: {
|
|
640
|
+
primary: {
|
|
641
|
+
background: string;
|
|
642
|
+
text: string;
|
|
643
|
+
hover: string;
|
|
644
|
+
active: string;
|
|
645
|
+
};
|
|
646
|
+
secondary: {
|
|
647
|
+
background: string;
|
|
648
|
+
text: string;
|
|
649
|
+
border: string;
|
|
650
|
+
hover: string;
|
|
651
|
+
active: string;
|
|
652
|
+
};
|
|
653
|
+
};
|
|
654
|
+
};
|
|
655
|
+
branding?: {
|
|
656
|
+
primaryColor?: string;
|
|
657
|
+
};
|
|
658
|
+
}
|
|
659
|
+
type PortalThemePreset = 'dark' | 'light' | 'corporateBlue' | 'purple' | 'green' | 'orange';
|
|
660
|
+
interface PortalTheme {
|
|
661
|
+
preset?: PortalThemePreset;
|
|
662
|
+
custom?: PortalThemeConfig;
|
|
663
|
+
}
|
|
664
|
+
interface PortalProps {
|
|
665
|
+
config: PortalConfig;
|
|
666
|
+
onClose?: () => void;
|
|
667
|
+
onReady?: () => void;
|
|
668
|
+
onError?: (error: Error) => void;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
interface FinaticConnectOptions {
|
|
672
|
+
/** The portal token from your backend */
|
|
673
|
+
token: string;
|
|
674
|
+
/** Optional base URL for API requests */
|
|
675
|
+
baseUrl?: string;
|
|
676
|
+
/** Optional origin for the portal */
|
|
677
|
+
origin?: string;
|
|
678
|
+
/** Callback when user successfully connects */
|
|
679
|
+
onSuccess?: (tokens: UserToken) => void;
|
|
680
|
+
/** Callback when an error occurs */
|
|
681
|
+
onError?: (error: Error) => void;
|
|
682
|
+
/** Callback when the portal is closed */
|
|
683
|
+
onClose?: () => void;
|
|
684
|
+
/** Optional theme configuration */
|
|
685
|
+
theme?: Theme;
|
|
686
|
+
/** Callback when tokens are received */
|
|
687
|
+
onTokensReceived?: (tokens: {
|
|
688
|
+
access_token?: string;
|
|
689
|
+
refresh_token?: string;
|
|
690
|
+
}) => void;
|
|
691
|
+
}
|
|
692
|
+
interface FinaticUserToken {
|
|
693
|
+
accessToken: string;
|
|
694
|
+
refreshToken: string;
|
|
695
|
+
userId: string;
|
|
696
|
+
companyId: string;
|
|
697
|
+
expiresAt: Date;
|
|
698
|
+
}
|
|
699
|
+
interface PortalMessage {
|
|
700
|
+
type: 'success' | 'error' | 'close' | 'resize';
|
|
701
|
+
userId?: string;
|
|
702
|
+
error?: string;
|
|
703
|
+
height?: number;
|
|
704
|
+
access_token?: string;
|
|
705
|
+
refresh_token?: string;
|
|
706
|
+
}
|
|
707
|
+
interface PortalOptions {
|
|
708
|
+
/** Callback when user successfully connects */
|
|
709
|
+
onSuccess?: (userId: string) => void;
|
|
710
|
+
/** Callback when an error occurs */
|
|
711
|
+
onError?: (error: Error) => void;
|
|
712
|
+
/** Callback when the portal is closed */
|
|
713
|
+
onClose?: () => void;
|
|
714
|
+
/** Callback when portal events occur */
|
|
715
|
+
onEvent?: (type: string, data: any) => void;
|
|
716
|
+
/** Optional theme configuration for the portal */
|
|
717
|
+
theme?: PortalTheme;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Error-related types for Finatic Connect SDK
|
|
722
|
+
*/
|
|
723
|
+
interface BaseError$1 {
|
|
724
|
+
code: string;
|
|
725
|
+
message: string;
|
|
726
|
+
details?: Record<string, any>;
|
|
727
|
+
}
|
|
728
|
+
interface ApiError$1 extends BaseError$1 {
|
|
729
|
+
status: number;
|
|
730
|
+
headers?: Record<string, string>;
|
|
731
|
+
}
|
|
732
|
+
interface SessionError extends BaseError$1 {
|
|
733
|
+
sessionId?: string;
|
|
734
|
+
status?: string;
|
|
735
|
+
}
|
|
736
|
+
interface AuthenticationError extends BaseError$1 {
|
|
737
|
+
userId?: string;
|
|
738
|
+
tokenType?: string;
|
|
739
|
+
}
|
|
740
|
+
interface AuthorizationError extends BaseError$1 {
|
|
741
|
+
resource?: string;
|
|
742
|
+
permission?: string;
|
|
743
|
+
}
|
|
744
|
+
interface RateLimitError extends BaseError$1 {
|
|
745
|
+
retryAfter?: number;
|
|
746
|
+
limit?: number;
|
|
747
|
+
remaining?: number;
|
|
748
|
+
}
|
|
749
|
+
interface TokenError extends BaseError$1 {
|
|
750
|
+
tokenType?: string;
|
|
751
|
+
expiresAt?: string;
|
|
752
|
+
}
|
|
753
|
+
interface ValidationError extends BaseError$1 {
|
|
754
|
+
field?: string;
|
|
755
|
+
value?: any;
|
|
756
|
+
constraints?: string[];
|
|
757
|
+
}
|
|
758
|
+
interface NetworkError extends BaseError$1 {
|
|
759
|
+
url?: string;
|
|
760
|
+
method?: string;
|
|
761
|
+
status?: number;
|
|
762
|
+
}
|
|
763
|
+
interface SecurityError extends BaseError$1 {
|
|
764
|
+
securityContext?: Record<string, any>;
|
|
765
|
+
validationResult?: Record<string, any>;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
interface ApiPaginationInfo {
|
|
769
|
+
has_more: boolean;
|
|
770
|
+
next_offset: number;
|
|
771
|
+
current_offset: number;
|
|
772
|
+
limit: number;
|
|
773
|
+
}
|
|
774
|
+
interface PaginationMetadata {
|
|
775
|
+
hasMore: boolean;
|
|
776
|
+
nextOffset: number;
|
|
777
|
+
currentOffset: number;
|
|
778
|
+
limit: number;
|
|
779
|
+
currentPage: number;
|
|
780
|
+
hasNext: boolean;
|
|
781
|
+
hasPrevious: boolean;
|
|
782
|
+
}
|
|
783
|
+
declare class PaginatedResult<T> {
|
|
784
|
+
readonly data: T;
|
|
785
|
+
readonly metadata: PaginationMetadata;
|
|
786
|
+
private navigationCallback?;
|
|
787
|
+
constructor(data: T, paginationInfo: ApiPaginationInfo, navigationCallback?: (offset: number, limit: number) => Promise<PaginatedResult<T>>);
|
|
788
|
+
get hasNext(): boolean;
|
|
789
|
+
get hasPrevious(): boolean;
|
|
790
|
+
get currentPage(): number;
|
|
791
|
+
/**
|
|
792
|
+
* Navigate to the next page
|
|
793
|
+
* @returns Promise<PaginatedResult<T> | null> - Next page result or null if no next page
|
|
794
|
+
*/
|
|
795
|
+
nextPage(): Promise<PaginatedResult<T> | null>;
|
|
796
|
+
/**
|
|
797
|
+
* Navigate to the previous page
|
|
798
|
+
* @returns Promise<PaginatedResult<T> | null> - Previous page result or null if no previous page
|
|
799
|
+
*/
|
|
800
|
+
previousPage(): Promise<PaginatedResult<T> | null>;
|
|
801
|
+
/**
|
|
802
|
+
* Navigate to a specific page
|
|
803
|
+
* @param pageNumber - The page number to navigate to (1-based)
|
|
804
|
+
* @returns Promise<PaginatedResult<T> | null> - Page result or null if page doesn't exist
|
|
805
|
+
*/
|
|
806
|
+
goToPage(pageNumber: number): Promise<PaginatedResult<T> | null>;
|
|
807
|
+
/**
|
|
808
|
+
* Get the first page
|
|
809
|
+
* @returns Promise<PaginatedResult<T> | null> - First page result or null if error
|
|
810
|
+
*/
|
|
811
|
+
firstPage(): Promise<PaginatedResult<T> | null>;
|
|
812
|
+
/**
|
|
813
|
+
* Get the last page (this is a best effort - we don't know the total count)
|
|
814
|
+
* @returns Promise<PaginatedResult<T> | null> - Last page result or null if error
|
|
815
|
+
*/
|
|
816
|
+
lastPage(): Promise<PaginatedResult<T> | null>;
|
|
817
|
+
/**
|
|
818
|
+
* Get pagination info as a string
|
|
819
|
+
* @returns string - Human readable pagination info
|
|
820
|
+
*/
|
|
821
|
+
getPaginationInfo(): string;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
declare class BaseError extends Error {
|
|
825
|
+
readonly code: string;
|
|
826
|
+
constructor(message: string, code?: string);
|
|
827
|
+
}
|
|
828
|
+
declare class ApiError extends BaseError {
|
|
829
|
+
readonly status: number;
|
|
830
|
+
readonly details?: Record<string, any> | undefined;
|
|
831
|
+
constructor(status: number, message: string, details?: Record<string, any> | undefined);
|
|
832
|
+
}
|
|
833
|
+
declare class CompanyAccessError extends ApiError {
|
|
834
|
+
constructor(message: string, details?: Record<string, any>);
|
|
835
|
+
}
|
|
836
|
+
declare class OrderError extends ApiError {
|
|
837
|
+
constructor(message: string, details?: Record<string, any>);
|
|
838
|
+
}
|
|
839
|
+
declare class OrderValidationError extends ApiError {
|
|
840
|
+
constructor(message: string, details?: Record<string, any>);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
declare class ApiClient$1 {
|
|
844
|
+
private readonly baseUrl;
|
|
845
|
+
protected readonly deviceInfo?: DeviceInfo$1;
|
|
846
|
+
protected currentSessionState: SessionState | null;
|
|
847
|
+
protected currentSessionId: string | null;
|
|
848
|
+
private tradingContext;
|
|
849
|
+
private tokenInfo;
|
|
850
|
+
private refreshPromise;
|
|
851
|
+
private readonly REFRESH_BUFFER_MINUTES;
|
|
852
|
+
private companyId;
|
|
853
|
+
private csrfToken;
|
|
854
|
+
constructor(baseUrl: string, deviceInfo?: DeviceInfo$1);
|
|
855
|
+
/**
|
|
856
|
+
* Set session context (session ID, company ID, CSRF token)
|
|
857
|
+
*/
|
|
858
|
+
setSessionContext(sessionId: string, companyId: string, csrfToken?: string): void;
|
|
859
|
+
/**
|
|
860
|
+
* Get the current session ID
|
|
861
|
+
*/
|
|
862
|
+
getCurrentSessionId(): string | null;
|
|
863
|
+
/**
|
|
864
|
+
* Get the current company ID
|
|
865
|
+
*/
|
|
866
|
+
getCurrentCompanyId(): string | null;
|
|
867
|
+
/**
|
|
868
|
+
* Get the current CSRF token
|
|
869
|
+
*/
|
|
870
|
+
getCurrentCsrfToken(): string | null;
|
|
871
|
+
/**
|
|
872
|
+
* Store tokens after successful authentication
|
|
873
|
+
*/
|
|
874
|
+
setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
|
|
875
|
+
/**
|
|
876
|
+
* Get the current access token, refreshing if necessary
|
|
877
|
+
*/
|
|
878
|
+
getValidAccessToken(): Promise<string>;
|
|
879
|
+
/**
|
|
880
|
+
* Check if the current token is expired or about to expire
|
|
881
|
+
*/
|
|
882
|
+
private isTokenExpired;
|
|
883
|
+
/**
|
|
884
|
+
* Refresh the access token using the refresh token
|
|
885
|
+
*/
|
|
886
|
+
private refreshTokens;
|
|
887
|
+
/**
|
|
888
|
+
* Perform the actual token refresh request
|
|
889
|
+
*/
|
|
890
|
+
private performTokenRefresh;
|
|
891
|
+
/**
|
|
892
|
+
* Clear stored tokens (useful for logout)
|
|
893
|
+
*/
|
|
894
|
+
clearTokens(): void;
|
|
895
|
+
/**
|
|
896
|
+
* Get current token info (for debugging/testing)
|
|
897
|
+
*/
|
|
898
|
+
getTokenInfo(): TokenInfo | null;
|
|
899
|
+
/**
|
|
900
|
+
* Make a request to the API.
|
|
901
|
+
*/
|
|
902
|
+
protected request<T>(path: string, options: {
|
|
903
|
+
method: string;
|
|
904
|
+
headers?: Record<string, string>;
|
|
905
|
+
body?: any;
|
|
906
|
+
params?: Record<string, string>;
|
|
907
|
+
}): Promise<T>;
|
|
908
|
+
/**
|
|
909
|
+
* Handle API errors. This method can be overridden by language-specific implementations.
|
|
910
|
+
*/
|
|
911
|
+
protected handleError(status: number, error: any): ApiError;
|
|
912
|
+
startSession(token: string, userId?: string): Promise<SessionResponse>;
|
|
913
|
+
requestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
|
|
914
|
+
verifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
|
|
915
|
+
authenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
|
|
916
|
+
/**
|
|
917
|
+
* Get the portal URL for an active session
|
|
918
|
+
* @param sessionId The session identifier
|
|
919
|
+
* @returns Portal URL response
|
|
920
|
+
* @throws SessionError if session is not in ACTIVE state
|
|
921
|
+
*/
|
|
922
|
+
getPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
|
|
923
|
+
validatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
|
|
924
|
+
completePortalSession(sessionId: string): Promise<PortalUrlResponse>;
|
|
925
|
+
getHoldings(accessToken: string): Promise<{
|
|
926
|
+
data: Holding[];
|
|
927
|
+
}>;
|
|
928
|
+
getOrders(accessToken: string): Promise<{
|
|
929
|
+
data: Order[];
|
|
930
|
+
}>;
|
|
931
|
+
getPortfolio(accessToken: string): Promise<{
|
|
932
|
+
data: Portfolio;
|
|
933
|
+
}>;
|
|
934
|
+
placeOrder(accessToken: string, order: Order): Promise<void>;
|
|
935
|
+
getHoldingsAuto(): Promise<{
|
|
936
|
+
data: Holding[];
|
|
937
|
+
}>;
|
|
938
|
+
getOrdersAuto(): Promise<{
|
|
939
|
+
data: Order[];
|
|
940
|
+
}>;
|
|
941
|
+
getPortfolioAuto(): Promise<{
|
|
942
|
+
data: Portfolio;
|
|
943
|
+
}>;
|
|
944
|
+
placeOrderAuto(order: Order): Promise<void>;
|
|
945
|
+
placeBrokerOrder(accessToken: string, params: Partial<BrokerOrderParams> & {
|
|
946
|
+
symbol: string;
|
|
947
|
+
orderQty: number;
|
|
948
|
+
action: 'Buy' | 'Sell';
|
|
949
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
|
|
950
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
951
|
+
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
952
|
+
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
953
|
+
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
954
|
+
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
955
|
+
setAccount(accountNumber: string, accountId?: string): void;
|
|
956
|
+
getTradingContext(): TradingContext;
|
|
957
|
+
clearTradingContext(): void;
|
|
958
|
+
placeStockMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
959
|
+
placeStockLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
960
|
+
placeStockStopOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
961
|
+
placeCryptoMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
962
|
+
placeCryptoLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
963
|
+
placeOptionsMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
964
|
+
placeOptionsLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, options: OptionsOrderOptions, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
965
|
+
placeFuturesMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
966
|
+
placeFuturesLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
967
|
+
private buildOrderRequestBody;
|
|
968
|
+
private buildModifyRequestBody;
|
|
969
|
+
private applyBrokerDefaults;
|
|
970
|
+
revokeToken(accessToken: string): Promise<void>;
|
|
971
|
+
getUserToken(userId: string): Promise<UserToken>;
|
|
972
|
+
getCurrentSessionState(): SessionState | null;
|
|
973
|
+
getBrokerList(accessToken: string): Promise<{
|
|
974
|
+
_id: string;
|
|
975
|
+
response_data: BrokerInfo[];
|
|
976
|
+
message: string;
|
|
977
|
+
status_code: number;
|
|
978
|
+
warnings: null;
|
|
979
|
+
errors: null;
|
|
980
|
+
}>;
|
|
981
|
+
getBrokerAccounts(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
982
|
+
_id: string;
|
|
983
|
+
response_data: BrokerAccount[];
|
|
984
|
+
message: string;
|
|
985
|
+
status_code: number;
|
|
986
|
+
warnings: null;
|
|
987
|
+
errors: null;
|
|
988
|
+
}>;
|
|
989
|
+
getBrokerOrders(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
990
|
+
_id: string;
|
|
991
|
+
response_data: BrokerOrder[];
|
|
992
|
+
message: string;
|
|
993
|
+
status_code: number;
|
|
994
|
+
warnings: null;
|
|
995
|
+
errors: null;
|
|
996
|
+
}>;
|
|
997
|
+
getBrokerPositions(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
998
|
+
_id: string;
|
|
999
|
+
response_data: BrokerPosition[];
|
|
1000
|
+
message: string;
|
|
1001
|
+
status_code: number;
|
|
1002
|
+
warnings: null;
|
|
1003
|
+
errors: null;
|
|
1004
|
+
}>;
|
|
1005
|
+
getBrokerConnections(accessToken: string): Promise<{
|
|
1006
|
+
_id: string;
|
|
1007
|
+
response_data: BrokerConnection[];
|
|
1008
|
+
message: string;
|
|
1009
|
+
status_code: number;
|
|
1010
|
+
warnings: null;
|
|
1011
|
+
errors: null;
|
|
1012
|
+
}>;
|
|
1013
|
+
getBrokerListAuto(): Promise<{
|
|
1014
|
+
_id: string;
|
|
1015
|
+
response_data: BrokerInfo[];
|
|
1016
|
+
message: string;
|
|
1017
|
+
status_code: number;
|
|
1018
|
+
warnings: null;
|
|
1019
|
+
errors: null;
|
|
1020
|
+
}>;
|
|
1021
|
+
getBrokerAccountsAuto(options?: BrokerDataOptions): Promise<{
|
|
1022
|
+
_id: string;
|
|
1023
|
+
response_data: BrokerAccount[];
|
|
1024
|
+
message: string;
|
|
1025
|
+
status_code: number;
|
|
1026
|
+
warnings: null;
|
|
1027
|
+
errors: null;
|
|
1028
|
+
}>;
|
|
1029
|
+
getBrokerOrdersAuto(options?: BrokerDataOptions): Promise<{
|
|
1030
|
+
_id: string;
|
|
1031
|
+
response_data: BrokerOrder[];
|
|
1032
|
+
message: string;
|
|
1033
|
+
status_code: number;
|
|
1034
|
+
warnings: null;
|
|
1035
|
+
errors: null;
|
|
1036
|
+
}>;
|
|
1037
|
+
getBrokerPositionsAuto(options?: BrokerDataOptions): Promise<{
|
|
1038
|
+
_id: string;
|
|
1039
|
+
response_data: BrokerPosition[];
|
|
1040
|
+
message: string;
|
|
1041
|
+
status_code: number;
|
|
1042
|
+
warnings: null;
|
|
1043
|
+
errors: null;
|
|
1044
|
+
}>;
|
|
1045
|
+
getBrokerConnectionsAuto(): Promise<{
|
|
1046
|
+
_id: string;
|
|
1047
|
+
response_data: BrokerConnection[];
|
|
1048
|
+
message: string;
|
|
1049
|
+
status_code: number;
|
|
1050
|
+
warnings: null;
|
|
1051
|
+
errors: null;
|
|
1052
|
+
}>;
|
|
1053
|
+
placeBrokerOrderAuto(params: Partial<BrokerOrderParams> & {
|
|
1054
|
+
symbol: string;
|
|
1055
|
+
orderQty: number;
|
|
1056
|
+
action: 'Buy' | 'Sell';
|
|
1057
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
|
|
1058
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
1059
|
+
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1060
|
+
placeStockMarketOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1061
|
+
placeStockLimitOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1062
|
+
placeStockStopOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1063
|
+
getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<BrokerOrder[]>>;
|
|
1064
|
+
getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<BrokerAccount[]>>;
|
|
1065
|
+
getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<BrokerPosition[]>>;
|
|
1066
|
+
getNextPage<T>(previousResult: PaginatedResult<T>, fetchFunction: (offset: number, limit: number) => Promise<PaginatedResult<T>>): Promise<PaginatedResult<T> | null>;
|
|
1067
|
+
/**
|
|
1068
|
+
* Check if this is a mock client
|
|
1069
|
+
* @returns false for real API client
|
|
1070
|
+
*/
|
|
1071
|
+
isMockClient(): boolean;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
type EventCallback = (...args: any[]) => void;
|
|
1075
|
+
declare class EventEmitter {
|
|
1076
|
+
private events;
|
|
1077
|
+
on(event: string, callback: EventCallback): void;
|
|
1078
|
+
off(event: string, callback: EventCallback): void;
|
|
1079
|
+
once(event: string, callback: EventCallback): void;
|
|
1080
|
+
emit(event: string, ...args: any[]): void;
|
|
1081
|
+
removeAllListeners(event?: string): void;
|
|
1082
|
+
listenerCount(event: string): number;
|
|
1083
|
+
listeners(event: string): EventCallback[];
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
interface DeviceInfo {
|
|
1087
|
+
ip_address: string;
|
|
1088
|
+
user_agent: string;
|
|
1089
|
+
fingerprint: string;
|
|
1090
|
+
}
|
|
1091
|
+
declare class FinaticConnect extends EventEmitter {
|
|
1092
|
+
private static instance;
|
|
1093
|
+
private apiClient;
|
|
1094
|
+
private portalUI;
|
|
1095
|
+
private options;
|
|
1096
|
+
private userToken;
|
|
1097
|
+
private sessionId;
|
|
1098
|
+
private companyId;
|
|
1099
|
+
private baseUrl;
|
|
1100
|
+
private readonly BROKER_LIST_CACHE_KEY;
|
|
1101
|
+
private readonly BROKER_LIST_CACHE_VERSION;
|
|
1102
|
+
private readonly BROKER_LIST_CACHE_DURATION;
|
|
1103
|
+
private readonly deviceInfo?;
|
|
1104
|
+
private currentSessionState;
|
|
1105
|
+
constructor(options: FinaticConnectOptions, deviceInfo?: DeviceInfo);
|
|
1106
|
+
private handleTokens;
|
|
1107
|
+
/**
|
|
1108
|
+
* Check if the user is authenticated
|
|
1109
|
+
* @returns True if the user has a valid access token
|
|
1110
|
+
*/
|
|
1111
|
+
isAuthenticated(): boolean;
|
|
1112
|
+
/**
|
|
1113
|
+
* Check if the user is fully authenticated (has userId, access token, and refresh token)
|
|
1114
|
+
* @returns True if the user is fully authenticated and ready for API calls
|
|
1115
|
+
*/
|
|
1116
|
+
isAuthed(): boolean;
|
|
1117
|
+
/**
|
|
1118
|
+
* Get user's orders with pagination and optional filtering
|
|
1119
|
+
* @param params - Query parameters including page, perPage, and filters
|
|
1120
|
+
* @returns Promise with paginated result that supports navigation
|
|
1121
|
+
*/
|
|
1122
|
+
getOrders(params?: {
|
|
1123
|
+
page?: number;
|
|
1124
|
+
perPage?: number;
|
|
1125
|
+
filter?: OrdersFilter;
|
|
1126
|
+
}): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Get user's positions with pagination and optional filtering
|
|
1129
|
+
* @param params - Query parameters including page, perPage, and filters
|
|
1130
|
+
* @returns Promise with paginated result that supports navigation
|
|
1131
|
+
*/
|
|
1132
|
+
getPositions(params?: {
|
|
1133
|
+
page?: number;
|
|
1134
|
+
perPage?: number;
|
|
1135
|
+
filter?: PositionsFilter;
|
|
1136
|
+
}): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
1137
|
+
/**
|
|
1138
|
+
* Get user's accounts with pagination and optional filtering
|
|
1139
|
+
* @param params - Query parameters including page, perPage, and filters
|
|
1140
|
+
* @returns Promise with paginated result that supports navigation
|
|
1141
|
+
*/
|
|
1142
|
+
getAccounts(params?: {
|
|
1143
|
+
page?: number;
|
|
1144
|
+
perPage?: number;
|
|
1145
|
+
filter?: AccountsFilter;
|
|
1146
|
+
}): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Revoke the current user's access
|
|
1149
|
+
*/
|
|
1150
|
+
revokeToken(): Promise<void>;
|
|
1151
|
+
/**
|
|
1152
|
+
* Initialize the Finatic Connect SDK
|
|
1153
|
+
* @param token - The portal token from your backend
|
|
1154
|
+
* @param userId - Optional: The user ID if you have it from a previous session
|
|
1155
|
+
* @param options - Optional configuration including baseUrl
|
|
1156
|
+
* @returns FinaticConnect instance
|
|
1157
|
+
*/
|
|
1158
|
+
static init(token: string, userId?: string | null | undefined, options?: {
|
|
1159
|
+
baseUrl?: string;
|
|
1160
|
+
} | undefined): Promise<FinaticConnect>;
|
|
1161
|
+
/**
|
|
1162
|
+
* Initialize the SDK with a user ID
|
|
1163
|
+
* @param userId - The user ID from a previous session
|
|
1164
|
+
*/
|
|
1165
|
+
setUserId(userId: string): Promise<void>;
|
|
1166
|
+
private initializeWithUser;
|
|
1167
|
+
/**
|
|
1168
|
+
* Handle company access error by opening the portal
|
|
1169
|
+
* @param error The company access error
|
|
1170
|
+
* @param options Optional configuration for the portal
|
|
1171
|
+
*/
|
|
1172
|
+
private handleCompanyAccessError;
|
|
1173
|
+
/**
|
|
1174
|
+
* Open the portal for user authentication
|
|
1175
|
+
* @param options Optional configuration for the portal
|
|
1176
|
+
*/
|
|
1177
|
+
openPortal(options?: PortalOptions): Promise<void>;
|
|
1178
|
+
/**
|
|
1179
|
+
* Close the Finatic Connect Portal
|
|
1180
|
+
*/
|
|
1181
|
+
closePortal(): void;
|
|
1182
|
+
/**
|
|
1183
|
+
* Initialize a new session
|
|
1184
|
+
* @param oneTimeToken - The one-time token from initSession
|
|
1185
|
+
*/
|
|
1186
|
+
protected startSession(oneTimeToken: string): Promise<void>;
|
|
1187
|
+
/**
|
|
1188
|
+
* Place a new order using the broker order API
|
|
1189
|
+
* @param order - Order details with broker context
|
|
1190
|
+
*/
|
|
1191
|
+
placeOrder(order: {
|
|
1192
|
+
symbol: string;
|
|
1193
|
+
quantity: number;
|
|
1194
|
+
side: 'buy' | 'sell';
|
|
1195
|
+
orderType: 'market' | 'limit' | 'stop' | 'stop_limit';
|
|
1196
|
+
price?: number;
|
|
1197
|
+
stopPrice?: number;
|
|
1198
|
+
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
1199
|
+
broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader';
|
|
1200
|
+
accountNumber?: string;
|
|
1201
|
+
assetType?: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
1202
|
+
}): Promise<OrderResponse>;
|
|
1203
|
+
/**
|
|
1204
|
+
* Cancel a broker order
|
|
1205
|
+
* @param orderId - The order ID to cancel
|
|
1206
|
+
* @param broker - Optional broker override
|
|
1207
|
+
*/
|
|
1208
|
+
cancelOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader'): Promise<OrderResponse>;
|
|
1209
|
+
/**
|
|
1210
|
+
* Modify a broker order
|
|
1211
|
+
* @param orderId - The order ID to modify
|
|
1212
|
+
* @param modifications - The modifications to apply
|
|
1213
|
+
* @param broker - Optional broker override
|
|
1214
|
+
*/
|
|
1215
|
+
modifyOrder(orderId: string, modifications: Partial<{
|
|
1216
|
+
symbol: string;
|
|
1217
|
+
quantity: number;
|
|
1218
|
+
price: number;
|
|
1219
|
+
stopPrice: number;
|
|
1220
|
+
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
1221
|
+
}>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader'): Promise<OrderResponse>;
|
|
1222
|
+
/**
|
|
1223
|
+
* Set the broker context for trading
|
|
1224
|
+
* @param broker - The broker to use for trading
|
|
1225
|
+
*/
|
|
1226
|
+
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
1227
|
+
/**
|
|
1228
|
+
* Set the account context for trading
|
|
1229
|
+
* @param accountNumber - The account number to use for trading
|
|
1230
|
+
* @param accountId - Optional account ID
|
|
1231
|
+
*/
|
|
1232
|
+
setAccount(accountNumber: string, accountId?: string): void;
|
|
1233
|
+
/**
|
|
1234
|
+
* Get the current trading context
|
|
1235
|
+
*/
|
|
1236
|
+
getTradingContext(): TradingContext;
|
|
1237
|
+
/**
|
|
1238
|
+
* Clear the trading context
|
|
1239
|
+
*/
|
|
1240
|
+
clearTradingContext(): void;
|
|
1241
|
+
/**
|
|
1242
|
+
* Place a stock market order (convenience method)
|
|
1243
|
+
*/
|
|
1244
|
+
placeStockMarketOrder(symbol: string, quantity: number, side: 'buy' | 'sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string): Promise<OrderResponse>;
|
|
1245
|
+
/**
|
|
1246
|
+
* Place a stock limit order (convenience method)
|
|
1247
|
+
*/
|
|
1248
|
+
placeStockLimitOrder(symbol: string, quantity: number, side: 'buy' | 'sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string): Promise<OrderResponse>;
|
|
1249
|
+
/**
|
|
1250
|
+
* Get the current user ID
|
|
1251
|
+
* @returns The current user ID or undefined if not authenticated
|
|
1252
|
+
* @throws AuthenticationError if user is not authenticated
|
|
1253
|
+
*/
|
|
1254
|
+
getUserId(): string | null;
|
|
1255
|
+
/**
|
|
1256
|
+
* Get list of supported brokers
|
|
1257
|
+
* @returns Promise with array of broker information
|
|
1258
|
+
*/
|
|
1259
|
+
getBrokerList(): Promise<BrokerInfo[]>;
|
|
1260
|
+
/**
|
|
1261
|
+
* Get broker connections
|
|
1262
|
+
* @returns Promise with array of broker connections
|
|
1263
|
+
* @throws AuthenticationError if user is not authenticated
|
|
1264
|
+
*/
|
|
1265
|
+
getBrokerConnections(): Promise<BrokerConnection[]>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Get only open positions
|
|
1268
|
+
* @returns Promise with array of open positions
|
|
1269
|
+
*/
|
|
1270
|
+
getOpenPositions(): Promise<BrokerDataPosition[]>;
|
|
1271
|
+
/**
|
|
1272
|
+
* Get only filled orders
|
|
1273
|
+
* @returns Promise with array of filled orders
|
|
1274
|
+
*/
|
|
1275
|
+
getFilledOrders(): Promise<BrokerDataOrder[]>;
|
|
1276
|
+
/**
|
|
1277
|
+
* Get only pending orders
|
|
1278
|
+
* @returns Promise with array of pending orders
|
|
1279
|
+
*/
|
|
1280
|
+
getPendingOrders(): Promise<BrokerDataOrder[]>;
|
|
1281
|
+
/**
|
|
1282
|
+
* Get only active accounts
|
|
1283
|
+
* @returns Promise with array of active accounts
|
|
1284
|
+
*/
|
|
1285
|
+
getActiveAccounts(): Promise<BrokerDataAccount[]>;
|
|
1286
|
+
/**
|
|
1287
|
+
* Get orders for a specific symbol
|
|
1288
|
+
* @param symbol - The symbol to filter by
|
|
1289
|
+
* @returns Promise with array of orders for the symbol
|
|
1290
|
+
*/
|
|
1291
|
+
getOrdersBySymbol(symbol: string): Promise<BrokerDataOrder[]>;
|
|
1292
|
+
/**
|
|
1293
|
+
* Get positions for a specific symbol
|
|
1294
|
+
* @param symbol - The symbol to filter by
|
|
1295
|
+
* @returns Promise with array of positions for the symbol
|
|
1296
|
+
*/
|
|
1297
|
+
getPositionsBySymbol(symbol: string): Promise<BrokerDataPosition[]>;
|
|
1298
|
+
/**
|
|
1299
|
+
* Get orders for a specific broker
|
|
1300
|
+
* @param brokerId - The broker ID to filter by
|
|
1301
|
+
* @returns Promise with array of orders for the broker
|
|
1302
|
+
*/
|
|
1303
|
+
getOrdersByBroker(brokerId: string): Promise<BrokerDataOrder[]>;
|
|
1304
|
+
/**
|
|
1305
|
+
* Get positions for a specific broker
|
|
1306
|
+
* @param brokerId - The broker ID to filter by
|
|
1307
|
+
* @returns Promise with array of positions for the broker
|
|
1308
|
+
*/
|
|
1309
|
+
getPositionsByBroker(brokerId: string): Promise<BrokerDataPosition[]>;
|
|
1310
|
+
/**
|
|
1311
|
+
* Get a specific page of orders with pagination metadata
|
|
1312
|
+
* @param page - Page number (default: 1)
|
|
1313
|
+
* @param perPage - Items per page (default: 100)
|
|
1314
|
+
* @param filter - Optional filter parameters
|
|
1315
|
+
* @returns Promise with paginated orders result
|
|
1316
|
+
*/
|
|
1317
|
+
getOrdersPage(page?: number, perPage?: number, filter?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Get a specific page of positions with pagination metadata
|
|
1320
|
+
* @param page - Page number (default: 1)
|
|
1321
|
+
* @param perPage - Items per page (default: 100)
|
|
1322
|
+
* @param filter - Optional filter parameters
|
|
1323
|
+
* @returns Promise with paginated positions result
|
|
1324
|
+
*/
|
|
1325
|
+
getPositionsPage(page?: number, perPage?: number, filter?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Get a specific page of accounts with pagination metadata
|
|
1328
|
+
* @param page - Page number (default: 1)
|
|
1329
|
+
* @param perPage - Items per page (default: 100)
|
|
1330
|
+
* @param filter - Optional filter parameters
|
|
1331
|
+
* @returns Promise with paginated accounts result
|
|
1332
|
+
*/
|
|
1333
|
+
getAccountsPage(page?: number, perPage?: number, filter?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
1334
|
+
/**
|
|
1335
|
+
* Get the next page of orders
|
|
1336
|
+
* @param previousResult - The previous paginated result
|
|
1337
|
+
* @returns Promise with next page of orders or null if no more pages
|
|
1338
|
+
*/
|
|
1339
|
+
getNextOrdersPage(previousResult: PaginatedResult<BrokerDataOrder[]>): Promise<PaginatedResult<BrokerDataOrder[]> | null>;
|
|
1340
|
+
/**
|
|
1341
|
+
* Get the next page of positions
|
|
1342
|
+
* @param previousResult - The previous paginated result
|
|
1343
|
+
* @returns Promise with next page of positions or null if no more pages
|
|
1344
|
+
*/
|
|
1345
|
+
getNextPositionsPage(previousResult: PaginatedResult<BrokerDataPosition[]>): Promise<PaginatedResult<BrokerDataPosition[]> | null>;
|
|
1346
|
+
/**
|
|
1347
|
+
* Get the next page of accounts
|
|
1348
|
+
* @param previousResult - The previous paginated result
|
|
1349
|
+
* @returns Promise with next page of accounts or null if no more pages
|
|
1350
|
+
*/
|
|
1351
|
+
getNextAccountsPage(previousResult: PaginatedResult<BrokerDataAccount[]>): Promise<PaginatedResult<BrokerDataAccount[]> | null>;
|
|
1352
|
+
/**
|
|
1353
|
+
* Get all orders across all pages (convenience method)
|
|
1354
|
+
* @param filter - Optional filter parameters
|
|
1355
|
+
* @returns Promise with all orders
|
|
1356
|
+
*/
|
|
1357
|
+
getAllOrders(filter?: OrdersFilter): Promise<BrokerDataOrder[]>;
|
|
1358
|
+
/**
|
|
1359
|
+
* Get all positions across all pages (convenience method)
|
|
1360
|
+
* @param filter - Optional filter parameters
|
|
1361
|
+
* @returns Promise with all positions
|
|
1362
|
+
*/
|
|
1363
|
+
getAllPositions(filter?: PositionsFilter): Promise<BrokerDataPosition[]>;
|
|
1364
|
+
/**
|
|
1365
|
+
* Get all accounts across all pages (convenience method)
|
|
1366
|
+
* @param filter - Optional filter parameters
|
|
1367
|
+
* @returns Promise with all accounts
|
|
1368
|
+
*/
|
|
1369
|
+
getAllAccounts(filter?: AccountsFilter): Promise<BrokerDataAccount[]>;
|
|
1370
|
+
/**
|
|
1371
|
+
* Register automatic session cleanup on page unload/visibility change
|
|
1372
|
+
*/
|
|
1373
|
+
private registerSessionCleanup;
|
|
1374
|
+
/**
|
|
1375
|
+
* Handle session cleanup when page is unloading
|
|
1376
|
+
*/
|
|
1377
|
+
private handleSessionCleanup;
|
|
1378
|
+
/**
|
|
1379
|
+
* Handle visibility change (mobile browsers)
|
|
1380
|
+
*/
|
|
1381
|
+
private handleVisibilityChange;
|
|
1382
|
+
/**
|
|
1383
|
+
* Complete the session by calling the API
|
|
1384
|
+
* @param sessionId - The session ID to complete
|
|
1385
|
+
*/
|
|
1386
|
+
private completeSession;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
declare class ApiClient {
|
|
1390
|
+
private baseUrl;
|
|
1391
|
+
private apiKey;
|
|
1392
|
+
private accessToken?;
|
|
1393
|
+
private refreshToken?;
|
|
1394
|
+
private isSandbox;
|
|
1395
|
+
constructor(config: ApiConfig);
|
|
1396
|
+
private getBaseUrl;
|
|
1397
|
+
private request;
|
|
1398
|
+
getPortalContent(): Promise<ApiResponse<{
|
|
1399
|
+
content: string;
|
|
1400
|
+
}>>;
|
|
1401
|
+
getInitToken(): Promise<ApiResponse<{
|
|
1402
|
+
token: string;
|
|
1403
|
+
}>>;
|
|
1404
|
+
login(otp: string): Promise<ApiResponse<{
|
|
1405
|
+
success: boolean;
|
|
1406
|
+
}>>;
|
|
1407
|
+
verifyOTP(otp: string): Promise<ApiResponse<{
|
|
1408
|
+
userId: string;
|
|
1409
|
+
connectionIds: string[];
|
|
1410
|
+
}>>;
|
|
1411
|
+
getUserProfile(): Promise<ApiResponse<{
|
|
1412
|
+
profile: any;
|
|
1413
|
+
brokers: any[];
|
|
1414
|
+
}>>;
|
|
1415
|
+
getConnectionComplete(): Promise<ApiResponse<{
|
|
1416
|
+
userId: string;
|
|
1417
|
+
connectionIds: string[];
|
|
1418
|
+
}>>;
|
|
1419
|
+
getUserToken(userId: string): Promise<ApiResponse<{
|
|
1420
|
+
accessToken: string;
|
|
1421
|
+
refreshToken: string;
|
|
1422
|
+
}>>;
|
|
1423
|
+
refreshAccessToken(): Promise<ApiResponse<{
|
|
1424
|
+
accessToken: string;
|
|
1425
|
+
refreshToken: string;
|
|
1426
|
+
}>>;
|
|
1427
|
+
revokeTokens(): Promise<ApiResponse<{
|
|
1428
|
+
success: boolean;
|
|
1429
|
+
}>>;
|
|
1430
|
+
connectBroker(brokerId: string): Promise<ApiResponse<{
|
|
1431
|
+
success: boolean;
|
|
1432
|
+
}>>;
|
|
1433
|
+
disconnectBroker(brokerId: string): Promise<ApiResponse<{
|
|
1434
|
+
success: boolean;
|
|
1435
|
+
}>>;
|
|
1436
|
+
getBrokerAccounts(): Promise<ApiResponse<{
|
|
1437
|
+
accounts: any[];
|
|
1438
|
+
}>>;
|
|
1439
|
+
getConnections(): Promise<ApiResponse<{
|
|
1440
|
+
connections: any[];
|
|
1441
|
+
}>>;
|
|
1442
|
+
getConnectionDetails(connectionId: string): Promise<ApiResponse<{
|
|
1443
|
+
connection: any;
|
|
1444
|
+
}>>;
|
|
1445
|
+
getAccounts(filter?: AccountsFilter): Promise<ApiResponse<{
|
|
1446
|
+
accounts: any[];
|
|
1447
|
+
}>>;
|
|
1448
|
+
getHoldings(): Promise<ApiResponse<{
|
|
1449
|
+
holdings: any[];
|
|
1450
|
+
}>>;
|
|
1451
|
+
getBalances(): Promise<ApiResponse<{
|
|
1452
|
+
balances: any;
|
|
1453
|
+
}>>;
|
|
1454
|
+
getTransactions(): Promise<ApiResponse<{
|
|
1455
|
+
transactions: any[];
|
|
1456
|
+
}>>;
|
|
1457
|
+
getPerformance(): Promise<ApiResponse<{
|
|
1458
|
+
performance: any;
|
|
1459
|
+
}>>;
|
|
1460
|
+
getOrders(filter?: OrdersFilter): Promise<ApiResponse<{
|
|
1461
|
+
orders: any[];
|
|
1462
|
+
}>>;
|
|
1463
|
+
getTrades(): Promise<ApiResponse<{
|
|
1464
|
+
trades: any[];
|
|
1465
|
+
}>>;
|
|
1466
|
+
placeOrder(order: any): Promise<ApiResponse<{
|
|
1467
|
+
orderId: string;
|
|
1468
|
+
}>>;
|
|
1469
|
+
cancelOrder(orderId: string): Promise<ApiResponse<{
|
|
1470
|
+
success: boolean;
|
|
1471
|
+
}>>;
|
|
1472
|
+
getOrderStatus(orderId: string): Promise<ApiResponse<{
|
|
1473
|
+
status: string;
|
|
1474
|
+
}>>;
|
|
1475
|
+
getOptionsChain(symbol: string): Promise<ApiResponse<{
|
|
1476
|
+
chain: any[];
|
|
1477
|
+
}>>;
|
|
1478
|
+
getOptionQuote(symbol: string, strike: number, expiry: string): Promise<ApiResponse<{
|
|
1479
|
+
quote: any;
|
|
1480
|
+
}>>;
|
|
1481
|
+
placeOptionsOrder(order: any): Promise<ApiResponse<{
|
|
1482
|
+
orderId: string;
|
|
1483
|
+
}>>;
|
|
1484
|
+
getDailyHistory(): Promise<ApiResponse<{
|
|
1485
|
+
history: any[];
|
|
1486
|
+
}>>;
|
|
1487
|
+
getWeeklySnapshots(): Promise<ApiResponse<{
|
|
1488
|
+
snapshots: any[];
|
|
1489
|
+
}>>;
|
|
1490
|
+
getPortfolioDeltas(): Promise<ApiResponse<{
|
|
1491
|
+
deltas: any[];
|
|
1492
|
+
}>>;
|
|
1493
|
+
getUserLogs(userId: string): Promise<ApiResponse<{
|
|
1494
|
+
logs: any[];
|
|
1495
|
+
}>>;
|
|
1496
|
+
getBrokerOrders(filter?: OrdersFilter): Promise<ApiResponse<FilteredOrdersResponse>>;
|
|
1497
|
+
getBrokerPositions(filter?: PositionsFilter): Promise<ApiResponse<FilteredPositionsResponse>>;
|
|
1498
|
+
getBrokerDataAccounts(filter?: AccountsFilter): Promise<ApiResponse<FilteredAccountsResponse>>;
|
|
1499
|
+
testWebhook(): Promise<ApiResponse<{
|
|
1500
|
+
success: boolean;
|
|
1501
|
+
}>>;
|
|
1502
|
+
private buildQueryParams;
|
|
1503
|
+
getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<any[]>>;
|
|
1504
|
+
getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<any[]>>;
|
|
1505
|
+
getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<any[]>>;
|
|
1506
|
+
getNextPage<T>(previousResult: PaginatedResult<T>, fetchFunction: (offset: number, limit: number) => Promise<PaginatedResult<T>>): Promise<PaginatedResult<T> | null>;
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
interface ITradingService {
|
|
1510
|
+
getAccounts(filter?: AccountsFilter): Promise<BrokerDataAccount[]>;
|
|
1511
|
+
getOrders(filter?: OrdersFilter): Promise<BrokerDataOrder[]>;
|
|
1512
|
+
getPositions(filter?: PositionsFilter): Promise<BrokerDataPosition[]>;
|
|
1513
|
+
placeOrder(order: Order): Promise<string>;
|
|
1514
|
+
cancelOrder(orderId: string): Promise<boolean>;
|
|
1515
|
+
placeOptionsOrder(order: OptionsOrder): Promise<string>;
|
|
1516
|
+
getAccountsPage(page?: number, perPage?: number, filter?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
1517
|
+
getOrdersPage(page?: number, perPage?: number, filter?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
1518
|
+
getPositionsPage(page?: number, perPage?: number, filter?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
1519
|
+
getNextAccountsPage(previousResult: PaginatedResult<BrokerDataAccount[]>): Promise<PaginatedResult<BrokerDataAccount[]> | null>;
|
|
1520
|
+
getNextOrdersPage(previousResult: PaginatedResult<BrokerDataOrder[]>): Promise<PaginatedResult<BrokerDataOrder[]> | null>;
|
|
1521
|
+
getNextPositionsPage(previousResult: PaginatedResult<BrokerDataPosition[]>): Promise<PaginatedResult<BrokerDataPosition[]> | null>;
|
|
1522
|
+
getAllAccounts(filter?: AccountsFilter): Promise<BrokerDataAccount[]>;
|
|
1523
|
+
getAllOrders(filter?: OrdersFilter): Promise<BrokerDataOrder[]>;
|
|
1524
|
+
getAllPositions(filter?: PositionsFilter): Promise<BrokerDataPosition[]>;
|
|
1525
|
+
getOpenPositions(): Promise<BrokerDataPosition[]>;
|
|
1526
|
+
getFilledOrders(): Promise<BrokerDataOrder[]>;
|
|
1527
|
+
getPendingOrders(): Promise<BrokerDataOrder[]>;
|
|
1528
|
+
getActiveAccounts(): Promise<BrokerDataAccount[]>;
|
|
1529
|
+
getOrdersBySymbol(symbol: string): Promise<BrokerDataOrder[]>;
|
|
1530
|
+
getPositionsBySymbol(symbol: string): Promise<BrokerDataPosition[]>;
|
|
1531
|
+
getOrdersByBroker(brokerId: string): Promise<BrokerDataOrder[]>;
|
|
1532
|
+
getPositionsByBroker(brokerId: string): Promise<BrokerDataPosition[]>;
|
|
1533
|
+
}
|
|
1534
|
+
declare class CoreTradingService implements ITradingService {
|
|
1535
|
+
private apiClient;
|
|
1536
|
+
constructor(apiClient: ApiClient);
|
|
1537
|
+
getAccounts(filter?: AccountsFilter): Promise<BrokerDataAccount[]>;
|
|
1538
|
+
getOrders(filter?: OrdersFilter): Promise<BrokerDataOrder[]>;
|
|
1539
|
+
getPositions(filter?: PositionsFilter): Promise<BrokerDataPosition[]>;
|
|
1540
|
+
placeOrder(order: Order): Promise<string>;
|
|
1541
|
+
cancelOrder(orderId: string): Promise<boolean>;
|
|
1542
|
+
placeOptionsOrder(order: OptionsOrder): Promise<string>;
|
|
1543
|
+
getAccountsPage(page?: number, perPage?: number, filter?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
1544
|
+
getOrdersPage(page?: number, perPage?: number, filter?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
1545
|
+
getPositionsPage(page?: number, perPage?: number, filter?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
1546
|
+
getNextAccountsPage(previousResult: PaginatedResult<BrokerDataAccount[]>): Promise<PaginatedResult<BrokerDataAccount[]> | null>;
|
|
1547
|
+
getNextOrdersPage(previousResult: PaginatedResult<BrokerDataOrder[]>): Promise<PaginatedResult<BrokerDataOrder[]> | null>;
|
|
1548
|
+
getNextPositionsPage(previousResult: PaginatedResult<BrokerDataPosition[]>): Promise<PaginatedResult<BrokerDataPosition[]> | null>;
|
|
1549
|
+
getAllAccounts(filter?: AccountsFilter): Promise<BrokerDataAccount[]>;
|
|
1550
|
+
getAllOrders(filter?: OrdersFilter): Promise<BrokerDataOrder[]>;
|
|
1551
|
+
getAllPositions(filter?: PositionsFilter): Promise<BrokerDataPosition[]>;
|
|
1552
|
+
getOpenPositions(): Promise<BrokerDataPosition[]>;
|
|
1553
|
+
getFilledOrders(): Promise<BrokerDataOrder[]>;
|
|
1554
|
+
getPendingOrders(): Promise<BrokerDataOrder[]>;
|
|
1555
|
+
getActiveAccounts(): Promise<BrokerDataAccount[]>;
|
|
1556
|
+
getOrdersBySymbol(symbol: string): Promise<BrokerDataOrder[]>;
|
|
1557
|
+
getPositionsBySymbol(symbol: string): Promise<BrokerDataPosition[]>;
|
|
1558
|
+
getOrdersByBroker(brokerId: string): Promise<BrokerDataOrder[]>;
|
|
1559
|
+
getPositionsByBroker(brokerId: string): Promise<BrokerDataPosition[]>;
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
interface IAnalyticsService {
|
|
1563
|
+
getPerformance(): Promise<PerformanceMetrics>;
|
|
1564
|
+
getDailyHistory(): Promise<any[]>;
|
|
1565
|
+
getWeeklySnapshots(): Promise<PortfolioSnapshot[]>;
|
|
1566
|
+
getPortfolioDeltas(): Promise<any[]>;
|
|
1567
|
+
getUserLogs(userId: string): Promise<any[]>;
|
|
1568
|
+
}
|
|
1569
|
+
declare class CoreAnalyticsService implements IAnalyticsService {
|
|
1570
|
+
private apiClient;
|
|
1571
|
+
constructor(apiClient: ApiClient);
|
|
1572
|
+
getPerformance(): Promise<PerformanceMetrics>;
|
|
1573
|
+
getDailyHistory(): Promise<any[]>;
|
|
1574
|
+
getWeeklySnapshots(): Promise<PortfolioSnapshot[]>;
|
|
1575
|
+
getPortfolioDeltas(): Promise<any[]>;
|
|
1576
|
+
getUserLogs(userId: string): Promise<any[]>;
|
|
1577
|
+
}
|
|
1578
|
+
|
|
1579
|
+
interface IPortalService {
|
|
1580
|
+
createPortal(config: PortalConfig): Promise<void>;
|
|
1581
|
+
closePortal(): Promise<void>;
|
|
1582
|
+
updateTheme(theme: Theme): Promise<void>;
|
|
1583
|
+
getBrokerAccounts(): Promise<any[]>;
|
|
1584
|
+
linkBrokerAccount(brokerId: string): Promise<void>;
|
|
1585
|
+
unlinkBrokerAccount(brokerId: string): Promise<void>;
|
|
1586
|
+
}
|
|
1587
|
+
declare class CorePortalService implements IPortalService {
|
|
1588
|
+
private apiClient;
|
|
1589
|
+
private iframe;
|
|
1590
|
+
constructor(apiClient: ApiClient);
|
|
1591
|
+
createPortal(config: PortalConfig): Promise<void>;
|
|
1592
|
+
closePortal(): Promise<void>;
|
|
1593
|
+
updateTheme(theme: Theme): Promise<void>;
|
|
1594
|
+
getBrokerAccounts(): Promise<any[]>;
|
|
1595
|
+
linkBrokerAccount(brokerId: string): Promise<void>;
|
|
1596
|
+
unlinkBrokerAccount(brokerId: string): Promise<void>;
|
|
1597
|
+
private positionIframe;
|
|
1598
|
+
private styleIframe;
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
/**
|
|
1602
|
+
* Generate a portal URL with theme parameters
|
|
1603
|
+
* @param baseUrl The base portal URL
|
|
1604
|
+
* @param theme The theme configuration
|
|
1605
|
+
* @returns The portal URL with theme parameters
|
|
1606
|
+
*/
|
|
1607
|
+
declare function generatePortalThemeURL(baseUrl: string, theme?: PortalTheme): string;
|
|
1608
|
+
/**
|
|
1609
|
+
* Generate a portal URL with theme parameters, appending to existing query params
|
|
1610
|
+
* @param baseUrl The base portal URL (may already have query parameters)
|
|
1611
|
+
* @param theme The theme configuration
|
|
1612
|
+
* @returns The portal URL with theme parameters appended
|
|
1613
|
+
*/
|
|
1614
|
+
declare function appendThemeToURL(baseUrl: string, theme?: PortalTheme): string;
|
|
1615
|
+
/**
|
|
1616
|
+
* Get a theme configuration by preset name
|
|
1617
|
+
* @param preset The preset theme name
|
|
1618
|
+
* @returns The theme configuration or undefined if not found
|
|
1619
|
+
*/
|
|
1620
|
+
declare function getThemePreset(preset: string): PortalThemeConfig | undefined;
|
|
1621
|
+
/**
|
|
1622
|
+
* Validate a custom theme configuration
|
|
1623
|
+
* @param theme The theme configuration to validate
|
|
1624
|
+
* @returns True if valid, false otherwise
|
|
1625
|
+
*/
|
|
1626
|
+
declare function validateCustomTheme(theme: PortalThemeConfig): boolean;
|
|
1627
|
+
/**
|
|
1628
|
+
* Create a custom theme from a preset with modifications
|
|
1629
|
+
* @param preset The base preset theme
|
|
1630
|
+
* @param modifications Partial theme modifications
|
|
1631
|
+
* @returns The modified theme configuration
|
|
1632
|
+
*/
|
|
1633
|
+
declare function createCustomThemeFromPreset(preset: string, modifications: Partial<PortalThemeConfig>): PortalThemeConfig | null;
|
|
1634
|
+
|
|
1635
|
+
declare const portalThemePresets: Record<string, PortalThemeConfig>;
|
|
1636
|
+
|
|
1637
|
+
/**
|
|
1638
|
+
* Configuration for mock behavior
|
|
1639
|
+
*/
|
|
1640
|
+
interface MockConfig {
|
|
1641
|
+
delay?: number;
|
|
1642
|
+
scenario?: MockScenario;
|
|
1643
|
+
customData?: Record<string, any>;
|
|
1644
|
+
mockApiOnly?: boolean;
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* Different mock scenarios for testing
|
|
1648
|
+
*/
|
|
1649
|
+
type MockScenario = 'success' | 'error' | 'network_error' | 'rate_limit' | 'auth_failure';
|
|
1650
|
+
/**
|
|
1651
|
+
* Mock data provider for Finatic API endpoints
|
|
1652
|
+
*/
|
|
1653
|
+
declare class MockDataProvider {
|
|
1654
|
+
private config;
|
|
1655
|
+
private sessionData;
|
|
1656
|
+
private userTokens;
|
|
1657
|
+
constructor(config?: MockConfig);
|
|
1658
|
+
/**
|
|
1659
|
+
* Get a random delay between min and max milliseconds
|
|
1660
|
+
*/
|
|
1661
|
+
private getRandomDelay;
|
|
1662
|
+
/**
|
|
1663
|
+
* Simulate network delay
|
|
1664
|
+
*/
|
|
1665
|
+
simulateDelay(): Promise<void>;
|
|
1666
|
+
/**
|
|
1667
|
+
* Generate a realistic session ID
|
|
1668
|
+
*/
|
|
1669
|
+
private generateSessionId;
|
|
1670
|
+
/**
|
|
1671
|
+
* Generate a realistic user ID
|
|
1672
|
+
*/
|
|
1673
|
+
private generateUserId;
|
|
1674
|
+
/**
|
|
1675
|
+
* Generate a realistic company ID
|
|
1676
|
+
*/
|
|
1677
|
+
private generateCompanyId;
|
|
1678
|
+
/**
|
|
1679
|
+
* Generate mock tokens
|
|
1680
|
+
*/
|
|
1681
|
+
private generateTokens;
|
|
1682
|
+
mockStartSession(token: string, userId?: string): Promise<SessionResponse>;
|
|
1683
|
+
mockRequestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
|
|
1684
|
+
mockVerifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
|
|
1685
|
+
mockAuthenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
|
|
1686
|
+
mockGetPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
|
|
1687
|
+
mockValidatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
|
|
1688
|
+
mockCompletePortalSession(sessionId: string): Promise<PortalUrlResponse>;
|
|
1689
|
+
mockRefreshToken(refreshToken: string): Promise<RefreshTokenResponse>;
|
|
1690
|
+
mockGetBrokerList(): Promise<{
|
|
1691
|
+
_id: string;
|
|
1692
|
+
response_data: BrokerInfo[];
|
|
1693
|
+
message: string;
|
|
1694
|
+
status_code: number;
|
|
1695
|
+
warnings: null;
|
|
1696
|
+
errors: null;
|
|
1697
|
+
}>;
|
|
1698
|
+
mockGetBrokerAccounts(): Promise<{
|
|
1699
|
+
_id: string;
|
|
1700
|
+
response_data: BrokerAccount[];
|
|
1701
|
+
message: string;
|
|
1702
|
+
status_code: number;
|
|
1703
|
+
warnings: null;
|
|
1704
|
+
errors: null;
|
|
1705
|
+
}>;
|
|
1706
|
+
mockGetBrokerConnections(): Promise<{
|
|
1707
|
+
_id: string;
|
|
1708
|
+
response_data: BrokerConnection[];
|
|
1709
|
+
message: string;
|
|
1710
|
+
status_code: number;
|
|
1711
|
+
warnings: null;
|
|
1712
|
+
errors: null;
|
|
1713
|
+
}>;
|
|
1714
|
+
mockGetHoldings(): Promise<{
|
|
1715
|
+
data: Holding[];
|
|
1716
|
+
}>;
|
|
1717
|
+
mockGetPortfolio(): Promise<{
|
|
1718
|
+
data: Portfolio;
|
|
1719
|
+
}>;
|
|
1720
|
+
mockGetOrders(filter?: OrdersFilter): Promise<{
|
|
1721
|
+
data: Order[];
|
|
1722
|
+
}>;
|
|
1723
|
+
mockGetBrokerOrders(filter?: OrdersFilter): Promise<{
|
|
1724
|
+
data: BrokerDataOrder[];
|
|
1725
|
+
}>;
|
|
1726
|
+
mockGetBrokerPositions(filter?: PositionsFilter): Promise<{
|
|
1727
|
+
data: BrokerDataPosition[];
|
|
1728
|
+
}>;
|
|
1729
|
+
mockGetBrokerDataAccounts(filter?: AccountsFilter): Promise<{
|
|
1730
|
+
data: BrokerDataAccount[];
|
|
1731
|
+
}>;
|
|
1732
|
+
mockPlaceOrder(order: Order): Promise<OrderResponse>;
|
|
1733
|
+
/**
|
|
1734
|
+
* Get stored session data
|
|
1735
|
+
*/
|
|
1736
|
+
getSessionData(sessionId: string): any;
|
|
1737
|
+
/**
|
|
1738
|
+
* Get stored user token
|
|
1739
|
+
*/
|
|
1740
|
+
getUserToken(userId: string): UserToken | undefined;
|
|
1741
|
+
/**
|
|
1742
|
+
* Clear all stored data
|
|
1743
|
+
*/
|
|
1744
|
+
clearData(): void;
|
|
1745
|
+
/**
|
|
1746
|
+
* Update configuration
|
|
1747
|
+
*/
|
|
1748
|
+
updateConfig(config: Partial<MockConfig>): void;
|
|
1749
|
+
setScenario(scenario: MockScenario): void;
|
|
1750
|
+
getScenario(): MockScenario;
|
|
1751
|
+
private applyOrderFilters;
|
|
1752
|
+
private applyBrokerOrderFilters;
|
|
1753
|
+
private applyBrokerPositionFilters;
|
|
1754
|
+
private applyBrokerAccountFilters;
|
|
1755
|
+
/**
|
|
1756
|
+
* Generate mock orders with diverse data
|
|
1757
|
+
*/
|
|
1758
|
+
private generateMockOrders;
|
|
1759
|
+
/**
|
|
1760
|
+
* Generate mock positions with diverse data
|
|
1761
|
+
*/
|
|
1762
|
+
private generateMockPositions;
|
|
1763
|
+
/**
|
|
1764
|
+
* Generate mock accounts with diverse data
|
|
1765
|
+
*/
|
|
1766
|
+
private generateMockAccounts;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
/**
|
|
1770
|
+
* Mock API Client that implements the same interface as the real ApiClient
|
|
1771
|
+
* but returns mock data instead of making HTTP requests
|
|
1772
|
+
*/
|
|
1773
|
+
declare class MockApiClient {
|
|
1774
|
+
private readonly baseUrl;
|
|
1775
|
+
protected readonly deviceInfo?: DeviceInfo$1;
|
|
1776
|
+
protected currentSessionState: SessionState | null;
|
|
1777
|
+
protected currentSessionId: string | null;
|
|
1778
|
+
private tradingContext;
|
|
1779
|
+
private tokenInfo;
|
|
1780
|
+
private refreshPromise;
|
|
1781
|
+
private readonly REFRESH_BUFFER_MINUTES;
|
|
1782
|
+
private companyId;
|
|
1783
|
+
private csrfToken;
|
|
1784
|
+
private mockDataProvider;
|
|
1785
|
+
private readonly mockApiOnly;
|
|
1786
|
+
constructor(baseUrl: string, deviceInfo?: DeviceInfo$1, mockConfig?: MockConfig);
|
|
1787
|
+
/**
|
|
1788
|
+
* Store tokens after successful authentication
|
|
1789
|
+
*/
|
|
1790
|
+
setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
|
|
1791
|
+
/**
|
|
1792
|
+
* Get the current access token, refreshing if necessary
|
|
1793
|
+
*/
|
|
1794
|
+
getValidAccessToken(): Promise<string>;
|
|
1795
|
+
/**
|
|
1796
|
+
* Check if the current token is expired or about to expire
|
|
1797
|
+
*/
|
|
1798
|
+
private isTokenExpired;
|
|
1799
|
+
/**
|
|
1800
|
+
* Refresh the access token using the refresh token
|
|
1801
|
+
*/
|
|
1802
|
+
private refreshTokens;
|
|
1803
|
+
/**
|
|
1804
|
+
* Perform the actual token refresh request
|
|
1805
|
+
*/
|
|
1806
|
+
private performTokenRefresh;
|
|
1807
|
+
/**
|
|
1808
|
+
* Clear stored tokens (useful for logout)
|
|
1809
|
+
*/
|
|
1810
|
+
clearTokens(): void;
|
|
1811
|
+
/**
|
|
1812
|
+
* Get current token info (for debugging/testing)
|
|
1813
|
+
*/
|
|
1814
|
+
getTokenInfo(): TokenInfo | null;
|
|
1815
|
+
/**
|
|
1816
|
+
* Set session context (session ID, company ID, CSRF token)
|
|
1817
|
+
*/
|
|
1818
|
+
setSessionContext(sessionId: string, companyId: string, csrfToken?: string): void;
|
|
1819
|
+
/**
|
|
1820
|
+
* Get the current session ID
|
|
1821
|
+
*/
|
|
1822
|
+
getCurrentSessionId(): string | null;
|
|
1823
|
+
/**
|
|
1824
|
+
* Get the current company ID
|
|
1825
|
+
*/
|
|
1826
|
+
getCurrentCompanyId(): string | null;
|
|
1827
|
+
/**
|
|
1828
|
+
* Get the current CSRF token
|
|
1829
|
+
*/
|
|
1830
|
+
getCurrentCsrfToken(): string | null;
|
|
1831
|
+
startSession(token: string, userId?: string): Promise<SessionResponse>;
|
|
1832
|
+
requestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
|
|
1833
|
+
verifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
|
|
1834
|
+
authenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
|
|
1835
|
+
getPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
|
|
1836
|
+
validatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
|
|
1837
|
+
completePortalSession(sessionId: string): Promise<PortalUrlResponse>;
|
|
1838
|
+
getHoldings(accessToken: string): Promise<{
|
|
1839
|
+
data: Holding[];
|
|
1840
|
+
}>;
|
|
1841
|
+
getOrders(accessToken: string, filter?: OrdersFilter): Promise<{
|
|
1842
|
+
data: Order[];
|
|
1843
|
+
}>;
|
|
1844
|
+
getPortfolio(accessToken: string): Promise<{
|
|
1845
|
+
data: Portfolio;
|
|
1846
|
+
}>;
|
|
1847
|
+
placeOrder(accessToken: string, order: Order): Promise<void>;
|
|
1848
|
+
getHoldingsAuto(): Promise<{
|
|
1849
|
+
data: Holding[];
|
|
1850
|
+
}>;
|
|
1851
|
+
getOrdersAuto(): Promise<{
|
|
1852
|
+
data: Order[];
|
|
1853
|
+
}>;
|
|
1854
|
+
getPortfolioAuto(): Promise<{
|
|
1855
|
+
data: Portfolio;
|
|
1856
|
+
}>;
|
|
1857
|
+
placeOrderAuto(order: Order): Promise<void>;
|
|
1858
|
+
placeBrokerOrder(accessToken: string, params: Partial<BrokerOrderParams> & {
|
|
1859
|
+
symbol: string;
|
|
1860
|
+
orderQty: number;
|
|
1861
|
+
action: 'Buy' | 'Sell';
|
|
1862
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
|
|
1863
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
1864
|
+
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1865
|
+
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
1866
|
+
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
1867
|
+
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
1868
|
+
setAccount(accountNumber: string, accountId?: string): void;
|
|
1869
|
+
getTradingContext(): TradingContext;
|
|
1870
|
+
clearTradingContext(): void;
|
|
1871
|
+
placeStockMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1872
|
+
placeStockLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1873
|
+
placeStockStopOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1874
|
+
placeCryptoMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1875
|
+
placeCryptoLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1876
|
+
placeOptionsMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1877
|
+
placeOptionsLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, options: OptionsOrderOptions, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1878
|
+
placeFuturesMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1879
|
+
placeFuturesLimitOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1880
|
+
revokeToken(accessToken: string): Promise<void>;
|
|
1881
|
+
getUserToken(userId: string): Promise<UserToken>;
|
|
1882
|
+
getCurrentSessionState(): SessionState | null;
|
|
1883
|
+
getBrokerList(accessToken: string): Promise<{
|
|
1884
|
+
_id: string;
|
|
1885
|
+
response_data: BrokerInfo[];
|
|
1886
|
+
message: string;
|
|
1887
|
+
status_code: number;
|
|
1888
|
+
warnings: null;
|
|
1889
|
+
errors: null;
|
|
1890
|
+
}>;
|
|
1891
|
+
getBrokerAccounts(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
1892
|
+
_id: string;
|
|
1893
|
+
response_data: BrokerAccount[];
|
|
1894
|
+
message: string;
|
|
1895
|
+
status_code: number;
|
|
1896
|
+
warnings: null;
|
|
1897
|
+
errors: null;
|
|
1898
|
+
}>;
|
|
1899
|
+
getBrokerOrders(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
1900
|
+
_id: string;
|
|
1901
|
+
response_data: BrokerOrder[];
|
|
1902
|
+
message: string;
|
|
1903
|
+
status_code: number;
|
|
1904
|
+
warnings: null;
|
|
1905
|
+
errors: null;
|
|
1906
|
+
}>;
|
|
1907
|
+
getBrokerPositions(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
1908
|
+
_id: string;
|
|
1909
|
+
response_data: BrokerPosition[];
|
|
1910
|
+
message: string;
|
|
1911
|
+
status_code: number;
|
|
1912
|
+
warnings: null;
|
|
1913
|
+
errors: null;
|
|
1914
|
+
}>;
|
|
1915
|
+
getBrokerOrdersWithFilter(filter?: OrdersFilter): Promise<{
|
|
1916
|
+
data: BrokerDataOrder[];
|
|
1917
|
+
}>;
|
|
1918
|
+
getBrokerPositionsWithFilter(filter?: PositionsFilter): Promise<{
|
|
1919
|
+
data: BrokerDataPosition[];
|
|
1920
|
+
}>;
|
|
1921
|
+
getBrokerDataAccountsWithFilter(filter?: AccountsFilter): Promise<{
|
|
1922
|
+
data: BrokerDataAccount[];
|
|
1923
|
+
}>;
|
|
1924
|
+
getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<any[]>>;
|
|
1925
|
+
getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<any[]>>;
|
|
1926
|
+
getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<any[]>>;
|
|
1927
|
+
getBrokerConnections(accessToken: string): Promise<{
|
|
1928
|
+
_id: string;
|
|
1929
|
+
response_data: BrokerConnection[];
|
|
1930
|
+
message: string;
|
|
1931
|
+
status_code: number;
|
|
1932
|
+
warnings: null;
|
|
1933
|
+
errors: null;
|
|
1934
|
+
}>;
|
|
1935
|
+
getBrokerListAuto(): Promise<{
|
|
1936
|
+
_id: string;
|
|
1937
|
+
response_data: BrokerInfo[];
|
|
1938
|
+
message: string;
|
|
1939
|
+
status_code: number;
|
|
1940
|
+
warnings: null;
|
|
1941
|
+
errors: null;
|
|
1942
|
+
}>;
|
|
1943
|
+
getBrokerAccountsAuto(options?: BrokerDataOptions): Promise<{
|
|
1944
|
+
_id: string;
|
|
1945
|
+
response_data: BrokerAccount[];
|
|
1946
|
+
message: string;
|
|
1947
|
+
status_code: number;
|
|
1948
|
+
warnings: null;
|
|
1949
|
+
errors: null;
|
|
1950
|
+
}>;
|
|
1951
|
+
getBrokerOrdersAuto(options?: BrokerDataOptions): Promise<{
|
|
1952
|
+
_id: string;
|
|
1953
|
+
response_data: BrokerOrder[];
|
|
1954
|
+
message: string;
|
|
1955
|
+
status_code: number;
|
|
1956
|
+
warnings: null;
|
|
1957
|
+
errors: null;
|
|
1958
|
+
}>;
|
|
1959
|
+
getBrokerPositionsAuto(options?: BrokerDataOptions): Promise<{
|
|
1960
|
+
_id: string;
|
|
1961
|
+
response_data: BrokerPosition[];
|
|
1962
|
+
message: string;
|
|
1963
|
+
status_code: number;
|
|
1964
|
+
warnings: null;
|
|
1965
|
+
errors: null;
|
|
1966
|
+
}>;
|
|
1967
|
+
getBrokerConnectionsAuto(): Promise<{
|
|
1968
|
+
_id: string;
|
|
1969
|
+
response_data: BrokerConnection[];
|
|
1970
|
+
message: string;
|
|
1971
|
+
status_code: number;
|
|
1972
|
+
warnings: null;
|
|
1973
|
+
errors: null;
|
|
1974
|
+
}>;
|
|
1975
|
+
placeBrokerOrderAuto(params: Partial<BrokerOrderParams> & {
|
|
1976
|
+
symbol: string;
|
|
1977
|
+
orderQty: number;
|
|
1978
|
+
action: 'Buy' | 'Sell';
|
|
1979
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
|
|
1980
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
1981
|
+
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1982
|
+
placeStockMarketOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1983
|
+
placeStockLimitOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1984
|
+
placeStockStopOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
1985
|
+
getMockDataProvider(): MockDataProvider;
|
|
1986
|
+
clearMockData(): void;
|
|
1987
|
+
/**
|
|
1988
|
+
* Check if this is a mock client
|
|
1989
|
+
* @returns true if this is a mock client
|
|
1990
|
+
*/
|
|
1991
|
+
isMockClient(): boolean;
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Factory class for creating API clients (real or mock)
|
|
1996
|
+
*/
|
|
1997
|
+
declare class MockFactory {
|
|
1998
|
+
/**
|
|
1999
|
+
* Create an API client based on environment configuration
|
|
2000
|
+
* @param baseUrl - The base URL for the API
|
|
2001
|
+
* @param deviceInfo - Optional device information
|
|
2002
|
+
* @param mockConfig - Optional mock configuration (only used if mocks are enabled)
|
|
2003
|
+
* @returns ApiClient or MockApiClient instance
|
|
2004
|
+
*/
|
|
2005
|
+
static createApiClient(baseUrl: string, deviceInfo?: DeviceInfo$1, mockConfig?: MockConfig): ApiClient$1 | MockApiClient;
|
|
2006
|
+
/**
|
|
2007
|
+
* Force create a mock API client regardless of environment settings
|
|
2008
|
+
* @param baseUrl - The base URL for the API
|
|
2009
|
+
* @param deviceInfo - Optional device information
|
|
2010
|
+
* @param mockConfig - Optional mock configuration
|
|
2011
|
+
* @returns MockApiClient instance
|
|
2012
|
+
*/
|
|
2013
|
+
static createMockApiClient(baseUrl: string, deviceInfo?: DeviceInfo$1, mockConfig?: MockConfig): MockApiClient;
|
|
2014
|
+
/**
|
|
2015
|
+
* Force create a real API client regardless of environment settings
|
|
2016
|
+
* @param baseUrl - The base URL for the API
|
|
2017
|
+
* @param deviceInfo - Optional device information
|
|
2018
|
+
* @returns ApiClient instance
|
|
2019
|
+
*/
|
|
2020
|
+
static createRealApiClient(baseUrl: string, deviceInfo?: DeviceInfo$1): ApiClient$1;
|
|
2021
|
+
/**
|
|
2022
|
+
* Check if mocks are currently enabled
|
|
2023
|
+
* @returns boolean indicating if mocks are enabled
|
|
2024
|
+
*/
|
|
2025
|
+
static isMockMode(): boolean;
|
|
2026
|
+
/**
|
|
2027
|
+
* Get current mock configuration
|
|
2028
|
+
* @returns Mock configuration object
|
|
2029
|
+
*/
|
|
2030
|
+
static getMockConfig(): {
|
|
2031
|
+
enabled: boolean;
|
|
2032
|
+
delay?: number;
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
export { ApiClient$1 as ApiClient, CompanyAccessError, CoreAnalyticsService, CorePortalService, CoreTradingService, EventEmitter, FinaticConnect, MockFactory, OrderError, OrderValidationError, PaginatedResult, appendThemeToURL, createCustomThemeFromPreset, generatePortalThemeURL, getThemePreset, portalThemePresets, validateCustomTheme };
|
|
2037
|
+
export type { AccountsFilter, ApiConfig, ApiError$1 as ApiError, ApiResponse, AuthenticationError, AuthorizationError, BaseError$1 as BaseError, BrokerAccount, BrokerConnection, BrokerDataAccount, BrokerDataOptions, BrokerDataOrder, BrokerDataPosition, BrokerExtras, BrokerInfo, BrokerOrder, BrokerOrderParams, BrokerPosition, CryptoOrderOptions, DeviceInfo$1 as DeviceInfo, FilteredAccountsResponse, FilteredOrdersResponse, FilteredPositionsResponse, FinaticConnectOptions, FinaticUserToken, Holding, NetworkError, OptionsOrder, OptionsOrderOptions, Order, OrderResponse, OrdersFilter, OtpRequestResponse, OtpVerifyResponse, PerformanceMetrics, PortalConfig$1 as PortalConfig, PortalMessage, PortalProps, PortalResponse, PortalTheme, PortalThemeConfig, PortalThemePreset, PortalUrlResponse, Portfolio, PortfolioSnapshot, PositionsFilter, RateLimitError, RefreshTokenRequest, RefreshTokenResponse, RequestHeaders, SDKConfig, SecurityError, SessionAuthenticateResponse, SessionError, SessionInitResponse, SessionStartResponse, SessionStatus, SessionValidationResponse, Theme, TokenError, TokenInfo, TradingContext, UserToken, ValidationError };
|