@finatic/client 0.0.140 → 0.0.142
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 +72 -0
- package/dist/index.d.ts +256 -2
- package/dist/index.js +767 -94
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +764 -95
- package/dist/index.mjs.map +1 -1
- package/dist/types/core/client/ApiClient.d.ts +71 -1
- package/dist/types/core/client/FinaticConnect.d.ts +35 -0
- package/dist/types/core/portal/PortalUI.d.ts +2 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/lib/logger/index.d.ts +2 -0
- package/dist/types/lib/logger/logger.d.ts +4 -0
- package/dist/types/lib/logger/logger.types.d.ts +28 -0
- package/dist/types/mocks/MockApiClient.d.ts +2 -0
- package/dist/types/types/api/broker.d.ts +116 -0
- package/package.json +1 -1
- package/src/core/client/ApiClient.ts +302 -19
- package/src/core/client/FinaticConnect.ts +160 -30
- package/src/core/portal/PortalUI.ts +58 -23
- package/src/index.ts +13 -0
- package/src/lib/logger/index.ts +3 -0
- package/src/lib/logger/logger.ts +332 -0
- package/src/lib/logger/logger.types.ts +34 -0
- package/src/mocks/MockApiClient.ts +43 -17
- package/src/types/api/broker.ts +131 -0
- package/src/types/common/pagination.ts +31 -5
- package/src/utils/brokerUtils.ts +21 -2
- package/src/utils/events.ts +13 -1
- package/src/utils/themeUtils.ts +23 -4
|
@@ -3,7 +3,7 @@ import { BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerBalance,
|
|
|
3
3
|
import { BrokerOrderParams, BrokerExtras } from '../../types/api/broker';
|
|
4
4
|
import { CryptoOrderOptions, OptionsOrderOptions, OrderResponse } from '../../types/api/orders';
|
|
5
5
|
import { BrokerConnection } from '../../types/api/broker';
|
|
6
|
-
import { OrdersFilter, PositionsFilter, AccountsFilter, BalancesFilter } from '../../types/api/broker';
|
|
6
|
+
import { OrdersFilter, PositionsFilter, AccountsFilter, BalancesFilter, OrderFill, OrderEvent, OrderGroup, PositionLot, PositionLotFill, OrderFillsFilter, OrderEventsFilter, OrderGroupsFilter, PositionLotsFilter, PositionLotFillsFilter } from '../../types/api/broker';
|
|
7
7
|
import { PaginatedResult } from '../../types/common/pagination';
|
|
8
8
|
import { PortalUrlResponse } from '../../types/api/core';
|
|
9
9
|
import { DeviceInfo, SessionState, SessionResponse, OtpRequestResponse, OtpVerifyResponse, SessionAuthenticateResponse, UserToken } from '../../types/api/auth';
|
|
@@ -16,6 +16,8 @@ export declare class ApiClient {
|
|
|
16
16
|
private tradingContext;
|
|
17
17
|
private companyId;
|
|
18
18
|
private csrfToken;
|
|
19
|
+
private readonly logger;
|
|
20
|
+
private buildLoggerExtra;
|
|
19
21
|
constructor(baseUrl: string, deviceInfo?: DeviceInfo);
|
|
20
22
|
/**
|
|
21
23
|
* Set session context (session ID, company ID, CSRF token)
|
|
@@ -197,4 +199,72 @@ export declare class ApiClient {
|
|
|
197
199
|
* @returns Promise with disconnect response
|
|
198
200
|
*/
|
|
199
201
|
disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Get order fills for a specific order
|
|
204
|
+
* @param orderId - The order ID
|
|
205
|
+
* @param filter - Optional filter parameters
|
|
206
|
+
* @returns Promise with order fills response
|
|
207
|
+
*/
|
|
208
|
+
getOrderFills(orderId: string, filter?: OrderFillsFilter): Promise<{
|
|
209
|
+
_id: string;
|
|
210
|
+
response_data: OrderFill[];
|
|
211
|
+
message: string;
|
|
212
|
+
status_code: number;
|
|
213
|
+
warnings: null;
|
|
214
|
+
errors: null;
|
|
215
|
+
}>;
|
|
216
|
+
/**
|
|
217
|
+
* Get order events for a specific order
|
|
218
|
+
* @param orderId - The order ID
|
|
219
|
+
* @param filter - Optional filter parameters
|
|
220
|
+
* @returns Promise with order events response
|
|
221
|
+
*/
|
|
222
|
+
getOrderEvents(orderId: string, filter?: OrderEventsFilter): Promise<{
|
|
223
|
+
_id: string;
|
|
224
|
+
response_data: OrderEvent[];
|
|
225
|
+
message: string;
|
|
226
|
+
status_code: number;
|
|
227
|
+
warnings: null;
|
|
228
|
+
errors: null;
|
|
229
|
+
}>;
|
|
230
|
+
/**
|
|
231
|
+
* Get order groups
|
|
232
|
+
* @param filter - Optional filter parameters
|
|
233
|
+
* @returns Promise with order groups response
|
|
234
|
+
*/
|
|
235
|
+
getOrderGroups(filter?: OrderGroupsFilter): Promise<{
|
|
236
|
+
_id: string;
|
|
237
|
+
response_data: OrderGroup[];
|
|
238
|
+
message: string;
|
|
239
|
+
status_code: number;
|
|
240
|
+
warnings: null;
|
|
241
|
+
errors: null;
|
|
242
|
+
}>;
|
|
243
|
+
/**
|
|
244
|
+
* Get position lots (tax lots for positions)
|
|
245
|
+
* @param filter - Optional filter parameters
|
|
246
|
+
* @returns Promise with position lots response
|
|
247
|
+
*/
|
|
248
|
+
getPositionLots(filter?: PositionLotsFilter): Promise<{
|
|
249
|
+
_id: string;
|
|
250
|
+
response_data: PositionLot[];
|
|
251
|
+
message: string;
|
|
252
|
+
status_code: number;
|
|
253
|
+
warnings: null;
|
|
254
|
+
errors: null;
|
|
255
|
+
}>;
|
|
256
|
+
/**
|
|
257
|
+
* Get position lot fills for a specific lot
|
|
258
|
+
* @param lotId - The position lot ID
|
|
259
|
+
* @param filter - Optional filter parameters
|
|
260
|
+
* @returns Promise with position lot fills response
|
|
261
|
+
*/
|
|
262
|
+
getPositionLotFills(lotId: string, filter?: PositionLotFillsFilter): Promise<{
|
|
263
|
+
_id: string;
|
|
264
|
+
response_data: PositionLotFill[];
|
|
265
|
+
message: string;
|
|
266
|
+
status_code: number;
|
|
267
|
+
warnings: null;
|
|
268
|
+
errors: null;
|
|
269
|
+
}>;
|
|
200
270
|
}
|
|
@@ -27,6 +27,8 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
27
27
|
private readonly SESSION_VALIDATION_TIMEOUT;
|
|
28
28
|
private readonly SESSION_REFRESH_BUFFER_HOURS;
|
|
29
29
|
private sessionStartTime;
|
|
30
|
+
private readonly logger;
|
|
31
|
+
private buildLoggerExtra;
|
|
30
32
|
constructor(options: FinaticConnectOptions, deviceInfo?: DeviceInfo);
|
|
31
33
|
private linkUserToSession;
|
|
32
34
|
/**
|
|
@@ -293,5 +295,38 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
293
295
|
* @throws AuthenticationError if user is not authenticated
|
|
294
296
|
*/
|
|
295
297
|
disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
298
|
+
/**
|
|
299
|
+
* Get order fills for a specific order
|
|
300
|
+
* @param orderId - The order ID
|
|
301
|
+
* @param filter - Optional filter parameters
|
|
302
|
+
* @returns Promise with order fills response
|
|
303
|
+
*/
|
|
304
|
+
getOrderFills(orderId: string, filter?: import('../../types/api/broker').OrderFillsFilter): Promise<import('../../types/api/broker').OrderFill[]>;
|
|
305
|
+
/**
|
|
306
|
+
* Get order events for a specific order
|
|
307
|
+
* @param orderId - The order ID
|
|
308
|
+
* @param filter - Optional filter parameters
|
|
309
|
+
* @returns Promise with order events response
|
|
310
|
+
*/
|
|
311
|
+
getOrderEvents(orderId: string, filter?: import('../../types/api/broker').OrderEventsFilter): Promise<import('../../types/api/broker').OrderEvent[]>;
|
|
312
|
+
/**
|
|
313
|
+
* Get order groups
|
|
314
|
+
* @param filter - Optional filter parameters
|
|
315
|
+
* @returns Promise with order groups response
|
|
316
|
+
*/
|
|
317
|
+
getOrderGroups(filter?: import('../../types/api/broker').OrderGroupsFilter): Promise<import('../../types/api/broker').OrderGroup[]>;
|
|
318
|
+
/**
|
|
319
|
+
* Get position lots (tax lots for positions)
|
|
320
|
+
* @param filter - Optional filter parameters
|
|
321
|
+
* @returns Promise with position lots response
|
|
322
|
+
*/
|
|
323
|
+
getPositionLots(filter?: import('../../types/api/broker').PositionLotsFilter): Promise<import('../../types/api/broker').PositionLot[]>;
|
|
324
|
+
/**
|
|
325
|
+
* Get position lot fills for a specific lot
|
|
326
|
+
* @param lotId - The position lot ID
|
|
327
|
+
* @param filter - Optional filter parameters
|
|
328
|
+
* @returns Promise with position lot fills response
|
|
329
|
+
*/
|
|
330
|
+
getPositionLotFills(lotId: string, filter?: import('../../types/api/broker').PositionLotFillsFilter): Promise<import('../../types/api/broker').PositionLotFill[]>;
|
|
296
331
|
}
|
|
297
332
|
export {};
|
|
@@ -6,7 +6,9 @@ export declare class PortalUI {
|
|
|
6
6
|
private portalOrigin;
|
|
7
7
|
private options?;
|
|
8
8
|
private originalBodyStyle;
|
|
9
|
+
private readonly logger;
|
|
9
10
|
constructor(portalUrl: string);
|
|
11
|
+
private buildLoggerExtra;
|
|
10
12
|
private createContainer;
|
|
11
13
|
/**
|
|
12
14
|
* Lock background scrolling by setting overflow: hidden on body
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { ApiConfig, ApiResponse, Order, OptionsOrder, BrokerAccount, PortfolioSnapshot, PerformanceMetrics, UserToken, Holding, Portfolio, PortalResponse, SessionInitResponse, SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, RequestHeaders, SessionStatus, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, TradingContext, DeviceInfo, BrokerOrder, BrokerPosition, BrokerBalance, BrokerDataOptions, BrokerInfo, TokenInfo, RefreshTokenRequest, RefreshTokenResponse, AccountsFilter, OrdersFilter, PositionsFilter, BalancesFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount, FilteredOrdersResponse, FilteredPositionsResponse, FilteredAccountsResponse, FilteredBalancesResponse, BrokerConnection, } from './types';
|
|
1
|
+
export type { ApiConfig, ApiResponse, Order, OptionsOrder, BrokerAccount, PortfolioSnapshot, PerformanceMetrics, UserToken, Holding, Portfolio, PortalResponse, SessionInitResponse, SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, RequestHeaders, SessionStatus, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, TradingContext, DeviceInfo, BrokerOrder, BrokerPosition, BrokerBalance, BrokerDataOptions, BrokerInfo, TokenInfo, RefreshTokenRequest, RefreshTokenResponse, AccountsFilter, OrdersFilter, PositionsFilter, BalancesFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount, FilteredOrdersResponse, FilteredPositionsResponse, FilteredAccountsResponse, FilteredBalancesResponse, BrokerConnection, OrderFill, OrderEvent, OrderLeg, OrderGroup, OrderGroupOrder, PositionLot, PositionLotFill, OrderFillsFilter, OrderEventsFilter, OrderGroupsFilter, PositionLotsFilter, PositionLotFillsFilter, } from './types';
|
|
2
2
|
export type { FinaticConnectOptions, FinaticUserToken, PortalMessage } from './types/connect';
|
|
3
3
|
export type { PortalProps, PortalTheme, PortalThemeConfig, PortalThemePreset, } from './types/portal';
|
|
4
4
|
export type { TradeAccessDeniedError, OrderNotFoundError, ValidationError, } from './types/api/errors';
|
|
@@ -8,4 +8,5 @@ export { PaginatedResult } from './types/common/pagination';
|
|
|
8
8
|
export * from './utils/errors';
|
|
9
9
|
export * from './utils/events';
|
|
10
10
|
export * from './utils/themeUtils';
|
|
11
|
+
export * from './lib/logger';
|
|
11
12
|
export { portalThemePresets } from './themes/portalPresets';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Logger, LoggerExtra, LoggerMetadata, LoggerOptions, LogLevel } from './logger.types';
|
|
2
|
+
export declare const setupLogger: (nameOrOptions: string | LoggerOptions, level?: LogLevel, defaultMetadata?: LoggerMetadata) => Logger;
|
|
3
|
+
export declare const buildLoggerExtra: (metadata: LoggerMetadata) => LoggerExtra;
|
|
4
|
+
export declare const logStartEnd: (logger: Logger) => <Args extends unknown[], ReturnType>(fn: (...args: Args) => ReturnType | Promise<ReturnType>) => (...args: Args) => Promise<ReturnType>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
|
|
2
|
+
export interface LoggerMetadata {
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
export interface LoggerExtra {
|
|
6
|
+
metadata?: LoggerMetadata;
|
|
7
|
+
module?: string;
|
|
8
|
+
function?: string;
|
|
9
|
+
event?: string;
|
|
10
|
+
duration_ms?: number;
|
|
11
|
+
error?: unknown;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface LoggerOptions {
|
|
15
|
+
name: string;
|
|
16
|
+
level?: LogLevel;
|
|
17
|
+
defaultMetadata?: LoggerMetadata;
|
|
18
|
+
}
|
|
19
|
+
export interface Logger {
|
|
20
|
+
getLevel: () => LogLevel;
|
|
21
|
+
setLevel: (level: LogLevel) => void;
|
|
22
|
+
debug: (message: string, extra?: LoggerExtra) => void;
|
|
23
|
+
info: (message: string, extra?: LoggerExtra) => void;
|
|
24
|
+
warn: (message: string, extra?: LoggerExtra) => void;
|
|
25
|
+
error: (message: string, extra?: LoggerExtra) => void;
|
|
26
|
+
exception: (message: string, error: unknown, extra?: LoggerExtra) => void;
|
|
27
|
+
}
|
|
28
|
+
export type LogVerbosity = 0 | 1 | 2 | 3;
|
|
@@ -19,6 +19,8 @@ export declare class MockApiClient {
|
|
|
19
19
|
private csrfToken;
|
|
20
20
|
private mockDataProvider;
|
|
21
21
|
private readonly mockApiOnly;
|
|
22
|
+
private readonly logger;
|
|
23
|
+
private buildLoggerExtra;
|
|
22
24
|
constructor(baseUrl: string, deviceInfo?: DeviceInfo, mockConfig?: MockConfig);
|
|
23
25
|
/**
|
|
24
26
|
* Store tokens after successful authentication
|
|
@@ -303,3 +303,119 @@ export interface DisconnectCompanyResponse {
|
|
|
303
303
|
message: string;
|
|
304
304
|
status_code: number;
|
|
305
305
|
}
|
|
306
|
+
export interface OrderFill {
|
|
307
|
+
id: string;
|
|
308
|
+
order_id: string;
|
|
309
|
+
leg_id: string | null;
|
|
310
|
+
price: number;
|
|
311
|
+
quantity: number;
|
|
312
|
+
executed_at: string;
|
|
313
|
+
execution_id: string | null;
|
|
314
|
+
trade_id: string | null;
|
|
315
|
+
venue: string | null;
|
|
316
|
+
commission_fee: number | null;
|
|
317
|
+
created_at: string;
|
|
318
|
+
updated_at: string;
|
|
319
|
+
}
|
|
320
|
+
export interface OrderEvent {
|
|
321
|
+
id: string;
|
|
322
|
+
order_id: string;
|
|
323
|
+
order_group_id: string | null;
|
|
324
|
+
event_type: string | null;
|
|
325
|
+
event_time: string;
|
|
326
|
+
event_id: string | null;
|
|
327
|
+
order_status: string | null;
|
|
328
|
+
inferred: boolean;
|
|
329
|
+
confidence: number | null;
|
|
330
|
+
reason_code: string | null;
|
|
331
|
+
recorded_at: string | null;
|
|
332
|
+
}
|
|
333
|
+
export interface OrderLeg {
|
|
334
|
+
id: string;
|
|
335
|
+
order_id: string;
|
|
336
|
+
leg_index: number;
|
|
337
|
+
asset_type: string;
|
|
338
|
+
broker_provided_symbol: string | null;
|
|
339
|
+
quantity: number;
|
|
340
|
+
filled_quantity: number | null;
|
|
341
|
+
avg_fill_price: number | null;
|
|
342
|
+
created_at: string | null;
|
|
343
|
+
updated_at: string | null;
|
|
344
|
+
}
|
|
345
|
+
export interface OrderGroupOrder extends BrokerDataOrder {
|
|
346
|
+
legs: OrderLeg[];
|
|
347
|
+
}
|
|
348
|
+
export interface OrderGroup {
|
|
349
|
+
id: string;
|
|
350
|
+
user_broker_connection_id: string | null;
|
|
351
|
+
created_at: string;
|
|
352
|
+
updated_at: string;
|
|
353
|
+
orders: OrderGroupOrder[];
|
|
354
|
+
}
|
|
355
|
+
export interface PositionLot {
|
|
356
|
+
id: string;
|
|
357
|
+
position_id: string | null;
|
|
358
|
+
user_broker_connection_id: string;
|
|
359
|
+
broker_provided_account_id: string;
|
|
360
|
+
instrument_key: string;
|
|
361
|
+
asset_type: string | null;
|
|
362
|
+
side: 'long' | 'short' | null;
|
|
363
|
+
open_quantity: number;
|
|
364
|
+
closed_quantity: number;
|
|
365
|
+
remaining_quantity: number;
|
|
366
|
+
open_price: number;
|
|
367
|
+
close_price_avg: number | null;
|
|
368
|
+
cost_basis: number;
|
|
369
|
+
cost_basis_w_commission: number;
|
|
370
|
+
realized_pl: number;
|
|
371
|
+
realized_pl_w_commission: number;
|
|
372
|
+
lot_opened_at: string;
|
|
373
|
+
lot_closed_at: string | null;
|
|
374
|
+
position_group_id: string | null;
|
|
375
|
+
created_at: string;
|
|
376
|
+
updated_at: string;
|
|
377
|
+
position_lot_fills?: PositionLotFill[];
|
|
378
|
+
}
|
|
379
|
+
export interface PositionLotFill {
|
|
380
|
+
id: string;
|
|
381
|
+
lot_id: string;
|
|
382
|
+
order_fill_id: string;
|
|
383
|
+
fill_price: number;
|
|
384
|
+
fill_quantity: number;
|
|
385
|
+
executed_at: string;
|
|
386
|
+
commission_share: number | null;
|
|
387
|
+
created_at: string;
|
|
388
|
+
updated_at: string;
|
|
389
|
+
}
|
|
390
|
+
export interface OrderFillsFilter {
|
|
391
|
+
connection_id?: string;
|
|
392
|
+
limit?: number;
|
|
393
|
+
offset?: number;
|
|
394
|
+
}
|
|
395
|
+
export interface OrderEventsFilter {
|
|
396
|
+
connection_id?: string;
|
|
397
|
+
limit?: number;
|
|
398
|
+
offset?: number;
|
|
399
|
+
}
|
|
400
|
+
export interface OrderGroupsFilter {
|
|
401
|
+
broker_id?: string;
|
|
402
|
+
connection_id?: string;
|
|
403
|
+
limit?: number;
|
|
404
|
+
offset?: number;
|
|
405
|
+
created_after?: string;
|
|
406
|
+
created_before?: string;
|
|
407
|
+
}
|
|
408
|
+
export interface PositionLotsFilter {
|
|
409
|
+
broker_id?: string;
|
|
410
|
+
connection_id?: string;
|
|
411
|
+
account_id?: string;
|
|
412
|
+
symbol?: string;
|
|
413
|
+
position_id?: string;
|
|
414
|
+
limit?: number;
|
|
415
|
+
offset?: number;
|
|
416
|
+
}
|
|
417
|
+
export interface PositionLotFillsFilter {
|
|
418
|
+
connection_id?: string;
|
|
419
|
+
limit?: number;
|
|
420
|
+
offset?: number;
|
|
421
|
+
}
|