@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
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, Holding, Order, Portfolio, BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerDataOptions, SessionState, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, TradingContext, BrokerConnection, TokenInfo, OrdersFilter, PositionsFilter, AccountsFilter } from '../types/api';
|
|
2
|
+
import { PaginatedResult } from '../types';
|
|
3
|
+
import { DeviceInfo } from '../types/api';
|
|
4
|
+
import { ApiError } from '../utils/errors';
|
|
5
|
+
export declare class ApiClient {
|
|
6
|
+
private readonly baseUrl;
|
|
7
|
+
protected readonly deviceInfo?: DeviceInfo;
|
|
8
|
+
protected currentSessionState: SessionState | null;
|
|
9
|
+
protected currentSessionId: string | null;
|
|
10
|
+
private tradingContext;
|
|
11
|
+
private tokenInfo;
|
|
12
|
+
private refreshPromise;
|
|
13
|
+
private readonly REFRESH_BUFFER_MINUTES;
|
|
14
|
+
private companyId;
|
|
15
|
+
private csrfToken;
|
|
16
|
+
constructor(baseUrl: string, deviceInfo?: DeviceInfo);
|
|
17
|
+
/**
|
|
18
|
+
* Set session context (session ID, company ID, CSRF token)
|
|
19
|
+
*/
|
|
20
|
+
setSessionContext(sessionId: string, companyId: string, csrfToken?: string): void;
|
|
21
|
+
/**
|
|
22
|
+
* Get the current session ID
|
|
23
|
+
*/
|
|
24
|
+
getCurrentSessionId(): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Get the current company ID
|
|
27
|
+
*/
|
|
28
|
+
getCurrentCompanyId(): string | null;
|
|
29
|
+
/**
|
|
30
|
+
* Get the current CSRF token
|
|
31
|
+
*/
|
|
32
|
+
getCurrentCsrfToken(): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Store tokens after successful authentication
|
|
35
|
+
*/
|
|
36
|
+
setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Get the current access token, refreshing if necessary
|
|
39
|
+
*/
|
|
40
|
+
getValidAccessToken(): Promise<string>;
|
|
41
|
+
/**
|
|
42
|
+
* Check if the current token is expired or about to expire
|
|
43
|
+
*/
|
|
44
|
+
private isTokenExpired;
|
|
45
|
+
/**
|
|
46
|
+
* Refresh the access token using the refresh token
|
|
47
|
+
*/
|
|
48
|
+
private refreshTokens;
|
|
49
|
+
/**
|
|
50
|
+
* Perform the actual token refresh request
|
|
51
|
+
*/
|
|
52
|
+
private performTokenRefresh;
|
|
53
|
+
/**
|
|
54
|
+
* Clear stored tokens (useful for logout)
|
|
55
|
+
*/
|
|
56
|
+
clearTokens(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Get current token info (for debugging/testing)
|
|
59
|
+
*/
|
|
60
|
+
getTokenInfo(): TokenInfo | null;
|
|
61
|
+
/**
|
|
62
|
+
* Make a request to the API.
|
|
63
|
+
*/
|
|
64
|
+
protected request<T>(path: string, options: {
|
|
65
|
+
method: string;
|
|
66
|
+
headers?: Record<string, string>;
|
|
67
|
+
body?: any;
|
|
68
|
+
params?: Record<string, string>;
|
|
69
|
+
}): Promise<T>;
|
|
70
|
+
/**
|
|
71
|
+
* Handle API errors. This method can be overridden by language-specific implementations.
|
|
72
|
+
*/
|
|
73
|
+
protected handleError(status: number, error: any): ApiError;
|
|
74
|
+
startSession(token: string, userId?: string): Promise<SessionResponse>;
|
|
75
|
+
requestOtp(sessionId: string, email: string): Promise<OtpRequestResponse>;
|
|
76
|
+
verifyOtp(sessionId: string, otp: string): Promise<OtpVerifyResponse>;
|
|
77
|
+
authenticateDirectly(sessionId: string, userId: string): Promise<SessionAuthenticateResponse>;
|
|
78
|
+
/**
|
|
79
|
+
* Get the portal URL for an active session
|
|
80
|
+
* @param sessionId The session identifier
|
|
81
|
+
* @returns Portal URL response
|
|
82
|
+
* @throws SessionError if session is not in ACTIVE state
|
|
83
|
+
*/
|
|
84
|
+
getPortalUrl(sessionId: string): Promise<PortalUrlResponse>;
|
|
85
|
+
validatePortalSession(sessionId: string, signature: string): Promise<SessionValidationResponse>;
|
|
86
|
+
completePortalSession(sessionId: string): Promise<PortalUrlResponse>;
|
|
87
|
+
getHoldings(accessToken: string): Promise<{
|
|
88
|
+
data: Holding[];
|
|
89
|
+
}>;
|
|
90
|
+
getOrders(accessToken: string): Promise<{
|
|
91
|
+
data: Order[];
|
|
92
|
+
}>;
|
|
93
|
+
getPortfolio(accessToken: string): Promise<{
|
|
94
|
+
data: Portfolio;
|
|
95
|
+
}>;
|
|
96
|
+
placeOrder(accessToken: string, order: Order): Promise<void>;
|
|
97
|
+
getHoldingsAuto(): Promise<{
|
|
98
|
+
data: Holding[];
|
|
99
|
+
}>;
|
|
100
|
+
getOrdersAuto(): Promise<{
|
|
101
|
+
data: Order[];
|
|
102
|
+
}>;
|
|
103
|
+
getPortfolioAuto(): Promise<{
|
|
104
|
+
data: Portfolio;
|
|
105
|
+
}>;
|
|
106
|
+
placeOrderAuto(order: Order): Promise<void>;
|
|
107
|
+
placeBrokerOrder(accessToken: string, params: Partial<BrokerOrderParams> & {
|
|
108
|
+
symbol: string;
|
|
109
|
+
orderQty: number;
|
|
110
|
+
action: 'Buy' | 'Sell';
|
|
111
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
|
|
112
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
113
|
+
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
114
|
+
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
115
|
+
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any): Promise<OrderResponse>;
|
|
116
|
+
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
117
|
+
setAccount(accountNumber: string, accountId?: string): void;
|
|
118
|
+
getTradingContext(): TradingContext;
|
|
119
|
+
clearTradingContext(): void;
|
|
120
|
+
placeStockMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
121
|
+
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>;
|
|
122
|
+
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>;
|
|
123
|
+
placeCryptoMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options?: CryptoOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
124
|
+
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>;
|
|
125
|
+
placeOptionsMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', options: OptionsOrderOptions, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
126
|
+
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>;
|
|
127
|
+
placeFuturesMarketOrder(accessToken: string, symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
128
|
+
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>;
|
|
129
|
+
private buildOrderRequestBody;
|
|
130
|
+
private buildModifyRequestBody;
|
|
131
|
+
private applyBrokerDefaults;
|
|
132
|
+
revokeToken(accessToken: string): Promise<void>;
|
|
133
|
+
getUserToken(userId: string): Promise<UserToken>;
|
|
134
|
+
getCurrentSessionState(): SessionState | null;
|
|
135
|
+
getBrokerList(accessToken: string): Promise<{
|
|
136
|
+
_id: string;
|
|
137
|
+
response_data: BrokerInfo[];
|
|
138
|
+
message: string;
|
|
139
|
+
status_code: number;
|
|
140
|
+
warnings: null;
|
|
141
|
+
errors: null;
|
|
142
|
+
}>;
|
|
143
|
+
getBrokerAccounts(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
144
|
+
_id: string;
|
|
145
|
+
response_data: BrokerAccount[];
|
|
146
|
+
message: string;
|
|
147
|
+
status_code: number;
|
|
148
|
+
warnings: null;
|
|
149
|
+
errors: null;
|
|
150
|
+
}>;
|
|
151
|
+
getBrokerOrders(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
152
|
+
_id: string;
|
|
153
|
+
response_data: BrokerOrder[];
|
|
154
|
+
message: string;
|
|
155
|
+
status_code: number;
|
|
156
|
+
warnings: null;
|
|
157
|
+
errors: null;
|
|
158
|
+
}>;
|
|
159
|
+
getBrokerPositions(accessToken: string, options?: BrokerDataOptions): Promise<{
|
|
160
|
+
_id: string;
|
|
161
|
+
response_data: BrokerPosition[];
|
|
162
|
+
message: string;
|
|
163
|
+
status_code: number;
|
|
164
|
+
warnings: null;
|
|
165
|
+
errors: null;
|
|
166
|
+
}>;
|
|
167
|
+
getBrokerConnections(accessToken: string): Promise<{
|
|
168
|
+
_id: string;
|
|
169
|
+
response_data: BrokerConnection[];
|
|
170
|
+
message: string;
|
|
171
|
+
status_code: number;
|
|
172
|
+
warnings: null;
|
|
173
|
+
errors: null;
|
|
174
|
+
}>;
|
|
175
|
+
getBrokerListAuto(): Promise<{
|
|
176
|
+
_id: string;
|
|
177
|
+
response_data: BrokerInfo[];
|
|
178
|
+
message: string;
|
|
179
|
+
status_code: number;
|
|
180
|
+
warnings: null;
|
|
181
|
+
errors: null;
|
|
182
|
+
}>;
|
|
183
|
+
getBrokerAccountsAuto(options?: BrokerDataOptions): Promise<{
|
|
184
|
+
_id: string;
|
|
185
|
+
response_data: BrokerAccount[];
|
|
186
|
+
message: string;
|
|
187
|
+
status_code: number;
|
|
188
|
+
warnings: null;
|
|
189
|
+
errors: null;
|
|
190
|
+
}>;
|
|
191
|
+
getBrokerOrdersAuto(options?: BrokerDataOptions): Promise<{
|
|
192
|
+
_id: string;
|
|
193
|
+
response_data: BrokerOrder[];
|
|
194
|
+
message: string;
|
|
195
|
+
status_code: number;
|
|
196
|
+
warnings: null;
|
|
197
|
+
errors: null;
|
|
198
|
+
}>;
|
|
199
|
+
getBrokerPositionsAuto(options?: BrokerDataOptions): Promise<{
|
|
200
|
+
_id: string;
|
|
201
|
+
response_data: BrokerPosition[];
|
|
202
|
+
message: string;
|
|
203
|
+
status_code: number;
|
|
204
|
+
warnings: null;
|
|
205
|
+
errors: null;
|
|
206
|
+
}>;
|
|
207
|
+
getBrokerConnectionsAuto(): Promise<{
|
|
208
|
+
_id: string;
|
|
209
|
+
response_data: BrokerConnection[];
|
|
210
|
+
message: string;
|
|
211
|
+
status_code: number;
|
|
212
|
+
warnings: null;
|
|
213
|
+
errors: null;
|
|
214
|
+
}>;
|
|
215
|
+
placeBrokerOrderAuto(params: Partial<BrokerOrderParams> & {
|
|
216
|
+
symbol: string;
|
|
217
|
+
orderQty: number;
|
|
218
|
+
action: 'Buy' | 'Sell';
|
|
219
|
+
orderType: 'Market' | 'Limit' | 'Stop' | 'TrailingStop';
|
|
220
|
+
assetType: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
221
|
+
}, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
222
|
+
placeStockMarketOrderAuto(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
223
|
+
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>;
|
|
224
|
+
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>;
|
|
225
|
+
getBrokerOrdersPage(page?: number, perPage?: number, filters?: OrdersFilter): Promise<PaginatedResult<BrokerOrder[]>>;
|
|
226
|
+
getBrokerAccountsPage(page?: number, perPage?: number, filters?: AccountsFilter): Promise<PaginatedResult<BrokerAccount[]>>;
|
|
227
|
+
getBrokerPositionsPage(page?: number, perPage?: number, filters?: PositionsFilter): Promise<PaginatedResult<BrokerPosition[]>>;
|
|
228
|
+
getNextPage<T>(previousResult: PaginatedResult<T>, fetchFunction: (offset: number, limit: number) => Promise<PaginatedResult<T>>): Promise<PaginatedResult<T> | null>;
|
|
229
|
+
/**
|
|
230
|
+
* Check if this is a mock client
|
|
231
|
+
* @returns false for real API client
|
|
232
|
+
*/
|
|
233
|
+
isMockClient(): boolean;
|
|
234
|
+
}
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { EventEmitter } from '../utils/events';
|
|
2
|
+
import { PaginatedResult } from '../types';
|
|
3
|
+
import { BrokerInfo, OrderResponse, TradingContext, BrokerConnection, OrdersFilter, PositionsFilter, AccountsFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount } from '../types/api';
|
|
4
|
+
import { FinaticConnectOptions, PortalOptions } from '../types/connect';
|
|
5
|
+
interface DeviceInfo {
|
|
6
|
+
ip_address: string;
|
|
7
|
+
user_agent: string;
|
|
8
|
+
fingerprint: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class FinaticConnect extends EventEmitter {
|
|
11
|
+
private static instance;
|
|
12
|
+
private apiClient;
|
|
13
|
+
private portalUI;
|
|
14
|
+
private options;
|
|
15
|
+
private userToken;
|
|
16
|
+
private sessionId;
|
|
17
|
+
private companyId;
|
|
18
|
+
private baseUrl;
|
|
19
|
+
private readonly BROKER_LIST_CACHE_KEY;
|
|
20
|
+
private readonly BROKER_LIST_CACHE_VERSION;
|
|
21
|
+
private readonly BROKER_LIST_CACHE_DURATION;
|
|
22
|
+
private readonly deviceInfo?;
|
|
23
|
+
private currentSessionState;
|
|
24
|
+
constructor(options: FinaticConnectOptions, deviceInfo?: DeviceInfo);
|
|
25
|
+
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
|
+
* Check if the user is fully authenticated (has userId, access token, and refresh token)
|
|
33
|
+
* @returns True if the user is fully authenticated and ready for API calls
|
|
34
|
+
*/
|
|
35
|
+
isAuthed(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Get user's orders with pagination and optional filtering
|
|
38
|
+
* @param params - Query parameters including page, perPage, and filters
|
|
39
|
+
* @returns Promise with paginated result that supports navigation
|
|
40
|
+
*/
|
|
41
|
+
getOrders(params?: {
|
|
42
|
+
page?: number;
|
|
43
|
+
perPage?: number;
|
|
44
|
+
filter?: OrdersFilter;
|
|
45
|
+
}): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
46
|
+
/**
|
|
47
|
+
* Get user's positions with pagination and optional filtering
|
|
48
|
+
* @param params - Query parameters including page, perPage, and filters
|
|
49
|
+
* @returns Promise with paginated result that supports navigation
|
|
50
|
+
*/
|
|
51
|
+
getPositions(params?: {
|
|
52
|
+
page?: number;
|
|
53
|
+
perPage?: number;
|
|
54
|
+
filter?: PositionsFilter;
|
|
55
|
+
}): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
56
|
+
/**
|
|
57
|
+
* Get user's accounts with pagination and optional filtering
|
|
58
|
+
* @param params - Query parameters including page, perPage, and filters
|
|
59
|
+
* @returns Promise with paginated result that supports navigation
|
|
60
|
+
*/
|
|
61
|
+
getAccounts(params?: {
|
|
62
|
+
page?: number;
|
|
63
|
+
perPage?: number;
|
|
64
|
+
filter?: AccountsFilter;
|
|
65
|
+
}): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
66
|
+
/**
|
|
67
|
+
* Revoke the current user's access
|
|
68
|
+
*/
|
|
69
|
+
revokeToken(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Initialize the Finatic Connect SDK
|
|
72
|
+
* @param token - The portal token from your backend
|
|
73
|
+
* @param userId - Optional: The user ID if you have it from a previous session
|
|
74
|
+
* @param options - Optional configuration including baseUrl
|
|
75
|
+
* @returns FinaticConnect instance
|
|
76
|
+
*/
|
|
77
|
+
static init(token: string, userId?: string | null | undefined, options?: {
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
} | undefined): Promise<FinaticConnect>;
|
|
80
|
+
/**
|
|
81
|
+
* Initialize the SDK with a user ID
|
|
82
|
+
* @param userId - The user ID from a previous session
|
|
83
|
+
*/
|
|
84
|
+
setUserId(userId: string): Promise<void>;
|
|
85
|
+
private initializeWithUser;
|
|
86
|
+
/**
|
|
87
|
+
* Handle company access error by opening the portal
|
|
88
|
+
* @param error The company access error
|
|
89
|
+
* @param options Optional configuration for the portal
|
|
90
|
+
*/
|
|
91
|
+
private handleCompanyAccessError;
|
|
92
|
+
/**
|
|
93
|
+
* Open the portal for user authentication
|
|
94
|
+
* @param options Optional configuration for the portal
|
|
95
|
+
*/
|
|
96
|
+
openPortal(options?: PortalOptions): Promise<void>;
|
|
97
|
+
/**
|
|
98
|
+
* Close the Finatic Connect Portal
|
|
99
|
+
*/
|
|
100
|
+
closePortal(): void;
|
|
101
|
+
/**
|
|
102
|
+
* Initialize a new session
|
|
103
|
+
* @param oneTimeToken - The one-time token from initSession
|
|
104
|
+
*/
|
|
105
|
+
protected startSession(oneTimeToken: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Place a new order using the broker order API
|
|
108
|
+
* @param order - Order details with broker context
|
|
109
|
+
*/
|
|
110
|
+
placeOrder(order: {
|
|
111
|
+
symbol: string;
|
|
112
|
+
quantity: number;
|
|
113
|
+
side: 'buy' | 'sell';
|
|
114
|
+
orderType: 'market' | 'limit' | 'stop' | 'stop_limit';
|
|
115
|
+
price?: number;
|
|
116
|
+
stopPrice?: number;
|
|
117
|
+
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
118
|
+
broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader';
|
|
119
|
+
accountNumber?: string;
|
|
120
|
+
assetType?: 'Stock' | 'Option' | 'Crypto' | 'Futures';
|
|
121
|
+
}): Promise<OrderResponse>;
|
|
122
|
+
/**
|
|
123
|
+
* Cancel a broker order
|
|
124
|
+
* @param orderId - The order ID to cancel
|
|
125
|
+
* @param broker - Optional broker override
|
|
126
|
+
*/
|
|
127
|
+
cancelOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader'): Promise<OrderResponse>;
|
|
128
|
+
/**
|
|
129
|
+
* Modify a broker order
|
|
130
|
+
* @param orderId - The order ID to modify
|
|
131
|
+
* @param modifications - The modifications to apply
|
|
132
|
+
* @param broker - Optional broker override
|
|
133
|
+
*/
|
|
134
|
+
modifyOrder(orderId: string, modifications: Partial<{
|
|
135
|
+
symbol: string;
|
|
136
|
+
quantity: number;
|
|
137
|
+
price: number;
|
|
138
|
+
stopPrice: number;
|
|
139
|
+
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
140
|
+
}>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader'): Promise<OrderResponse>;
|
|
141
|
+
/**
|
|
142
|
+
* Set the broker context for trading
|
|
143
|
+
* @param broker - The broker to use for trading
|
|
144
|
+
*/
|
|
145
|
+
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
146
|
+
/**
|
|
147
|
+
* Set the account context for trading
|
|
148
|
+
* @param accountNumber - The account number to use for trading
|
|
149
|
+
* @param accountId - Optional account ID
|
|
150
|
+
*/
|
|
151
|
+
setAccount(accountNumber: string, accountId?: string): void;
|
|
152
|
+
/**
|
|
153
|
+
* Get the current trading context
|
|
154
|
+
*/
|
|
155
|
+
getTradingContext(): TradingContext;
|
|
156
|
+
/**
|
|
157
|
+
* Clear the trading context
|
|
158
|
+
*/
|
|
159
|
+
clearTradingContext(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Place a stock market order (convenience method)
|
|
162
|
+
*/
|
|
163
|
+
placeStockMarketOrder(symbol: string, quantity: number, side: 'buy' | 'sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string): Promise<OrderResponse>;
|
|
164
|
+
/**
|
|
165
|
+
* Place a stock limit order (convenience method)
|
|
166
|
+
*/
|
|
167
|
+
placeStockLimitOrder(symbol: string, quantity: number, side: 'buy' | 'sell', price: number, timeInForce?: 'day' | 'gtc', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string): Promise<OrderResponse>;
|
|
168
|
+
/**
|
|
169
|
+
* Get the current user ID
|
|
170
|
+
* @returns The current user ID or undefined if not authenticated
|
|
171
|
+
* @throws AuthenticationError if user is not authenticated
|
|
172
|
+
*/
|
|
173
|
+
getUserId(): string | null;
|
|
174
|
+
/**
|
|
175
|
+
* Get list of supported brokers
|
|
176
|
+
* @returns Promise with array of broker information
|
|
177
|
+
*/
|
|
178
|
+
getBrokerList(): Promise<BrokerInfo[]>;
|
|
179
|
+
/**
|
|
180
|
+
* Get broker connections
|
|
181
|
+
* @returns Promise with array of broker connections
|
|
182
|
+
* @throws AuthenticationError if user is not authenticated
|
|
183
|
+
*/
|
|
184
|
+
getBrokerConnections(): Promise<BrokerConnection[]>;
|
|
185
|
+
/**
|
|
186
|
+
* Get only open positions
|
|
187
|
+
* @returns Promise with array of open positions
|
|
188
|
+
*/
|
|
189
|
+
getOpenPositions(): Promise<BrokerDataPosition[]>;
|
|
190
|
+
/**
|
|
191
|
+
* Get only filled orders
|
|
192
|
+
* @returns Promise with array of filled orders
|
|
193
|
+
*/
|
|
194
|
+
getFilledOrders(): Promise<BrokerDataOrder[]>;
|
|
195
|
+
/**
|
|
196
|
+
* Get only pending orders
|
|
197
|
+
* @returns Promise with array of pending orders
|
|
198
|
+
*/
|
|
199
|
+
getPendingOrders(): Promise<BrokerDataOrder[]>;
|
|
200
|
+
/**
|
|
201
|
+
* Get only active accounts
|
|
202
|
+
* @returns Promise with array of active accounts
|
|
203
|
+
*/
|
|
204
|
+
getActiveAccounts(): Promise<BrokerDataAccount[]>;
|
|
205
|
+
/**
|
|
206
|
+
* Get orders for a specific symbol
|
|
207
|
+
* @param symbol - The symbol to filter by
|
|
208
|
+
* @returns Promise with array of orders for the symbol
|
|
209
|
+
*/
|
|
210
|
+
getOrdersBySymbol(symbol: string): Promise<BrokerDataOrder[]>;
|
|
211
|
+
/**
|
|
212
|
+
* Get positions for a specific symbol
|
|
213
|
+
* @param symbol - The symbol to filter by
|
|
214
|
+
* @returns Promise with array of positions for the symbol
|
|
215
|
+
*/
|
|
216
|
+
getPositionsBySymbol(symbol: string): Promise<BrokerDataPosition[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Get orders for a specific broker
|
|
219
|
+
* @param brokerId - The broker ID to filter by
|
|
220
|
+
* @returns Promise with array of orders for the broker
|
|
221
|
+
*/
|
|
222
|
+
getOrdersByBroker(brokerId: string): Promise<BrokerDataOrder[]>;
|
|
223
|
+
/**
|
|
224
|
+
* Get positions for a specific broker
|
|
225
|
+
* @param brokerId - The broker ID to filter by
|
|
226
|
+
* @returns Promise with array of positions for the broker
|
|
227
|
+
*/
|
|
228
|
+
getPositionsByBroker(brokerId: string): Promise<BrokerDataPosition[]>;
|
|
229
|
+
/**
|
|
230
|
+
* Get a specific page of orders with pagination metadata
|
|
231
|
+
* @param page - Page number (default: 1)
|
|
232
|
+
* @param perPage - Items per page (default: 100)
|
|
233
|
+
* @param filter - Optional filter parameters
|
|
234
|
+
* @returns Promise with paginated orders result
|
|
235
|
+
*/
|
|
236
|
+
getOrdersPage(page?: number, perPage?: number, filter?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
237
|
+
/**
|
|
238
|
+
* Get a specific page of positions with pagination metadata
|
|
239
|
+
* @param page - Page number (default: 1)
|
|
240
|
+
* @param perPage - Items per page (default: 100)
|
|
241
|
+
* @param filter - Optional filter parameters
|
|
242
|
+
* @returns Promise with paginated positions result
|
|
243
|
+
*/
|
|
244
|
+
getPositionsPage(page?: number, perPage?: number, filter?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
245
|
+
/**
|
|
246
|
+
* Get a specific page of accounts with pagination metadata
|
|
247
|
+
* @param page - Page number (default: 1)
|
|
248
|
+
* @param perPage - Items per page (default: 100)
|
|
249
|
+
* @param filter - Optional filter parameters
|
|
250
|
+
* @returns Promise with paginated accounts result
|
|
251
|
+
*/
|
|
252
|
+
getAccountsPage(page?: number, perPage?: number, filter?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
253
|
+
/**
|
|
254
|
+
* Get the next page of orders
|
|
255
|
+
* @param previousResult - The previous paginated result
|
|
256
|
+
* @returns Promise with next page of orders or null if no more pages
|
|
257
|
+
*/
|
|
258
|
+
getNextOrdersPage(previousResult: PaginatedResult<BrokerDataOrder[]>): Promise<PaginatedResult<BrokerDataOrder[]> | null>;
|
|
259
|
+
/**
|
|
260
|
+
* Get the next page of positions
|
|
261
|
+
* @param previousResult - The previous paginated result
|
|
262
|
+
* @returns Promise with next page of positions or null if no more pages
|
|
263
|
+
*/
|
|
264
|
+
getNextPositionsPage(previousResult: PaginatedResult<BrokerDataPosition[]>): Promise<PaginatedResult<BrokerDataPosition[]> | null>;
|
|
265
|
+
/**
|
|
266
|
+
* Get the next page of accounts
|
|
267
|
+
* @param previousResult - The previous paginated result
|
|
268
|
+
* @returns Promise with next page of accounts or null if no more pages
|
|
269
|
+
*/
|
|
270
|
+
getNextAccountsPage(previousResult: PaginatedResult<BrokerDataAccount[]>): Promise<PaginatedResult<BrokerDataAccount[]> | null>;
|
|
271
|
+
/**
|
|
272
|
+
* Get all orders across all pages (convenience method)
|
|
273
|
+
* @param filter - Optional filter parameters
|
|
274
|
+
* @returns Promise with all orders
|
|
275
|
+
*/
|
|
276
|
+
getAllOrders(filter?: OrdersFilter): Promise<BrokerDataOrder[]>;
|
|
277
|
+
/**
|
|
278
|
+
* Get all positions across all pages (convenience method)
|
|
279
|
+
* @param filter - Optional filter parameters
|
|
280
|
+
* @returns Promise with all positions
|
|
281
|
+
*/
|
|
282
|
+
getAllPositions(filter?: PositionsFilter): Promise<BrokerDataPosition[]>;
|
|
283
|
+
/**
|
|
284
|
+
* Get all accounts across all pages (convenience method)
|
|
285
|
+
* @param filter - Optional filter parameters
|
|
286
|
+
* @returns Promise with all accounts
|
|
287
|
+
*/
|
|
288
|
+
getAllAccounts(filter?: AccountsFilter): Promise<BrokerDataAccount[]>;
|
|
289
|
+
/**
|
|
290
|
+
* Register automatic session cleanup on page unload/visibility change
|
|
291
|
+
*/
|
|
292
|
+
private registerSessionCleanup;
|
|
293
|
+
/**
|
|
294
|
+
* Handle session cleanup when page is unloading
|
|
295
|
+
*/
|
|
296
|
+
private handleSessionCleanup;
|
|
297
|
+
/**
|
|
298
|
+
* Handle visibility change (mobile browsers)
|
|
299
|
+
*/
|
|
300
|
+
private handleVisibilityChange;
|
|
301
|
+
/**
|
|
302
|
+
* Complete the session by calling the API
|
|
303
|
+
* @param sessionId - The session ID to complete
|
|
304
|
+
*/
|
|
305
|
+
private completeSession;
|
|
306
|
+
}
|
|
307
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
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/api';
|
|
2
|
+
export type { SDKConfig, PortalConfig } from './types/config';
|
|
3
|
+
export type { Theme } from './types/theme';
|
|
4
|
+
export type { FinaticConnectOptions, FinaticUserToken, PortalMessage } from './types/connect';
|
|
5
|
+
export type { PortalProps, PortalTheme, PortalThemeConfig, PortalThemePreset, } from './types/portal';
|
|
6
|
+
export type { BaseError, ApiError, SessionError, AuthenticationError, AuthorizationError, RateLimitError, TokenError, ValidationError, NetworkError, SecurityError, } from './types/errors';
|
|
7
|
+
export { ApiClient } from './client/ApiClient';
|
|
8
|
+
export { FinaticConnect } from './client/FinaticConnect';
|
|
9
|
+
export { CoreTradingService } from './services/TradingService';
|
|
10
|
+
export { CoreAnalyticsService } from './services/AnalyticsService';
|
|
11
|
+
export { CorePortalService } from './services/PortalService';
|
|
12
|
+
export { PaginatedResult } from './types';
|
|
13
|
+
export * from './utils/errors';
|
|
14
|
+
export * from './utils/events';
|
|
15
|
+
export * from './utils/themeUtils';
|
|
16
|
+
export { portalThemePresets } from './shared/themes/portalPresets';
|
|
17
|
+
export { MockFactory } from './mocks/MockFactory';
|