@finatic/client 0.9.2 → 0.9.3
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/dist/index.d.ts +485 -174
- package/dist/index.js +928 -396
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +928 -397
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -15
package/dist/index.js
CHANGED
|
@@ -1230,6 +1230,256 @@ exports.SessionStatus = void 0;
|
|
|
1230
1230
|
SessionStatus["Expired"] = "expired";
|
|
1231
1231
|
})(exports.SessionStatus || (exports.SessionStatus = {}));
|
|
1232
1232
|
|
|
1233
|
+
/**
|
|
1234
|
+
* Pagination utilities for TypeScript SDK.
|
|
1235
|
+
*
|
|
1236
|
+
* Provides PaginatedData class for wrapping paginated responses with helper methods.
|
|
1237
|
+
*/
|
|
1238
|
+
/**
|
|
1239
|
+
* PaginatedData wraps a data array with pagination metadata and helper methods.
|
|
1240
|
+
*
|
|
1241
|
+
* This class behaves like an array, so you can use it directly:
|
|
1242
|
+
* - paginatedData.length returns the number of items
|
|
1243
|
+
* - paginatedData[0] returns the first item
|
|
1244
|
+
* - paginatedData.forEach(...) works directly
|
|
1245
|
+
* - paginatedData.map(...) works directly
|
|
1246
|
+
*
|
|
1247
|
+
* It also provides pagination methods:
|
|
1248
|
+
* - hasMore: Check if there are more pages
|
|
1249
|
+
* - nextPage(): Get the next page
|
|
1250
|
+
* - prevPage(): Get the previous page
|
|
1251
|
+
* - firstPage(): Get the first page
|
|
1252
|
+
* - lastPage(): Get the last page
|
|
1253
|
+
*
|
|
1254
|
+
* @template T - The element type (e.g., FDXBrokerAccount)
|
|
1255
|
+
*
|
|
1256
|
+
* Usage:
|
|
1257
|
+
* ```typescript
|
|
1258
|
+
* const response = await sdk.getAccounts();
|
|
1259
|
+
* const accounts = response.success.data; // Can use directly as array!
|
|
1260
|
+
* console.log(accounts.length); // Works directly
|
|
1261
|
+
* console.log(accounts[0]); // Works directly
|
|
1262
|
+
* accounts.forEach(account => console.log(account)); // Works directly
|
|
1263
|
+
*
|
|
1264
|
+
* if (accounts.hasMore) {
|
|
1265
|
+
* const nextPage = await accounts.nextPage(); // Returns PaginatedData<FDXBrokerAccount>
|
|
1266
|
+
* const nextAccounts = nextPage; // Can use directly as array too!
|
|
1267
|
+
* }
|
|
1268
|
+
* ```
|
|
1269
|
+
*/
|
|
1270
|
+
class PaginatedData {
|
|
1271
|
+
constructor(items, // The actual data array
|
|
1272
|
+
meta,
|
|
1273
|
+
// Use any for method type since it's only called for paginated endpoints
|
|
1274
|
+
// and will return PaginatedData<T> at runtime
|
|
1275
|
+
originalMethod, currentParams, wrapperInstance // Reference to wrapper for method calls
|
|
1276
|
+
) {
|
|
1277
|
+
this.items = items;
|
|
1278
|
+
this.meta = meta;
|
|
1279
|
+
this.originalMethod = originalMethod;
|
|
1280
|
+
this.currentParams = currentParams;
|
|
1281
|
+
this.wrapperInstance = wrapperInstance;
|
|
1282
|
+
// Create a Proxy to allow array-like indexing (paginatedData[0])
|
|
1283
|
+
return new Proxy(this, {
|
|
1284
|
+
get(target, prop) {
|
|
1285
|
+
// Handle numeric indices
|
|
1286
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1287
|
+
return target.items[Number(prop)];
|
|
1288
|
+
}
|
|
1289
|
+
// Handle length property
|
|
1290
|
+
if (prop === 'length') {
|
|
1291
|
+
return target.items.length;
|
|
1292
|
+
}
|
|
1293
|
+
// Handle array methods and other properties
|
|
1294
|
+
return target[prop];
|
|
1295
|
+
},
|
|
1296
|
+
has(target, prop) {
|
|
1297
|
+
// Support 'in' operator
|
|
1298
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1299
|
+
return Number(prop) < target.items.length;
|
|
1300
|
+
}
|
|
1301
|
+
return prop in target;
|
|
1302
|
+
},
|
|
1303
|
+
ownKeys(target) {
|
|
1304
|
+
// Include numeric indices for Object.keys()
|
|
1305
|
+
const keys = Object.keys(target);
|
|
1306
|
+
for (let i = 0; i < target.items.length; i++) {
|
|
1307
|
+
keys.push(String(i));
|
|
1308
|
+
}
|
|
1309
|
+
return keys;
|
|
1310
|
+
},
|
|
1311
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
1312
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1313
|
+
const index = Number(prop);
|
|
1314
|
+
if (index < target.items.length) {
|
|
1315
|
+
return {
|
|
1316
|
+
enumerable: true,
|
|
1317
|
+
configurable: true,
|
|
1318
|
+
value: target.items[index],
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
1323
|
+
},
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
/**
|
|
1327
|
+
* Get the number of items (allows paginatedData.length).
|
|
1328
|
+
*/
|
|
1329
|
+
get length() {
|
|
1330
|
+
return this.items.length;
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Check if there are more pages available.
|
|
1334
|
+
*/
|
|
1335
|
+
get hasMore() {
|
|
1336
|
+
return this.meta.has_more;
|
|
1337
|
+
}
|
|
1338
|
+
// Array-like methods - delegate to items array
|
|
1339
|
+
/**
|
|
1340
|
+
* Calls a function for each element in the array.
|
|
1341
|
+
*/
|
|
1342
|
+
forEach(callbackfn, thisArg) {
|
|
1343
|
+
return this.items.forEach(callbackfn, thisArg);
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Creates a new array with the results of calling a function for every array element.
|
|
1347
|
+
*/
|
|
1348
|
+
map(callbackfn, thisArg) {
|
|
1349
|
+
return this.items.map(callbackfn, thisArg);
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Returns the elements of an array that meet the condition specified in a callback function.
|
|
1353
|
+
*/
|
|
1354
|
+
filter(callbackfn, thisArg) {
|
|
1355
|
+
return this.items.filter(callbackfn, thisArg);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Returns the value of the first element in the array where predicate is true.
|
|
1359
|
+
*/
|
|
1360
|
+
find(predicate, thisArg) {
|
|
1361
|
+
return this.items.find(predicate, thisArg);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Returns the index of the first element in the array where predicate is true.
|
|
1365
|
+
*/
|
|
1366
|
+
findIndex(predicate, thisArg) {
|
|
1367
|
+
return this.items.findIndex(predicate, thisArg);
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Returns a section of an array.
|
|
1371
|
+
*/
|
|
1372
|
+
slice(start, end) {
|
|
1373
|
+
return this.items.slice(start, end);
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Determines whether an array includes a certain element.
|
|
1377
|
+
*/
|
|
1378
|
+
includes(searchElement, fromIndex) {
|
|
1379
|
+
return this.items.includes(searchElement, fromIndex);
|
|
1380
|
+
}
|
|
1381
|
+
/**
|
|
1382
|
+
* Returns the index of the first occurrence of a value in an array.
|
|
1383
|
+
*/
|
|
1384
|
+
indexOf(searchElement, fromIndex) {
|
|
1385
|
+
return this.items.indexOf(searchElement, fromIndex);
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Returns a string representation of an array.
|
|
1389
|
+
*/
|
|
1390
|
+
toString() {
|
|
1391
|
+
return this.items.toString();
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Returns a string representation of an array.
|
|
1395
|
+
*/
|
|
1396
|
+
toLocaleString() {
|
|
1397
|
+
return this.items.toLocaleString();
|
|
1398
|
+
}
|
|
1399
|
+
/**
|
|
1400
|
+
* Get the next page of data.
|
|
1401
|
+
* @returns Promise<PaginatedData<T>> - The next page (not wrapped in FinaticResponse)
|
|
1402
|
+
* @throws Error if no more pages are available
|
|
1403
|
+
*/
|
|
1404
|
+
async nextPage() {
|
|
1405
|
+
if (!this.hasMore) {
|
|
1406
|
+
throw new Error('No more pages available');
|
|
1407
|
+
}
|
|
1408
|
+
if (this.meta.next_offset === null) {
|
|
1409
|
+
throw new Error('Next offset is null');
|
|
1410
|
+
}
|
|
1411
|
+
const newParams = {
|
|
1412
|
+
...this.currentParams,
|
|
1413
|
+
offset: this.meta.next_offset,
|
|
1414
|
+
};
|
|
1415
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1416
|
+
if (!response.success) {
|
|
1417
|
+
throw new Error(response.error?.message || 'Failed to fetch next page');
|
|
1418
|
+
}
|
|
1419
|
+
return response.success.data; // Return PaginatedData directly
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Get the previous page of data.
|
|
1423
|
+
* @returns Promise<PaginatedData<T>> - The previous page (not wrapped in FinaticResponse)
|
|
1424
|
+
* @throws Error if fetch fails
|
|
1425
|
+
*/
|
|
1426
|
+
async prevPage() {
|
|
1427
|
+
const prevOffset = Math.max(0, this.meta.current_offset - this.meta.limit);
|
|
1428
|
+
const newParams = {
|
|
1429
|
+
...this.currentParams,
|
|
1430
|
+
offset: prevOffset,
|
|
1431
|
+
};
|
|
1432
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1433
|
+
if (!response.success) {
|
|
1434
|
+
throw new Error(response.error?.message || 'Failed to fetch previous page');
|
|
1435
|
+
}
|
|
1436
|
+
return response.success.data; // Return PaginatedData directly
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Get the first page of data.
|
|
1440
|
+
* @returns Promise<PaginatedData<T>> - The first page (not wrapped in FinaticResponse)
|
|
1441
|
+
* @throws Error if fetch fails
|
|
1442
|
+
*/
|
|
1443
|
+
async firstPage() {
|
|
1444
|
+
const newParams = {
|
|
1445
|
+
...this.currentParams,
|
|
1446
|
+
offset: 0,
|
|
1447
|
+
};
|
|
1448
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1449
|
+
if (!response.success) {
|
|
1450
|
+
throw new Error(response.error?.message || 'Failed to fetch first page');
|
|
1451
|
+
}
|
|
1452
|
+
return response.success.data; // Return PaginatedData directly
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Get the last page of data.
|
|
1456
|
+
* Uses iterative approach to find the last page.
|
|
1457
|
+
* @returns Promise<PaginatedData<T>> - The last page (not wrapped in FinaticResponse)
|
|
1458
|
+
* @throws Error if fetch fails
|
|
1459
|
+
*/
|
|
1460
|
+
async lastPage() {
|
|
1461
|
+
// Iterative approach to find last page
|
|
1462
|
+
let currentOffset = this.meta.current_offset;
|
|
1463
|
+
let lastValidData = null;
|
|
1464
|
+
while (true) {
|
|
1465
|
+
const testParams = { ...this.currentParams, offset: currentOffset };
|
|
1466
|
+
const response = await this.originalMethod.call(this.wrapperInstance, testParams);
|
|
1467
|
+
if (!response.success) {
|
|
1468
|
+
break;
|
|
1469
|
+
}
|
|
1470
|
+
lastValidData = response.success.data;
|
|
1471
|
+
if (!lastValidData || !lastValidData.hasMore) {
|
|
1472
|
+
break;
|
|
1473
|
+
}
|
|
1474
|
+
currentOffset += this.meta.limit;
|
|
1475
|
+
}
|
|
1476
|
+
if (!lastValidData) {
|
|
1477
|
+
throw new Error('Failed to fetch last page');
|
|
1478
|
+
}
|
|
1479
|
+
return lastValidData; // Return PaginatedData directly
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1233
1483
|
/**
|
|
1234
1484
|
* Generated wrapper functions for brokers operations (Phase 2A).
|
|
1235
1485
|
*
|
|
@@ -1279,7 +1529,7 @@ class BrokersWrapper {
|
|
|
1279
1529
|
* -------
|
|
1280
1530
|
* FinaticResponse[list[BrokerInfo]]
|
|
1281
1531
|
* list of available brokers with their metadata.
|
|
1282
|
-
* @param No parameters required for this method
|
|
1532
|
+
* @param params No parameters required for this method
|
|
1283
1533
|
* @returns {Promise<FinaticResponse<BrokerInfo[]>>} Standard response with success/Error/Warning structure
|
|
1284
1534
|
*
|
|
1285
1535
|
* Generated from: GET /api/v1/brokers/
|
|
@@ -1288,7 +1538,7 @@ class BrokersWrapper {
|
|
|
1288
1538
|
* @example
|
|
1289
1539
|
* ```typescript-client
|
|
1290
1540
|
* // Example with no parameters
|
|
1291
|
-
* const result = await finatic.getBrokers();
|
|
1541
|
+
* const result = await finatic.getBrokers({});
|
|
1292
1542
|
*
|
|
1293
1543
|
* // Access the response data
|
|
1294
1544
|
* if (result.success) {
|
|
@@ -1296,9 +1546,9 @@ class BrokersWrapper {
|
|
|
1296
1546
|
* }
|
|
1297
1547
|
* ```
|
|
1298
1548
|
*/
|
|
1299
|
-
async getBrokers() {
|
|
1549
|
+
async getBrokers(params) {
|
|
1300
1550
|
// No parameters - use empty params object
|
|
1301
|
-
const
|
|
1551
|
+
const resolvedParams = params || {}; // Generate request ID
|
|
1302
1552
|
const requestId = this._generateRequestId();
|
|
1303
1553
|
// Input validation (Phase 2B: zod)
|
|
1304
1554
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -1306,7 +1556,7 @@ class BrokersWrapper {
|
|
|
1306
1556
|
const shouldCache = true;
|
|
1307
1557
|
const cache = getCache(this.sdkConfig);
|
|
1308
1558
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1309
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/',
|
|
1559
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
|
|
1310
1560
|
const cached = cache.get(cacheKey);
|
|
1311
1561
|
if (cached) {
|
|
1312
1562
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1318,7 +1568,7 @@ class BrokersWrapper {
|
|
|
1318
1568
|
request_id: requestId,
|
|
1319
1569
|
method: 'GET',
|
|
1320
1570
|
path: '/api/v1/brokers/',
|
|
1321
|
-
params:
|
|
1571
|
+
params: resolvedParams,
|
|
1322
1572
|
action: 'getBrokers'
|
|
1323
1573
|
});
|
|
1324
1574
|
try {
|
|
@@ -1332,9 +1582,15 @@ class BrokersWrapper {
|
|
|
1332
1582
|
throw new Error('Unexpected response shape: missing success field');
|
|
1333
1583
|
}
|
|
1334
1584
|
// Convert response to plain object, removing _id fields recursively
|
|
1585
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1335
1586
|
const standardResponse = convertToPlainObject(responseData);
|
|
1587
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1588
|
+
const hasLimit = false;
|
|
1589
|
+
const hasOffset = false;
|
|
1590
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1591
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1336
1592
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1337
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/',
|
|
1593
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
|
|
1338
1594
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1339
1595
|
}
|
|
1340
1596
|
this.logger.debug('Get Brokers completed', {
|
|
@@ -1342,6 +1598,7 @@ class BrokersWrapper {
|
|
|
1342
1598
|
action: 'getBrokers'
|
|
1343
1599
|
});
|
|
1344
1600
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1601
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1345
1602
|
return standardResponse;
|
|
1346
1603
|
}
|
|
1347
1604
|
catch (error) {
|
|
@@ -1419,7 +1676,7 @@ class BrokersWrapper {
|
|
|
1419
1676
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1420
1677
|
* Returns connections that the user has any permissions for, including the current
|
|
1421
1678
|
* company's permissions (read/write) for each connection.
|
|
1422
|
-
* @param No parameters required for this method
|
|
1679
|
+
* @param params No parameters required for this method
|
|
1423
1680
|
* @returns {Promise<FinaticResponse<UserBrokerConnectionWithPermissions[]>>} Standard response with success/Error/Warning structure
|
|
1424
1681
|
*
|
|
1425
1682
|
* Generated from: GET /api/v1/brokers/connections
|
|
@@ -1428,7 +1685,7 @@ class BrokersWrapper {
|
|
|
1428
1685
|
* @example
|
|
1429
1686
|
* ```typescript-client
|
|
1430
1687
|
* // Example with no parameters
|
|
1431
|
-
* const result = await finatic.getBrokerConnections();
|
|
1688
|
+
* const result = await finatic.getBrokerConnections({});
|
|
1432
1689
|
*
|
|
1433
1690
|
* // Access the response data
|
|
1434
1691
|
* if (result.success) {
|
|
@@ -1436,10 +1693,10 @@ class BrokersWrapper {
|
|
|
1436
1693
|
* }
|
|
1437
1694
|
* ```
|
|
1438
1695
|
*/
|
|
1439
|
-
async getBrokerConnections() {
|
|
1696
|
+
async getBrokerConnections(params) {
|
|
1440
1697
|
// No parameters - use empty params object
|
|
1441
|
-
const
|
|
1442
|
-
if (!this.sessionId) {
|
|
1698
|
+
const resolvedParams = params || {}; // Authentication check
|
|
1699
|
+
if (!this.sessionId || !this.companyId) {
|
|
1443
1700
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1444
1701
|
}
|
|
1445
1702
|
// Generate request ID
|
|
@@ -1450,7 +1707,7 @@ class BrokersWrapper {
|
|
|
1450
1707
|
const shouldCache = true;
|
|
1451
1708
|
const cache = getCache(this.sdkConfig);
|
|
1452
1709
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1453
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections',
|
|
1710
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
|
|
1454
1711
|
const cached = cache.get(cacheKey);
|
|
1455
1712
|
if (cached) {
|
|
1456
1713
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1462,12 +1719,12 @@ class BrokersWrapper {
|
|
|
1462
1719
|
request_id: requestId,
|
|
1463
1720
|
method: 'GET',
|
|
1464
1721
|
path: '/api/v1/brokers/connections',
|
|
1465
|
-
params:
|
|
1722
|
+
params: resolvedParams,
|
|
1466
1723
|
action: 'getBrokerConnections'
|
|
1467
1724
|
});
|
|
1468
1725
|
try {
|
|
1469
1726
|
const response = await retryApiCall(async () => {
|
|
1470
|
-
const apiResponse = await this.api.listBrokerConnectionsApiV1BrokersConnectionsGet({ headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
1727
|
+
const apiResponse = await this.api.listBrokerConnectionsApiV1BrokersConnectionsGet({ headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
1471
1728
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1472
1729
|
}, {}, this.sdkConfig);
|
|
1473
1730
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1476,9 +1733,15 @@ class BrokersWrapper {
|
|
|
1476
1733
|
throw new Error('Unexpected response shape: missing success field');
|
|
1477
1734
|
}
|
|
1478
1735
|
// Convert response to plain object, removing _id fields recursively
|
|
1736
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1479
1737
|
const standardResponse = convertToPlainObject(responseData);
|
|
1738
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1739
|
+
const hasLimit = false;
|
|
1740
|
+
const hasOffset = false;
|
|
1741
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1742
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1480
1743
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1481
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections',
|
|
1744
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
|
|
1482
1745
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1483
1746
|
}
|
|
1484
1747
|
this.logger.debug('List Broker Connections completed', {
|
|
@@ -1486,6 +1749,7 @@ class BrokersWrapper {
|
|
|
1486
1749
|
action: 'getBrokerConnections'
|
|
1487
1750
|
});
|
|
1488
1751
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1752
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1489
1753
|
return standardResponse;
|
|
1490
1754
|
}
|
|
1491
1755
|
catch (error) {
|
|
@@ -1562,7 +1826,7 @@ class BrokersWrapper {
|
|
|
1562
1826
|
*
|
|
1563
1827
|
* If the company is the only one with access, the entire connection is deleted.
|
|
1564
1828
|
* If other companies have access, only the company's access is removed.
|
|
1565
|
-
* @param connectionId {string}
|
|
1829
|
+
* @param params.connectionId {string} Connection ID
|
|
1566
1830
|
* @returns {Promise<FinaticResponse<DisconnectActionResult>>} Standard response with success/Error/Warning structure
|
|
1567
1831
|
*
|
|
1568
1832
|
* Generated from: DELETE /api/v1/brokers/disconnect-company/{connection_id}
|
|
@@ -1571,7 +1835,9 @@ class BrokersWrapper {
|
|
|
1571
1835
|
* @example
|
|
1572
1836
|
* ```typescript-client
|
|
1573
1837
|
* // Minimal example with required parameters only
|
|
1574
|
-
* const result = await finatic.disconnectCompanyFromBroker(
|
|
1838
|
+
* const result = await finatic.disconnectCompanyFromBroker({
|
|
1839
|
+
connectionId: '00000000-0000-0000-0000-000000000000'
|
|
1840
|
+
* });
|
|
1575
1841
|
*
|
|
1576
1842
|
* // Access the response data
|
|
1577
1843
|
* if (result.success) {
|
|
@@ -1581,12 +1847,10 @@ class BrokersWrapper {
|
|
|
1581
1847
|
* }
|
|
1582
1848
|
* ```
|
|
1583
1849
|
*/
|
|
1584
|
-
async disconnectCompanyFromBroker(
|
|
1585
|
-
//
|
|
1586
|
-
const
|
|
1587
|
-
|
|
1588
|
-
}; // Authentication check
|
|
1589
|
-
if (!this.sessionId) {
|
|
1850
|
+
async disconnectCompanyFromBroker(params) {
|
|
1851
|
+
// Use params object (required parameters present)
|
|
1852
|
+
const resolvedParams = params; // Authentication check
|
|
1853
|
+
if (!this.sessionId || !this.companyId) {
|
|
1590
1854
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1591
1855
|
}
|
|
1592
1856
|
// Generate request ID
|
|
@@ -1597,7 +1861,7 @@ class BrokersWrapper {
|
|
|
1597
1861
|
const shouldCache = true;
|
|
1598
1862
|
const cache = getCache(this.sdkConfig);
|
|
1599
1863
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1600
|
-
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1864
|
+
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
|
|
1601
1865
|
const cached = cache.get(cacheKey);
|
|
1602
1866
|
if (cached) {
|
|
1603
1867
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1609,12 +1873,12 @@ class BrokersWrapper {
|
|
|
1609
1873
|
request_id: requestId,
|
|
1610
1874
|
method: 'DELETE',
|
|
1611
1875
|
path: '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1612
|
-
params:
|
|
1876
|
+
params: resolvedParams,
|
|
1613
1877
|
action: 'disconnectCompanyFromBroker'
|
|
1614
1878
|
});
|
|
1615
1879
|
try {
|
|
1616
1880
|
const response = await retryApiCall(async () => {
|
|
1617
|
-
const apiResponse = await this.api.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete({ connectionId: connectionId }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
1881
|
+
const apiResponse = await this.api.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete({ connectionId: resolvedParams.connectionId }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
1618
1882
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1619
1883
|
}, {}, this.sdkConfig);
|
|
1620
1884
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1623,9 +1887,15 @@ class BrokersWrapper {
|
|
|
1623
1887
|
throw new Error('Unexpected response shape: missing success field');
|
|
1624
1888
|
}
|
|
1625
1889
|
// Convert response to plain object, removing _id fields recursively
|
|
1890
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1626
1891
|
const standardResponse = convertToPlainObject(responseData);
|
|
1892
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1893
|
+
const hasLimit = false;
|
|
1894
|
+
const hasOffset = false;
|
|
1895
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1896
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1627
1897
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1628
|
-
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1898
|
+
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
|
|
1629
1899
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1630
1900
|
}
|
|
1631
1901
|
this.logger.debug('Disconnect Company From Broker completed', {
|
|
@@ -1633,6 +1903,7 @@ class BrokersWrapper {
|
|
|
1633
1903
|
action: 'disconnectCompanyFromBroker'
|
|
1634
1904
|
});
|
|
1635
1905
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1906
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1636
1907
|
return standardResponse;
|
|
1637
1908
|
}
|
|
1638
1909
|
catch (error) {
|
|
@@ -1709,19 +1980,19 @@ class BrokersWrapper {
|
|
|
1709
1980
|
*
|
|
1710
1981
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1711
1982
|
* Returns orders from connections the company has read access to.
|
|
1712
|
-
* @param brokerId {string} (optional)
|
|
1713
|
-
* @param connectionId {string} (optional)
|
|
1714
|
-
* @param accountId {string} (optional)
|
|
1715
|
-
* @param symbol {string} (optional)
|
|
1716
|
-
* @param orderStatus {BrokerDataOrderStatusEnum} (optional)
|
|
1717
|
-
* @param side {BrokerDataOrderSideEnum} (optional)
|
|
1718
|
-
* @param assetType {BrokerDataAssetTypeEnum} (optional)
|
|
1719
|
-
* @param limit {number} (optional)
|
|
1720
|
-
* @param offset {number} (optional)
|
|
1721
|
-
* @param createdAfter {string} (optional)
|
|
1722
|
-
* @param createdBefore {string} (optional)
|
|
1723
|
-
* @param includeMetadata {boolean} (optional)
|
|
1724
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrder
|
|
1983
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
1984
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
1985
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID
|
|
1986
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
1987
|
+
* @param params.orderStatus {BrokerDataOrderStatusEnum} (optional) Filter by order status (e.g., 'filled', 'pending_new', 'cancelled')
|
|
1988
|
+
* @param params.side {BrokerDataOrderSideEnum} (optional) Filter by order side (e.g., 'buy', 'sell')
|
|
1989
|
+
* @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
|
|
1990
|
+
* @param params.limit {number} (optional) Maximum number of orders to return
|
|
1991
|
+
* @param params.offset {number} (optional) Number of orders to skip for pagination
|
|
1992
|
+
* @param params.createdAfter {string} (optional) Filter orders created after this timestamp
|
|
1993
|
+
* @param params.createdBefore {string} (optional) Filter orders created before this timestamp
|
|
1994
|
+
* @param params.includeMetadata {boolean} (optional) Include order metadata in response (excluded by default for FDX compliance)
|
|
1995
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrder>>>} Standard response with success/Error/Warning structure
|
|
1725
1996
|
*
|
|
1726
1997
|
* Generated from: GET /api/v1/brokers/data/orders
|
|
1727
1998
|
* @methodId get_orders_api_v1_brokers_data_orders_get
|
|
@@ -1729,7 +2000,7 @@ class BrokersWrapper {
|
|
|
1729
2000
|
* @example
|
|
1730
2001
|
* ```typescript-client
|
|
1731
2002
|
* // Example with no parameters
|
|
1732
|
-
* const result = await finatic.getOrders();
|
|
2003
|
+
* const result = await finatic.getOrders({});
|
|
1733
2004
|
*
|
|
1734
2005
|
* // Access the response data
|
|
1735
2006
|
* if (result.success) {
|
|
@@ -1739,7 +2010,11 @@ class BrokersWrapper {
|
|
|
1739
2010
|
* @example
|
|
1740
2011
|
* ```typescript-client
|
|
1741
2012
|
* // Full example with optional parameters
|
|
1742
|
-
* const result = await finatic.getOrders(
|
|
2013
|
+
* const result = await finatic.getOrders({
|
|
2014
|
+
brokerId: 'alpaca',
|
|
2015
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2016
|
+
accountId: '123456789'
|
|
2017
|
+
* });
|
|
1743
2018
|
*
|
|
1744
2019
|
* // Handle response with warnings
|
|
1745
2020
|
* if (result.success) {
|
|
@@ -1752,23 +2027,19 @@ class BrokersWrapper {
|
|
|
1752
2027
|
* }
|
|
1753
2028
|
* ```
|
|
1754
2029
|
*/
|
|
1755
|
-
async getOrders(
|
|
1756
|
-
//
|
|
1757
|
-
const
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
createdBefore: createdBefore,
|
|
1769
|
-
includeMetadata: includeMetadata
|
|
1770
|
-
}; // Authentication check
|
|
1771
|
-
if (!this.sessionId) {
|
|
2030
|
+
async getOrders(params) {
|
|
2031
|
+
// Use params object (with default empty object)
|
|
2032
|
+
const resolvedParams = params || {};
|
|
2033
|
+
if (params?.orderStatus !== undefined) {
|
|
2034
|
+
params.orderStatus = coerceEnumValue(params.orderStatus, exports.BrokerDataOrderStatusEnum, 'orderStatus');
|
|
2035
|
+
}
|
|
2036
|
+
if (params?.side !== undefined) {
|
|
2037
|
+
params.side = coerceEnumValue(params.side, exports.BrokerDataOrderSideEnum, 'side');
|
|
2038
|
+
}
|
|
2039
|
+
if (params?.assetType !== undefined) {
|
|
2040
|
+
params.assetType = coerceEnumValue(params.assetType, exports.BrokerDataAssetTypeEnum, 'assetType');
|
|
2041
|
+
} // Authentication check
|
|
2042
|
+
if (!this.sessionId || !this.companyId) {
|
|
1772
2043
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1773
2044
|
}
|
|
1774
2045
|
// Generate request ID
|
|
@@ -1779,7 +2050,7 @@ class BrokersWrapper {
|
|
|
1779
2050
|
const shouldCache = true;
|
|
1780
2051
|
const cache = getCache(this.sdkConfig);
|
|
1781
2052
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1782
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders',
|
|
2053
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
|
|
1783
2054
|
const cached = cache.get(cacheKey);
|
|
1784
2055
|
if (cached) {
|
|
1785
2056
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1791,12 +2062,12 @@ class BrokersWrapper {
|
|
|
1791
2062
|
request_id: requestId,
|
|
1792
2063
|
method: 'GET',
|
|
1793
2064
|
path: '/api/v1/brokers/data/orders',
|
|
1794
|
-
params:
|
|
2065
|
+
params: resolvedParams,
|
|
1795
2066
|
action: 'getOrders'
|
|
1796
2067
|
});
|
|
1797
2068
|
try {
|
|
1798
2069
|
const response = await retryApiCall(async () => {
|
|
1799
|
-
const apiResponse = await this.api.getOrdersApiV1BrokersDataOrdersGet({
|
|
2070
|
+
const apiResponse = await this.api.getOrdersApiV1BrokersDataOrdersGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, symbol: resolvedParams.symbol, orderStatus: resolvedParams.orderStatus, side: resolvedParams.side, assetType: resolvedParams.assetType, limit: resolvedParams.limit, offset: resolvedParams.offset, createdAfter: resolvedParams.createdAfter, createdBefore: resolvedParams.createdBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
1800
2071
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1801
2072
|
}, {}, this.sdkConfig);
|
|
1802
2073
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1805,9 +2076,27 @@ class BrokersWrapper {
|
|
|
1805
2076
|
throw new Error('Unexpected response shape: missing success field');
|
|
1806
2077
|
}
|
|
1807
2078
|
// Convert response to plain object, removing _id fields recursively
|
|
2079
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1808
2080
|
const standardResponse = convertToPlainObject(responseData);
|
|
2081
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2082
|
+
const hasLimit = true;
|
|
2083
|
+
const hasOffset = true;
|
|
2084
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2085
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2086
|
+
// PaginatedData is already imported at top of file
|
|
2087
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2088
|
+
if (paginationMeta) {
|
|
2089
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2090
|
+
has_more: paginationMeta.has_more,
|
|
2091
|
+
next_offset: paginationMeta.next_offset,
|
|
2092
|
+
current_offset: paginationMeta.current_offset,
|
|
2093
|
+
limit: paginationMeta.limit,
|
|
2094
|
+
}, this.getOrders.bind(this), resolvedParams, this);
|
|
2095
|
+
standardResponse.success.data = paginatedData;
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
1809
2098
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1810
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders',
|
|
2099
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
|
|
1811
2100
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1812
2101
|
}
|
|
1813
2102
|
this.logger.debug('Get Orders completed', {
|
|
@@ -1815,6 +2104,7 @@ class BrokersWrapper {
|
|
|
1815
2104
|
action: 'getOrders'
|
|
1816
2105
|
});
|
|
1817
2106
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2107
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1818
2108
|
return standardResponse;
|
|
1819
2109
|
}
|
|
1820
2110
|
catch (error) {
|
|
@@ -1891,19 +2181,19 @@ class BrokersWrapper {
|
|
|
1891
2181
|
*
|
|
1892
2182
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1893
2183
|
* Returns positions from connections the company has read access to.
|
|
1894
|
-
* @param brokerId {string} (optional)
|
|
1895
|
-
* @param connectionId {string} (optional)
|
|
1896
|
-
* @param accountId {string} (optional)
|
|
1897
|
-
* @param symbol {string} (optional)
|
|
1898
|
-
* @param side {BrokerDataOrderSideEnum} (optional)
|
|
1899
|
-
* @param assetType {BrokerDataAssetTypeEnum} (optional)
|
|
1900
|
-
* @param positionStatus {BrokerDataPositionStatusEnum} (optional)
|
|
1901
|
-
* @param limit {number} (optional)
|
|
1902
|
-
* @param offset {number} (optional)
|
|
1903
|
-
* @param updatedAfter {string} (optional)
|
|
1904
|
-
* @param updatedBefore {string} (optional)
|
|
1905
|
-
* @param includeMetadata {boolean} (optional)
|
|
1906
|
-
* @returns {Promise<FinaticResponse<FDXBrokerPosition
|
|
2184
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2185
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2186
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID
|
|
2187
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
2188
|
+
* @param params.side {BrokerDataOrderSideEnum} (optional) Filter by position side (e.g., 'long', 'short')
|
|
2189
|
+
* @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
|
|
2190
|
+
* @param params.positionStatus {BrokerDataPositionStatusEnum} (optional) Filter by position status: 'open' (quantity > 0) or 'closed' (quantity = 0)
|
|
2191
|
+
* @param params.limit {number} (optional) Maximum number of positions to return
|
|
2192
|
+
* @param params.offset {number} (optional) Number of positions to skip for pagination
|
|
2193
|
+
* @param params.updatedAfter {string} (optional) Filter positions updated after this timestamp
|
|
2194
|
+
* @param params.updatedBefore {string} (optional) Filter positions updated before this timestamp
|
|
2195
|
+
* @param params.includeMetadata {boolean} (optional) Include position metadata in response (excluded by default for FDX compliance)
|
|
2196
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPosition>>>} Standard response with success/Error/Warning structure
|
|
1907
2197
|
*
|
|
1908
2198
|
* Generated from: GET /api/v1/brokers/data/positions
|
|
1909
2199
|
* @methodId get_positions_api_v1_brokers_data_positions_get
|
|
@@ -1911,7 +2201,7 @@ class BrokersWrapper {
|
|
|
1911
2201
|
* @example
|
|
1912
2202
|
* ```typescript-client
|
|
1913
2203
|
* // Example with no parameters
|
|
1914
|
-
* const result = await finatic.getPositions();
|
|
2204
|
+
* const result = await finatic.getPositions({});
|
|
1915
2205
|
*
|
|
1916
2206
|
* // Access the response data
|
|
1917
2207
|
* if (result.success) {
|
|
@@ -1921,7 +2211,11 @@ class BrokersWrapper {
|
|
|
1921
2211
|
* @example
|
|
1922
2212
|
* ```typescript-client
|
|
1923
2213
|
* // Full example with optional parameters
|
|
1924
|
-
* const result = await finatic.getPositions(
|
|
2214
|
+
* const result = await finatic.getPositions({
|
|
2215
|
+
brokerId: 'alpaca',
|
|
2216
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2217
|
+
accountId: '123456789'
|
|
2218
|
+
* });
|
|
1925
2219
|
*
|
|
1926
2220
|
* // Handle response with warnings
|
|
1927
2221
|
* if (result.success) {
|
|
@@ -1934,23 +2228,19 @@ class BrokersWrapper {
|
|
|
1934
2228
|
* }
|
|
1935
2229
|
* ```
|
|
1936
2230
|
*/
|
|
1937
|
-
async getPositions(
|
|
1938
|
-
//
|
|
1939
|
-
const
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
updatedBefore: updatedBefore,
|
|
1951
|
-
includeMetadata: includeMetadata
|
|
1952
|
-
}; // Authentication check
|
|
1953
|
-
if (!this.sessionId) {
|
|
2231
|
+
async getPositions(params) {
|
|
2232
|
+
// Use params object (with default empty object)
|
|
2233
|
+
const resolvedParams = params || {};
|
|
2234
|
+
if (params?.side !== undefined) {
|
|
2235
|
+
params.side = coerceEnumValue(params.side, exports.BrokerDataOrderSideEnum, 'side');
|
|
2236
|
+
}
|
|
2237
|
+
if (params?.assetType !== undefined) {
|
|
2238
|
+
params.assetType = coerceEnumValue(params.assetType, exports.BrokerDataAssetTypeEnum, 'assetType');
|
|
2239
|
+
}
|
|
2240
|
+
if (params?.positionStatus !== undefined) {
|
|
2241
|
+
params.positionStatus = coerceEnumValue(params.positionStatus, exports.BrokerDataPositionStatusEnum, 'positionStatus');
|
|
2242
|
+
} // Authentication check
|
|
2243
|
+
if (!this.sessionId || !this.companyId) {
|
|
1954
2244
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1955
2245
|
}
|
|
1956
2246
|
// Generate request ID
|
|
@@ -1961,7 +2251,7 @@ class BrokersWrapper {
|
|
|
1961
2251
|
const shouldCache = true;
|
|
1962
2252
|
const cache = getCache(this.sdkConfig);
|
|
1963
2253
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1964
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions',
|
|
2254
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
|
|
1965
2255
|
const cached = cache.get(cacheKey);
|
|
1966
2256
|
if (cached) {
|
|
1967
2257
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1973,12 +2263,12 @@ class BrokersWrapper {
|
|
|
1973
2263
|
request_id: requestId,
|
|
1974
2264
|
method: 'GET',
|
|
1975
2265
|
path: '/api/v1/brokers/data/positions',
|
|
1976
|
-
params:
|
|
2266
|
+
params: resolvedParams,
|
|
1977
2267
|
action: 'getPositions'
|
|
1978
2268
|
});
|
|
1979
2269
|
try {
|
|
1980
2270
|
const response = await retryApiCall(async () => {
|
|
1981
|
-
const apiResponse = await this.api.getPositionsApiV1BrokersDataPositionsGet({
|
|
2271
|
+
const apiResponse = await this.api.getPositionsApiV1BrokersDataPositionsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, symbol: resolvedParams.symbol, side: resolvedParams.side, assetType: resolvedParams.assetType, positionStatus: resolvedParams.positionStatus, limit: resolvedParams.limit, offset: resolvedParams.offset, updatedAfter: resolvedParams.updatedAfter, updatedBefore: resolvedParams.updatedBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
1982
2272
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1983
2273
|
}, {}, this.sdkConfig);
|
|
1984
2274
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1987,9 +2277,27 @@ class BrokersWrapper {
|
|
|
1987
2277
|
throw new Error('Unexpected response shape: missing success field');
|
|
1988
2278
|
}
|
|
1989
2279
|
// Convert response to plain object, removing _id fields recursively
|
|
2280
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1990
2281
|
const standardResponse = convertToPlainObject(responseData);
|
|
2282
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2283
|
+
const hasLimit = true;
|
|
2284
|
+
const hasOffset = true;
|
|
2285
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2286
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2287
|
+
// PaginatedData is already imported at top of file
|
|
2288
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2289
|
+
if (paginationMeta) {
|
|
2290
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2291
|
+
has_more: paginationMeta.has_more,
|
|
2292
|
+
next_offset: paginationMeta.next_offset,
|
|
2293
|
+
current_offset: paginationMeta.current_offset,
|
|
2294
|
+
limit: paginationMeta.limit,
|
|
2295
|
+
}, this.getPositions.bind(this), resolvedParams, this);
|
|
2296
|
+
standardResponse.success.data = paginatedData;
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
1991
2299
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1992
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions',
|
|
2300
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
|
|
1993
2301
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1994
2302
|
}
|
|
1995
2303
|
this.logger.debug('Get Positions completed', {
|
|
@@ -1997,6 +2305,7 @@ class BrokersWrapper {
|
|
|
1997
2305
|
action: 'getPositions'
|
|
1998
2306
|
});
|
|
1999
2307
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2308
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2000
2309
|
return standardResponse;
|
|
2001
2310
|
}
|
|
2002
2311
|
catch (error) {
|
|
@@ -2073,16 +2382,16 @@ class BrokersWrapper {
|
|
|
2073
2382
|
*
|
|
2074
2383
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
2075
2384
|
* Returns balances from connections the company has read access to.
|
|
2076
|
-
* @param brokerId {string} (optional)
|
|
2077
|
-
* @param connectionId {string} (optional)
|
|
2078
|
-
* @param accountId {string} (optional)
|
|
2079
|
-
* @param isEndOfDaySnapshot {boolean} (optional)
|
|
2080
|
-
* @param limit {number} (optional)
|
|
2081
|
-
* @param offset {number} (optional)
|
|
2082
|
-
* @param balanceCreatedAfter {string} (optional)
|
|
2083
|
-
* @param balanceCreatedBefore {string} (optional)
|
|
2084
|
-
* @param includeMetadata {boolean} (optional)
|
|
2085
|
-
* @returns {Promise<FinaticResponse<FDXBrokerBalance
|
|
2385
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2386
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2387
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID
|
|
2388
|
+
* @param params.isEndOfDaySnapshot {boolean} (optional) Filter by end-of-day snapshot status (true/false)
|
|
2389
|
+
* @param params.limit {number} (optional) Maximum number of balances to return
|
|
2390
|
+
* @param params.offset {number} (optional) Number of balances to skip for pagination
|
|
2391
|
+
* @param params.balanceCreatedAfter {string} (optional) Filter balances created after this timestamp
|
|
2392
|
+
* @param params.balanceCreatedBefore {string} (optional) Filter balances created before this timestamp
|
|
2393
|
+
* @param params.includeMetadata {boolean} (optional) Include balance metadata in response (excluded by default for FDX compliance)
|
|
2394
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerBalance>>>} Standard response with success/Error/Warning structure
|
|
2086
2395
|
*
|
|
2087
2396
|
* Generated from: GET /api/v1/brokers/data/balances
|
|
2088
2397
|
* @methodId get_balances_api_v1_brokers_data_balances_get
|
|
@@ -2090,7 +2399,7 @@ class BrokersWrapper {
|
|
|
2090
2399
|
* @example
|
|
2091
2400
|
* ```typescript-client
|
|
2092
2401
|
* // Example with no parameters
|
|
2093
|
-
* const result = await finatic.getBalances();
|
|
2402
|
+
* const result = await finatic.getBalances({});
|
|
2094
2403
|
*
|
|
2095
2404
|
* // Access the response data
|
|
2096
2405
|
* if (result.success) {
|
|
@@ -2100,7 +2409,11 @@ class BrokersWrapper {
|
|
|
2100
2409
|
* @example
|
|
2101
2410
|
* ```typescript-client
|
|
2102
2411
|
* // Full example with optional parameters
|
|
2103
|
-
* const result = await finatic.getBalances(
|
|
2412
|
+
* const result = await finatic.getBalances({
|
|
2413
|
+
brokerId: 'alpaca',
|
|
2414
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2415
|
+
accountId: '123456789'
|
|
2416
|
+
* });
|
|
2104
2417
|
*
|
|
2105
2418
|
* // Handle response with warnings
|
|
2106
2419
|
* if (result.success) {
|
|
@@ -2113,20 +2426,10 @@ class BrokersWrapper {
|
|
|
2113
2426
|
* }
|
|
2114
2427
|
* ```
|
|
2115
2428
|
*/
|
|
2116
|
-
async getBalances(
|
|
2117
|
-
//
|
|
2118
|
-
const
|
|
2119
|
-
|
|
2120
|
-
connectionId: connectionId,
|
|
2121
|
-
accountId: accountId,
|
|
2122
|
-
isEndOfDaySnapshot: isEndOfDaySnapshot,
|
|
2123
|
-
limit: limit,
|
|
2124
|
-
offset: offset,
|
|
2125
|
-
balanceCreatedAfter: balanceCreatedAfter,
|
|
2126
|
-
balanceCreatedBefore: balanceCreatedBefore,
|
|
2127
|
-
includeMetadata: includeMetadata
|
|
2128
|
-
}; // Authentication check
|
|
2129
|
-
if (!this.sessionId) {
|
|
2429
|
+
async getBalances(params) {
|
|
2430
|
+
// Use params object (with default empty object)
|
|
2431
|
+
const resolvedParams = params || {}; // Authentication check
|
|
2432
|
+
if (!this.sessionId || !this.companyId) {
|
|
2130
2433
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2131
2434
|
}
|
|
2132
2435
|
// Generate request ID
|
|
@@ -2137,7 +2440,7 @@ class BrokersWrapper {
|
|
|
2137
2440
|
const shouldCache = true;
|
|
2138
2441
|
const cache = getCache(this.sdkConfig);
|
|
2139
2442
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2140
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances',
|
|
2443
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
|
|
2141
2444
|
const cached = cache.get(cacheKey);
|
|
2142
2445
|
if (cached) {
|
|
2143
2446
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2149,12 +2452,12 @@ class BrokersWrapper {
|
|
|
2149
2452
|
request_id: requestId,
|
|
2150
2453
|
method: 'GET',
|
|
2151
2454
|
path: '/api/v1/brokers/data/balances',
|
|
2152
|
-
params:
|
|
2455
|
+
params: resolvedParams,
|
|
2153
2456
|
action: 'getBalances'
|
|
2154
2457
|
});
|
|
2155
2458
|
try {
|
|
2156
2459
|
const response = await retryApiCall(async () => {
|
|
2157
|
-
const apiResponse = await this.api.getBalancesApiV1BrokersDataBalancesGet({
|
|
2460
|
+
const apiResponse = await this.api.getBalancesApiV1BrokersDataBalancesGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, isEndOfDaySnapshot: resolvedParams.isEndOfDaySnapshot, limit: resolvedParams.limit, offset: resolvedParams.offset, balanceCreatedAfter: resolvedParams.balanceCreatedAfter, balanceCreatedBefore: resolvedParams.balanceCreatedBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
2158
2461
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2159
2462
|
}, {}, this.sdkConfig);
|
|
2160
2463
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2163,9 +2466,27 @@ class BrokersWrapper {
|
|
|
2163
2466
|
throw new Error('Unexpected response shape: missing success field');
|
|
2164
2467
|
}
|
|
2165
2468
|
// Convert response to plain object, removing _id fields recursively
|
|
2469
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2166
2470
|
const standardResponse = convertToPlainObject(responseData);
|
|
2471
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2472
|
+
const hasLimit = true;
|
|
2473
|
+
const hasOffset = true;
|
|
2474
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2475
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2476
|
+
// PaginatedData is already imported at top of file
|
|
2477
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2478
|
+
if (paginationMeta) {
|
|
2479
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2480
|
+
has_more: paginationMeta.has_more,
|
|
2481
|
+
next_offset: paginationMeta.next_offset,
|
|
2482
|
+
current_offset: paginationMeta.current_offset,
|
|
2483
|
+
limit: paginationMeta.limit,
|
|
2484
|
+
}, this.getBalances.bind(this), resolvedParams, this);
|
|
2485
|
+
standardResponse.success.data = paginatedData;
|
|
2486
|
+
}
|
|
2487
|
+
}
|
|
2167
2488
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2168
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances',
|
|
2489
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
|
|
2169
2490
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2170
2491
|
}
|
|
2171
2492
|
this.logger.debug('Get Balances completed', {
|
|
@@ -2173,6 +2494,7 @@ class BrokersWrapper {
|
|
|
2173
2494
|
action: 'getBalances'
|
|
2174
2495
|
});
|
|
2175
2496
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2497
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2176
2498
|
return standardResponse;
|
|
2177
2499
|
}
|
|
2178
2500
|
catch (error) {
|
|
@@ -2249,15 +2571,15 @@ class BrokersWrapper {
|
|
|
2249
2571
|
*
|
|
2250
2572
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
2251
2573
|
* Returns accounts from connections the company has read access to.
|
|
2252
|
-
* @param brokerId {string} (optional)
|
|
2253
|
-
* @param connectionId {string} (optional)
|
|
2254
|
-
* @param accountType {BrokerDataAccountTypeEnum} (optional)
|
|
2255
|
-
* @param status {AccountStatus} (optional)
|
|
2256
|
-
* @param currency {string} (optional)
|
|
2257
|
-
* @param limit {number} (optional)
|
|
2258
|
-
* @param offset {number} (optional)
|
|
2259
|
-
* @param includeMetadata {boolean} (optional)
|
|
2260
|
-
* @returns {Promise<FinaticResponse<FDXBrokerAccount
|
|
2574
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2575
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2576
|
+
* @param params.accountType {BrokerDataAccountTypeEnum} (optional) Filter by account type (e.g., 'margin', 'cash', 'crypto_wallet', 'live', 'sim')
|
|
2577
|
+
* @param params.status {AccountStatus} (optional) Filter by account status (e.g., 'active', 'inactive')
|
|
2578
|
+
* @param params.currency {string} (optional) Filter by currency (e.g., 'USD', 'EUR')
|
|
2579
|
+
* @param params.limit {number} (optional) Maximum number of accounts to return
|
|
2580
|
+
* @param params.offset {number} (optional) Number of accounts to skip for pagination
|
|
2581
|
+
* @param params.includeMetadata {boolean} (optional) Include connection metadata in response (excluded by default for FDX compliance)
|
|
2582
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerAccount>>>} Standard response with success/Error/Warning structure
|
|
2261
2583
|
*
|
|
2262
2584
|
* Generated from: GET /api/v1/brokers/data/accounts
|
|
2263
2585
|
* @methodId get_accounts_api_v1_brokers_data_accounts_get
|
|
@@ -2265,7 +2587,7 @@ class BrokersWrapper {
|
|
|
2265
2587
|
* @example
|
|
2266
2588
|
* ```typescript-client
|
|
2267
2589
|
* // Example with no parameters
|
|
2268
|
-
* const result = await finatic.getAccounts();
|
|
2590
|
+
* const result = await finatic.getAccounts({});
|
|
2269
2591
|
*
|
|
2270
2592
|
* // Access the response data
|
|
2271
2593
|
* if (result.success) {
|
|
@@ -2275,7 +2597,11 @@ class BrokersWrapper {
|
|
|
2275
2597
|
* @example
|
|
2276
2598
|
* ```typescript-client
|
|
2277
2599
|
* // Full example with optional parameters
|
|
2278
|
-
* const result = await finatic.getAccounts(
|
|
2600
|
+
* const result = await finatic.getAccounts({
|
|
2601
|
+
brokerId: 'alpaca',
|
|
2602
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2603
|
+
accountType: 'margin'
|
|
2604
|
+
* });
|
|
2279
2605
|
*
|
|
2280
2606
|
* // Handle response with warnings
|
|
2281
2607
|
* if (result.success) {
|
|
@@ -2288,19 +2614,13 @@ class BrokersWrapper {
|
|
|
2288
2614
|
* }
|
|
2289
2615
|
* ```
|
|
2290
2616
|
*/
|
|
2291
|
-
async getAccounts(
|
|
2292
|
-
//
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
currency: currency,
|
|
2299
|
-
limit: limit,
|
|
2300
|
-
offset: offset,
|
|
2301
|
-
includeMetadata: includeMetadata
|
|
2302
|
-
}; // Authentication check
|
|
2303
|
-
if (!this.sessionId) {
|
|
2617
|
+
async getAccounts(params) {
|
|
2618
|
+
// Use params object (with default empty object)
|
|
2619
|
+
const resolvedParams = params || {};
|
|
2620
|
+
if (params?.accountType !== undefined) {
|
|
2621
|
+
params.accountType = coerceEnumValue(params.accountType, exports.BrokerDataAccountTypeEnum, 'accountType');
|
|
2622
|
+
} // Authentication check
|
|
2623
|
+
if (!this.sessionId || !this.companyId) {
|
|
2304
2624
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2305
2625
|
}
|
|
2306
2626
|
// Generate request ID
|
|
@@ -2311,7 +2631,7 @@ class BrokersWrapper {
|
|
|
2311
2631
|
const shouldCache = true;
|
|
2312
2632
|
const cache = getCache(this.sdkConfig);
|
|
2313
2633
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2314
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts',
|
|
2634
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
|
|
2315
2635
|
const cached = cache.get(cacheKey);
|
|
2316
2636
|
if (cached) {
|
|
2317
2637
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2323,12 +2643,12 @@ class BrokersWrapper {
|
|
|
2323
2643
|
request_id: requestId,
|
|
2324
2644
|
method: 'GET',
|
|
2325
2645
|
path: '/api/v1/brokers/data/accounts',
|
|
2326
|
-
params:
|
|
2646
|
+
params: resolvedParams,
|
|
2327
2647
|
action: 'getAccounts'
|
|
2328
2648
|
});
|
|
2329
2649
|
try {
|
|
2330
2650
|
const response = await retryApiCall(async () => {
|
|
2331
|
-
const apiResponse = await this.api.getAccountsApiV1BrokersDataAccountsGet({
|
|
2651
|
+
const apiResponse = await this.api.getAccountsApiV1BrokersDataAccountsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountType: resolvedParams.accountType, status: resolvedParams.status, currency: resolvedParams.currency, limit: resolvedParams.limit, offset: resolvedParams.offset, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
2332
2652
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2333
2653
|
}, {}, this.sdkConfig);
|
|
2334
2654
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2337,9 +2657,27 @@ class BrokersWrapper {
|
|
|
2337
2657
|
throw new Error('Unexpected response shape: missing success field');
|
|
2338
2658
|
}
|
|
2339
2659
|
// Convert response to plain object, removing _id fields recursively
|
|
2660
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2340
2661
|
const standardResponse = convertToPlainObject(responseData);
|
|
2662
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2663
|
+
const hasLimit = true;
|
|
2664
|
+
const hasOffset = true;
|
|
2665
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2666
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2667
|
+
// PaginatedData is already imported at top of file
|
|
2668
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2669
|
+
if (paginationMeta) {
|
|
2670
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2671
|
+
has_more: paginationMeta.has_more,
|
|
2672
|
+
next_offset: paginationMeta.next_offset,
|
|
2673
|
+
current_offset: paginationMeta.current_offset,
|
|
2674
|
+
limit: paginationMeta.limit,
|
|
2675
|
+
}, this.getAccounts.bind(this), resolvedParams, this);
|
|
2676
|
+
standardResponse.success.data = paginatedData;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2341
2679
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2342
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts',
|
|
2680
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
|
|
2343
2681
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2344
2682
|
}
|
|
2345
2683
|
this.logger.debug('Get Accounts completed', {
|
|
@@ -2347,6 +2685,7 @@ class BrokersWrapper {
|
|
|
2347
2685
|
action: 'getAccounts'
|
|
2348
2686
|
});
|
|
2349
2687
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2688
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2350
2689
|
return standardResponse;
|
|
2351
2690
|
}
|
|
2352
2691
|
catch (error) {
|
|
@@ -2422,12 +2761,12 @@ class BrokersWrapper {
|
|
|
2422
2761
|
* Get order fills for a specific order.
|
|
2423
2762
|
*
|
|
2424
2763
|
* This endpoint returns all execution fills for the specified order.
|
|
2425
|
-
* @param orderId {string}
|
|
2426
|
-
* @param connectionId {string} (optional)
|
|
2427
|
-
* @param limit {number} (optional)
|
|
2428
|
-
* @param offset {number} (optional)
|
|
2429
|
-
* @param includeMetadata {boolean} (optional)
|
|
2430
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrderFill
|
|
2764
|
+
* @param params.orderId {string} Order ID
|
|
2765
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2766
|
+
* @param params.limit {number} (optional) Maximum number of fills to return
|
|
2767
|
+
* @param params.offset {number} (optional) Number of fills to skip for pagination
|
|
2768
|
+
* @param params.includeMetadata {boolean} (optional) Include fill metadata in response (excluded by default for FDX compliance)
|
|
2769
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderFill>>>} Standard response with success/Error/Warning structure
|
|
2431
2770
|
*
|
|
2432
2771
|
* Generated from: GET /api/v1/brokers/data/orders/{order_id}/fills
|
|
2433
2772
|
* @methodId get_order_fills_api_v1_brokers_data_orders__order_id__fills_get
|
|
@@ -2435,7 +2774,9 @@ class BrokersWrapper {
|
|
|
2435
2774
|
* @example
|
|
2436
2775
|
* ```typescript-client
|
|
2437
2776
|
* // Minimal example with required parameters only
|
|
2438
|
-
* const result = await finatic.getOrderFills(
|
|
2777
|
+
* const result = await finatic.getOrderFills({
|
|
2778
|
+
orderId: '00000000-0000-0000-0000-000000000000'
|
|
2779
|
+
* });
|
|
2439
2780
|
*
|
|
2440
2781
|
* // Access the response data
|
|
2441
2782
|
* if (result.success) {
|
|
@@ -2447,7 +2788,12 @@ class BrokersWrapper {
|
|
|
2447
2788
|
* @example
|
|
2448
2789
|
* ```typescript-client
|
|
2449
2790
|
* // Full example with optional parameters
|
|
2450
|
-
* const result = await finatic.getOrderFills(
|
|
2791
|
+
* const result = await finatic.getOrderFills({
|
|
2792
|
+
orderId: '00000000-0000-0000-0000-000000000000',
|
|
2793
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2794
|
+
limit: 100,
|
|
2795
|
+
offset: 0
|
|
2796
|
+
* });
|
|
2451
2797
|
*
|
|
2452
2798
|
* // Handle response with warnings
|
|
2453
2799
|
* if (result.success) {
|
|
@@ -2460,16 +2806,10 @@ class BrokersWrapper {
|
|
|
2460
2806
|
* }
|
|
2461
2807
|
* ```
|
|
2462
2808
|
*/
|
|
2463
|
-
async getOrderFills(
|
|
2464
|
-
//
|
|
2465
|
-
const
|
|
2466
|
-
|
|
2467
|
-
connectionId: connectionId,
|
|
2468
|
-
limit: limit,
|
|
2469
|
-
offset: offset,
|
|
2470
|
-
includeMetadata: includeMetadata
|
|
2471
|
-
}; // Authentication check
|
|
2472
|
-
if (!this.sessionId) {
|
|
2809
|
+
async getOrderFills(params) {
|
|
2810
|
+
// Use params object (required parameters present)
|
|
2811
|
+
const resolvedParams = params; // Authentication check
|
|
2812
|
+
if (!this.sessionId || !this.companyId) {
|
|
2473
2813
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2474
2814
|
}
|
|
2475
2815
|
// Generate request ID
|
|
@@ -2480,7 +2820,7 @@ class BrokersWrapper {
|
|
|
2480
2820
|
const shouldCache = true;
|
|
2481
2821
|
const cache = getCache(this.sdkConfig);
|
|
2482
2822
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2483
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2823
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
|
|
2484
2824
|
const cached = cache.get(cacheKey);
|
|
2485
2825
|
if (cached) {
|
|
2486
2826
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2492,12 +2832,12 @@ class BrokersWrapper {
|
|
|
2492
2832
|
request_id: requestId,
|
|
2493
2833
|
method: 'GET',
|
|
2494
2834
|
path: '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2495
|
-
params:
|
|
2835
|
+
params: resolvedParams,
|
|
2496
2836
|
action: 'getOrderFills'
|
|
2497
2837
|
});
|
|
2498
2838
|
try {
|
|
2499
2839
|
const response = await retryApiCall(async () => {
|
|
2500
|
-
const apiResponse = await this.api.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet({ orderId: orderId,
|
|
2840
|
+
const apiResponse = await this.api.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet({ orderId: resolvedParams.orderId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
2501
2841
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2502
2842
|
}, {}, this.sdkConfig);
|
|
2503
2843
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2506,9 +2846,27 @@ class BrokersWrapper {
|
|
|
2506
2846
|
throw new Error('Unexpected response shape: missing success field');
|
|
2507
2847
|
}
|
|
2508
2848
|
// Convert response to plain object, removing _id fields recursively
|
|
2849
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2509
2850
|
const standardResponse = convertToPlainObject(responseData);
|
|
2851
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2852
|
+
const hasLimit = true;
|
|
2853
|
+
const hasOffset = true;
|
|
2854
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2855
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2856
|
+
// PaginatedData is already imported at top of file
|
|
2857
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2858
|
+
if (paginationMeta) {
|
|
2859
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2860
|
+
has_more: paginationMeta.has_more,
|
|
2861
|
+
next_offset: paginationMeta.next_offset,
|
|
2862
|
+
current_offset: paginationMeta.current_offset,
|
|
2863
|
+
limit: paginationMeta.limit,
|
|
2864
|
+
}, this.getOrderFills.bind(this), resolvedParams, this);
|
|
2865
|
+
standardResponse.success.data = paginatedData;
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2510
2868
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2511
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2869
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
|
|
2512
2870
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2513
2871
|
}
|
|
2514
2872
|
this.logger.debug('Get Order Fills completed', {
|
|
@@ -2516,6 +2874,7 @@ class BrokersWrapper {
|
|
|
2516
2874
|
action: 'getOrderFills'
|
|
2517
2875
|
});
|
|
2518
2876
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2877
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2519
2878
|
return standardResponse;
|
|
2520
2879
|
}
|
|
2521
2880
|
catch (error) {
|
|
@@ -2591,12 +2950,12 @@ class BrokersWrapper {
|
|
|
2591
2950
|
* Get order events for a specific order.
|
|
2592
2951
|
*
|
|
2593
2952
|
* This endpoint returns all lifecycle events for the specified order.
|
|
2594
|
-
* @param orderId {string}
|
|
2595
|
-
* @param connectionId {string} (optional)
|
|
2596
|
-
* @param limit {number} (optional)
|
|
2597
|
-
* @param offset {number} (optional)
|
|
2598
|
-
* @param includeMetadata {boolean} (optional)
|
|
2599
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrderEvent
|
|
2953
|
+
* @param params.orderId {string} Order ID
|
|
2954
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2955
|
+
* @param params.limit {number} (optional) Maximum number of events to return
|
|
2956
|
+
* @param params.offset {number} (optional) Number of events to skip for pagination
|
|
2957
|
+
* @param params.includeMetadata {boolean} (optional) Include event metadata in response (excluded by default for FDX compliance)
|
|
2958
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderEvent>>>} Standard response with success/Error/Warning structure
|
|
2600
2959
|
*
|
|
2601
2960
|
* Generated from: GET /api/v1/brokers/data/orders/{order_id}/events
|
|
2602
2961
|
* @methodId get_order_events_api_v1_brokers_data_orders__order_id__events_get
|
|
@@ -2604,7 +2963,9 @@ class BrokersWrapper {
|
|
|
2604
2963
|
* @example
|
|
2605
2964
|
* ```typescript-client
|
|
2606
2965
|
* // Minimal example with required parameters only
|
|
2607
|
-
* const result = await finatic.getOrderEvents(
|
|
2966
|
+
* const result = await finatic.getOrderEvents({
|
|
2967
|
+
orderId: '00000000-0000-0000-0000-000000000000'
|
|
2968
|
+
* });
|
|
2608
2969
|
*
|
|
2609
2970
|
* // Access the response data
|
|
2610
2971
|
* if (result.success) {
|
|
@@ -2616,7 +2977,12 @@ class BrokersWrapper {
|
|
|
2616
2977
|
* @example
|
|
2617
2978
|
* ```typescript-client
|
|
2618
2979
|
* // Full example with optional parameters
|
|
2619
|
-
* const result = await finatic.getOrderEvents(
|
|
2980
|
+
* const result = await finatic.getOrderEvents({
|
|
2981
|
+
orderId: '00000000-0000-0000-0000-000000000000',
|
|
2982
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2983
|
+
limit: 100,
|
|
2984
|
+
offset: 0
|
|
2985
|
+
* });
|
|
2620
2986
|
*
|
|
2621
2987
|
* // Handle response with warnings
|
|
2622
2988
|
* if (result.success) {
|
|
@@ -2629,16 +2995,10 @@ class BrokersWrapper {
|
|
|
2629
2995
|
* }
|
|
2630
2996
|
* ```
|
|
2631
2997
|
*/
|
|
2632
|
-
async getOrderEvents(
|
|
2633
|
-
//
|
|
2634
|
-
const
|
|
2635
|
-
|
|
2636
|
-
connectionId: connectionId,
|
|
2637
|
-
limit: limit,
|
|
2638
|
-
offset: offset,
|
|
2639
|
-
includeMetadata: includeMetadata
|
|
2640
|
-
}; // Authentication check
|
|
2641
|
-
if (!this.sessionId) {
|
|
2998
|
+
async getOrderEvents(params) {
|
|
2999
|
+
// Use params object (required parameters present)
|
|
3000
|
+
const resolvedParams = params; // Authentication check
|
|
3001
|
+
if (!this.sessionId || !this.companyId) {
|
|
2642
3002
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2643
3003
|
}
|
|
2644
3004
|
// Generate request ID
|
|
@@ -2649,7 +3009,7 @@ class BrokersWrapper {
|
|
|
2649
3009
|
const shouldCache = true;
|
|
2650
3010
|
const cache = getCache(this.sdkConfig);
|
|
2651
3011
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2652
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events',
|
|
3012
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
|
|
2653
3013
|
const cached = cache.get(cacheKey);
|
|
2654
3014
|
if (cached) {
|
|
2655
3015
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2661,12 +3021,12 @@ class BrokersWrapper {
|
|
|
2661
3021
|
request_id: requestId,
|
|
2662
3022
|
method: 'GET',
|
|
2663
3023
|
path: '/api/v1/brokers/data/orders/{order_id}/events',
|
|
2664
|
-
params:
|
|
3024
|
+
params: resolvedParams,
|
|
2665
3025
|
action: 'getOrderEvents'
|
|
2666
3026
|
});
|
|
2667
3027
|
try {
|
|
2668
3028
|
const response = await retryApiCall(async () => {
|
|
2669
|
-
const apiResponse = await this.api.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet({ orderId: orderId,
|
|
3029
|
+
const apiResponse = await this.api.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet({ orderId: resolvedParams.orderId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
2670
3030
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2671
3031
|
}, {}, this.sdkConfig);
|
|
2672
3032
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2675,9 +3035,27 @@ class BrokersWrapper {
|
|
|
2675
3035
|
throw new Error('Unexpected response shape: missing success field');
|
|
2676
3036
|
}
|
|
2677
3037
|
// Convert response to plain object, removing _id fields recursively
|
|
3038
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2678
3039
|
const standardResponse = convertToPlainObject(responseData);
|
|
3040
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3041
|
+
const hasLimit = true;
|
|
3042
|
+
const hasOffset = true;
|
|
3043
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3044
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3045
|
+
// PaginatedData is already imported at top of file
|
|
3046
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3047
|
+
if (paginationMeta) {
|
|
3048
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3049
|
+
has_more: paginationMeta.has_more,
|
|
3050
|
+
next_offset: paginationMeta.next_offset,
|
|
3051
|
+
current_offset: paginationMeta.current_offset,
|
|
3052
|
+
limit: paginationMeta.limit,
|
|
3053
|
+
}, this.getOrderEvents.bind(this), resolvedParams, this);
|
|
3054
|
+
standardResponse.success.data = paginatedData;
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
2679
3057
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2680
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events',
|
|
3058
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
|
|
2681
3059
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2682
3060
|
}
|
|
2683
3061
|
this.logger.debug('Get Order Events completed', {
|
|
@@ -2685,6 +3063,7 @@ class BrokersWrapper {
|
|
|
2685
3063
|
action: 'getOrderEvents'
|
|
2686
3064
|
});
|
|
2687
3065
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3066
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2688
3067
|
return standardResponse;
|
|
2689
3068
|
}
|
|
2690
3069
|
catch (error) {
|
|
@@ -2760,14 +3139,14 @@ class BrokersWrapper {
|
|
|
2760
3139
|
* Get order groups.
|
|
2761
3140
|
*
|
|
2762
3141
|
* This endpoint returns order groups that contain multiple orders.
|
|
2763
|
-
* @param brokerId {string} (optional)
|
|
2764
|
-
* @param connectionId {string} (optional)
|
|
2765
|
-
* @param limit {number} (optional)
|
|
2766
|
-
* @param offset {number} (optional)
|
|
2767
|
-
* @param createdAfter {string} (optional)
|
|
2768
|
-
* @param createdBefore {string} (optional)
|
|
2769
|
-
* @param includeMetadata {boolean} (optional)
|
|
2770
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrderGroup
|
|
3142
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
3143
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3144
|
+
* @param params.limit {number} (optional) Maximum number of order groups to return
|
|
3145
|
+
* @param params.offset {number} (optional) Number of order groups to skip for pagination
|
|
3146
|
+
* @param params.createdAfter {string} (optional) Filter order groups created after this timestamp
|
|
3147
|
+
* @param params.createdBefore {string} (optional) Filter order groups created before this timestamp
|
|
3148
|
+
* @param params.includeMetadata {boolean} (optional) Include group metadata in response (excluded by default for FDX compliance)
|
|
3149
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderGroup>>>} Standard response with success/Error/Warning structure
|
|
2771
3150
|
*
|
|
2772
3151
|
* Generated from: GET /api/v1/brokers/data/orders/groups
|
|
2773
3152
|
* @methodId get_order_groups_api_v1_brokers_data_orders_groups_get
|
|
@@ -2775,7 +3154,7 @@ class BrokersWrapper {
|
|
|
2775
3154
|
* @example
|
|
2776
3155
|
* ```typescript-client
|
|
2777
3156
|
* // Example with no parameters
|
|
2778
|
-
* const result = await finatic.getOrderGroups();
|
|
3157
|
+
* const result = await finatic.getOrderGroups({});
|
|
2779
3158
|
*
|
|
2780
3159
|
* // Access the response data
|
|
2781
3160
|
* if (result.success) {
|
|
@@ -2785,7 +3164,11 @@ class BrokersWrapper {
|
|
|
2785
3164
|
* @example
|
|
2786
3165
|
* ```typescript-client
|
|
2787
3166
|
* // Full example with optional parameters
|
|
2788
|
-
* const result = await finatic.getOrderGroups(
|
|
3167
|
+
* const result = await finatic.getOrderGroups({
|
|
3168
|
+
brokerId: 'alpaca',
|
|
3169
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3170
|
+
limit: 100
|
|
3171
|
+
* });
|
|
2789
3172
|
*
|
|
2790
3173
|
* // Handle response with warnings
|
|
2791
3174
|
* if (result.success) {
|
|
@@ -2798,18 +3181,10 @@ class BrokersWrapper {
|
|
|
2798
3181
|
* }
|
|
2799
3182
|
* ```
|
|
2800
3183
|
*/
|
|
2801
|
-
async getOrderGroups(
|
|
2802
|
-
//
|
|
2803
|
-
const
|
|
2804
|
-
|
|
2805
|
-
connectionId: connectionId,
|
|
2806
|
-
limit: limit,
|
|
2807
|
-
offset: offset,
|
|
2808
|
-
createdAfter: createdAfter,
|
|
2809
|
-
createdBefore: createdBefore,
|
|
2810
|
-
includeMetadata: includeMetadata
|
|
2811
|
-
}; // Authentication check
|
|
2812
|
-
if (!this.sessionId) {
|
|
3184
|
+
async getOrderGroups(params) {
|
|
3185
|
+
// Use params object (with default empty object)
|
|
3186
|
+
const resolvedParams = params || {}; // Authentication check
|
|
3187
|
+
if (!this.sessionId || !this.companyId) {
|
|
2813
3188
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2814
3189
|
}
|
|
2815
3190
|
// Generate request ID
|
|
@@ -2820,7 +3195,7 @@ class BrokersWrapper {
|
|
|
2820
3195
|
const shouldCache = true;
|
|
2821
3196
|
const cache = getCache(this.sdkConfig);
|
|
2822
3197
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2823
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups',
|
|
3198
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
|
|
2824
3199
|
const cached = cache.get(cacheKey);
|
|
2825
3200
|
if (cached) {
|
|
2826
3201
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2832,12 +3207,12 @@ class BrokersWrapper {
|
|
|
2832
3207
|
request_id: requestId,
|
|
2833
3208
|
method: 'GET',
|
|
2834
3209
|
path: '/api/v1/brokers/data/orders/groups',
|
|
2835
|
-
params:
|
|
3210
|
+
params: resolvedParams,
|
|
2836
3211
|
action: 'getOrderGroups'
|
|
2837
3212
|
});
|
|
2838
3213
|
try {
|
|
2839
3214
|
const response = await retryApiCall(async () => {
|
|
2840
|
-
const apiResponse = await this.api.getOrderGroupsApiV1BrokersDataOrdersGroupsGet({
|
|
3215
|
+
const apiResponse = await this.api.getOrderGroupsApiV1BrokersDataOrdersGroupsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset, createdAfter: resolvedParams.createdAfter, createdBefore: resolvedParams.createdBefore, includeMetadata: resolvedParams.includeMetadata }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
2841
3216
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2842
3217
|
}, {}, this.sdkConfig);
|
|
2843
3218
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2846,9 +3221,27 @@ class BrokersWrapper {
|
|
|
2846
3221
|
throw new Error('Unexpected response shape: missing success field');
|
|
2847
3222
|
}
|
|
2848
3223
|
// Convert response to plain object, removing _id fields recursively
|
|
3224
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2849
3225
|
const standardResponse = convertToPlainObject(responseData);
|
|
3226
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3227
|
+
const hasLimit = true;
|
|
3228
|
+
const hasOffset = true;
|
|
3229
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3230
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3231
|
+
// PaginatedData is already imported at top of file
|
|
3232
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3233
|
+
if (paginationMeta) {
|
|
3234
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3235
|
+
has_more: paginationMeta.has_more,
|
|
3236
|
+
next_offset: paginationMeta.next_offset,
|
|
3237
|
+
current_offset: paginationMeta.current_offset,
|
|
3238
|
+
limit: paginationMeta.limit,
|
|
3239
|
+
}, this.getOrderGroups.bind(this), resolvedParams, this);
|
|
3240
|
+
standardResponse.success.data = paginatedData;
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
2850
3243
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2851
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups',
|
|
3244
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
|
|
2852
3245
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2853
3246
|
}
|
|
2854
3247
|
this.logger.debug('Get Order Groups completed', {
|
|
@@ -2856,6 +3249,7 @@ class BrokersWrapper {
|
|
|
2856
3249
|
action: 'getOrderGroups'
|
|
2857
3250
|
});
|
|
2858
3251
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3252
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2859
3253
|
return standardResponse;
|
|
2860
3254
|
}
|
|
2861
3255
|
catch (error) {
|
|
@@ -2932,14 +3326,14 @@ class BrokersWrapper {
|
|
|
2932
3326
|
*
|
|
2933
3327
|
* This endpoint returns tax lots for positions, which are used for tax reporting.
|
|
2934
3328
|
* Each lot tracks when a position was opened/closed and at what prices.
|
|
2935
|
-
* @param brokerId {string} (optional)
|
|
2936
|
-
* @param connectionId {string} (optional)
|
|
2937
|
-
* @param accountId {string} (optional)
|
|
2938
|
-
* @param symbol {string} (optional)
|
|
2939
|
-
* @param positionId {string} (optional)
|
|
2940
|
-
* @param limit {number} (optional)
|
|
2941
|
-
* @param offset {number} (optional)
|
|
2942
|
-
* @returns {Promise<FinaticResponse<FDXBrokerPositionLot
|
|
3329
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
3330
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3331
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID
|
|
3332
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
3333
|
+
* @param params.positionId {string} (optional) Filter by position ID
|
|
3334
|
+
* @param params.limit {number} (optional) Maximum number of position lots to return
|
|
3335
|
+
* @param params.offset {number} (optional) Number of position lots to skip for pagination
|
|
3336
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLot>>>} Standard response with success/Error/Warning structure
|
|
2943
3337
|
*
|
|
2944
3338
|
* Generated from: GET /api/v1/brokers/data/positions/lots
|
|
2945
3339
|
* @methodId get_position_lots_api_v1_brokers_data_positions_lots_get
|
|
@@ -2947,7 +3341,7 @@ class BrokersWrapper {
|
|
|
2947
3341
|
* @example
|
|
2948
3342
|
* ```typescript-client
|
|
2949
3343
|
* // Example with no parameters
|
|
2950
|
-
* const result = await finatic.getPositionLots();
|
|
3344
|
+
* const result = await finatic.getPositionLots({});
|
|
2951
3345
|
*
|
|
2952
3346
|
* // Access the response data
|
|
2953
3347
|
* if (result.success) {
|
|
@@ -2957,7 +3351,11 @@ class BrokersWrapper {
|
|
|
2957
3351
|
* @example
|
|
2958
3352
|
* ```typescript-client
|
|
2959
3353
|
* // Full example with optional parameters
|
|
2960
|
-
* const result = await finatic.getPositionLots(
|
|
3354
|
+
* const result = await finatic.getPositionLots({
|
|
3355
|
+
brokerId: 'alpaca',
|
|
3356
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3357
|
+
accountId: '123456789'
|
|
3358
|
+
* });
|
|
2961
3359
|
*
|
|
2962
3360
|
* // Handle response with warnings
|
|
2963
3361
|
* if (result.success) {
|
|
@@ -2970,18 +3368,10 @@ class BrokersWrapper {
|
|
|
2970
3368
|
* }
|
|
2971
3369
|
* ```
|
|
2972
3370
|
*/
|
|
2973
|
-
async getPositionLots(
|
|
2974
|
-
//
|
|
2975
|
-
const
|
|
2976
|
-
|
|
2977
|
-
connectionId: connectionId,
|
|
2978
|
-
accountId: accountId,
|
|
2979
|
-
symbol: symbol,
|
|
2980
|
-
positionId: positionId,
|
|
2981
|
-
limit: limit,
|
|
2982
|
-
offset: offset
|
|
2983
|
-
}; // Authentication check
|
|
2984
|
-
if (!this.sessionId) {
|
|
3371
|
+
async getPositionLots(params) {
|
|
3372
|
+
// Use params object (with default empty object)
|
|
3373
|
+
const resolvedParams = params || {}; // Authentication check
|
|
3374
|
+
if (!this.sessionId || !this.companyId) {
|
|
2985
3375
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2986
3376
|
}
|
|
2987
3377
|
// Generate request ID
|
|
@@ -2992,7 +3382,7 @@ class BrokersWrapper {
|
|
|
2992
3382
|
const shouldCache = true;
|
|
2993
3383
|
const cache = getCache(this.sdkConfig);
|
|
2994
3384
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2995
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots',
|
|
3385
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
|
|
2996
3386
|
const cached = cache.get(cacheKey);
|
|
2997
3387
|
if (cached) {
|
|
2998
3388
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3004,12 +3394,12 @@ class BrokersWrapper {
|
|
|
3004
3394
|
request_id: requestId,
|
|
3005
3395
|
method: 'GET',
|
|
3006
3396
|
path: '/api/v1/brokers/data/positions/lots',
|
|
3007
|
-
params:
|
|
3397
|
+
params: resolvedParams,
|
|
3008
3398
|
action: 'getPositionLots'
|
|
3009
3399
|
});
|
|
3010
3400
|
try {
|
|
3011
3401
|
const response = await retryApiCall(async () => {
|
|
3012
|
-
const apiResponse = await this.api.getPositionLotsApiV1BrokersDataPositionsLotsGet({
|
|
3402
|
+
const apiResponse = await this.api.getPositionLotsApiV1BrokersDataPositionsLotsGet({ brokerId: resolvedParams.brokerId, connectionId: resolvedParams.connectionId, accountId: resolvedParams.accountId, symbol: resolvedParams.symbol, positionId: resolvedParams.positionId, limit: resolvedParams.limit, offset: resolvedParams.offset }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
3013
3403
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3014
3404
|
}, {}, this.sdkConfig);
|
|
3015
3405
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3018,9 +3408,27 @@ class BrokersWrapper {
|
|
|
3018
3408
|
throw new Error('Unexpected response shape: missing success field');
|
|
3019
3409
|
}
|
|
3020
3410
|
// Convert response to plain object, removing _id fields recursively
|
|
3411
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3021
3412
|
const standardResponse = convertToPlainObject(responseData);
|
|
3413
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3414
|
+
const hasLimit = true;
|
|
3415
|
+
const hasOffset = true;
|
|
3416
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3417
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3418
|
+
// PaginatedData is already imported at top of file
|
|
3419
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3420
|
+
if (paginationMeta) {
|
|
3421
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3422
|
+
has_more: paginationMeta.has_more,
|
|
3423
|
+
next_offset: paginationMeta.next_offset,
|
|
3424
|
+
current_offset: paginationMeta.current_offset,
|
|
3425
|
+
limit: paginationMeta.limit,
|
|
3426
|
+
}, this.getPositionLots.bind(this), resolvedParams, this);
|
|
3427
|
+
standardResponse.success.data = paginatedData;
|
|
3428
|
+
}
|
|
3429
|
+
}
|
|
3022
3430
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3023
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots',
|
|
3431
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
|
|
3024
3432
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3025
3433
|
}
|
|
3026
3434
|
this.logger.debug('Get Position Lots completed', {
|
|
@@ -3028,6 +3436,7 @@ class BrokersWrapper {
|
|
|
3028
3436
|
action: 'getPositionLots'
|
|
3029
3437
|
});
|
|
3030
3438
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3439
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3031
3440
|
return standardResponse;
|
|
3032
3441
|
}
|
|
3033
3442
|
catch (error) {
|
|
@@ -3103,11 +3512,11 @@ class BrokersWrapper {
|
|
|
3103
3512
|
* Get position lot fills for a specific lot.
|
|
3104
3513
|
*
|
|
3105
3514
|
* This endpoint returns all fills associated with a specific position lot.
|
|
3106
|
-
* @param lotId {string}
|
|
3107
|
-
* @param connectionId {string} (optional)
|
|
3108
|
-
* @param limit {number} (optional)
|
|
3109
|
-
* @param offset {number} (optional)
|
|
3110
|
-
* @returns {Promise<FinaticResponse<FDXBrokerPositionLotFill
|
|
3515
|
+
* @param params.lotId {string} Position lot ID
|
|
3516
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3517
|
+
* @param params.limit {number} (optional) Maximum number of fills to return
|
|
3518
|
+
* @param params.offset {number} (optional) Number of fills to skip for pagination
|
|
3519
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLotFill>>>} Standard response with success/Error/Warning structure
|
|
3111
3520
|
*
|
|
3112
3521
|
* Generated from: GET /api/v1/brokers/data/positions/lots/{lot_id}/fills
|
|
3113
3522
|
* @methodId get_position_lot_fills_api_v1_brokers_data_positions_lots__lot_id__fills_get
|
|
@@ -3115,7 +3524,9 @@ class BrokersWrapper {
|
|
|
3115
3524
|
* @example
|
|
3116
3525
|
* ```typescript-client
|
|
3117
3526
|
* // Minimal example with required parameters only
|
|
3118
|
-
* const result = await finatic.getPositionLotFills(
|
|
3527
|
+
* const result = await finatic.getPositionLotFills({
|
|
3528
|
+
lotId: '00000000-0000-0000-0000-000000000000'
|
|
3529
|
+
* });
|
|
3119
3530
|
*
|
|
3120
3531
|
* // Access the response data
|
|
3121
3532
|
* if (result.success) {
|
|
@@ -3127,7 +3538,12 @@ class BrokersWrapper {
|
|
|
3127
3538
|
* @example
|
|
3128
3539
|
* ```typescript-client
|
|
3129
3540
|
* // Full example with optional parameters
|
|
3130
|
-
* const result = await finatic.getPositionLotFills(
|
|
3541
|
+
* const result = await finatic.getPositionLotFills({
|
|
3542
|
+
lotId: '00000000-0000-0000-0000-000000000000',
|
|
3543
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3544
|
+
limit: 100,
|
|
3545
|
+
offset: 0
|
|
3546
|
+
* });
|
|
3131
3547
|
*
|
|
3132
3548
|
* // Handle response with warnings
|
|
3133
3549
|
* if (result.success) {
|
|
@@ -3140,15 +3556,10 @@ class BrokersWrapper {
|
|
|
3140
3556
|
* }
|
|
3141
3557
|
* ```
|
|
3142
3558
|
*/
|
|
3143
|
-
async getPositionLotFills(
|
|
3144
|
-
//
|
|
3145
|
-
const
|
|
3146
|
-
|
|
3147
|
-
connectionId: connectionId,
|
|
3148
|
-
limit: limit,
|
|
3149
|
-
offset: offset
|
|
3150
|
-
}; // Authentication check
|
|
3151
|
-
if (!this.sessionId) {
|
|
3559
|
+
async getPositionLotFills(params) {
|
|
3560
|
+
// Use params object (required parameters present)
|
|
3561
|
+
const resolvedParams = params; // Authentication check
|
|
3562
|
+
if (!this.sessionId || !this.companyId) {
|
|
3152
3563
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3153
3564
|
}
|
|
3154
3565
|
// Generate request ID
|
|
@@ -3159,7 +3570,7 @@ class BrokersWrapper {
|
|
|
3159
3570
|
const shouldCache = true;
|
|
3160
3571
|
const cache = getCache(this.sdkConfig);
|
|
3161
3572
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3162
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3573
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
|
|
3163
3574
|
const cached = cache.get(cacheKey);
|
|
3164
3575
|
if (cached) {
|
|
3165
3576
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3171,12 +3582,12 @@ class BrokersWrapper {
|
|
|
3171
3582
|
request_id: requestId,
|
|
3172
3583
|
method: 'GET',
|
|
3173
3584
|
path: '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3174
|
-
params:
|
|
3585
|
+
params: resolvedParams,
|
|
3175
3586
|
action: 'getPositionLotFills'
|
|
3176
3587
|
});
|
|
3177
3588
|
try {
|
|
3178
3589
|
const response = await retryApiCall(async () => {
|
|
3179
|
-
const apiResponse = await this.api.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet({ lotId: lotId,
|
|
3590
|
+
const apiResponse = await this.api.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet({ lotId: resolvedParams.lotId, connectionId: resolvedParams.connectionId, limit: resolvedParams.limit, offset: resolvedParams.offset }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
3180
3591
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3181
3592
|
}, {}, this.sdkConfig);
|
|
3182
3593
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3185,9 +3596,27 @@ class BrokersWrapper {
|
|
|
3185
3596
|
throw new Error('Unexpected response shape: missing success field');
|
|
3186
3597
|
}
|
|
3187
3598
|
// Convert response to plain object, removing _id fields recursively
|
|
3599
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3188
3600
|
const standardResponse = convertToPlainObject(responseData);
|
|
3601
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3602
|
+
const hasLimit = true;
|
|
3603
|
+
const hasOffset = true;
|
|
3604
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3605
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3606
|
+
// PaginatedData is already imported at top of file
|
|
3607
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3608
|
+
if (paginationMeta) {
|
|
3609
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3610
|
+
has_more: paginationMeta.has_more,
|
|
3611
|
+
next_offset: paginationMeta.next_offset,
|
|
3612
|
+
current_offset: paginationMeta.current_offset,
|
|
3613
|
+
limit: paginationMeta.limit,
|
|
3614
|
+
}, this.getPositionLotFills.bind(this), resolvedParams, this);
|
|
3615
|
+
standardResponse.success.data = paginatedData;
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3189
3618
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3190
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3619
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
|
|
3191
3620
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3192
3621
|
}
|
|
3193
3622
|
this.logger.debug('Get Position Lot Fills completed', {
|
|
@@ -3195,6 +3624,7 @@ class BrokersWrapper {
|
|
|
3195
3624
|
action: 'getPositionLotFills'
|
|
3196
3625
|
});
|
|
3197
3626
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3627
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3198
3628
|
return standardResponse;
|
|
3199
3629
|
}
|
|
3200
3630
|
catch (error) {
|
|
@@ -3307,7 +3737,7 @@ class CompanyWrapper {
|
|
|
3307
3737
|
* Get Company
|
|
3308
3738
|
*
|
|
3309
3739
|
* Get public company details by ID (no user check, no sensitive data).
|
|
3310
|
-
* @param companyId {string}
|
|
3740
|
+
* @param params.companyId {string} Company ID
|
|
3311
3741
|
* @returns {Promise<FinaticResponse<CompanyResponse>>} Standard response with success/Error/Warning structure
|
|
3312
3742
|
*
|
|
3313
3743
|
* Generated from: GET /api/v1/company/{company_id}
|
|
@@ -3316,7 +3746,9 @@ class CompanyWrapper {
|
|
|
3316
3746
|
* @example
|
|
3317
3747
|
* ```typescript-client
|
|
3318
3748
|
* // Minimal example with required parameters only
|
|
3319
|
-
* const result = await finatic.getCompany(
|
|
3749
|
+
* const result = await finatic.getCompany({
|
|
3750
|
+
companyId: '00000000-0000-0000-0000-000000000000'
|
|
3751
|
+
* });
|
|
3320
3752
|
*
|
|
3321
3753
|
* // Access the response data
|
|
3322
3754
|
* if (result.success) {
|
|
@@ -3326,11 +3758,9 @@ class CompanyWrapper {
|
|
|
3326
3758
|
* }
|
|
3327
3759
|
* ```
|
|
3328
3760
|
*/
|
|
3329
|
-
async getCompany(
|
|
3330
|
-
//
|
|
3331
|
-
const
|
|
3332
|
-
companyId: companyId
|
|
3333
|
-
}; // Generate request ID
|
|
3761
|
+
async getCompany(params) {
|
|
3762
|
+
// Use params object (required parameters present)
|
|
3763
|
+
const resolvedParams = params; // Generate request ID
|
|
3334
3764
|
const requestId = this._generateRequestId();
|
|
3335
3765
|
// Input validation (Phase 2B: zod)
|
|
3336
3766
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3338,7 +3768,7 @@ class CompanyWrapper {
|
|
|
3338
3768
|
const shouldCache = true;
|
|
3339
3769
|
const cache = getCache(this.sdkConfig);
|
|
3340
3770
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3341
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}',
|
|
3771
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
|
|
3342
3772
|
const cached = cache.get(cacheKey);
|
|
3343
3773
|
if (cached) {
|
|
3344
3774
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3350,12 +3780,12 @@ class CompanyWrapper {
|
|
|
3350
3780
|
request_id: requestId,
|
|
3351
3781
|
method: 'GET',
|
|
3352
3782
|
path: '/api/v1/company/{company_id}',
|
|
3353
|
-
params:
|
|
3783
|
+
params: resolvedParams,
|
|
3354
3784
|
action: 'getCompany'
|
|
3355
3785
|
});
|
|
3356
3786
|
try {
|
|
3357
3787
|
const response = await retryApiCall(async () => {
|
|
3358
|
-
const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: companyId }, { headers: { 'x-request-id': requestId } });
|
|
3788
|
+
const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: resolvedParams.companyId }, { headers: { 'x-request-id': requestId } });
|
|
3359
3789
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3360
3790
|
}, {}, this.sdkConfig);
|
|
3361
3791
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3364,9 +3794,15 @@ class CompanyWrapper {
|
|
|
3364
3794
|
throw new Error('Unexpected response shape: missing success field');
|
|
3365
3795
|
}
|
|
3366
3796
|
// Convert response to plain object, removing _id fields recursively
|
|
3797
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3367
3798
|
const standardResponse = convertToPlainObject(responseData);
|
|
3799
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3800
|
+
const hasLimit = false;
|
|
3801
|
+
const hasOffset = false;
|
|
3802
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3803
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3368
3804
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3369
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}',
|
|
3805
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
|
|
3370
3806
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3371
3807
|
}
|
|
3372
3808
|
this.logger.debug('Get Company completed', {
|
|
@@ -3374,6 +3810,7 @@ class CompanyWrapper {
|
|
|
3374
3810
|
action: 'getCompany'
|
|
3375
3811
|
});
|
|
3376
3812
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3813
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3377
3814
|
return standardResponse;
|
|
3378
3815
|
}
|
|
3379
3816
|
catch (error) {
|
|
@@ -3486,7 +3923,7 @@ class SessionWrapper {
|
|
|
3486
3923
|
* Init Session
|
|
3487
3924
|
*
|
|
3488
3925
|
* Initialize a new session with company API key.
|
|
3489
|
-
* @param xApiKey {string}
|
|
3926
|
+
* @param params.xApiKey {string} Company API key
|
|
3490
3927
|
* @returns {Promise<FinaticResponse<TokenResponseData>>} Standard response with success/Error/Warning structure
|
|
3491
3928
|
*
|
|
3492
3929
|
* Generated from: POST /api/v1/session/init
|
|
@@ -3495,7 +3932,7 @@ class SessionWrapper {
|
|
|
3495
3932
|
* @example
|
|
3496
3933
|
* ```typescript-client
|
|
3497
3934
|
* // Example with no parameters
|
|
3498
|
-
* const result = await finatic.initSession();
|
|
3935
|
+
* const result = await finatic.initSession({});
|
|
3499
3936
|
*
|
|
3500
3937
|
* // Access the response data
|
|
3501
3938
|
* if (result.success) {
|
|
@@ -3503,11 +3940,9 @@ class SessionWrapper {
|
|
|
3503
3940
|
* }
|
|
3504
3941
|
* ```
|
|
3505
3942
|
*/
|
|
3506
|
-
async initSession(
|
|
3507
|
-
//
|
|
3508
|
-
const
|
|
3509
|
-
xApiKey: xApiKey
|
|
3510
|
-
}; // Generate request ID
|
|
3943
|
+
async initSession(params) {
|
|
3944
|
+
// Use params object (required parameters present)
|
|
3945
|
+
const resolvedParams = params; // Generate request ID
|
|
3511
3946
|
const requestId = this._generateRequestId();
|
|
3512
3947
|
// Input validation (Phase 2B: zod)
|
|
3513
3948
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3515,7 +3950,7 @@ class SessionWrapper {
|
|
|
3515
3950
|
const shouldCache = true;
|
|
3516
3951
|
const cache = getCache(this.sdkConfig);
|
|
3517
3952
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3518
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/init',
|
|
3953
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
|
|
3519
3954
|
const cached = cache.get(cacheKey);
|
|
3520
3955
|
if (cached) {
|
|
3521
3956
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3527,12 +3962,12 @@ class SessionWrapper {
|
|
|
3527
3962
|
request_id: requestId,
|
|
3528
3963
|
method: 'POST',
|
|
3529
3964
|
path: '/api/v1/session/init',
|
|
3530
|
-
params:
|
|
3965
|
+
params: resolvedParams,
|
|
3531
3966
|
action: 'initSession'
|
|
3532
3967
|
});
|
|
3533
3968
|
try {
|
|
3534
3969
|
const response = await retryApiCall(async () => {
|
|
3535
|
-
const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: xApiKey }, { headers: { 'x-request-id': requestId } });
|
|
3970
|
+
const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: resolvedParams.xApiKey }, { headers: { 'x-request-id': requestId } });
|
|
3536
3971
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3537
3972
|
}, {}, this.sdkConfig);
|
|
3538
3973
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3541,9 +3976,15 @@ class SessionWrapper {
|
|
|
3541
3976
|
throw new Error('Unexpected response shape: missing success field');
|
|
3542
3977
|
}
|
|
3543
3978
|
// Convert response to plain object, removing _id fields recursively
|
|
3979
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3544
3980
|
const standardResponse = convertToPlainObject(responseData);
|
|
3981
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3982
|
+
const hasLimit = false;
|
|
3983
|
+
const hasOffset = false;
|
|
3984
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3985
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3545
3986
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3546
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/init',
|
|
3987
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
|
|
3547
3988
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3548
3989
|
}
|
|
3549
3990
|
this.logger.debug('Init Session completed', {
|
|
@@ -3551,6 +3992,7 @@ class SessionWrapper {
|
|
|
3551
3992
|
action: 'initSession'
|
|
3552
3993
|
});
|
|
3553
3994
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3995
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3554
3996
|
return standardResponse;
|
|
3555
3997
|
}
|
|
3556
3998
|
catch (error) {
|
|
@@ -3624,8 +4066,8 @@ class SessionWrapper {
|
|
|
3624
4066
|
* Start Session
|
|
3625
4067
|
*
|
|
3626
4068
|
* Start a session with a one-time token.
|
|
3627
|
-
* @param OneTimeToken {string}
|
|
3628
|
-
* @param body {SessionStartRequest}
|
|
4069
|
+
* @param params.OneTimeToken {string} One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
4070
|
+
* @param params.body {SessionStartRequest} Session start request containing optional user ID to associate with the session
|
|
3629
4071
|
* @returns {Promise<FinaticResponse<SessionResponseData>>} Standard response with success/Error/Warning structure
|
|
3630
4072
|
*
|
|
3631
4073
|
* Generated from: POST /api/v1/session/start
|
|
@@ -3634,7 +4076,7 @@ class SessionWrapper {
|
|
|
3634
4076
|
* @example
|
|
3635
4077
|
* ```typescript-client
|
|
3636
4078
|
* // Example with no parameters
|
|
3637
|
-
* const result = await finatic.startSession();
|
|
4079
|
+
* const result = await finatic.startSession({});
|
|
3638
4080
|
*
|
|
3639
4081
|
* // Access the response data
|
|
3640
4082
|
* if (result.success) {
|
|
@@ -3642,12 +4084,9 @@ class SessionWrapper {
|
|
|
3642
4084
|
* }
|
|
3643
4085
|
* ```
|
|
3644
4086
|
*/
|
|
3645
|
-
async startSession(
|
|
3646
|
-
//
|
|
3647
|
-
const
|
|
3648
|
-
OneTimeToken: OneTimeToken,
|
|
3649
|
-
body: body
|
|
3650
|
-
}; // Generate request ID
|
|
4087
|
+
async startSession(params) {
|
|
4088
|
+
// Use params object (required parameters present)
|
|
4089
|
+
const resolvedParams = params; // Generate request ID
|
|
3651
4090
|
const requestId = this._generateRequestId();
|
|
3652
4091
|
// Input validation (Phase 2B: zod)
|
|
3653
4092
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3655,7 +4094,7 @@ class SessionWrapper {
|
|
|
3655
4094
|
const shouldCache = true;
|
|
3656
4095
|
const cache = getCache(this.sdkConfig);
|
|
3657
4096
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3658
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/start',
|
|
4097
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
|
|
3659
4098
|
const cached = cache.get(cacheKey);
|
|
3660
4099
|
if (cached) {
|
|
3661
4100
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3667,12 +4106,12 @@ class SessionWrapper {
|
|
|
3667
4106
|
request_id: requestId,
|
|
3668
4107
|
method: 'POST',
|
|
3669
4108
|
path: '/api/v1/session/start',
|
|
3670
|
-
params:
|
|
4109
|
+
params: resolvedParams,
|
|
3671
4110
|
action: 'startSession'
|
|
3672
4111
|
});
|
|
3673
4112
|
try {
|
|
3674
4113
|
const response = await retryApiCall(async () => {
|
|
3675
|
-
const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: OneTimeToken, sessionStartRequest: body }, { headers: { 'x-request-id': requestId } });
|
|
4114
|
+
const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: resolvedParams.OneTimeToken, sessionStartRequest: resolvedParams.body }, { headers: { 'x-request-id': requestId } });
|
|
3676
4115
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3677
4116
|
}, {}, this.sdkConfig);
|
|
3678
4117
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3681,9 +4120,15 @@ class SessionWrapper {
|
|
|
3681
4120
|
throw new Error('Unexpected response shape: missing success field');
|
|
3682
4121
|
}
|
|
3683
4122
|
// Convert response to plain object, removing _id fields recursively
|
|
4123
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3684
4124
|
const standardResponse = convertToPlainObject(responseData);
|
|
4125
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4126
|
+
const hasLimit = false;
|
|
4127
|
+
const hasOffset = false;
|
|
4128
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4129
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3685
4130
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3686
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/start',
|
|
4131
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
|
|
3687
4132
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3688
4133
|
}
|
|
3689
4134
|
this.logger.debug('Start Session completed', {
|
|
@@ -3691,6 +4136,7 @@ class SessionWrapper {
|
|
|
3691
4136
|
action: 'startSession'
|
|
3692
4137
|
});
|
|
3693
4138
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4139
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3694
4140
|
return standardResponse;
|
|
3695
4141
|
}
|
|
3696
4142
|
catch (error) {
|
|
@@ -3767,7 +4213,7 @@ class SessionWrapper {
|
|
|
3767
4213
|
*
|
|
3768
4214
|
* The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device
|
|
3769
4215
|
* that initiated the session. Device info is automatically validated from the request.
|
|
3770
|
-
* @param No parameters required for this method
|
|
4216
|
+
* @param params No parameters required for this method
|
|
3771
4217
|
* @returns {Promise<FinaticResponse<PortalUrlResponse>>} Standard response with success/Error/Warning structure
|
|
3772
4218
|
*
|
|
3773
4219
|
* Generated from: GET /api/v1/session/portal
|
|
@@ -3776,7 +4222,7 @@ class SessionWrapper {
|
|
|
3776
4222
|
* @example
|
|
3777
4223
|
* ```typescript-client
|
|
3778
4224
|
* // Example with no parameters
|
|
3779
|
-
* const result = await finatic.getPortalUrl();
|
|
4225
|
+
* const result = await finatic.getPortalUrl({});
|
|
3780
4226
|
*
|
|
3781
4227
|
* // Access the response data
|
|
3782
4228
|
* if (result.success) {
|
|
@@ -3784,10 +4230,10 @@ class SessionWrapper {
|
|
|
3784
4230
|
* }
|
|
3785
4231
|
* ```
|
|
3786
4232
|
*/
|
|
3787
|
-
async getPortalUrl() {
|
|
4233
|
+
async getPortalUrl(params) {
|
|
3788
4234
|
// No parameters - use empty params object
|
|
3789
|
-
const
|
|
3790
|
-
if (!this.sessionId) {
|
|
4235
|
+
const resolvedParams = params || {}; // Authentication check
|
|
4236
|
+
if (!this.sessionId || !this.companyId) {
|
|
3791
4237
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3792
4238
|
}
|
|
3793
4239
|
// Generate request ID
|
|
@@ -3798,7 +4244,7 @@ class SessionWrapper {
|
|
|
3798
4244
|
const shouldCache = true;
|
|
3799
4245
|
const cache = getCache(this.sdkConfig);
|
|
3800
4246
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3801
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal',
|
|
4247
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
|
|
3802
4248
|
const cached = cache.get(cacheKey);
|
|
3803
4249
|
if (cached) {
|
|
3804
4250
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3810,12 +4256,12 @@ class SessionWrapper {
|
|
|
3810
4256
|
request_id: requestId,
|
|
3811
4257
|
method: 'GET',
|
|
3812
4258
|
path: '/api/v1/session/portal',
|
|
3813
|
-
params:
|
|
4259
|
+
params: resolvedParams,
|
|
3814
4260
|
action: 'getPortalUrl'
|
|
3815
4261
|
});
|
|
3816
4262
|
try {
|
|
3817
4263
|
const response = await retryApiCall(async () => {
|
|
3818
|
-
const apiResponse = await this.api.getPortalUrlApiV1SessionPortalGet({ sessionId: this.sessionId }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
4264
|
+
const apiResponse = await this.api.getPortalUrlApiV1SessionPortalGet({ sessionId: this.sessionId }, { headers: { 'x-request-id': requestId, ...(this.sessionId && this.companyId ? { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, ...(this.csrfToken ? { 'x-csrf-token': this.csrfToken } : {}) } : {}) } });
|
|
3819
4265
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3820
4266
|
}, {}, this.sdkConfig);
|
|
3821
4267
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3824,9 +4270,15 @@ class SessionWrapper {
|
|
|
3824
4270
|
throw new Error('Unexpected response shape: missing success field');
|
|
3825
4271
|
}
|
|
3826
4272
|
// Convert response to plain object, removing _id fields recursively
|
|
4273
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3827
4274
|
const standardResponse = convertToPlainObject(responseData);
|
|
4275
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4276
|
+
const hasLimit = false;
|
|
4277
|
+
const hasOffset = false;
|
|
4278
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4279
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3828
4280
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3829
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal',
|
|
4281
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
|
|
3830
4282
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3831
4283
|
}
|
|
3832
4284
|
this.logger.debug('Get Portal Url completed', {
|
|
@@ -3834,6 +4286,7 @@ class SessionWrapper {
|
|
|
3834
4286
|
action: 'getPortalUrl'
|
|
3835
4287
|
});
|
|
3836
4288
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4289
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3837
4290
|
return standardResponse;
|
|
3838
4291
|
}
|
|
3839
4292
|
catch (error) {
|
|
@@ -3918,7 +4371,7 @@ class SessionWrapper {
|
|
|
3918
4371
|
* - Generates fresh tokens (not returning stored ones)
|
|
3919
4372
|
* - Only accessible to authenticated sessions with user_id
|
|
3920
4373
|
* - Validates that header session_id matches path session_id
|
|
3921
|
-
* @param sessionId {string}
|
|
4374
|
+
* @param params.sessionId {string} Session ID
|
|
3922
4375
|
* @returns {Promise<FinaticResponse<SessionUserResponse>>} Standard response with success/Error/Warning structure
|
|
3923
4376
|
*
|
|
3924
4377
|
* Generated from: GET /api/v1/session/{session_id}/user
|
|
@@ -3927,7 +4380,9 @@ class SessionWrapper {
|
|
|
3927
4380
|
* @example
|
|
3928
4381
|
* ```typescript-client
|
|
3929
4382
|
* // Minimal example with required parameters only
|
|
3930
|
-
* const result = await finatic.getSessionUser(
|
|
4383
|
+
* const result = await finatic.getSessionUser({
|
|
4384
|
+
sessionId: 'sess_1234567890abcdef'
|
|
4385
|
+
* });
|
|
3931
4386
|
*
|
|
3932
4387
|
* // Access the response data
|
|
3933
4388
|
* if (result.success) {
|
|
@@ -3937,12 +4392,10 @@ class SessionWrapper {
|
|
|
3937
4392
|
* }
|
|
3938
4393
|
* ```
|
|
3939
4394
|
*/
|
|
3940
|
-
async getSessionUser(
|
|
3941
|
-
//
|
|
3942
|
-
const
|
|
3943
|
-
|
|
3944
|
-
}; // Authentication check
|
|
3945
|
-
if (!this.sessionId) {
|
|
4395
|
+
async getSessionUser(params) {
|
|
4396
|
+
// Use params object (required parameters present)
|
|
4397
|
+
const resolvedParams = params; // Authentication check
|
|
4398
|
+
if (!this.sessionId || !this.companyId) {
|
|
3946
4399
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3947
4400
|
}
|
|
3948
4401
|
// Generate request ID
|
|
@@ -3953,7 +4406,7 @@ class SessionWrapper {
|
|
|
3953
4406
|
const shouldCache = true;
|
|
3954
4407
|
const cache = getCache(this.sdkConfig);
|
|
3955
4408
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3956
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user',
|
|
4409
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
|
|
3957
4410
|
const cached = cache.get(cacheKey);
|
|
3958
4411
|
if (cached) {
|
|
3959
4412
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3965,12 +4418,12 @@ class SessionWrapper {
|
|
|
3965
4418
|
request_id: requestId,
|
|
3966
4419
|
method: 'GET',
|
|
3967
4420
|
path: '/api/v1/session/{session_id}/user',
|
|
3968
|
-
params:
|
|
4421
|
+
params: resolvedParams,
|
|
3969
4422
|
action: 'getSessionUser'
|
|
3970
4423
|
});
|
|
3971
4424
|
try {
|
|
3972
4425
|
const response = await retryApiCall(async () => {
|
|
3973
|
-
const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: sessionId, xSessionId: sessionId }, { headers: { 'x-request-id': requestId } });
|
|
4426
|
+
const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: resolvedParams.sessionId, xSessionId: resolvedParams.sessionId }, { headers: { 'x-request-id': requestId } });
|
|
3974
4427
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3975
4428
|
}, {}, this.sdkConfig);
|
|
3976
4429
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3979,9 +4432,15 @@ class SessionWrapper {
|
|
|
3979
4432
|
throw new Error('Unexpected response shape: missing success field');
|
|
3980
4433
|
}
|
|
3981
4434
|
// Convert response to plain object, removing _id fields recursively
|
|
4435
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3982
4436
|
const standardResponse = convertToPlainObject(responseData);
|
|
4437
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4438
|
+
const hasLimit = false;
|
|
4439
|
+
const hasOffset = false;
|
|
4440
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4441
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3983
4442
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3984
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user',
|
|
4443
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
|
|
3985
4444
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3986
4445
|
}
|
|
3987
4446
|
this.logger.debug('Get Session User completed', {
|
|
@@ -3989,6 +4448,7 @@ class SessionWrapper {
|
|
|
3989
4448
|
action: 'getSessionUser'
|
|
3990
4449
|
});
|
|
3991
4450
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4451
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3992
4452
|
return standardResponse;
|
|
3993
4453
|
}
|
|
3994
4454
|
catch (error) {
|
|
@@ -4737,8 +5197,8 @@ const SessionApiAxiosParamCreator = function (configuration) {
|
|
|
4737
5197
|
/**
|
|
4738
5198
|
* Start a session with a one-time token.
|
|
4739
5199
|
* @summary Start Session
|
|
4740
|
-
* @param {string} oneTimeToken
|
|
4741
|
-
* @param {SessionStartRequest} sessionStartRequest
|
|
5200
|
+
* @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
5201
|
+
* @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
|
|
4742
5202
|
* @param {*} [options] Override http request option.
|
|
4743
5203
|
* @throws {RequiredError}
|
|
4744
5204
|
*/
|
|
@@ -4821,8 +5281,8 @@ const SessionApiFp = function (configuration) {
|
|
|
4821
5281
|
/**
|
|
4822
5282
|
* Start a session with a one-time token.
|
|
4823
5283
|
* @summary Start Session
|
|
4824
|
-
* @param {string} oneTimeToken
|
|
4825
|
-
* @param {SessionStartRequest} sessionStartRequest
|
|
5284
|
+
* @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
5285
|
+
* @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
|
|
4826
5286
|
* @param {*} [options] Override http request option.
|
|
4827
5287
|
* @throws {RequiredError}
|
|
4828
5288
|
*/
|
|
@@ -6357,11 +6817,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6357
6817
|
}
|
|
6358
6818
|
const sessionId = data?.session_id || '';
|
|
6359
6819
|
const companyId = data?.company_id || '';
|
|
6820
|
+
const responseUserId = data?.user_id || '';
|
|
6360
6821
|
// csrf_token is not in SessionResponseData, get from response headers if available
|
|
6361
6822
|
const csrfToken = data?.csrf_token || '';
|
|
6362
6823
|
this.logger.debug?.('_startSession extracted data', {
|
|
6363
6824
|
sessionId,
|
|
6364
6825
|
companyId,
|
|
6826
|
+
responseUserId,
|
|
6365
6827
|
csrfToken,
|
|
6366
6828
|
fullData: data,
|
|
6367
6829
|
dataKeys: data ? Object.keys(data) : []
|
|
@@ -6383,6 +6845,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6383
6845
|
responseKeys: response ? Object.keys(response) : []
|
|
6384
6846
|
});
|
|
6385
6847
|
}
|
|
6848
|
+
// Store userId if present in response (for getUserId() and isAuthed())
|
|
6849
|
+
// Use userId from response if parameter wasn't provided, or if response has a different userId
|
|
6850
|
+
const finalUserId = responseUserId || userId;
|
|
6851
|
+
if (finalUserId) {
|
|
6852
|
+
this.userId = finalUserId;
|
|
6853
|
+
this.logger.debug?.('_startSession set userId', { userId: finalUserId, source: responseUserId ? 'response' : 'parameter' });
|
|
6854
|
+
}
|
|
6386
6855
|
return { session_id: sessionId, company_id: companyId };
|
|
6387
6856
|
}
|
|
6388
6857
|
/**
|
|
@@ -6394,28 +6863,30 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6394
6863
|
*
|
|
6395
6864
|
* @methodId get_portal_url_api_v1_session_portal_get
|
|
6396
6865
|
* @category session
|
|
6397
|
-
* @param
|
|
6398
|
-
* @param
|
|
6399
|
-
* @param
|
|
6400
|
-
* @param
|
|
6866
|
+
* @param params - Optional parameters object
|
|
6867
|
+
* @param params.theme - Optional theme preset or custom theme object
|
|
6868
|
+
* @param params.brokers - Optional array of broker IDs to filter
|
|
6869
|
+
* @param params.email - Optional email address
|
|
6870
|
+
* @param params.mode - Optional mode ('light' or 'dark')
|
|
6401
6871
|
* @returns Portal URL string
|
|
6402
6872
|
* @example
|
|
6403
6873
|
* ```typescript-client
|
|
6404
|
-
* const url = await finatic.getPortalUrl('
|
|
6874
|
+
* const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
|
|
6405
6875
|
* ```
|
|
6406
6876
|
* @example
|
|
6407
6877
|
* ```typescript-server
|
|
6408
|
-
* const url = await finatic.getPortalUrl('
|
|
6878
|
+
* const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
|
|
6409
6879
|
* ```
|
|
6410
6880
|
* @example
|
|
6411
6881
|
* ```python
|
|
6412
|
-
* url = await finatic.get_portal_url('
|
|
6882
|
+
* url = await finatic.get_portal_url(theme='default', brokers=['broker-1'], email='user@example.com', mode='dark')
|
|
6413
6883
|
* ```
|
|
6414
6884
|
*/
|
|
6415
|
-
async getPortalUrl(
|
|
6885
|
+
async getPortalUrl(params) {
|
|
6416
6886
|
if (!this.sessionId) {
|
|
6417
6887
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
6418
6888
|
}
|
|
6889
|
+
const { theme, brokers, email, mode } = params || {};
|
|
6419
6890
|
// Get raw portal URL from SessionApi directly (not a wrapper)
|
|
6420
6891
|
const axiosResponse = await this.sessionApi.getPortalUrlApiV1SessionPortalGet({
|
|
6421
6892
|
sessionId: this.sessionId,
|
|
@@ -6489,29 +6960,35 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6489
6960
|
*
|
|
6490
6961
|
* @methodId open_portal_client_sdk
|
|
6491
6962
|
* @category session
|
|
6492
|
-
* @param
|
|
6493
|
-
* @param
|
|
6494
|
-
* @param
|
|
6495
|
-
* @param
|
|
6963
|
+
* @param params - Optional parameters object
|
|
6964
|
+
* @param params.theme - Optional theme preset or custom theme object
|
|
6965
|
+
* @param params.brokers - Optional array of broker IDs to filter
|
|
6966
|
+
* @param params.email - Optional email address
|
|
6967
|
+
* @param params.mode - Optional mode ('light' or 'dark')
|
|
6496
6968
|
* @param onSuccess - Optional callback when portal authentication succeeds
|
|
6497
6969
|
* @param onError - Optional callback when portal authentication fails
|
|
6498
6970
|
* @param onClose - Optional callback when portal is closed
|
|
6499
6971
|
* @returns Promise that resolves when portal is opened
|
|
6500
6972
|
* @example
|
|
6501
6973
|
* ```typescript-client
|
|
6502
|
-
* await finatic.openPortal(
|
|
6974
|
+
* await finatic.openPortal({
|
|
6975
|
+
* theme: 'default',
|
|
6976
|
+
* brokers: ['broker-1'],
|
|
6977
|
+
* email: 'user@example.com',
|
|
6978
|
+
* mode: 'dark'
|
|
6979
|
+
* },
|
|
6503
6980
|
* (userId) => console.log('User authenticated:', userId),
|
|
6504
6981
|
* (error) => console.error('Portal error:', error),
|
|
6505
6982
|
* () => console.log('Portal closed')
|
|
6506
6983
|
* );
|
|
6507
6984
|
* ```
|
|
6508
6985
|
*/
|
|
6509
|
-
async openPortal(
|
|
6986
|
+
async openPortal(params, onSuccess, onError, onClose) {
|
|
6510
6987
|
if (!this.sessionId) {
|
|
6511
6988
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
6512
6989
|
}
|
|
6513
6990
|
// Get portal URL with all parameters
|
|
6514
|
-
const portalUrl = await this.getPortalUrl(
|
|
6991
|
+
const portalUrl = await this.getPortalUrl(params);
|
|
6515
6992
|
// Create portal UI if not exists
|
|
6516
6993
|
if (!this.portalUI) {
|
|
6517
6994
|
this.portalUI = new PortalUI(this.sdkConfig.baseUrl || 'https://api.finatic.dev');
|
|
@@ -6698,7 +7175,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6698
7175
|
* ```
|
|
6699
7176
|
*/
|
|
6700
7177
|
async getCompany(params) {
|
|
6701
|
-
return await this.company.getCompany(params
|
|
7178
|
+
return await this.company.getCompany(params);
|
|
6702
7179
|
}
|
|
6703
7180
|
/**
|
|
6704
7181
|
* Get Brokers
|
|
@@ -6856,7 +7333,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6856
7333
|
* ```
|
|
6857
7334
|
*/
|
|
6858
7335
|
async disconnectCompanyFromBroker(params) {
|
|
6859
|
-
return await this.brokers.disconnectCompanyFromBroker(params
|
|
7336
|
+
return await this.brokers.disconnectCompanyFromBroker(params);
|
|
6860
7337
|
}
|
|
6861
7338
|
/**
|
|
6862
7339
|
* Get Orders
|
|
@@ -6936,7 +7413,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6936
7413
|
* ```
|
|
6937
7414
|
*/
|
|
6938
7415
|
async getOrders(params) {
|
|
6939
|
-
return await this.brokers.getOrders(params
|
|
7416
|
+
return await this.brokers.getOrders(params);
|
|
6940
7417
|
}
|
|
6941
7418
|
/**
|
|
6942
7419
|
* Get Positions
|
|
@@ -7016,7 +7493,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7016
7493
|
* ```
|
|
7017
7494
|
*/
|
|
7018
7495
|
async getPositions(params) {
|
|
7019
|
-
return await this.brokers.getPositions(params
|
|
7496
|
+
return await this.brokers.getPositions(params);
|
|
7020
7497
|
}
|
|
7021
7498
|
/**
|
|
7022
7499
|
* Get Balances
|
|
@@ -7096,7 +7573,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7096
7573
|
* ```
|
|
7097
7574
|
*/
|
|
7098
7575
|
async getBalances(params) {
|
|
7099
|
-
return await this.brokers.getBalances(params
|
|
7576
|
+
return await this.brokers.getBalances(params);
|
|
7100
7577
|
}
|
|
7101
7578
|
/**
|
|
7102
7579
|
* Get Accounts
|
|
@@ -7176,7 +7653,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7176
7653
|
* ```
|
|
7177
7654
|
*/
|
|
7178
7655
|
async getAccounts(params) {
|
|
7179
|
-
return await this.brokers.getAccounts(params
|
|
7656
|
+
return await this.brokers.getAccounts(params);
|
|
7180
7657
|
}
|
|
7181
7658
|
/**
|
|
7182
7659
|
* Get Order Fills
|
|
@@ -7264,7 +7741,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7264
7741
|
* ```
|
|
7265
7742
|
*/
|
|
7266
7743
|
async getOrderFills(params) {
|
|
7267
|
-
return await this.brokers.getOrderFills(params
|
|
7744
|
+
return await this.brokers.getOrderFills(params);
|
|
7268
7745
|
}
|
|
7269
7746
|
/**
|
|
7270
7747
|
* Get Order Events
|
|
@@ -7352,7 +7829,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7352
7829
|
* ```
|
|
7353
7830
|
*/
|
|
7354
7831
|
async getOrderEvents(params) {
|
|
7355
|
-
return await this.brokers.getOrderEvents(params
|
|
7832
|
+
return await this.brokers.getOrderEvents(params);
|
|
7356
7833
|
}
|
|
7357
7834
|
/**
|
|
7358
7835
|
* Get Order Groups
|
|
@@ -7431,7 +7908,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7431
7908
|
* ```
|
|
7432
7909
|
*/
|
|
7433
7910
|
async getOrderGroups(params) {
|
|
7434
|
-
return await this.brokers.getOrderGroups(params
|
|
7911
|
+
return await this.brokers.getOrderGroups(params);
|
|
7435
7912
|
}
|
|
7436
7913
|
/**
|
|
7437
7914
|
* Get Position Lots
|
|
@@ -7511,7 +7988,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7511
7988
|
* ```
|
|
7512
7989
|
*/
|
|
7513
7990
|
async getPositionLots(params) {
|
|
7514
|
-
return await this.brokers.getPositionLots(params
|
|
7991
|
+
return await this.brokers.getPositionLots(params);
|
|
7515
7992
|
}
|
|
7516
7993
|
/**
|
|
7517
7994
|
* Get Position Lot Fills
|
|
@@ -7599,7 +8076,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7599
8076
|
* ```
|
|
7600
8077
|
*/
|
|
7601
8078
|
async getPositionLotFills(params) {
|
|
7602
|
-
return await this.brokers.getPositionLotFills(params
|
|
8079
|
+
return await this.brokers.getPositionLotFills(params);
|
|
7603
8080
|
}
|
|
7604
8081
|
/**
|
|
7605
8082
|
* Get all Orders across all pages.
|
|
@@ -7670,7 +8147,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7670
8147
|
let lastError = null;
|
|
7671
8148
|
let warnings = [];
|
|
7672
8149
|
while (true) {
|
|
7673
|
-
const response = await this.brokers.getOrders(
|
|
8150
|
+
const response = await this.brokers.getOrders({ ...filterParams, limit, offset });
|
|
7674
8151
|
// Collect warnings from each page
|
|
7675
8152
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7676
8153
|
warnings.push(...response.warning);
|
|
@@ -7680,10 +8157,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7680
8157
|
break;
|
|
7681
8158
|
}
|
|
7682
8159
|
const result = response.success?.data || [];
|
|
7683
|
-
if
|
|
8160
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8161
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8162
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8163
|
+
? result.items
|
|
8164
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8165
|
+
if (!items || items.length === 0)
|
|
7684
8166
|
break;
|
|
7685
|
-
allData.push(...
|
|
7686
|
-
|
|
8167
|
+
allData.push(...items);
|
|
8168
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8169
|
+
if (items.length < limit)
|
|
7687
8170
|
break;
|
|
7688
8171
|
offset += limit;
|
|
7689
8172
|
}
|
|
@@ -7775,7 +8258,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7775
8258
|
let lastError = null;
|
|
7776
8259
|
let warnings = [];
|
|
7777
8260
|
while (true) {
|
|
7778
|
-
const response = await this.brokers.getPositions(
|
|
8261
|
+
const response = await this.brokers.getPositions({ ...filterParams, limit, offset });
|
|
7779
8262
|
// Collect warnings from each page
|
|
7780
8263
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7781
8264
|
warnings.push(...response.warning);
|
|
@@ -7785,10 +8268,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7785
8268
|
break;
|
|
7786
8269
|
}
|
|
7787
8270
|
const result = response.success?.data || [];
|
|
7788
|
-
if
|
|
8271
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8272
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8273
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8274
|
+
? result.items
|
|
8275
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8276
|
+
if (!items || items.length === 0)
|
|
7789
8277
|
break;
|
|
7790
|
-
allData.push(...
|
|
7791
|
-
|
|
8278
|
+
allData.push(...items);
|
|
8279
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8280
|
+
if (items.length < limit)
|
|
7792
8281
|
break;
|
|
7793
8282
|
offset += limit;
|
|
7794
8283
|
}
|
|
@@ -7880,7 +8369,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7880
8369
|
let lastError = null;
|
|
7881
8370
|
let warnings = [];
|
|
7882
8371
|
while (true) {
|
|
7883
|
-
const response = await this.brokers.getBalances(
|
|
8372
|
+
const response = await this.brokers.getBalances({ ...filterParams, limit, offset });
|
|
7884
8373
|
// Collect warnings from each page
|
|
7885
8374
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7886
8375
|
warnings.push(...response.warning);
|
|
@@ -7890,10 +8379,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7890
8379
|
break;
|
|
7891
8380
|
}
|
|
7892
8381
|
const result = response.success?.data || [];
|
|
7893
|
-
if
|
|
8382
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8383
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8384
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8385
|
+
? result.items
|
|
8386
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8387
|
+
if (!items || items.length === 0)
|
|
7894
8388
|
break;
|
|
7895
|
-
allData.push(...
|
|
7896
|
-
|
|
8389
|
+
allData.push(...items);
|
|
8390
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8391
|
+
if (items.length < limit)
|
|
7897
8392
|
break;
|
|
7898
8393
|
offset += limit;
|
|
7899
8394
|
}
|
|
@@ -7985,7 +8480,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7985
8480
|
let lastError = null;
|
|
7986
8481
|
let warnings = [];
|
|
7987
8482
|
while (true) {
|
|
7988
|
-
const response = await this.brokers.getAccounts(
|
|
8483
|
+
const response = await this.brokers.getAccounts({ ...filterParams, limit, offset });
|
|
7989
8484
|
// Collect warnings from each page
|
|
7990
8485
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7991
8486
|
warnings.push(...response.warning);
|
|
@@ -7995,10 +8490,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7995
8490
|
break;
|
|
7996
8491
|
}
|
|
7997
8492
|
const result = response.success?.data || [];
|
|
7998
|
-
if
|
|
8493
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8494
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8495
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8496
|
+
? result.items
|
|
8497
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8498
|
+
if (!items || items.length === 0)
|
|
7999
8499
|
break;
|
|
8000
|
-
allData.push(...
|
|
8001
|
-
|
|
8500
|
+
allData.push(...items);
|
|
8501
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8502
|
+
if (items.length < limit)
|
|
8002
8503
|
break;
|
|
8003
8504
|
offset += limit;
|
|
8004
8505
|
}
|
|
@@ -8089,7 +8590,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8089
8590
|
let lastError = null;
|
|
8090
8591
|
let warnings = [];
|
|
8091
8592
|
while (true) {
|
|
8092
|
-
const response = await this.brokers.getOrderFills(
|
|
8593
|
+
const response = await this.brokers.getOrderFills({ ...filterParams, limit, offset });
|
|
8093
8594
|
// Collect warnings from each page
|
|
8094
8595
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8095
8596
|
warnings.push(...response.warning);
|
|
@@ -8099,10 +8600,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8099
8600
|
break;
|
|
8100
8601
|
}
|
|
8101
8602
|
const result = response.success?.data || [];
|
|
8102
|
-
if
|
|
8603
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8604
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8605
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8606
|
+
? result.items
|
|
8607
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8608
|
+
if (!items || items.length === 0)
|
|
8103
8609
|
break;
|
|
8104
|
-
allData.push(...
|
|
8105
|
-
|
|
8610
|
+
allData.push(...items);
|
|
8611
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8612
|
+
if (items.length < limit)
|
|
8106
8613
|
break;
|
|
8107
8614
|
offset += limit;
|
|
8108
8615
|
}
|
|
@@ -8193,7 +8700,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8193
8700
|
let lastError = null;
|
|
8194
8701
|
let warnings = [];
|
|
8195
8702
|
while (true) {
|
|
8196
|
-
const response = await this.brokers.getOrderEvents(
|
|
8703
|
+
const response = await this.brokers.getOrderEvents({ ...filterParams, limit, offset });
|
|
8197
8704
|
// Collect warnings from each page
|
|
8198
8705
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8199
8706
|
warnings.push(...response.warning);
|
|
@@ -8203,10 +8710,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8203
8710
|
break;
|
|
8204
8711
|
}
|
|
8205
8712
|
const result = response.success?.data || [];
|
|
8206
|
-
if
|
|
8713
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8714
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8715
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8716
|
+
? result.items
|
|
8717
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8718
|
+
if (!items || items.length === 0)
|
|
8207
8719
|
break;
|
|
8208
|
-
allData.push(...
|
|
8209
|
-
|
|
8720
|
+
allData.push(...items);
|
|
8721
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8722
|
+
if (items.length < limit)
|
|
8210
8723
|
break;
|
|
8211
8724
|
offset += limit;
|
|
8212
8725
|
}
|
|
@@ -8298,7 +8811,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8298
8811
|
let lastError = null;
|
|
8299
8812
|
let warnings = [];
|
|
8300
8813
|
while (true) {
|
|
8301
|
-
const response = await this.brokers.getOrderGroups(
|
|
8814
|
+
const response = await this.brokers.getOrderGroups({ ...filterParams, limit, offset });
|
|
8302
8815
|
// Collect warnings from each page
|
|
8303
8816
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8304
8817
|
warnings.push(...response.warning);
|
|
@@ -8308,10 +8821,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8308
8821
|
break;
|
|
8309
8822
|
}
|
|
8310
8823
|
const result = response.success?.data || [];
|
|
8311
|
-
if
|
|
8824
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8825
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8826
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8827
|
+
? result.items
|
|
8828
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8829
|
+
if (!items || items.length === 0)
|
|
8312
8830
|
break;
|
|
8313
|
-
allData.push(...
|
|
8314
|
-
|
|
8831
|
+
allData.push(...items);
|
|
8832
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8833
|
+
if (items.length < limit)
|
|
8315
8834
|
break;
|
|
8316
8835
|
offset += limit;
|
|
8317
8836
|
}
|
|
@@ -8403,7 +8922,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8403
8922
|
let lastError = null;
|
|
8404
8923
|
let warnings = [];
|
|
8405
8924
|
while (true) {
|
|
8406
|
-
const response = await this.brokers.getPositionLots(
|
|
8925
|
+
const response = await this.brokers.getPositionLots({ ...filterParams, limit, offset });
|
|
8407
8926
|
// Collect warnings from each page
|
|
8408
8927
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8409
8928
|
warnings.push(...response.warning);
|
|
@@ -8413,10 +8932,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8413
8932
|
break;
|
|
8414
8933
|
}
|
|
8415
8934
|
const result = response.success?.data || [];
|
|
8416
|
-
if
|
|
8935
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8936
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8937
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8938
|
+
? result.items
|
|
8939
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8940
|
+
if (!items || items.length === 0)
|
|
8417
8941
|
break;
|
|
8418
|
-
allData.push(...
|
|
8419
|
-
|
|
8942
|
+
allData.push(...items);
|
|
8943
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8944
|
+
if (items.length < limit)
|
|
8420
8945
|
break;
|
|
8421
8946
|
offset += limit;
|
|
8422
8947
|
}
|
|
@@ -8506,7 +9031,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8506
9031
|
let lastError = null;
|
|
8507
9032
|
let warnings = [];
|
|
8508
9033
|
while (true) {
|
|
8509
|
-
const response = await this.brokers.getPositionLotFills(
|
|
9034
|
+
const response = await this.brokers.getPositionLotFills({ ...filterParams, limit, offset });
|
|
8510
9035
|
// Collect warnings from each page
|
|
8511
9036
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8512
9037
|
warnings.push(...response.warning);
|
|
@@ -8516,10 +9041,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8516
9041
|
break;
|
|
8517
9042
|
}
|
|
8518
9043
|
const result = response.success?.data || [];
|
|
8519
|
-
if
|
|
9044
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
9045
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
9046
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
9047
|
+
? result.items
|
|
9048
|
+
: (Array.isArray(result) ? result : [result]);
|
|
9049
|
+
if (!items || items.length === 0)
|
|
8520
9050
|
break;
|
|
8521
|
-
allData.push(...
|
|
8522
|
-
|
|
9051
|
+
allData.push(...items);
|
|
9052
|
+
// If we got fewer items than the limit, there are no more pages
|
|
9053
|
+
if (items.length < limit)
|
|
8523
9054
|
break;
|
|
8524
9055
|
offset += limit;
|
|
8525
9056
|
}
|
|
@@ -8579,6 +9110,7 @@ exports.Configuration = Configuration;
|
|
|
8579
9110
|
exports.EventEmitter = EventEmitter;
|
|
8580
9111
|
exports.FinaticConnect = FinaticConnect;
|
|
8581
9112
|
exports.FinaticError = FinaticError;
|
|
9113
|
+
exports.PaginatedData = PaginatedData;
|
|
8582
9114
|
exports.SessionApi = SessionApi;
|
|
8583
9115
|
exports.SessionApiAxiosParamCreator = SessionApiAxiosParamCreator;
|
|
8584
9116
|
exports.SessionApiFactory = SessionApiFactory;
|