@finatic/client 0.0.132 → 0.0.134
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 +87 -4
- package/dist/index.d.ts +471 -735
- package/dist/index.js +862 -756
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +863 -754
- package/dist/index.mjs.map +1 -1
- package/dist/types/core/client/ApiClient.d.ts +206 -0
- package/dist/types/{client → core/client}/FinaticConnect.d.ts +54 -18
- package/dist/types/{portal → core/portal}/PortalUI.d.ts +1 -1
- package/dist/types/index.d.ts +6 -11
- package/dist/types/mocks/MockApiClient.d.ts +36 -90
- package/dist/types/mocks/MockDataProvider.d.ts +13 -3
- package/dist/types/mocks/MockFactory.d.ts +2 -2
- package/dist/types/{shared/themes → themes}/portalPresets.d.ts +1 -1
- package/dist/types/types/api/auth.d.ts +111 -0
- package/dist/types/types/{api.d.ts → api/broker.d.ts} +56 -284
- package/dist/types/types/api/core.d.ts +46 -0
- package/dist/types/types/api/errors.d.ts +23 -0
- package/dist/types/types/api/orders.d.ts +39 -0
- package/dist/types/types/{shared.d.ts → api/portfolio.d.ts} +26 -21
- package/dist/types/types/common/pagination.d.ts +33 -0
- package/dist/types/types/connect.d.ts +4 -2
- package/dist/types/types/index.d.ts +13 -0
- package/dist/types/types/{theme.d.ts → ui/theme.d.ts} +3 -0
- package/dist/types/utils/brokerUtils.d.ts +30 -0
- package/package.json +4 -3
- package/dist/types/client/ApiClient.d.ts +0 -234
- package/dist/types/mocks/index.d.ts +0 -5
- package/dist/types/security/ApiSecurity.d.ts +0 -24
- package/dist/types/security/RuntimeSecurity.d.ts +0 -28
- package/dist/types/security/SecurityUtils.d.ts +0 -21
- package/dist/types/security/index.d.ts +0 -2
- package/dist/types/services/AnalyticsService.d.ts +0 -18
- package/dist/types/services/ApiClient.d.ts +0 -121
- package/dist/types/services/PortalService.d.ts +0 -24
- package/dist/types/services/TradingService.d.ts +0 -55
- package/dist/types/services/api.d.ts +0 -23
- package/dist/types/services/auth.d.ts +0 -9
- package/dist/types/services/index.d.ts +0 -4
- package/dist/types/services/portfolio.d.ts +0 -10
- package/dist/types/services/trading.d.ts +0 -10
- package/dist/types/shared/index.d.ts +0 -2
- package/dist/types/shared/themes/index.d.ts +0 -2
- package/dist/types/shared/themes/presets.d.ts +0 -3
- package/dist/types/shared/themes/system.d.ts +0 -2
- package/dist/types/shared/types/index.d.ts +0 -110
- package/dist/types/types/config.d.ts +0 -12
- package/dist/types/types/errors.d.ts +0 -47
- package/dist/types/types/security.d.ts +0 -35
- package/dist/types/types.d.ts +0 -157
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Holding, Portfolio } from '../../types/api/portfolio';
|
|
2
|
+
import { Order } from '../../types/api/orders';
|
|
3
|
+
import { BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerDataOptions, DisconnectCompanyResponse } from '../../types/api/broker';
|
|
4
|
+
import { BrokerOrderParams, BrokerExtras } from '../../types/api/broker';
|
|
5
|
+
import { CryptoOrderOptions, OptionsOrderOptions, OrderResponse } from '../../types/api/orders';
|
|
6
|
+
import { BrokerConnection } from '../../types/api/broker';
|
|
7
|
+
import { OrdersFilter, PositionsFilter, AccountsFilter } from '../../types/api/broker';
|
|
8
|
+
import { TradingContext } from '../../types/api/orders';
|
|
9
|
+
import { PaginatedResult } from '../../types/common/pagination';
|
|
10
|
+
import { PortalUrlResponse } from '../../types/api/core';
|
|
11
|
+
import { DeviceInfo, SessionState, TokenInfo, SessionResponse, OtpRequestResponse, OtpVerifyResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken } from '../../types/api/auth';
|
|
12
|
+
import { ApiError } from '../../utils/errors';
|
|
13
|
+
export declare class ApiClient {
|
|
14
|
+
private readonly baseUrl;
|
|
15
|
+
protected readonly deviceInfo?: DeviceInfo;
|
|
16
|
+
protected currentSessionState: SessionState | null;
|
|
17
|
+
protected currentSessionId: string | null;
|
|
18
|
+
private tradingContext;
|
|
19
|
+
private tokenInfo;
|
|
20
|
+
private refreshPromise;
|
|
21
|
+
private readonly REFRESH_BUFFER_MINUTES;
|
|
22
|
+
private companyId;
|
|
23
|
+
private csrfToken;
|
|
24
|
+
constructor(baseUrl: string, deviceInfo?: DeviceInfo);
|
|
25
|
+
/**
|
|
26
|
+
* Set session context (session ID, company ID, CSRF token)
|
|
27
|
+
*/
|
|
28
|
+
setSessionContext(sessionId: string, companyId: string, csrfToken?: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get the current session ID
|
|
31
|
+
*/
|
|
32
|
+
getCurrentSessionId(): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Get the current company ID
|
|
35
|
+
*/
|
|
36
|
+
getCurrentCompanyId(): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* Get the current CSRF token
|
|
39
|
+
*/
|
|
40
|
+
getCurrentCsrfToken(): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Store tokens after successful authentication
|
|
43
|
+
*/
|
|
44
|
+
setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get the current access token, refreshing if necessary
|
|
47
|
+
*/
|
|
48
|
+
getValidAccessToken(): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Check if the current token is expired or about to expire
|
|
51
|
+
*/
|
|
52
|
+
private isTokenExpired;
|
|
53
|
+
/**
|
|
54
|
+
* Refresh the access token using the refresh token
|
|
55
|
+
*/
|
|
56
|
+
private refreshTokens;
|
|
57
|
+
/**
|
|
58
|
+
* Perform the actual token refresh request
|
|
59
|
+
*/
|
|
60
|
+
private performTokenRefresh;
|
|
61
|
+
/**
|
|
62
|
+
* Clear stored tokens (useful for logout)
|
|
63
|
+
*/
|
|
64
|
+
clearTokens(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Get current token info (for debugging/testing)
|
|
67
|
+
*/
|
|
68
|
+
getTokenInfo(): TokenInfo | null;
|
|
69
|
+
/**
|
|
70
|
+
* Make a request to the API.
|
|
71
|
+
*/
|
|
72
|
+
protected request<T>(path: string, options: {
|
|
73
|
+
method: string;
|
|
74
|
+
headers?: Record<string, string>;
|
|
75
|
+
body?: any;
|
|
76
|
+
params?: Record<string, string>;
|
|
77
|
+
}): Promise<T>;
|
|
78
|
+
/**
|
|
79
|
+
* Handle API errors. This method can be overridden by language-specific implementations.
|
|
80
|
+
*/
|
|
81
|
+
protected handleError(status: number, error: any): ApiError;
|
|
82
|
+
startSession(token: string, userId?: string): Promise<SessionResponse>;
|
|
83
|
+
requestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
|
|
84
|
+
verifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
|
|
85
|
+
authenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
|
|
86
|
+
/**
|
|
87
|
+
* Get the portal URL for an active session
|
|
88
|
+
* @param sessionId The session identifier
|
|
89
|
+
* @returns Portal URL response
|
|
90
|
+
* @throws SessionError if session is not in ACTIVE state
|
|
91
|
+
*/
|
|
92
|
+
getPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
|
|
93
|
+
validatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
|
|
94
|
+
completePortalSession(sessionId: string): Promise<PortalUrlResponse>;
|
|
95
|
+
getHoldings(): Promise<{
|
|
96
|
+
data: Holding[];
|
|
97
|
+
}>;
|
|
98
|
+
getOrders(): Promise<{
|
|
99
|
+
data: Order[];
|
|
100
|
+
}>;
|
|
101
|
+
getPortfolio(): Promise<{
|
|
102
|
+
data: Portfolio;
|
|
103
|
+
}>;
|
|
104
|
+
placeBrokerOrder(params: Partial<BrokerOrderParams> & {
|
|
105
|
+
symbol: string;
|
|
106
|
+
orderQty: number;
|
|
107
|
+
action: 'Buy' | 'Sell';
|
|
108
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
|
|
109
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Future';
|
|
110
|
+
}, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
111
|
+
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
112
|
+
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
113
|
+
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
114
|
+
setAccount(accountNumber: string, accountId?: string): void;
|
|
115
|
+
getTradingContext(): TradingContext;
|
|
116
|
+
clearTradingContext(): void;
|
|
117
|
+
placeStockMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
118
|
+
placeStockLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
119
|
+
placeStockStopOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
120
|
+
placeCryptoMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
121
|
+
placeCryptoLimitOrder(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>;
|
|
122
|
+
placeOptionsMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
123
|
+
placeOptionsLimitOrder(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>;
|
|
124
|
+
placeFuturesMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
125
|
+
placeFuturesLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
126
|
+
private buildOrderRequestBody;
|
|
127
|
+
private buildModifyRequestBody;
|
|
128
|
+
private applyBrokerDefaults;
|
|
129
|
+
revokeToken(): Promise<void>;
|
|
130
|
+
getUserToken(userId: string): Promise<UserToken>;
|
|
131
|
+
/**
|
|
132
|
+
* Get the current session state
|
|
133
|
+
*/
|
|
134
|
+
getCurrentSessionState(): SessionState | null;
|
|
135
|
+
/**
|
|
136
|
+
* Refresh the current session to extend its lifetime
|
|
137
|
+
*/
|
|
138
|
+
refreshSession(): Promise<{
|
|
139
|
+
success: boolean;
|
|
140
|
+
response_data: {
|
|
141
|
+
session_id: string;
|
|
142
|
+
company_id: string;
|
|
143
|
+
status: string;
|
|
144
|
+
expires_at: string;
|
|
145
|
+
user_id: string;
|
|
146
|
+
auto_login: boolean;
|
|
147
|
+
};
|
|
148
|
+
message: string;
|
|
149
|
+
status_code: number;
|
|
150
|
+
}>;
|
|
151
|
+
getBrokerList(): Promise<{
|
|
152
|
+
_id: string;
|
|
153
|
+
response_data: BrokerInfo[];
|
|
154
|
+
message: string;
|
|
155
|
+
status_code: number;
|
|
156
|
+
warnings: null;
|
|
157
|
+
errors: null;
|
|
158
|
+
}>;
|
|
159
|
+
getBrokerAccounts(options?: BrokerDataOptions): Promise<{
|
|
160
|
+
_id: string;
|
|
161
|
+
response_data: BrokerAccount[];
|
|
162
|
+
message: string;
|
|
163
|
+
status_code: number;
|
|
164
|
+
warnings: null;
|
|
165
|
+
errors: null;
|
|
166
|
+
}>;
|
|
167
|
+
getBrokerOrders(options?: BrokerDataOptions): Promise<{
|
|
168
|
+
_id: string;
|
|
169
|
+
response_data: BrokerOrder[];
|
|
170
|
+
message: string;
|
|
171
|
+
status_code: number;
|
|
172
|
+
warnings: null;
|
|
173
|
+
errors: null;
|
|
174
|
+
}>;
|
|
175
|
+
getBrokerPositions(options?: BrokerDataOptions): Promise<{
|
|
176
|
+
_id: string;
|
|
177
|
+
response_data: BrokerPosition[];
|
|
178
|
+
message: string;
|
|
179
|
+
status_code: number;
|
|
180
|
+
warnings: null;
|
|
181
|
+
errors: null;
|
|
182
|
+
}>;
|
|
183
|
+
getBrokerConnections(): Promise<{
|
|
184
|
+
_id: string;
|
|
185
|
+
response_data: BrokerConnection[];
|
|
186
|
+
message: string;
|
|
187
|
+
status_code: number;
|
|
188
|
+
warnings: null;
|
|
189
|
+
errors: null;
|
|
190
|
+
}>;
|
|
191
|
+
getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<BrokerOrder[]>>;
|
|
192
|
+
getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<BrokerAccount[]>>;
|
|
193
|
+
getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<BrokerPosition[]>>;
|
|
194
|
+
getNextPage<T>(previousResult: PaginatedResult<T>, fetchFunction: (offset: number, limit: number) => Promise<PaginatedResult<T>>): Promise<PaginatedResult<T> | null>;
|
|
195
|
+
/**
|
|
196
|
+
* Check if this is a mock client
|
|
197
|
+
* @returns false for real API client
|
|
198
|
+
*/
|
|
199
|
+
isMockClient(): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Disconnect a company from a broker connection
|
|
202
|
+
* @param connectionId - The connection ID to disconnect
|
|
203
|
+
* @returns Promise with disconnect response
|
|
204
|
+
*/
|
|
205
|
+
disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
206
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { EventEmitter } from '
|
|
2
|
-
import { PaginatedResult } from '
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { EventEmitter } from '../../utils/events';
|
|
2
|
+
import { PaginatedResult } from '../../types/common/pagination';
|
|
3
|
+
import { OrderResponse, TradingContext } from '../../types/api/orders';
|
|
4
|
+
import { BrokerInfo, BrokerConnection, OrdersFilter, PositionsFilter, AccountsFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount, DisconnectCompanyResponse } from '../../types/api/broker';
|
|
5
|
+
import { FinaticConnectOptions, PortalOptions } from '../../types/connect';
|
|
5
6
|
interface DeviceInfo {
|
|
6
7
|
ip_address: string;
|
|
7
8
|
user_agent: string;
|
|
@@ -21,13 +22,13 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
21
22
|
private readonly BROKER_LIST_CACHE_DURATION;
|
|
22
23
|
private readonly deviceInfo?;
|
|
23
24
|
private currentSessionState;
|
|
25
|
+
private sessionKeepAliveInterval;
|
|
26
|
+
private readonly SESSION_KEEP_ALIVE_INTERVAL;
|
|
27
|
+
private readonly SESSION_VALIDATION_TIMEOUT;
|
|
28
|
+
private readonly SESSION_REFRESH_BUFFER_HOURS;
|
|
29
|
+
private sessionStartTime;
|
|
24
30
|
constructor(options: FinaticConnectOptions, deviceInfo?: DeviceInfo);
|
|
25
31
|
private handleTokens;
|
|
26
|
-
/**
|
|
27
|
-
* Check if the user is authenticated
|
|
28
|
-
* @returns True if the user has a valid access token
|
|
29
|
-
*/
|
|
30
|
-
isAuthenticated(): boolean;
|
|
31
32
|
/**
|
|
32
33
|
* Check if the user is fully authenticated (has userId, access token, and refresh token)
|
|
33
34
|
* @returns True if the user is fully authenticated and ready for API calls
|
|
@@ -117,27 +118,34 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
117
118
|
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
118
119
|
broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader';
|
|
119
120
|
accountNumber?: string;
|
|
120
|
-
assetType?: 'Stock' | 'Option' | 'Crypto' | '
|
|
121
|
+
assetType?: 'Stock' | 'Option' | 'Crypto' | 'Future';
|
|
122
|
+
order_id?: string;
|
|
123
|
+
connection_id?: string;
|
|
121
124
|
}): Promise<OrderResponse>;
|
|
122
125
|
/**
|
|
123
126
|
* Cancel a broker order
|
|
124
127
|
* @param orderId - The order ID to cancel
|
|
125
128
|
* @param broker - Optional broker override
|
|
129
|
+
* @param connection_id - Optional connection ID for testing bypass
|
|
126
130
|
*/
|
|
127
|
-
cancelOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader'): Promise<OrderResponse>;
|
|
131
|
+
cancelOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', connection_id?: string): Promise<OrderResponse>;
|
|
128
132
|
/**
|
|
129
133
|
* Modify a broker order
|
|
130
134
|
* @param orderId - The order ID to modify
|
|
131
135
|
* @param modifications - The modifications to apply
|
|
132
136
|
* @param broker - Optional broker override
|
|
137
|
+
* @param connection_id - Optional connection ID for testing bypass
|
|
133
138
|
*/
|
|
134
139
|
modifyOrder(orderId: string, modifications: Partial<{
|
|
135
|
-
symbol
|
|
136
|
-
quantity
|
|
137
|
-
price
|
|
138
|
-
stopPrice
|
|
139
|
-
timeInForce
|
|
140
|
-
|
|
140
|
+
symbol?: string;
|
|
141
|
+
quantity?: number;
|
|
142
|
+
price?: number;
|
|
143
|
+
stopPrice?: number;
|
|
144
|
+
timeInForce?: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
145
|
+
orderType?: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
|
|
146
|
+
side?: 'Buy' | 'Sell';
|
|
147
|
+
order_id?: string;
|
|
148
|
+
}>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', connection_id?: string): Promise<OrderResponse>;
|
|
141
149
|
/**
|
|
142
150
|
* Set the broker context for trading
|
|
143
151
|
* @param broker - The broker to use for trading
|
|
@@ -287,15 +295,36 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
287
295
|
*/
|
|
288
296
|
getAllAccounts(filter?: AccountsFilter): Promise<BrokerDataAccount[]>;
|
|
289
297
|
/**
|
|
290
|
-
* Register
|
|
298
|
+
* Register session management (but don't auto-cleanup for 24-hour sessions)
|
|
291
299
|
*/
|
|
292
300
|
private registerSessionCleanup;
|
|
301
|
+
/**
|
|
302
|
+
* Start the session keep-alive mechanism
|
|
303
|
+
*/
|
|
304
|
+
private startSessionKeepAlive;
|
|
305
|
+
/**
|
|
306
|
+
* Stop the session keep-alive mechanism
|
|
307
|
+
*/
|
|
308
|
+
private stopSessionKeepAlive;
|
|
309
|
+
/**
|
|
310
|
+
* Validate session for keep-alive purposes and handle automatic refresh
|
|
311
|
+
*/
|
|
312
|
+
private validateSessionKeepAlive;
|
|
313
|
+
/**
|
|
314
|
+
* Check if the session should be refreshed (after 16 hours)
|
|
315
|
+
*/
|
|
316
|
+
private shouldRefreshSession;
|
|
317
|
+
/**
|
|
318
|
+
* Automatically refresh the session to extend its lifetime
|
|
319
|
+
*/
|
|
320
|
+
private refreshSessionAutomatically;
|
|
293
321
|
/**
|
|
294
322
|
* Handle session cleanup when page is unloading
|
|
295
323
|
*/
|
|
296
324
|
private handleSessionCleanup;
|
|
297
325
|
/**
|
|
298
326
|
* Handle visibility change (mobile browsers)
|
|
327
|
+
* Note: We don't complete sessions on visibility change for 24-hour sessions
|
|
299
328
|
*/
|
|
300
329
|
private handleVisibilityChange;
|
|
301
330
|
/**
|
|
@@ -303,5 +332,12 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
303
332
|
* @param sessionId - The session ID to complete
|
|
304
333
|
*/
|
|
305
334
|
private completeSession;
|
|
335
|
+
/**
|
|
336
|
+
* Disconnect a company from a broker connection
|
|
337
|
+
* @param connectionId - The connection ID to disconnect
|
|
338
|
+
* @returns Promise with disconnect response
|
|
339
|
+
* @throws AuthenticationError if user is not authenticated
|
|
340
|
+
*/
|
|
341
|
+
disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
306
342
|
}
|
|
307
343
|
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
export type { ApiConfig, ApiResponse, Order, OptionsOrder, BrokerAccount, PortfolioSnapshot, PerformanceMetrics, UserToken, Holding, Portfolio, PortalResponse, SessionInitResponse, SessionStartResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, RequestHeaders, SessionStatus, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, TradingContext, DeviceInfo, BrokerOrder, BrokerPosition, BrokerDataOptions, BrokerInfo, TokenInfo, RefreshTokenRequest, RefreshTokenResponse, AccountsFilter, OrdersFilter, PositionsFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount, FilteredOrdersResponse, FilteredPositionsResponse, FilteredAccountsResponse, BrokerConnection, } from './types
|
|
2
|
-
export type { SDKConfig, PortalConfig } from './types/config';
|
|
3
|
-
export type { Theme } from './types/theme';
|
|
1
|
+
export type { ApiConfig, ApiResponse, Order, OptionsOrder, BrokerAccount, PortfolioSnapshot, PerformanceMetrics, UserToken, Holding, Portfolio, PortalResponse, SessionInitResponse, SessionStartResponse, SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, RequestHeaders, SessionStatus, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, TradingContext, DeviceInfo, BrokerOrder, BrokerPosition, BrokerDataOptions, BrokerInfo, TokenInfo, RefreshTokenRequest, RefreshTokenResponse, AccountsFilter, OrdersFilter, PositionsFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount, FilteredOrdersResponse, FilteredPositionsResponse, FilteredAccountsResponse, BrokerConnection, } from './types';
|
|
4
2
|
export type { FinaticConnectOptions, FinaticUserToken, PortalMessage } from './types/connect';
|
|
5
3
|
export type { PortalProps, PortalTheme, PortalThemeConfig, PortalThemePreset, } from './types/portal';
|
|
6
|
-
export type {
|
|
7
|
-
export { ApiClient } from './client/ApiClient';
|
|
8
|
-
export { FinaticConnect } from './client/FinaticConnect';
|
|
9
|
-
export {
|
|
10
|
-
export { CoreAnalyticsService } from './services/AnalyticsService';
|
|
11
|
-
export { CorePortalService } from './services/PortalService';
|
|
12
|
-
export { PaginatedResult } from './types';
|
|
4
|
+
export type { TradeAccessDeniedError, OrderNotFoundError, ValidationError, } from './types/api/errors';
|
|
5
|
+
export { ApiClient } from './core/client/ApiClient';
|
|
6
|
+
export { FinaticConnect } from './core/client/FinaticConnect';
|
|
7
|
+
export { PaginatedResult } from './types/common/pagination';
|
|
13
8
|
export * from './utils/errors';
|
|
14
9
|
export * from './utils/events';
|
|
15
10
|
export * from './utils/themeUtils';
|
|
16
|
-
export { portalThemePresets } from './
|
|
11
|
+
export { portalThemePresets } from './themes/portalPresets';
|
|
17
12
|
export { MockFactory } from './mocks/MockFactory';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, Holding, Order, Portfolio, BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerConnection, BrokerDataOptions,
|
|
2
|
-
import { DeviceInfo } from '../types/api';
|
|
1
|
+
import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, Holding, Order, Portfolio, BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerConnection, BrokerDataOptions, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, TradingContext, OrdersFilter, PositionsFilter, AccountsFilter, BrokerDataOrder, BrokerDataPosition, DisconnectCompanyResponse } from '../types';
|
|
3
2
|
import { PaginatedResult } from '../types';
|
|
3
|
+
import { DeviceInfo, SessionState, TokenInfo } from '../types/api/auth';
|
|
4
4
|
import { MockDataProvider, MockConfig } from './MockDataProvider';
|
|
5
5
|
/**
|
|
6
6
|
* Mock API Client that implements the same interface as the real ApiClient
|
|
@@ -71,52 +71,42 @@ export declare class MockApiClient {
|
|
|
71
71
|
getPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
|
|
72
72
|
validatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
|
|
73
73
|
completePortalSession(sessionId: string): Promise<PortalUrlResponse>;
|
|
74
|
-
getHoldings(
|
|
74
|
+
getHoldings(filter?: OrdersFilter): Promise<{
|
|
75
75
|
data: Holding[];
|
|
76
76
|
}>;
|
|
77
|
-
getOrders(
|
|
77
|
+
getOrders(filter?: OrdersFilter): Promise<{
|
|
78
78
|
data: Order[];
|
|
79
79
|
}>;
|
|
80
|
-
getPortfolio(
|
|
80
|
+
getPortfolio(): Promise<{
|
|
81
81
|
data: Portfolio;
|
|
82
82
|
}>;
|
|
83
|
-
placeOrder(
|
|
84
|
-
|
|
85
|
-
data: Holding[];
|
|
86
|
-
}>;
|
|
87
|
-
getOrdersAuto(): Promise<{
|
|
88
|
-
data: Order[];
|
|
89
|
-
}>;
|
|
90
|
-
getPortfolioAuto(): Promise<{
|
|
91
|
-
data: Portfolio;
|
|
92
|
-
}>;
|
|
93
|
-
placeOrderAuto(order: Order): Promise<void>;
|
|
94
|
-
placeBrokerOrder(accessToken: string, params: Partial<BrokerOrderParams> & {
|
|
83
|
+
placeOrder(order: BrokerOrderParams): Promise<void>;
|
|
84
|
+
placeBrokerOrder(params: Partial<BrokerOrderParams> & {
|
|
95
85
|
symbol: string;
|
|
96
86
|
orderQty: number;
|
|
97
87
|
action: 'Buy' | 'Sell';
|
|
98
|
-
orderType: 'Market' | 'Limit' | 'Stop' | '
|
|
99
|
-
assetType: 'Stock' | 'Option' | 'Crypto' | '
|
|
100
|
-
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
101
|
-
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
102
|
-
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
88
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
|
|
89
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Future';
|
|
90
|
+
}, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
91
|
+
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
92
|
+
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
103
93
|
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
104
94
|
setAccount(accountNumber: string, accountId?: string): void;
|
|
105
95
|
getTradingContext(): TradingContext;
|
|
106
96
|
clearTradingContext(): void;
|
|
107
|
-
placeStockMarketOrder(
|
|
108
|
-
placeStockLimitOrder(
|
|
109
|
-
placeStockStopOrder(
|
|
110
|
-
placeCryptoMarketOrder(
|
|
111
|
-
placeCryptoLimitOrder(
|
|
112
|
-
placeOptionsMarketOrder(
|
|
113
|
-
placeOptionsLimitOrder(
|
|
114
|
-
placeFuturesMarketOrder(
|
|
115
|
-
placeFuturesLimitOrder(
|
|
97
|
+
placeStockMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
98
|
+
placeStockLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
99
|
+
placeStockStopOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', stopPrice: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
100
|
+
placeCryptoMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
101
|
+
placeCryptoLimitOrder(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>;
|
|
102
|
+
placeOptionsMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
103
|
+
placeOptionsLimitOrder(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>;
|
|
104
|
+
placeFuturesMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
105
|
+
placeFuturesLimitOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
116
106
|
revokeToken(accessToken: string): Promise<void>;
|
|
117
107
|
getUserToken(userId: string): Promise<UserToken>;
|
|
118
108
|
getCurrentSessionState(): SessionState | null;
|
|
119
|
-
getBrokerList(
|
|
109
|
+
getBrokerList(): Promise<{
|
|
120
110
|
_id: string;
|
|
121
111
|
response_data: BrokerInfo[];
|
|
122
112
|
message: string;
|
|
@@ -124,7 +114,7 @@ export declare class MockApiClient {
|
|
|
124
114
|
warnings: null;
|
|
125
115
|
errors: null;
|
|
126
116
|
}>;
|
|
127
|
-
getBrokerAccounts(
|
|
117
|
+
getBrokerAccounts(options?: BrokerDataOptions): Promise<{
|
|
128
118
|
_id: string;
|
|
129
119
|
response_data: BrokerAccount[];
|
|
130
120
|
message: string;
|
|
@@ -132,7 +122,7 @@ export declare class MockApiClient {
|
|
|
132
122
|
warnings: null;
|
|
133
123
|
errors: null;
|
|
134
124
|
}>;
|
|
135
|
-
getBrokerOrders(
|
|
125
|
+
getBrokerOrders(options?: BrokerDataOptions): Promise<{
|
|
136
126
|
_id: string;
|
|
137
127
|
response_data: BrokerOrder[];
|
|
138
128
|
message: string;
|
|
@@ -140,7 +130,7 @@ export declare class MockApiClient {
|
|
|
140
130
|
warnings: null;
|
|
141
131
|
errors: null;
|
|
142
132
|
}>;
|
|
143
|
-
getBrokerPositions(
|
|
133
|
+
getBrokerPositions(options?: BrokerDataOptions): Promise<{
|
|
144
134
|
_id: string;
|
|
145
135
|
response_data: BrokerPosition[];
|
|
146
136
|
message: string;
|
|
@@ -155,52 +145,12 @@ export declare class MockApiClient {
|
|
|
155
145
|
data: BrokerDataPosition[];
|
|
156
146
|
}>;
|
|
157
147
|
getBrokerDataAccountsWithFilter(filter?: AccountsFilter): Promise<{
|
|
158
|
-
data:
|
|
159
|
-
}>;
|
|
160
|
-
getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<any[]>>;
|
|
161
|
-
getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<any[]>>;
|
|
162
|
-
getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<any[]>>;
|
|
163
|
-
getBrokerConnections(accessToken: string): Promise<{
|
|
164
|
-
_id: string;
|
|
165
|
-
response_data: BrokerConnection[];
|
|
166
|
-
message: string;
|
|
167
|
-
status_code: number;
|
|
168
|
-
warnings: null;
|
|
169
|
-
errors: null;
|
|
170
|
-
}>;
|
|
171
|
-
getBrokerListAuto(): Promise<{
|
|
172
|
-
_id: string;
|
|
173
|
-
response_data: BrokerInfo[];
|
|
174
|
-
message: string;
|
|
175
|
-
status_code: number;
|
|
176
|
-
warnings: null;
|
|
177
|
-
errors: null;
|
|
178
|
-
}>;
|
|
179
|
-
getBrokerAccountsAuto(options?: BrokerDataOptions): Promise<{
|
|
180
|
-
_id: string;
|
|
181
|
-
response_data: BrokerAccount[];
|
|
182
|
-
message: string;
|
|
183
|
-
status_code: number;
|
|
184
|
-
warnings: null;
|
|
185
|
-
errors: null;
|
|
186
|
-
}>;
|
|
187
|
-
getBrokerOrdersAuto(options?: BrokerDataOptions): Promise<{
|
|
188
|
-
_id: string;
|
|
189
|
-
response_data: BrokerOrder[];
|
|
190
|
-
message: string;
|
|
191
|
-
status_code: number;
|
|
192
|
-
warnings: null;
|
|
193
|
-
errors: null;
|
|
148
|
+
data: BrokerAccount[];
|
|
194
149
|
}>;
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
status_code: number;
|
|
200
|
-
warnings: null;
|
|
201
|
-
errors: null;
|
|
202
|
-
}>;
|
|
203
|
-
getBrokerConnectionsAuto(): Promise<{
|
|
150
|
+
getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
151
|
+
getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<BrokerAccount[]>>;
|
|
152
|
+
getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
153
|
+
getBrokerConnections(): Promise<{
|
|
204
154
|
_id: string;
|
|
205
155
|
response_data: BrokerConnection[];
|
|
206
156
|
message: string;
|
|
@@ -208,16 +158,12 @@ export declare class MockApiClient {
|
|
|
208
158
|
warnings: null;
|
|
209
159
|
errors: null;
|
|
210
160
|
}>;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
218
|
-
placeStockMarketOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
219
|
-
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>;
|
|
220
|
-
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>;
|
|
161
|
+
/**
|
|
162
|
+
* Mock disconnect company method
|
|
163
|
+
* @param connectionId - The connection ID to disconnect
|
|
164
|
+
* @returns Promise with mock disconnect response
|
|
165
|
+
*/
|
|
166
|
+
disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
221
167
|
getMockDataProvider(): MockDataProvider;
|
|
222
168
|
clearMockData(): void;
|
|
223
169
|
/**
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Holding, Portfolio } from '../types/api/portfolio';
|
|
2
|
+
import { Order, OrderResponse } from '../types/api/orders';
|
|
3
|
+
import { BrokerInfo, BrokerAccount, BrokerConnection, OrdersFilter, PositionsFilter, AccountsFilter, BrokerDataOrder, BrokerDataPosition, BrokerOrderParams, DisconnectCompanyResponse } from '../types/api/broker';
|
|
4
|
+
import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, RefreshTokenResponse } from '../types/api/auth';
|
|
5
|
+
import { PortalUrlResponse } from '../types/api/core';
|
|
2
6
|
/**
|
|
3
7
|
* Configuration for mock behavior
|
|
4
8
|
*/
|
|
@@ -92,9 +96,9 @@ export declare class MockDataProvider {
|
|
|
92
96
|
data: BrokerDataPosition[];
|
|
93
97
|
}>;
|
|
94
98
|
mockGetBrokerDataAccounts(filter?: AccountsFilter): Promise<{
|
|
95
|
-
data:
|
|
99
|
+
data: BrokerAccount[];
|
|
96
100
|
}>;
|
|
97
|
-
mockPlaceOrder(order:
|
|
101
|
+
mockPlaceOrder(order: BrokerOrderParams): Promise<OrderResponse>;
|
|
98
102
|
/**
|
|
99
103
|
* Get stored session data
|
|
100
104
|
*/
|
|
@@ -129,4 +133,10 @@ export declare class MockDataProvider {
|
|
|
129
133
|
* Generate mock accounts with diverse data
|
|
130
134
|
*/
|
|
131
135
|
private generateMockAccounts;
|
|
136
|
+
/**
|
|
137
|
+
* Mock disconnect company method
|
|
138
|
+
* @param connectionId - The connection ID to disconnect
|
|
139
|
+
* @returns Promise with mock disconnect response
|
|
140
|
+
*/
|
|
141
|
+
mockDisconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
132
142
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ApiClient } from '../client/ApiClient';
|
|
1
|
+
import { ApiClient } from '../core/client/ApiClient';
|
|
2
2
|
import { MockApiClient } from './MockApiClient';
|
|
3
3
|
import { MockConfig } from './MockDataProvider';
|
|
4
|
-
import { DeviceInfo } from '../types
|
|
4
|
+
import { DeviceInfo } from '../types';
|
|
5
5
|
/**
|
|
6
6
|
* Factory class for creating API clients (real or mock)
|
|
7
7
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PortalThemeConfig } from '
|
|
1
|
+
import { PortalThemeConfig } from '../types/portal';
|
|
2
2
|
export declare const darkTheme: PortalThemeConfig;
|
|
3
3
|
export declare const lightTheme: PortalThemeConfig;
|
|
4
4
|
export declare const corporateBlueTheme: PortalThemeConfig;
|