@finatic/client 0.0.139 → 0.0.141
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 +335 -446
- package/dist/index.d.ts +272 -515
- package/dist/index.js +531 -449
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +532 -449
- package/dist/index.mjs.map +1 -1
- package/dist/types/core/client/ApiClient.d.ts +81 -27
- package/dist/types/core/client/FinaticConnect.d.ts +53 -103
- package/dist/types/index.d.ts +1 -2
- package/dist/types/mocks/MockApiClient.d.ts +2 -4
- package/dist/types/mocks/utils.d.ts +0 -5
- package/dist/types/types/api/auth.d.ts +12 -30
- package/dist/types/types/api/broker.d.ts +117 -1
- package/package.json +7 -3
- package/src/core/client/ApiClient.ts +1978 -0
- package/src/core/client/FinaticConnect.ts +1557 -0
- package/src/core/portal/PortalUI.ts +300 -0
- package/src/index.d.ts +23 -0
- package/src/index.ts +99 -0
- package/src/mocks/MockApiClient.ts +1032 -0
- package/src/mocks/MockDataProvider.ts +986 -0
- package/src/mocks/MockFactory.ts +97 -0
- package/src/mocks/utils.ts +133 -0
- package/src/themes/portalPresets.ts +1307 -0
- package/src/types/api/auth.ts +112 -0
- package/src/types/api/broker.ts +461 -0
- package/src/types/api/core.ts +53 -0
- package/src/types/api/errors.ts +35 -0
- package/src/types/api/orders.ts +45 -0
- package/src/types/api/portfolio.ts +59 -0
- package/src/types/common/pagination.ts +138 -0
- package/src/types/connect.ts +56 -0
- package/src/types/index.ts +25 -0
- package/src/types/portal.ts +214 -0
- package/src/types/ui/theme.ts +105 -0
- package/src/utils/brokerUtils.ts +85 -0
- package/src/utils/errors.ts +104 -0
- package/src/utils/events.ts +54 -0
- package/src/utils/themeUtils.ts +146 -0
|
@@ -3,11 +3,10 @@ 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';
|
|
7
|
-
import { TradingContext } from '../../types/api/orders';
|
|
6
|
+
import { OrdersFilter, PositionsFilter, AccountsFilter, BalancesFilter, OrderFill, OrderEvent, OrderGroup, PositionLot, PositionLotFill, OrderFillsFilter, OrderEventsFilter, OrderGroupsFilter, PositionLotsFilter, PositionLotFillsFilter } from '../../types/api/broker';
|
|
8
7
|
import { PaginatedResult } from '../../types/common/pagination';
|
|
9
8
|
import { PortalUrlResponse } from '../../types/api/core';
|
|
10
|
-
import { DeviceInfo, SessionState,
|
|
9
|
+
import { DeviceInfo, SessionState, SessionResponse, OtpRequestResponse, OtpVerifyResponse, SessionAuthenticateResponse, UserToken } from '../../types/api/auth';
|
|
11
10
|
import { ApiError } from '../../utils/errors';
|
|
12
11
|
export declare class ApiClient {
|
|
13
12
|
private readonly baseUrl;
|
|
@@ -15,9 +14,6 @@ export declare class ApiClient {
|
|
|
15
14
|
protected currentSessionState: SessionState | null;
|
|
16
15
|
protected currentSessionId: string | null;
|
|
17
16
|
private tradingContext;
|
|
18
|
-
private tokenInfo;
|
|
19
|
-
private refreshPromise;
|
|
20
|
-
private readonly REFRESH_BUFFER_MINUTES;
|
|
21
17
|
private companyId;
|
|
22
18
|
private csrfToken;
|
|
23
19
|
constructor(baseUrl: string, deviceInfo?: DeviceInfo);
|
|
@@ -38,33 +34,24 @@ export declare class ApiClient {
|
|
|
38
34
|
*/
|
|
39
35
|
getCurrentCsrfToken(): string | null;
|
|
40
36
|
/**
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
setTokens(accessToken: string, refreshToken: string, expiresAt: string, userId?: string): void;
|
|
44
|
-
/**
|
|
45
|
-
* Get the current access token, refreshing if necessary
|
|
37
|
+
* Get a valid access token (session-based auth - no tokens needed)
|
|
46
38
|
*/
|
|
47
39
|
getValidAccessToken(): Promise<string>;
|
|
48
40
|
/**
|
|
49
|
-
*
|
|
50
|
-
*/
|
|
51
|
-
private isTokenExpired;
|
|
52
|
-
/**
|
|
53
|
-
* Refresh the access token using the refresh token
|
|
54
|
-
*/
|
|
55
|
-
private refreshTokens;
|
|
56
|
-
/**
|
|
57
|
-
* Perform the actual token refresh request
|
|
41
|
+
* Perform the actual Supabase session refresh
|
|
58
42
|
*/
|
|
59
|
-
private performTokenRefresh;
|
|
60
43
|
/**
|
|
61
|
-
* Clear
|
|
44
|
+
* Clear session tokens (useful for logout)
|
|
62
45
|
*/
|
|
63
46
|
clearTokens(): void;
|
|
64
47
|
/**
|
|
65
|
-
* Get current
|
|
48
|
+
* Get current session info (for debugging/testing) - session-based auth
|
|
66
49
|
*/
|
|
67
|
-
getTokenInfo():
|
|
50
|
+
getTokenInfo(): {
|
|
51
|
+
accessToken: string;
|
|
52
|
+
refreshToken: string;
|
|
53
|
+
expiresAt: number;
|
|
54
|
+
} | null;
|
|
68
55
|
/**
|
|
69
56
|
* Make a request to the API.
|
|
70
57
|
*/
|
|
@@ -98,14 +85,12 @@ export declare class ApiClient {
|
|
|
98
85
|
orderQty: number;
|
|
99
86
|
action: 'Buy' | 'Sell';
|
|
100
87
|
orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
|
|
101
|
-
assetType: '
|
|
88
|
+
assetType: 'equity' | 'equity_option' | 'crypto' | 'forex' | 'future' | 'future_option';
|
|
102
89
|
}, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
103
90
|
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
104
91
|
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
105
92
|
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
106
93
|
setAccount(accountNumber: string, accountId?: string): void;
|
|
107
|
-
getTradingContext(): TradingContext;
|
|
108
|
-
clearTradingContext(): void;
|
|
109
94
|
placeStockMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
110
95
|
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>;
|
|
111
96
|
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>;
|
|
@@ -125,6 +110,7 @@ export declare class ApiClient {
|
|
|
125
110
|
getCurrentSessionState(): SessionState | null;
|
|
126
111
|
/**
|
|
127
112
|
* Refresh the current session to extend its lifetime
|
|
113
|
+
* Note: This now uses Supabase session refresh instead of custom endpoint
|
|
128
114
|
*/
|
|
129
115
|
refreshSession(): Promise<{
|
|
130
116
|
success: boolean;
|
|
@@ -211,4 +197,72 @@ export declare class ApiClient {
|
|
|
211
197
|
* @returns Promise with disconnect response
|
|
212
198
|
*/
|
|
213
199
|
disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
200
|
+
/**
|
|
201
|
+
* Get order fills for a specific order
|
|
202
|
+
* @param orderId - The order ID
|
|
203
|
+
* @param filter - Optional filter parameters
|
|
204
|
+
* @returns Promise with order fills response
|
|
205
|
+
*/
|
|
206
|
+
getOrderFills(orderId: string, filter?: OrderFillsFilter): Promise<{
|
|
207
|
+
_id: string;
|
|
208
|
+
response_data: OrderFill[];
|
|
209
|
+
message: string;
|
|
210
|
+
status_code: number;
|
|
211
|
+
warnings: null;
|
|
212
|
+
errors: null;
|
|
213
|
+
}>;
|
|
214
|
+
/**
|
|
215
|
+
* Get order events for a specific order
|
|
216
|
+
* @param orderId - The order ID
|
|
217
|
+
* @param filter - Optional filter parameters
|
|
218
|
+
* @returns Promise with order events response
|
|
219
|
+
*/
|
|
220
|
+
getOrderEvents(orderId: string, filter?: OrderEventsFilter): Promise<{
|
|
221
|
+
_id: string;
|
|
222
|
+
response_data: OrderEvent[];
|
|
223
|
+
message: string;
|
|
224
|
+
status_code: number;
|
|
225
|
+
warnings: null;
|
|
226
|
+
errors: null;
|
|
227
|
+
}>;
|
|
228
|
+
/**
|
|
229
|
+
* Get order groups
|
|
230
|
+
* @param filter - Optional filter parameters
|
|
231
|
+
* @returns Promise with order groups response
|
|
232
|
+
*/
|
|
233
|
+
getOrderGroups(filter?: OrderGroupsFilter): Promise<{
|
|
234
|
+
_id: string;
|
|
235
|
+
response_data: OrderGroup[];
|
|
236
|
+
message: string;
|
|
237
|
+
status_code: number;
|
|
238
|
+
warnings: null;
|
|
239
|
+
errors: null;
|
|
240
|
+
}>;
|
|
241
|
+
/**
|
|
242
|
+
* Get position lots (tax lots for positions)
|
|
243
|
+
* @param filter - Optional filter parameters
|
|
244
|
+
* @returns Promise with position lots response
|
|
245
|
+
*/
|
|
246
|
+
getPositionLots(filter?: PositionLotsFilter): Promise<{
|
|
247
|
+
_id: string;
|
|
248
|
+
response_data: PositionLot[];
|
|
249
|
+
message: string;
|
|
250
|
+
status_code: number;
|
|
251
|
+
warnings: null;
|
|
252
|
+
errors: null;
|
|
253
|
+
}>;
|
|
254
|
+
/**
|
|
255
|
+
* Get position lot fills for a specific lot
|
|
256
|
+
* @param lotId - The position lot ID
|
|
257
|
+
* @param filter - Optional filter parameters
|
|
258
|
+
* @returns Promise with position lot fills response
|
|
259
|
+
*/
|
|
260
|
+
getPositionLotFills(lotId: string, filter?: PositionLotFillsFilter): Promise<{
|
|
261
|
+
_id: string;
|
|
262
|
+
response_data: PositionLotFill[];
|
|
263
|
+
message: string;
|
|
264
|
+
status_code: number;
|
|
265
|
+
warnings: null;
|
|
266
|
+
errors: null;
|
|
267
|
+
}>;
|
|
214
268
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from '../../utils/events';
|
|
2
2
|
import { PaginatedResult } from '../../types/common/pagination';
|
|
3
|
-
import { OrderResponse
|
|
4
|
-
import { BrokerBalance, BrokerInfo, BrokerConnection, OrdersFilter, PositionsFilter, AccountsFilter, BalancesFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount, DisconnectCompanyResponse } from '../../types/api/broker';
|
|
3
|
+
import { OrderResponse } from '../../types/api/orders';
|
|
4
|
+
import { BrokerDataOptions, BrokerBalance, BrokerInfo, BrokerOrderParams, BrokerConnection, OrdersFilter, PositionsFilter, AccountsFilter, BalancesFilter, BrokerDataOrder, BrokerDataPosition, BrokerDataAccount, DisconnectCompanyResponse } from '../../types/api/broker';
|
|
5
5
|
import { FinaticConnectOptions, PortalOptions } from '../../types/connect';
|
|
6
6
|
interface DeviceInfo {
|
|
7
7
|
ip_address: string;
|
|
@@ -28,47 +28,41 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
28
28
|
private readonly SESSION_REFRESH_BUFFER_HOURS;
|
|
29
29
|
private sessionStartTime;
|
|
30
30
|
constructor(options: FinaticConnectOptions, deviceInfo?: DeviceInfo);
|
|
31
|
-
private
|
|
31
|
+
private linkUserToSession;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
34
|
-
* @
|
|
33
|
+
* Store user ID for authentication state persistence
|
|
34
|
+
* @param userId - The user ID to store
|
|
35
35
|
*/
|
|
36
|
-
|
|
36
|
+
private storeUserId;
|
|
37
37
|
/**
|
|
38
|
-
* Check if the
|
|
39
|
-
* @returns True if authenticated
|
|
38
|
+
* Check if the user is fully authenticated (has userId in session context)
|
|
39
|
+
* @returns True if the user is fully authenticated and ready for API calls
|
|
40
40
|
*/
|
|
41
|
-
|
|
41
|
+
isAuthenticated(): Promise<boolean>;
|
|
42
42
|
/**
|
|
43
43
|
* Get user's orders with pagination and optional filtering
|
|
44
44
|
* @param params - Query parameters including page, perPage, and filters
|
|
45
45
|
* @returns Promise with paginated result that supports navigation
|
|
46
46
|
*/
|
|
47
|
-
getOrders(
|
|
48
|
-
page?: number;
|
|
49
|
-
perPage?: number;
|
|
50
|
-
filter?: OrdersFilter;
|
|
51
|
-
}): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
47
|
+
getOrders(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
52
48
|
/**
|
|
53
49
|
* Get user's positions with pagination and optional filtering
|
|
54
50
|
* @param params - Query parameters including page, perPage, and filters
|
|
55
51
|
* @returns Promise with paginated result that supports navigation
|
|
56
52
|
*/
|
|
57
|
-
getPositions(
|
|
58
|
-
page?: number;
|
|
59
|
-
perPage?: number;
|
|
60
|
-
filter?: PositionsFilter;
|
|
61
|
-
}): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
53
|
+
getPositions(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
62
54
|
/**
|
|
63
55
|
* Get user's accounts with pagination and optional filtering
|
|
64
56
|
* @param params - Query parameters including page, perPage, and filters
|
|
65
57
|
* @returns Promise with paginated result that supports navigation
|
|
66
58
|
*/
|
|
67
|
-
getAccounts(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
getAccounts(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
60
|
+
/**
|
|
61
|
+
* Get user's balances with pagination and optional filtering
|
|
62
|
+
* @param params - Query parameters including page, perPage, and filters
|
|
63
|
+
* @returns Promise with paginated result that supports navigation
|
|
64
|
+
*/
|
|
65
|
+
getBalances(page?: number, perPage?: number, options?: BrokerDataOptions, filters?: BalancesFilter): Promise<PaginatedResult<BrokerBalance[]>>;
|
|
72
66
|
/**
|
|
73
67
|
* Initialize the Finatic Connect SDK
|
|
74
68
|
* @param token - The portal token from your backend
|
|
@@ -88,7 +82,6 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
88
82
|
* Get the user and tokens for a completed session
|
|
89
83
|
* @returns Promise with user information and tokens
|
|
90
84
|
*/
|
|
91
|
-
getSessionUser(): Promise<Record<string, any>>;
|
|
92
85
|
private initializeWithUser;
|
|
93
86
|
/**
|
|
94
87
|
* Handle company access error by opening the portal
|
|
@@ -114,20 +107,7 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
114
107
|
* Place a new order using the broker order API
|
|
115
108
|
* @param order - Order details with broker context
|
|
116
109
|
*/
|
|
117
|
-
placeOrder(order:
|
|
118
|
-
symbol: string;
|
|
119
|
-
quantity: number;
|
|
120
|
-
side: 'buy' | 'sell';
|
|
121
|
-
orderType: 'market' | 'limit' | 'stop' | 'stop_limit';
|
|
122
|
-
price?: number;
|
|
123
|
-
stopPrice?: number;
|
|
124
|
-
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
125
|
-
broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader';
|
|
126
|
-
accountNumber?: string;
|
|
127
|
-
assetType?: 'Stock' | 'Option' | 'Crypto' | 'Future';
|
|
128
|
-
order_id?: string;
|
|
129
|
-
connection_id?: string;
|
|
130
|
-
}): Promise<OrderResponse>;
|
|
110
|
+
placeOrder(order: BrokerOrderParams, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
131
111
|
/**
|
|
132
112
|
* Cancel a broker order
|
|
133
113
|
* @param orderId - The order ID to cancel
|
|
@@ -152,25 +132,6 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
152
132
|
side?: 'Buy' | 'Sell';
|
|
153
133
|
order_id?: string;
|
|
154
134
|
}>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', connection_id?: string): Promise<OrderResponse>;
|
|
155
|
-
/**
|
|
156
|
-
* Set the broker context for trading
|
|
157
|
-
* @param broker - The broker to use for trading
|
|
158
|
-
*/
|
|
159
|
-
setTradingContextBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader' | 'interactive_brokers' | 'tradestation'): void;
|
|
160
|
-
/**
|
|
161
|
-
* Set the account context for trading
|
|
162
|
-
* @param accountNumber - The account number to use for trading
|
|
163
|
-
* @param accountId - Optional account ID
|
|
164
|
-
*/
|
|
165
|
-
setTradingContextAccount(accountNumber: string, accountId?: string): void;
|
|
166
|
-
/**
|
|
167
|
-
* Get the current trading context
|
|
168
|
-
*/
|
|
169
|
-
getTradingContext(): TradingContext;
|
|
170
|
-
/**
|
|
171
|
-
* Clear the trading context
|
|
172
|
-
*/
|
|
173
|
-
clearTradingContext(): void;
|
|
174
135
|
/**
|
|
175
136
|
* Place a stock market order (convenience method)
|
|
176
137
|
*/
|
|
@@ -212,7 +173,7 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
212
173
|
* @returns The current user ID or undefined if not authenticated
|
|
213
174
|
* @throws AuthenticationError if user is not authenticated
|
|
214
175
|
*/
|
|
215
|
-
getUserId(): string | null
|
|
176
|
+
getUserId(): Promise<string | null>;
|
|
216
177
|
/**
|
|
217
178
|
* Get list of supported brokers
|
|
218
179
|
* @returns Promise with array of broker information
|
|
@@ -268,50 +229,6 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
268
229
|
* @returns Promise with array of positions for the broker
|
|
269
230
|
*/
|
|
270
231
|
getPositionsByBroker(brokerId: string): Promise<BrokerDataPosition[]>;
|
|
271
|
-
/**
|
|
272
|
-
* Get a specific page of orders with pagination metadata
|
|
273
|
-
* @param page - Page number (default: 1)
|
|
274
|
-
* @param perPage - Items per page (default: 100)
|
|
275
|
-
* @param filter - Optional filter parameters
|
|
276
|
-
* @returns Promise with paginated orders result
|
|
277
|
-
*/
|
|
278
|
-
getOrdersPage(page?: number, perPage?: number, filter?: OrdersFilter): Promise<PaginatedResult<BrokerDataOrder[]>>;
|
|
279
|
-
/**
|
|
280
|
-
* Get a specific page of positions with pagination metadata
|
|
281
|
-
* @param page - Page number (default: 1)
|
|
282
|
-
* @param perPage - Items per page (default: 100)
|
|
283
|
-
* @param filter - Optional filter parameters
|
|
284
|
-
* @returns Promise with paginated positions result
|
|
285
|
-
*/
|
|
286
|
-
getPositionsPage(page?: number, perPage?: number, filter?: PositionsFilter): Promise<PaginatedResult<BrokerDataPosition[]>>;
|
|
287
|
-
/**
|
|
288
|
-
* Get a specific page of accounts with pagination metadata
|
|
289
|
-
* @param page - Page number (default: 1)
|
|
290
|
-
* @param perPage - Items per page (default: 100)
|
|
291
|
-
* @param filter - Optional filter parameters
|
|
292
|
-
* @returns Promise with paginated accounts result
|
|
293
|
-
*/
|
|
294
|
-
getAccountsPage(page?: number, perPage?: number, filter?: AccountsFilter): Promise<PaginatedResult<BrokerDataAccount[]>>;
|
|
295
|
-
getBalancesPage(page?: number, perPage?: number, filter?: BalancesFilter): Promise<PaginatedResult<BrokerBalance[]>>;
|
|
296
|
-
/**
|
|
297
|
-
* Get the next page of orders
|
|
298
|
-
* @param previousResult - The previous paginated result
|
|
299
|
-
* @returns Promise with next page of orders or null if no more pages
|
|
300
|
-
*/
|
|
301
|
-
getNextOrdersPage(previousResult: PaginatedResult<BrokerDataOrder[]>): Promise<PaginatedResult<BrokerDataOrder[]> | null>;
|
|
302
|
-
/**
|
|
303
|
-
* Get the next page of positions
|
|
304
|
-
* @param previousResult - The previous paginated result
|
|
305
|
-
* @returns Promise with next page of positions or null if no more pages
|
|
306
|
-
*/
|
|
307
|
-
getNextPositionsPage(previousResult: PaginatedResult<BrokerDataPosition[]>): Promise<PaginatedResult<BrokerDataPosition[]> | null>;
|
|
308
|
-
/**
|
|
309
|
-
* Get the next page of accounts
|
|
310
|
-
* @param previousResult - The previous paginated result
|
|
311
|
-
* @returns Promise with next page of accounts or null if no more pages
|
|
312
|
-
*/
|
|
313
|
-
getNextAccountsPage(previousResult: PaginatedResult<BrokerDataAccount[]>): Promise<PaginatedResult<BrokerDataAccount[]> | null>;
|
|
314
|
-
getNextBalancesPage(previousResult: PaginatedResult<BrokerBalance[]>): Promise<PaginatedResult<BrokerBalance[]> | null>;
|
|
315
232
|
/**
|
|
316
233
|
* Get all orders across all pages (convenience method)
|
|
317
234
|
* @param filter - Optional filter parameters
|
|
@@ -376,5 +293,38 @@ export declare class FinaticConnect extends EventEmitter {
|
|
|
376
293
|
* @throws AuthenticationError if user is not authenticated
|
|
377
294
|
*/
|
|
378
295
|
disconnectCompany(connectionId: string): Promise<DisconnectCompanyResponse>;
|
|
296
|
+
/**
|
|
297
|
+
* Get order fills for a specific order
|
|
298
|
+
* @param orderId - The order ID
|
|
299
|
+
* @param filter - Optional filter parameters
|
|
300
|
+
* @returns Promise with order fills response
|
|
301
|
+
*/
|
|
302
|
+
getOrderFills(orderId: string, filter?: import('../../types/api/broker').OrderFillsFilter): Promise<import('../../types/api/broker').OrderFill[]>;
|
|
303
|
+
/**
|
|
304
|
+
* Get order events for a specific order
|
|
305
|
+
* @param orderId - The order ID
|
|
306
|
+
* @param filter - Optional filter parameters
|
|
307
|
+
* @returns Promise with order events response
|
|
308
|
+
*/
|
|
309
|
+
getOrderEvents(orderId: string, filter?: import('../../types/api/broker').OrderEventsFilter): Promise<import('../../types/api/broker').OrderEvent[]>;
|
|
310
|
+
/**
|
|
311
|
+
* Get order groups
|
|
312
|
+
* @param filter - Optional filter parameters
|
|
313
|
+
* @returns Promise with order groups response
|
|
314
|
+
*/
|
|
315
|
+
getOrderGroups(filter?: import('../../types/api/broker').OrderGroupsFilter): Promise<import('../../types/api/broker').OrderGroup[]>;
|
|
316
|
+
/**
|
|
317
|
+
* Get position lots (tax lots for positions)
|
|
318
|
+
* @param filter - Optional filter parameters
|
|
319
|
+
* @returns Promise with position lots response
|
|
320
|
+
*/
|
|
321
|
+
getPositionLots(filter?: import('../../types/api/broker').PositionLotsFilter): Promise<import('../../types/api/broker').PositionLot[]>;
|
|
322
|
+
/**
|
|
323
|
+
* Get position lot fills for a specific lot
|
|
324
|
+
* @param lotId - The position lot ID
|
|
325
|
+
* @param filter - Optional filter parameters
|
|
326
|
+
* @returns Promise with position lot fills response
|
|
327
|
+
*/
|
|
328
|
+
getPositionLotFills(lotId: string, filter?: import('../../types/api/broker').PositionLotFillsFilter): Promise<import('../../types/api/broker').PositionLotFill[]>;
|
|
379
329
|
}
|
|
380
330
|
export {};
|
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,
|
|
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';
|
|
@@ -9,4 +9,3 @@ export * from './utils/errors';
|
|
|
9
9
|
export * from './utils/events';
|
|
10
10
|
export * from './utils/themeUtils';
|
|
11
11
|
export { portalThemePresets } from './themes/portalPresets';
|
|
12
|
-
export { MockFactory } from './mocks/MockFactory';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, Order, BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerBalance, BrokerConnection, BrokerDataOptions, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse,
|
|
1
|
+
import { SessionResponse, OtpRequestResponse, OtpVerifyResponse, PortalUrlResponse, SessionValidationResponse, SessionAuthenticateResponse, UserToken, Order, BrokerInfo, BrokerAccount, BrokerOrder, BrokerPosition, BrokerBalance, BrokerConnection, BrokerDataOptions, BrokerOrderParams, BrokerExtras, CryptoOrderOptions, OptionsOrderOptions, OrderResponse, OrdersFilter, PositionsFilter, AccountsFilter, BalancesFilter, BrokerDataOrder, BrokerDataPosition, DisconnectCompanyResponse } from '../types';
|
|
2
2
|
import { PaginatedResult } from '../types';
|
|
3
3
|
import { DeviceInfo, SessionState, TokenInfo } from '../types/api/auth';
|
|
4
4
|
import { MockDataProvider, MockConfig } from './MockDataProvider';
|
|
@@ -80,14 +80,12 @@ export declare class MockApiClient {
|
|
|
80
80
|
orderQty: number;
|
|
81
81
|
action: 'Buy' | 'Sell';
|
|
82
82
|
orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
|
|
83
|
-
assetType: '
|
|
83
|
+
assetType: 'equity' | 'equity_option' | 'crypto' | 'forex' | 'future' | 'future_option';
|
|
84
84
|
}, extras?: BrokerExtras, connection_id?: string): Promise<OrderResponse>;
|
|
85
85
|
cancelBrokerOrder(orderId: string, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
86
86
|
modifyBrokerOrder(orderId: string, params: Partial<BrokerOrderParams>, broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', extras?: any, connection_id?: string): Promise<OrderResponse>;
|
|
87
87
|
setBroker(broker: 'robinhood' | 'tasty_trade' | 'ninja_trader'): void;
|
|
88
88
|
setAccount(accountNumber: string, accountId?: string): void;
|
|
89
|
-
getTradingContext(): TradingContext;
|
|
90
|
-
clearTradingContext(): void;
|
|
91
89
|
placeStockMarketOrder(symbol: string, orderQty: number, action: 'Buy' | 'Sell', broker?: 'robinhood' | 'tasty_trade' | 'ninja_trader', accountNumber?: string, extras?: BrokerExtras): Promise<OrderResponse>;
|
|
92
90
|
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>;
|
|
93
91
|
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>;
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utility functions for mock system environment detection
|
|
3
3
|
*/
|
|
4
|
-
declare global {
|
|
5
|
-
var process: {
|
|
6
|
-
env: Record<string, string | undefined>;
|
|
7
|
-
} | undefined;
|
|
8
|
-
}
|
|
9
4
|
/**
|
|
10
5
|
* Check if mocks should be used based on environment variables
|
|
11
6
|
* Supports both browser and Node.js environments
|
|
@@ -9,16 +9,6 @@ export interface SessionInitResponse {
|
|
|
9
9
|
expires_at: string;
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
-
export interface SessionResponseData {
|
|
13
|
-
session_id: string;
|
|
14
|
-
company_id: string;
|
|
15
|
-
status: 'pending';
|
|
16
|
-
expires_at: string;
|
|
17
|
-
}
|
|
18
|
-
export interface SessionStartResponse {
|
|
19
|
-
data: SessionResponseData;
|
|
20
|
-
message: 'Session started successfully';
|
|
21
|
-
}
|
|
22
12
|
export interface OtpRequestResponse {
|
|
23
13
|
success: boolean;
|
|
24
14
|
message: string;
|
|
@@ -37,17 +27,14 @@ export interface OtpVerifyResponse {
|
|
|
37
27
|
};
|
|
38
28
|
}
|
|
39
29
|
export interface UserToken {
|
|
40
|
-
accessToken: string;
|
|
41
|
-
refreshToken: string;
|
|
42
|
-
expiresIn: number;
|
|
43
30
|
user_id: string;
|
|
44
|
-
tokenType: string;
|
|
45
|
-
scope: string;
|
|
46
31
|
}
|
|
47
32
|
export interface SessionValidationResponse {
|
|
48
33
|
valid: boolean;
|
|
49
34
|
company_id: string;
|
|
50
35
|
status: string;
|
|
36
|
+
is_sandbox: boolean;
|
|
37
|
+
environment: string;
|
|
51
38
|
}
|
|
52
39
|
export interface SessionAuthenticateResponse {
|
|
53
40
|
success: boolean;
|
|
@@ -78,23 +65,18 @@ export interface TokenInfo {
|
|
|
78
65
|
expiresAt: string;
|
|
79
66
|
userId?: string;
|
|
80
67
|
}
|
|
68
|
+
export interface SessionResponseData {
|
|
69
|
+
session_id: string;
|
|
70
|
+
company_id: string;
|
|
71
|
+
status: string;
|
|
72
|
+
expires_at: string;
|
|
73
|
+
user_id?: string | null;
|
|
74
|
+
auto_login?: boolean;
|
|
75
|
+
}
|
|
81
76
|
export interface SessionResponse {
|
|
82
|
-
|
|
83
|
-
session_id: string;
|
|
84
|
-
state: SessionState;
|
|
85
|
-
device_info?: Record<string, string>;
|
|
86
|
-
company_id?: string;
|
|
87
|
-
status?: string;
|
|
88
|
-
expires_at?: string;
|
|
89
|
-
user_id?: string | null;
|
|
90
|
-
auto_login?: boolean;
|
|
91
|
-
access_token?: string;
|
|
92
|
-
refresh_token?: string;
|
|
93
|
-
expires_in?: number;
|
|
94
|
-
token_type?: string;
|
|
95
|
-
scope?: string;
|
|
96
|
-
};
|
|
77
|
+
success: boolean;
|
|
97
78
|
message: string;
|
|
79
|
+
data: SessionResponseData;
|
|
98
80
|
}
|
|
99
81
|
export declare enum SessionState {
|
|
100
82
|
PENDING = "PENDING",
|
|
@@ -109,7 +109,7 @@ export interface BrokerOrderParams {
|
|
|
109
109
|
broker: 'robinhood' | 'tasty_trade' | 'ninja_trader';
|
|
110
110
|
order_id?: string;
|
|
111
111
|
orderType: 'Market' | 'Limit' | 'Stop' | 'StopLimit';
|
|
112
|
-
assetType: '
|
|
112
|
+
assetType: 'equity' | 'equity_option' | 'crypto' | 'forex' | 'future' | 'future_option';
|
|
113
113
|
action: 'Buy' | 'Sell';
|
|
114
114
|
timeInForce: 'day' | 'gtc' | 'gtd' | 'ioc' | 'fok';
|
|
115
115
|
accountNumber: string | number;
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finatic/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.141",
|
|
4
4
|
"description": "Finatic Client SDK for browser integration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,18 +8,22 @@
|
|
|
8
8
|
},
|
|
9
9
|
"main": "./dist/index.js",
|
|
10
10
|
"module": "./dist/index.mjs",
|
|
11
|
-
"types": "./dist/
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
14
|
"import": "./dist/index.mjs",
|
|
15
15
|
"require": "./dist/index.js",
|
|
16
|
-
"types": "./dist/
|
|
16
|
+
"types": "./dist/index.d.ts"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=16.0.0"
|
|
21
21
|
},
|
|
22
|
+
"workspaces": [
|
|
23
|
+
"demo-app"
|
|
24
|
+
],
|
|
22
25
|
"files": [
|
|
26
|
+
"src",
|
|
23
27
|
"dist"
|
|
24
28
|
],
|
|
25
29
|
"scripts": {
|