@finatic/client 0.9.2 → 0.9.4
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 +521 -214
- package/dist/index.js +973 -433
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +973 -434
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -15
package/dist/index.js
CHANGED
|
@@ -637,7 +637,11 @@ function coerceEnumValue(input, EnumObj, enumName) {
|
|
|
637
637
|
// Direct match by value (case-insensitive)
|
|
638
638
|
const valueMatch = values.find(v => v.toLowerCase() === normalized.toLowerCase());
|
|
639
639
|
if (valueMatch) {
|
|
640
|
-
|
|
640
|
+
// Find the enum key that has this value
|
|
641
|
+
const matchingKey = Object.keys(EnumObj).find(k => EnumObj[k] === valueMatch);
|
|
642
|
+
if (matchingKey) {
|
|
643
|
+
return EnumObj[matchingKey]; // Returns enum member (e.g., BrokerDataOrderStatusEnum.Filled)
|
|
644
|
+
}
|
|
641
645
|
}
|
|
642
646
|
// Match by key name (case-insensitive)
|
|
643
647
|
const keyMatch = Object.keys(EnumObj).find(k => String(k).toLowerCase() === normalized.toLowerCase());
|
|
@@ -785,34 +789,6 @@ exports.BrokerDataOrderSideEnum = void 0;
|
|
|
785
789
|
BrokerDataOrderSideEnum["Sell"] = "sell";
|
|
786
790
|
})(exports.BrokerDataOrderSideEnum || (exports.BrokerDataOrderSideEnum = {}));
|
|
787
791
|
|
|
788
|
-
/* tslint:disable */
|
|
789
|
-
/* eslint-disable */
|
|
790
|
-
/**
|
|
791
|
-
* Finatic FastAPI Backend
|
|
792
|
-
* FinaticAPI REST API
|
|
793
|
-
*
|
|
794
|
-
* The version of the OpenAPI document: 1.0.0
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
798
|
-
* https://openapi-generator.tech
|
|
799
|
-
* Do not edit the class manually.
|
|
800
|
-
*/
|
|
801
|
-
exports.BrokerDataOrderStatusEnum = void 0;
|
|
802
|
-
(function (BrokerDataOrderStatusEnum) {
|
|
803
|
-
BrokerDataOrderStatusEnum["Submitted"] = "submitted";
|
|
804
|
-
BrokerDataOrderStatusEnum["New"] = "new";
|
|
805
|
-
BrokerDataOrderStatusEnum["PartiallyFilled"] = "partially_filled";
|
|
806
|
-
BrokerDataOrderStatusEnum["Filled"] = "filled";
|
|
807
|
-
BrokerDataOrderStatusEnum["PendingCancel"] = "pending_cancel";
|
|
808
|
-
BrokerDataOrderStatusEnum["Cancelled"] = "cancelled";
|
|
809
|
-
BrokerDataOrderStatusEnum["Rejected"] = "rejected";
|
|
810
|
-
BrokerDataOrderStatusEnum["Expired"] = "expired";
|
|
811
|
-
BrokerDataOrderStatusEnum["Created"] = "created";
|
|
812
|
-
BrokerDataOrderStatusEnum["Received"] = "received";
|
|
813
|
-
BrokerDataOrderStatusEnum["Queued"] = "queued";
|
|
814
|
-
})(exports.BrokerDataOrderStatusEnum || (exports.BrokerDataOrderStatusEnum = {}));
|
|
815
|
-
|
|
816
792
|
/* tslint:disable */
|
|
817
793
|
/* eslint-disable */
|
|
818
794
|
/**
|
|
@@ -1230,6 +1206,273 @@ exports.SessionStatus = void 0;
|
|
|
1230
1206
|
SessionStatus["Expired"] = "expired";
|
|
1231
1207
|
})(exports.SessionStatus || (exports.SessionStatus = {}));
|
|
1232
1208
|
|
|
1209
|
+
/**
|
|
1210
|
+
* Pagination utilities for TypeScript SDK.
|
|
1211
|
+
*
|
|
1212
|
+
* Provides PaginatedData class for wrapping paginated responses with helper methods.
|
|
1213
|
+
*/
|
|
1214
|
+
/**
|
|
1215
|
+
* PaginatedData wraps a data array with pagination metadata and helper methods.
|
|
1216
|
+
*
|
|
1217
|
+
* This class behaves like an array, so you can use it directly:
|
|
1218
|
+
* - paginatedData.length returns the number of items
|
|
1219
|
+
* - paginatedData[0] returns the first item
|
|
1220
|
+
* - paginatedData.forEach(...) works directly
|
|
1221
|
+
* - paginatedData.map(...) works directly
|
|
1222
|
+
*
|
|
1223
|
+
* It also provides pagination methods:
|
|
1224
|
+
* - hasMore: Check if there are more pages
|
|
1225
|
+
* - nextPage(): Get the next page
|
|
1226
|
+
* - prevPage(): Get the previous page
|
|
1227
|
+
* - firstPage(): Get the first page
|
|
1228
|
+
* - lastPage(): Get the last page
|
|
1229
|
+
*
|
|
1230
|
+
* @template T - The element type (e.g., FDXBrokerAccount)
|
|
1231
|
+
*
|
|
1232
|
+
* Usage:
|
|
1233
|
+
* ```typescript
|
|
1234
|
+
* const response = await sdk.getAccounts();
|
|
1235
|
+
* const accounts = response.success.data; // Can use directly as array!
|
|
1236
|
+
* console.log(accounts.length); // Works directly
|
|
1237
|
+
* console.log(accounts[0]); // Works directly
|
|
1238
|
+
* accounts.forEach(account => console.log(account)); // Works directly
|
|
1239
|
+
*
|
|
1240
|
+
* if (accounts.hasMore) {
|
|
1241
|
+
* const nextPage = await accounts.nextPage(); // Returns PaginatedData<FDXBrokerAccount>
|
|
1242
|
+
* const nextAccounts = nextPage; // Can use directly as array too!
|
|
1243
|
+
* }
|
|
1244
|
+
* ```
|
|
1245
|
+
*/
|
|
1246
|
+
class PaginatedData {
|
|
1247
|
+
constructor(items, // The actual data array
|
|
1248
|
+
meta,
|
|
1249
|
+
// Use any for method type since it's only called for paginated endpoints
|
|
1250
|
+
// and will return PaginatedData<T> at runtime
|
|
1251
|
+
originalMethod, currentParams, wrapperInstance // Reference to wrapper for method calls
|
|
1252
|
+
) {
|
|
1253
|
+
this.items = items;
|
|
1254
|
+
this.meta = meta;
|
|
1255
|
+
this.originalMethod = originalMethod;
|
|
1256
|
+
this.currentParams = currentParams;
|
|
1257
|
+
this.wrapperInstance = wrapperInstance;
|
|
1258
|
+
// Create a Proxy to allow array-like indexing (paginatedData[0])
|
|
1259
|
+
return new Proxy(this, {
|
|
1260
|
+
get(target, prop) {
|
|
1261
|
+
// Handle numeric indices
|
|
1262
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1263
|
+
return target.items[Number(prop)];
|
|
1264
|
+
}
|
|
1265
|
+
// Handle length property
|
|
1266
|
+
if (prop === 'length') {
|
|
1267
|
+
return target.items.length;
|
|
1268
|
+
}
|
|
1269
|
+
// Handle array methods and other properties
|
|
1270
|
+
return target[prop];
|
|
1271
|
+
},
|
|
1272
|
+
has(target, prop) {
|
|
1273
|
+
// Support 'in' operator
|
|
1274
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1275
|
+
return Number(prop) < target.items.length;
|
|
1276
|
+
}
|
|
1277
|
+
return prop in target;
|
|
1278
|
+
},
|
|
1279
|
+
ownKeys(target) {
|
|
1280
|
+
// Include numeric indices for Object.keys()
|
|
1281
|
+
const keys = Object.keys(target);
|
|
1282
|
+
for (let i = 0; i < target.items.length; i++) {
|
|
1283
|
+
keys.push(String(i));
|
|
1284
|
+
}
|
|
1285
|
+
return keys;
|
|
1286
|
+
},
|
|
1287
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
1288
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1289
|
+
const index = Number(prop);
|
|
1290
|
+
if (index < target.items.length) {
|
|
1291
|
+
return {
|
|
1292
|
+
enumerable: true,
|
|
1293
|
+
configurable: true,
|
|
1294
|
+
value: target.items[index],
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
1299
|
+
},
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
/**
|
|
1303
|
+
* Get the number of items (allows paginatedData.length).
|
|
1304
|
+
*/
|
|
1305
|
+
get length() {
|
|
1306
|
+
return this.items.length;
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Check if there are more pages available.
|
|
1310
|
+
*/
|
|
1311
|
+
get hasMore() {
|
|
1312
|
+
return this.meta.has_more;
|
|
1313
|
+
}
|
|
1314
|
+
// Array-like methods - delegate to items array
|
|
1315
|
+
/**
|
|
1316
|
+
* Calls a function for each element in the array.
|
|
1317
|
+
*/
|
|
1318
|
+
forEach(callbackfn, thisArg) {
|
|
1319
|
+
return this.items.forEach(callbackfn, thisArg);
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Creates a new array with the results of calling a function for every array element.
|
|
1323
|
+
*/
|
|
1324
|
+
map(callbackfn, thisArg) {
|
|
1325
|
+
return this.items.map(callbackfn, thisArg);
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Returns the elements of an array that meet the condition specified in a callback function.
|
|
1329
|
+
*/
|
|
1330
|
+
filter(callbackfn, thisArg) {
|
|
1331
|
+
return this.items.filter(callbackfn, thisArg);
|
|
1332
|
+
}
|
|
1333
|
+
/**
|
|
1334
|
+
* Returns the value of the first element in the array where predicate is true.
|
|
1335
|
+
*/
|
|
1336
|
+
find(predicate, thisArg) {
|
|
1337
|
+
return this.items.find(predicate, thisArg);
|
|
1338
|
+
}
|
|
1339
|
+
/**
|
|
1340
|
+
* Returns the index of the first element in the array where predicate is true.
|
|
1341
|
+
*/
|
|
1342
|
+
findIndex(predicate, thisArg) {
|
|
1343
|
+
return this.items.findIndex(predicate, thisArg);
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* Returns a section of an array.
|
|
1347
|
+
*/
|
|
1348
|
+
slice(start, end) {
|
|
1349
|
+
return this.items.slice(start, end);
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Determines whether an array includes a certain element.
|
|
1353
|
+
*/
|
|
1354
|
+
includes(searchElement, fromIndex) {
|
|
1355
|
+
return this.items.includes(searchElement, fromIndex);
|
|
1356
|
+
}
|
|
1357
|
+
/**
|
|
1358
|
+
* Returns the index of the first occurrence of a value in an array.
|
|
1359
|
+
*/
|
|
1360
|
+
indexOf(searchElement, fromIndex) {
|
|
1361
|
+
return this.items.indexOf(searchElement, fromIndex);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Returns a string representation of an array.
|
|
1365
|
+
*/
|
|
1366
|
+
toString() {
|
|
1367
|
+
return this.items.toString();
|
|
1368
|
+
}
|
|
1369
|
+
/**
|
|
1370
|
+
* Returns a string representation of an array.
|
|
1371
|
+
*/
|
|
1372
|
+
toLocaleString() {
|
|
1373
|
+
return this.items.toLocaleString();
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Convert to JSON - returns just the items array for serialization.
|
|
1377
|
+
* This allows clean serialization without exposing internal methods.
|
|
1378
|
+
*
|
|
1379
|
+
* @returns The items array
|
|
1380
|
+
*
|
|
1381
|
+
* @example
|
|
1382
|
+
* ```typescript
|
|
1383
|
+
* const orders = await sdk.getOrders();
|
|
1384
|
+
* console.log(orders); // Shows full PaginatedData with methods
|
|
1385
|
+
* console.log(orders.toJSON()); // Shows just the items array
|
|
1386
|
+
* JSON.stringify(orders); // Automatically uses toJSON()
|
|
1387
|
+
* ```
|
|
1388
|
+
*/
|
|
1389
|
+
toJSON() {
|
|
1390
|
+
return this.items;
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Get the next page of data.
|
|
1394
|
+
* @returns Promise<PaginatedData<T>> - The next page (not wrapped in FinaticResponse)
|
|
1395
|
+
* @throws Error if no more pages are available
|
|
1396
|
+
*/
|
|
1397
|
+
async nextPage() {
|
|
1398
|
+
if (!this.hasMore) {
|
|
1399
|
+
throw new Error('No more pages available');
|
|
1400
|
+
}
|
|
1401
|
+
if (this.meta.next_offset === null) {
|
|
1402
|
+
throw new Error('Next offset is null');
|
|
1403
|
+
}
|
|
1404
|
+
const newParams = {
|
|
1405
|
+
...this.currentParams,
|
|
1406
|
+
offset: this.meta.next_offset,
|
|
1407
|
+
};
|
|
1408
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1409
|
+
if (!response.success) {
|
|
1410
|
+
throw new Error(response.error?.message || 'Failed to fetch next page');
|
|
1411
|
+
}
|
|
1412
|
+
return response.success.data; // Return PaginatedData directly
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Get the previous page of data.
|
|
1416
|
+
* @returns Promise<PaginatedData<T>> - The previous page (not wrapped in FinaticResponse)
|
|
1417
|
+
* @throws Error if fetch fails
|
|
1418
|
+
*/
|
|
1419
|
+
async prevPage() {
|
|
1420
|
+
const prevOffset = Math.max(0, this.meta.current_offset - this.meta.limit);
|
|
1421
|
+
const newParams = {
|
|
1422
|
+
...this.currentParams,
|
|
1423
|
+
offset: prevOffset,
|
|
1424
|
+
};
|
|
1425
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1426
|
+
if (!response.success) {
|
|
1427
|
+
throw new Error(response.error?.message || 'Failed to fetch previous page');
|
|
1428
|
+
}
|
|
1429
|
+
return response.success.data; // Return PaginatedData directly
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
* Get the first page of data.
|
|
1433
|
+
* @returns Promise<PaginatedData<T>> - The first page (not wrapped in FinaticResponse)
|
|
1434
|
+
* @throws Error if fetch fails
|
|
1435
|
+
*/
|
|
1436
|
+
async firstPage() {
|
|
1437
|
+
const newParams = {
|
|
1438
|
+
...this.currentParams,
|
|
1439
|
+
offset: 0,
|
|
1440
|
+
};
|
|
1441
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1442
|
+
if (!response.success) {
|
|
1443
|
+
throw new Error(response.error?.message || 'Failed to fetch first page');
|
|
1444
|
+
}
|
|
1445
|
+
return response.success.data; // Return PaginatedData directly
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Get the last page of data.
|
|
1449
|
+
* Uses iterative approach to find the last page.
|
|
1450
|
+
* @returns Promise<PaginatedData<T>> - The last page (not wrapped in FinaticResponse)
|
|
1451
|
+
* @throws Error if fetch fails
|
|
1452
|
+
*/
|
|
1453
|
+
async lastPage() {
|
|
1454
|
+
// Iterative approach to find last page
|
|
1455
|
+
let currentOffset = this.meta.current_offset;
|
|
1456
|
+
let lastValidData = null;
|
|
1457
|
+
while (true) {
|
|
1458
|
+
const testParams = { ...this.currentParams, offset: currentOffset };
|
|
1459
|
+
const response = await this.originalMethod.call(this.wrapperInstance, testParams);
|
|
1460
|
+
if (!response.success) {
|
|
1461
|
+
break;
|
|
1462
|
+
}
|
|
1463
|
+
lastValidData = response.success.data;
|
|
1464
|
+
if (!lastValidData || !lastValidData.hasMore) {
|
|
1465
|
+
break;
|
|
1466
|
+
}
|
|
1467
|
+
currentOffset += this.meta.limit;
|
|
1468
|
+
}
|
|
1469
|
+
if (!lastValidData) {
|
|
1470
|
+
throw new Error('Failed to fetch last page');
|
|
1471
|
+
}
|
|
1472
|
+
return lastValidData; // Return PaginatedData directly
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1233
1476
|
/**
|
|
1234
1477
|
* Generated wrapper functions for brokers operations (Phase 2A).
|
|
1235
1478
|
*
|
|
@@ -1279,7 +1522,7 @@ class BrokersWrapper {
|
|
|
1279
1522
|
* -------
|
|
1280
1523
|
* FinaticResponse[list[BrokerInfo]]
|
|
1281
1524
|
* list of available brokers with their metadata.
|
|
1282
|
-
* @param No parameters required for this method
|
|
1525
|
+
* @param params No parameters required for this method
|
|
1283
1526
|
* @returns {Promise<FinaticResponse<BrokerInfo[]>>} Standard response with success/Error/Warning structure
|
|
1284
1527
|
*
|
|
1285
1528
|
* Generated from: GET /api/v1/brokers/
|
|
@@ -1288,7 +1531,7 @@ class BrokersWrapper {
|
|
|
1288
1531
|
* @example
|
|
1289
1532
|
* ```typescript-client
|
|
1290
1533
|
* // Example with no parameters
|
|
1291
|
-
* const result = await finatic.getBrokers();
|
|
1534
|
+
* const result = await finatic.getBrokers({});
|
|
1292
1535
|
*
|
|
1293
1536
|
* // Access the response data
|
|
1294
1537
|
* if (result.success) {
|
|
@@ -1296,9 +1539,9 @@ class BrokersWrapper {
|
|
|
1296
1539
|
* }
|
|
1297
1540
|
* ```
|
|
1298
1541
|
*/
|
|
1299
|
-
async getBrokers() {
|
|
1542
|
+
async getBrokers(params) {
|
|
1300
1543
|
// No parameters - use empty params object
|
|
1301
|
-
const
|
|
1544
|
+
const resolvedParams = params || {}; // Generate request ID
|
|
1302
1545
|
const requestId = this._generateRequestId();
|
|
1303
1546
|
// Input validation (Phase 2B: zod)
|
|
1304
1547
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -1306,7 +1549,7 @@ class BrokersWrapper {
|
|
|
1306
1549
|
const shouldCache = true;
|
|
1307
1550
|
const cache = getCache(this.sdkConfig);
|
|
1308
1551
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1309
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/',
|
|
1552
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
|
|
1310
1553
|
const cached = cache.get(cacheKey);
|
|
1311
1554
|
if (cached) {
|
|
1312
1555
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1318,7 +1561,7 @@ class BrokersWrapper {
|
|
|
1318
1561
|
request_id: requestId,
|
|
1319
1562
|
method: 'GET',
|
|
1320
1563
|
path: '/api/v1/brokers/',
|
|
1321
|
-
params:
|
|
1564
|
+
params: resolvedParams,
|
|
1322
1565
|
action: 'getBrokers'
|
|
1323
1566
|
});
|
|
1324
1567
|
try {
|
|
@@ -1332,9 +1575,15 @@ class BrokersWrapper {
|
|
|
1332
1575
|
throw new Error('Unexpected response shape: missing success field');
|
|
1333
1576
|
}
|
|
1334
1577
|
// Convert response to plain object, removing _id fields recursively
|
|
1578
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1335
1579
|
const standardResponse = convertToPlainObject(responseData);
|
|
1580
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1581
|
+
const hasLimit = false;
|
|
1582
|
+
const hasOffset = false;
|
|
1583
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1584
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1336
1585
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1337
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/',
|
|
1586
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
|
|
1338
1587
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1339
1588
|
}
|
|
1340
1589
|
this.logger.debug('Get Brokers completed', {
|
|
@@ -1342,6 +1591,7 @@ class BrokersWrapper {
|
|
|
1342
1591
|
action: 'getBrokers'
|
|
1343
1592
|
});
|
|
1344
1593
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1594
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1345
1595
|
return standardResponse;
|
|
1346
1596
|
}
|
|
1347
1597
|
catch (error) {
|
|
@@ -1419,7 +1669,7 @@ class BrokersWrapper {
|
|
|
1419
1669
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1420
1670
|
* Returns connections that the user has any permissions for, including the current
|
|
1421
1671
|
* company's permissions (read/write) for each connection.
|
|
1422
|
-
* @param No parameters required for this method
|
|
1672
|
+
* @param params No parameters required for this method
|
|
1423
1673
|
* @returns {Promise<FinaticResponse<UserBrokerConnectionWithPermissions[]>>} Standard response with success/Error/Warning structure
|
|
1424
1674
|
*
|
|
1425
1675
|
* Generated from: GET /api/v1/brokers/connections
|
|
@@ -1428,7 +1678,7 @@ class BrokersWrapper {
|
|
|
1428
1678
|
* @example
|
|
1429
1679
|
* ```typescript-client
|
|
1430
1680
|
* // Example with no parameters
|
|
1431
|
-
* const result = await finatic.getBrokerConnections();
|
|
1681
|
+
* const result = await finatic.getBrokerConnections({});
|
|
1432
1682
|
*
|
|
1433
1683
|
* // Access the response data
|
|
1434
1684
|
* if (result.success) {
|
|
@@ -1436,10 +1686,10 @@ class BrokersWrapper {
|
|
|
1436
1686
|
* }
|
|
1437
1687
|
* ```
|
|
1438
1688
|
*/
|
|
1439
|
-
async getBrokerConnections() {
|
|
1689
|
+
async getBrokerConnections(params) {
|
|
1440
1690
|
// No parameters - use empty params object
|
|
1441
|
-
const
|
|
1442
|
-
if (!this.sessionId) {
|
|
1691
|
+
const resolvedParams = params || {}; // Authentication check
|
|
1692
|
+
if (!this.sessionId || !this.companyId) {
|
|
1443
1693
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1444
1694
|
}
|
|
1445
1695
|
// Generate request ID
|
|
@@ -1450,7 +1700,7 @@ class BrokersWrapper {
|
|
|
1450
1700
|
const shouldCache = true;
|
|
1451
1701
|
const cache = getCache(this.sdkConfig);
|
|
1452
1702
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1453
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections',
|
|
1703
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
|
|
1454
1704
|
const cached = cache.get(cacheKey);
|
|
1455
1705
|
if (cached) {
|
|
1456
1706
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1462,12 +1712,12 @@ class BrokersWrapper {
|
|
|
1462
1712
|
request_id: requestId,
|
|
1463
1713
|
method: 'GET',
|
|
1464
1714
|
path: '/api/v1/brokers/connections',
|
|
1465
|
-
params:
|
|
1715
|
+
params: resolvedParams,
|
|
1466
1716
|
action: 'getBrokerConnections'
|
|
1467
1717
|
});
|
|
1468
1718
|
try {
|
|
1469
1719
|
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
|
|
1720
|
+
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
1721
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1472
1722
|
}, {}, this.sdkConfig);
|
|
1473
1723
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1476,9 +1726,15 @@ class BrokersWrapper {
|
|
|
1476
1726
|
throw new Error('Unexpected response shape: missing success field');
|
|
1477
1727
|
}
|
|
1478
1728
|
// Convert response to plain object, removing _id fields recursively
|
|
1729
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1479
1730
|
const standardResponse = convertToPlainObject(responseData);
|
|
1731
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1732
|
+
const hasLimit = false;
|
|
1733
|
+
const hasOffset = false;
|
|
1734
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1735
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1480
1736
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1481
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections',
|
|
1737
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
|
|
1482
1738
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1483
1739
|
}
|
|
1484
1740
|
this.logger.debug('List Broker Connections completed', {
|
|
@@ -1486,6 +1742,7 @@ class BrokersWrapper {
|
|
|
1486
1742
|
action: 'getBrokerConnections'
|
|
1487
1743
|
});
|
|
1488
1744
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1745
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1489
1746
|
return standardResponse;
|
|
1490
1747
|
}
|
|
1491
1748
|
catch (error) {
|
|
@@ -1562,7 +1819,7 @@ class BrokersWrapper {
|
|
|
1562
1819
|
*
|
|
1563
1820
|
* If the company is the only one with access, the entire connection is deleted.
|
|
1564
1821
|
* If other companies have access, only the company's access is removed.
|
|
1565
|
-
* @param connectionId {string}
|
|
1822
|
+
* @param params.connectionId {string} Connection ID
|
|
1566
1823
|
* @returns {Promise<FinaticResponse<DisconnectActionResult>>} Standard response with success/Error/Warning structure
|
|
1567
1824
|
*
|
|
1568
1825
|
* Generated from: DELETE /api/v1/brokers/disconnect-company/{connection_id}
|
|
@@ -1571,7 +1828,9 @@ class BrokersWrapper {
|
|
|
1571
1828
|
* @example
|
|
1572
1829
|
* ```typescript-client
|
|
1573
1830
|
* // Minimal example with required parameters only
|
|
1574
|
-
* const result = await finatic.disconnectCompanyFromBroker(
|
|
1831
|
+
* const result = await finatic.disconnectCompanyFromBroker({
|
|
1832
|
+
connectionId: '00000000-0000-0000-0000-000000000000'
|
|
1833
|
+
* });
|
|
1575
1834
|
*
|
|
1576
1835
|
* // Access the response data
|
|
1577
1836
|
* if (result.success) {
|
|
@@ -1581,12 +1840,10 @@ class BrokersWrapper {
|
|
|
1581
1840
|
* }
|
|
1582
1841
|
* ```
|
|
1583
1842
|
*/
|
|
1584
|
-
async disconnectCompanyFromBroker(
|
|
1585
|
-
//
|
|
1586
|
-
const
|
|
1587
|
-
|
|
1588
|
-
}; // Authentication check
|
|
1589
|
-
if (!this.sessionId) {
|
|
1843
|
+
async disconnectCompanyFromBroker(params) {
|
|
1844
|
+
// Use params object (required parameters present)
|
|
1845
|
+
const resolvedParams = params; // Authentication check
|
|
1846
|
+
if (!this.sessionId || !this.companyId) {
|
|
1590
1847
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1591
1848
|
}
|
|
1592
1849
|
// Generate request ID
|
|
@@ -1597,7 +1854,7 @@ class BrokersWrapper {
|
|
|
1597
1854
|
const shouldCache = true;
|
|
1598
1855
|
const cache = getCache(this.sdkConfig);
|
|
1599
1856
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1600
|
-
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1857
|
+
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
|
|
1601
1858
|
const cached = cache.get(cacheKey);
|
|
1602
1859
|
if (cached) {
|
|
1603
1860
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1609,12 +1866,12 @@ class BrokersWrapper {
|
|
|
1609
1866
|
request_id: requestId,
|
|
1610
1867
|
method: 'DELETE',
|
|
1611
1868
|
path: '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1612
|
-
params:
|
|
1869
|
+
params: resolvedParams,
|
|
1613
1870
|
action: 'disconnectCompanyFromBroker'
|
|
1614
1871
|
});
|
|
1615
1872
|
try {
|
|
1616
1873
|
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
|
|
1874
|
+
const apiResponse = await this.api.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete({ connectionId: resolvedParams.connectionId ?? null }, { 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
1875
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1619
1876
|
}, {}, this.sdkConfig);
|
|
1620
1877
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1623,9 +1880,15 @@ class BrokersWrapper {
|
|
|
1623
1880
|
throw new Error('Unexpected response shape: missing success field');
|
|
1624
1881
|
}
|
|
1625
1882
|
// Convert response to plain object, removing _id fields recursively
|
|
1883
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1626
1884
|
const standardResponse = convertToPlainObject(responseData);
|
|
1885
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1886
|
+
const hasLimit = false;
|
|
1887
|
+
const hasOffset = false;
|
|
1888
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1889
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1627
1890
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1628
|
-
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1891
|
+
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
|
|
1629
1892
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1630
1893
|
}
|
|
1631
1894
|
this.logger.debug('Disconnect Company From Broker completed', {
|
|
@@ -1633,6 +1896,7 @@ class BrokersWrapper {
|
|
|
1633
1896
|
action: 'disconnectCompanyFromBroker'
|
|
1634
1897
|
});
|
|
1635
1898
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1899
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1636
1900
|
return standardResponse;
|
|
1637
1901
|
}
|
|
1638
1902
|
catch (error) {
|
|
@@ -1709,19 +1973,19 @@ class BrokersWrapper {
|
|
|
1709
1973
|
*
|
|
1710
1974
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1711
1975
|
* 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 {
|
|
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
|
|
1976
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
1977
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
1978
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID or internal account UUID
|
|
1979
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
1980
|
+
* @param params.orderStatus {string} (optional) Filter by order status (e.g., 'filled', 'pending_new', 'cancelled')
|
|
1981
|
+
* @param params.side {BrokerDataOrderSideEnum} (optional) Filter by order side (e.g., 'buy', 'sell')
|
|
1982
|
+
* @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
|
|
1983
|
+
* @param params.limit {number} (optional) Maximum number of orders to return
|
|
1984
|
+
* @param params.offset {number} (optional) Number of orders to skip for pagination
|
|
1985
|
+
* @param params.createdAfter {string} (optional) Filter orders created after this timestamp
|
|
1986
|
+
* @param params.createdBefore {string} (optional) Filter orders created before this timestamp
|
|
1987
|
+
* @param params.includeMetadata {boolean} (optional) Include order metadata in response (excluded by default for FDX compliance)
|
|
1988
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrder>>>} Standard response with success/Error/Warning structure
|
|
1725
1989
|
*
|
|
1726
1990
|
* Generated from: GET /api/v1/brokers/data/orders
|
|
1727
1991
|
* @methodId get_orders_api_v1_brokers_data_orders_get
|
|
@@ -1729,7 +1993,7 @@ class BrokersWrapper {
|
|
|
1729
1993
|
* @example
|
|
1730
1994
|
* ```typescript-client
|
|
1731
1995
|
* // Example with no parameters
|
|
1732
|
-
* const result = await finatic.getOrders();
|
|
1996
|
+
* const result = await finatic.getOrders({});
|
|
1733
1997
|
*
|
|
1734
1998
|
* // Access the response data
|
|
1735
1999
|
* if (result.success) {
|
|
@@ -1739,7 +2003,11 @@ class BrokersWrapper {
|
|
|
1739
2003
|
* @example
|
|
1740
2004
|
* ```typescript-client
|
|
1741
2005
|
* // Full example with optional parameters
|
|
1742
|
-
* const result = await finatic.getOrders(
|
|
2006
|
+
* const result = await finatic.getOrders({
|
|
2007
|
+
brokerId: 'alpaca',
|
|
2008
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2009
|
+
accountId: '123456789'
|
|
2010
|
+
* });
|
|
1743
2011
|
*
|
|
1744
2012
|
* // Handle response with warnings
|
|
1745
2013
|
* if (result.success) {
|
|
@@ -1752,23 +2020,22 @@ class BrokersWrapper {
|
|
|
1752
2020
|
* }
|
|
1753
2021
|
* ```
|
|
1754
2022
|
*/
|
|
1755
|
-
async getOrders(
|
|
1756
|
-
//
|
|
1757
|
-
const
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
if (!this.sessionId) {
|
|
2023
|
+
async getOrders(params) {
|
|
2024
|
+
// Use params object (with default empty object)
|
|
2025
|
+
const resolvedParams = params || {};
|
|
2026
|
+
if (params?.side !== undefined) {
|
|
2027
|
+
const coerced = coerceEnumValue(params.side, exports.BrokerDataOrderSideEnum, 'side');
|
|
2028
|
+
if (coerced !== undefined) {
|
|
2029
|
+
params.side = coerced;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
if (params?.assetType !== undefined) {
|
|
2033
|
+
const coerced = coerceEnumValue(params.assetType, exports.BrokerDataAssetTypeEnum, 'assetType');
|
|
2034
|
+
if (coerced !== undefined) {
|
|
2035
|
+
params.assetType = coerced;
|
|
2036
|
+
}
|
|
2037
|
+
} // Authentication check
|
|
2038
|
+
if (!this.sessionId || !this.companyId) {
|
|
1772
2039
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1773
2040
|
}
|
|
1774
2041
|
// Generate request ID
|
|
@@ -1779,7 +2046,7 @@ class BrokersWrapper {
|
|
|
1779
2046
|
const shouldCache = true;
|
|
1780
2047
|
const cache = getCache(this.sdkConfig);
|
|
1781
2048
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1782
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders',
|
|
2049
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
|
|
1783
2050
|
const cached = cache.get(cacheKey);
|
|
1784
2051
|
if (cached) {
|
|
1785
2052
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1791,12 +2058,12 @@ class BrokersWrapper {
|
|
|
1791
2058
|
request_id: requestId,
|
|
1792
2059
|
method: 'GET',
|
|
1793
2060
|
path: '/api/v1/brokers/data/orders',
|
|
1794
|
-
params:
|
|
2061
|
+
params: resolvedParams,
|
|
1795
2062
|
action: 'getOrders'
|
|
1796
2063
|
});
|
|
1797
2064
|
try {
|
|
1798
2065
|
const response = await retryApiCall(async () => {
|
|
1799
|
-
const apiResponse = await this.api.getOrdersApiV1BrokersDataOrdersGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(symbol !== undefined ? { symbol: symbol } : {}), ...(orderStatus !== undefined ? { orderStatus: orderStatus } : {}), ...(side !== undefined ? { side: side } : {}), ...(assetType !== undefined ? { assetType: assetType } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(createdAfter !== undefined ? { createdAfter: createdAfter } : {}), ...(createdBefore !== undefined ? { createdBefore: createdBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
2066
|
+
const apiResponse = await this.api.getOrdersApiV1BrokersDataOrdersGet({ ...(resolvedParams.brokerId !== undefined ? { brokerId: resolvedParams.brokerId } : {}), ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.accountId !== undefined ? { accountId: resolvedParams.accountId } : {}), ...(resolvedParams.symbol !== undefined ? { symbol: resolvedParams.symbol } : {}), ...(resolvedParams.orderStatus !== undefined ? { orderStatus: resolvedParams.orderStatus } : {}), ...(resolvedParams.side !== undefined ? { side: resolvedParams.side } : {}), ...(resolvedParams.assetType !== undefined ? { assetType: resolvedParams.assetType } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { offset: resolvedParams.offset } : {}), ...(resolvedParams.createdAfter !== undefined ? { createdAfter: resolvedParams.createdAfter } : {}), ...(resolvedParams.createdBefore !== undefined ? { createdBefore: resolvedParams.createdBefore } : {}), ...(resolvedParams.includeMetadata !== undefined ? { 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
2067
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1801
2068
|
}, {}, this.sdkConfig);
|
|
1802
2069
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1805,9 +2072,27 @@ class BrokersWrapper {
|
|
|
1805
2072
|
throw new Error('Unexpected response shape: missing success field');
|
|
1806
2073
|
}
|
|
1807
2074
|
// Convert response to plain object, removing _id fields recursively
|
|
2075
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1808
2076
|
const standardResponse = convertToPlainObject(responseData);
|
|
2077
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2078
|
+
const hasLimit = true;
|
|
2079
|
+
const hasOffset = true;
|
|
2080
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2081
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2082
|
+
// PaginatedData is already imported at top of file
|
|
2083
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2084
|
+
if (paginationMeta) {
|
|
2085
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2086
|
+
has_more: paginationMeta.has_more,
|
|
2087
|
+
next_offset: paginationMeta.next_offset,
|
|
2088
|
+
current_offset: paginationMeta.current_offset,
|
|
2089
|
+
limit: paginationMeta.limit,
|
|
2090
|
+
}, this.getOrders.bind(this), resolvedParams, this);
|
|
2091
|
+
standardResponse.success.data = paginatedData;
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
1809
2094
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1810
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders',
|
|
2095
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
|
|
1811
2096
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1812
2097
|
}
|
|
1813
2098
|
this.logger.debug('Get Orders completed', {
|
|
@@ -1815,6 +2100,7 @@ class BrokersWrapper {
|
|
|
1815
2100
|
action: 'getOrders'
|
|
1816
2101
|
});
|
|
1817
2102
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2103
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1818
2104
|
return standardResponse;
|
|
1819
2105
|
}
|
|
1820
2106
|
catch (error) {
|
|
@@ -1891,19 +2177,19 @@ class BrokersWrapper {
|
|
|
1891
2177
|
*
|
|
1892
2178
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1893
2179
|
* 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
|
|
2180
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2181
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2182
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID or internal account UUID
|
|
2183
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
2184
|
+
* @param params.side {BrokerDataOrderSideEnum} (optional) Filter by position side (e.g., 'long', 'short')
|
|
2185
|
+
* @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
|
|
2186
|
+
* @param params.positionStatus {BrokerDataPositionStatusEnum} (optional) Filter by position status: 'open' (quantity > 0) or 'closed' (quantity = 0)
|
|
2187
|
+
* @param params.limit {number} (optional) Maximum number of positions to return
|
|
2188
|
+
* @param params.offset {number} (optional) Number of positions to skip for pagination
|
|
2189
|
+
* @param params.updatedAfter {string} (optional) Filter positions updated after this timestamp
|
|
2190
|
+
* @param params.updatedBefore {string} (optional) Filter positions updated before this timestamp
|
|
2191
|
+
* @param params.includeMetadata {boolean} (optional) Include position metadata in response (excluded by default for FDX compliance)
|
|
2192
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPosition>>>} Standard response with success/Error/Warning structure
|
|
1907
2193
|
*
|
|
1908
2194
|
* Generated from: GET /api/v1/brokers/data/positions
|
|
1909
2195
|
* @methodId get_positions_api_v1_brokers_data_positions_get
|
|
@@ -1911,7 +2197,7 @@ class BrokersWrapper {
|
|
|
1911
2197
|
* @example
|
|
1912
2198
|
* ```typescript-client
|
|
1913
2199
|
* // Example with no parameters
|
|
1914
|
-
* const result = await finatic.getPositions();
|
|
2200
|
+
* const result = await finatic.getPositions({});
|
|
1915
2201
|
*
|
|
1916
2202
|
* // Access the response data
|
|
1917
2203
|
* if (result.success) {
|
|
@@ -1921,7 +2207,11 @@ class BrokersWrapper {
|
|
|
1921
2207
|
* @example
|
|
1922
2208
|
* ```typescript-client
|
|
1923
2209
|
* // Full example with optional parameters
|
|
1924
|
-
* const result = await finatic.getPositions(
|
|
2210
|
+
* const result = await finatic.getPositions({
|
|
2211
|
+
brokerId: 'alpaca',
|
|
2212
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2213
|
+
accountId: '123456789'
|
|
2214
|
+
* });
|
|
1925
2215
|
*
|
|
1926
2216
|
* // Handle response with warnings
|
|
1927
2217
|
* if (result.success) {
|
|
@@ -1934,23 +2224,28 @@ class BrokersWrapper {
|
|
|
1934
2224
|
* }
|
|
1935
2225
|
* ```
|
|
1936
2226
|
*/
|
|
1937
|
-
async getPositions(
|
|
1938
|
-
//
|
|
1939
|
-
const
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
2227
|
+
async getPositions(params) {
|
|
2228
|
+
// Use params object (with default empty object)
|
|
2229
|
+
const resolvedParams = params || {};
|
|
2230
|
+
if (params?.side !== undefined) {
|
|
2231
|
+
const coerced = coerceEnumValue(params.side, exports.BrokerDataOrderSideEnum, 'side');
|
|
2232
|
+
if (coerced !== undefined) {
|
|
2233
|
+
params.side = coerced;
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
if (params?.assetType !== undefined) {
|
|
2237
|
+
const coerced = coerceEnumValue(params.assetType, exports.BrokerDataAssetTypeEnum, 'assetType');
|
|
2238
|
+
if (coerced !== undefined) {
|
|
2239
|
+
params.assetType = coerced;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
if (params?.positionStatus !== undefined) {
|
|
2243
|
+
const coerced = coerceEnumValue(params.positionStatus, exports.BrokerDataPositionStatusEnum, 'positionStatus');
|
|
2244
|
+
if (coerced !== undefined) {
|
|
2245
|
+
params.positionStatus = coerced;
|
|
2246
|
+
}
|
|
2247
|
+
} // Authentication check
|
|
2248
|
+
if (!this.sessionId || !this.companyId) {
|
|
1954
2249
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1955
2250
|
}
|
|
1956
2251
|
// Generate request ID
|
|
@@ -1961,7 +2256,7 @@ class BrokersWrapper {
|
|
|
1961
2256
|
const shouldCache = true;
|
|
1962
2257
|
const cache = getCache(this.sdkConfig);
|
|
1963
2258
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1964
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions',
|
|
2259
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
|
|
1965
2260
|
const cached = cache.get(cacheKey);
|
|
1966
2261
|
if (cached) {
|
|
1967
2262
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1973,12 +2268,12 @@ class BrokersWrapper {
|
|
|
1973
2268
|
request_id: requestId,
|
|
1974
2269
|
method: 'GET',
|
|
1975
2270
|
path: '/api/v1/brokers/data/positions',
|
|
1976
|
-
params:
|
|
2271
|
+
params: resolvedParams,
|
|
1977
2272
|
action: 'getPositions'
|
|
1978
2273
|
});
|
|
1979
2274
|
try {
|
|
1980
2275
|
const response = await retryApiCall(async () => {
|
|
1981
|
-
const apiResponse = await this.api.getPositionsApiV1BrokersDataPositionsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(symbol !== undefined ? { symbol: symbol } : {}), ...(side !== undefined ? { side: side } : {}), ...(assetType !== undefined ? { assetType: assetType } : {}), ...(positionStatus !== undefined ? { positionStatus: positionStatus } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(updatedAfter !== undefined ? { updatedAfter: updatedAfter } : {}), ...(updatedBefore !== undefined ? { updatedBefore: updatedBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
2276
|
+
const apiResponse = await this.api.getPositionsApiV1BrokersDataPositionsGet({ ...(resolvedParams.brokerId !== undefined ? { brokerId: resolvedParams.brokerId } : {}), ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.accountId !== undefined ? { accountId: resolvedParams.accountId } : {}), ...(resolvedParams.symbol !== undefined ? { symbol: resolvedParams.symbol } : {}), ...(resolvedParams.side !== undefined ? { side: resolvedParams.side } : {}), ...(resolvedParams.assetType !== undefined ? { assetType: resolvedParams.assetType } : {}), ...(resolvedParams.positionStatus !== undefined ? { positionStatus: resolvedParams.positionStatus } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { offset: resolvedParams.offset } : {}), ...(resolvedParams.updatedAfter !== undefined ? { updatedAfter: resolvedParams.updatedAfter } : {}), ...(resolvedParams.updatedBefore !== undefined ? { updatedBefore: resolvedParams.updatedBefore } : {}), ...(resolvedParams.includeMetadata !== undefined ? { 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
2277
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1983
2278
|
}, {}, this.sdkConfig);
|
|
1984
2279
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1987,9 +2282,27 @@ class BrokersWrapper {
|
|
|
1987
2282
|
throw new Error('Unexpected response shape: missing success field');
|
|
1988
2283
|
}
|
|
1989
2284
|
// Convert response to plain object, removing _id fields recursively
|
|
2285
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1990
2286
|
const standardResponse = convertToPlainObject(responseData);
|
|
2287
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2288
|
+
const hasLimit = true;
|
|
2289
|
+
const hasOffset = true;
|
|
2290
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2291
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2292
|
+
// PaginatedData is already imported at top of file
|
|
2293
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2294
|
+
if (paginationMeta) {
|
|
2295
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2296
|
+
has_more: paginationMeta.has_more,
|
|
2297
|
+
next_offset: paginationMeta.next_offset,
|
|
2298
|
+
current_offset: paginationMeta.current_offset,
|
|
2299
|
+
limit: paginationMeta.limit,
|
|
2300
|
+
}, this.getPositions.bind(this), resolvedParams, this);
|
|
2301
|
+
standardResponse.success.data = paginatedData;
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
1991
2304
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1992
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions',
|
|
2305
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
|
|
1993
2306
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1994
2307
|
}
|
|
1995
2308
|
this.logger.debug('Get Positions completed', {
|
|
@@ -1997,6 +2310,7 @@ class BrokersWrapper {
|
|
|
1997
2310
|
action: 'getPositions'
|
|
1998
2311
|
});
|
|
1999
2312
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2313
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2000
2314
|
return standardResponse;
|
|
2001
2315
|
}
|
|
2002
2316
|
catch (error) {
|
|
@@ -2073,16 +2387,16 @@ class BrokersWrapper {
|
|
|
2073
2387
|
*
|
|
2074
2388
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
2075
2389
|
* 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
|
|
2390
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2391
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2392
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID or internal account UUID
|
|
2393
|
+
* @param params.isEndOfDaySnapshot {boolean} (optional) Filter by end-of-day snapshot status (true/false)
|
|
2394
|
+
* @param params.limit {number} (optional) Maximum number of balances to return
|
|
2395
|
+
* @param params.offset {number} (optional) Number of balances to skip for pagination
|
|
2396
|
+
* @param params.balanceCreatedAfter {string} (optional) Filter balances created after this timestamp
|
|
2397
|
+
* @param params.balanceCreatedBefore {string} (optional) Filter balances created before this timestamp
|
|
2398
|
+
* @param params.includeMetadata {boolean} (optional) Include balance metadata in response (excluded by default for FDX compliance)
|
|
2399
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerBalance>>>} Standard response with success/Error/Warning structure
|
|
2086
2400
|
*
|
|
2087
2401
|
* Generated from: GET /api/v1/brokers/data/balances
|
|
2088
2402
|
* @methodId get_balances_api_v1_brokers_data_balances_get
|
|
@@ -2090,7 +2404,7 @@ class BrokersWrapper {
|
|
|
2090
2404
|
* @example
|
|
2091
2405
|
* ```typescript-client
|
|
2092
2406
|
* // Example with no parameters
|
|
2093
|
-
* const result = await finatic.getBalances();
|
|
2407
|
+
* const result = await finatic.getBalances({});
|
|
2094
2408
|
*
|
|
2095
2409
|
* // Access the response data
|
|
2096
2410
|
* if (result.success) {
|
|
@@ -2100,7 +2414,11 @@ class BrokersWrapper {
|
|
|
2100
2414
|
* @example
|
|
2101
2415
|
* ```typescript-client
|
|
2102
2416
|
* // Full example with optional parameters
|
|
2103
|
-
* const result = await finatic.getBalances(
|
|
2417
|
+
* const result = await finatic.getBalances({
|
|
2418
|
+
brokerId: 'alpaca',
|
|
2419
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2420
|
+
accountId: '123456789'
|
|
2421
|
+
* });
|
|
2104
2422
|
*
|
|
2105
2423
|
* // Handle response with warnings
|
|
2106
2424
|
* if (result.success) {
|
|
@@ -2113,20 +2431,10 @@ class BrokersWrapper {
|
|
|
2113
2431
|
* }
|
|
2114
2432
|
* ```
|
|
2115
2433
|
*/
|
|
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) {
|
|
2434
|
+
async getBalances(params) {
|
|
2435
|
+
// Use params object (with default empty object)
|
|
2436
|
+
const resolvedParams = params || {}; // Authentication check
|
|
2437
|
+
if (!this.sessionId || !this.companyId) {
|
|
2130
2438
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2131
2439
|
}
|
|
2132
2440
|
// Generate request ID
|
|
@@ -2137,7 +2445,7 @@ class BrokersWrapper {
|
|
|
2137
2445
|
const shouldCache = true;
|
|
2138
2446
|
const cache = getCache(this.sdkConfig);
|
|
2139
2447
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2140
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances',
|
|
2448
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
|
|
2141
2449
|
const cached = cache.get(cacheKey);
|
|
2142
2450
|
if (cached) {
|
|
2143
2451
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2149,12 +2457,12 @@ class BrokersWrapper {
|
|
|
2149
2457
|
request_id: requestId,
|
|
2150
2458
|
method: 'GET',
|
|
2151
2459
|
path: '/api/v1/brokers/data/balances',
|
|
2152
|
-
params:
|
|
2460
|
+
params: resolvedParams,
|
|
2153
2461
|
action: 'getBalances'
|
|
2154
2462
|
});
|
|
2155
2463
|
try {
|
|
2156
2464
|
const response = await retryApiCall(async () => {
|
|
2157
|
-
const apiResponse = await this.api.getBalancesApiV1BrokersDataBalancesGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(isEndOfDaySnapshot !== undefined ? { isEndOfDaySnapshot: isEndOfDaySnapshot } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(balanceCreatedAfter !== undefined ? { balanceCreatedAfter: balanceCreatedAfter } : {}), ...(balanceCreatedBefore !== undefined ? { balanceCreatedBefore: balanceCreatedBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
2465
|
+
const apiResponse = await this.api.getBalancesApiV1BrokersDataBalancesGet({ ...(resolvedParams.brokerId !== undefined ? { brokerId: resolvedParams.brokerId } : {}), ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.accountId !== undefined ? { accountId: resolvedParams.accountId } : {}), ...(resolvedParams.isEndOfDaySnapshot !== undefined ? { isEndOfDaySnapshot: resolvedParams.isEndOfDaySnapshot } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { offset: resolvedParams.offset } : {}), ...(resolvedParams.balanceCreatedAfter !== undefined ? { balanceCreatedAfter: resolvedParams.balanceCreatedAfter } : {}), ...(resolvedParams.balanceCreatedBefore !== undefined ? { balanceCreatedBefore: resolvedParams.balanceCreatedBefore } : {}), ...(resolvedParams.includeMetadata !== undefined ? { 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
2466
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2159
2467
|
}, {}, this.sdkConfig);
|
|
2160
2468
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2163,9 +2471,27 @@ class BrokersWrapper {
|
|
|
2163
2471
|
throw new Error('Unexpected response shape: missing success field');
|
|
2164
2472
|
}
|
|
2165
2473
|
// Convert response to plain object, removing _id fields recursively
|
|
2474
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2166
2475
|
const standardResponse = convertToPlainObject(responseData);
|
|
2476
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2477
|
+
const hasLimit = true;
|
|
2478
|
+
const hasOffset = true;
|
|
2479
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2480
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2481
|
+
// PaginatedData is already imported at top of file
|
|
2482
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2483
|
+
if (paginationMeta) {
|
|
2484
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2485
|
+
has_more: paginationMeta.has_more,
|
|
2486
|
+
next_offset: paginationMeta.next_offset,
|
|
2487
|
+
current_offset: paginationMeta.current_offset,
|
|
2488
|
+
limit: paginationMeta.limit,
|
|
2489
|
+
}, this.getBalances.bind(this), resolvedParams, this);
|
|
2490
|
+
standardResponse.success.data = paginatedData;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2167
2493
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2168
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances',
|
|
2494
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
|
|
2169
2495
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2170
2496
|
}
|
|
2171
2497
|
this.logger.debug('Get Balances completed', {
|
|
@@ -2173,6 +2499,7 @@ class BrokersWrapper {
|
|
|
2173
2499
|
action: 'getBalances'
|
|
2174
2500
|
});
|
|
2175
2501
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2502
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2176
2503
|
return standardResponse;
|
|
2177
2504
|
}
|
|
2178
2505
|
catch (error) {
|
|
@@ -2249,15 +2576,15 @@ class BrokersWrapper {
|
|
|
2249
2576
|
*
|
|
2250
2577
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
2251
2578
|
* 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
|
|
2579
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2580
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2581
|
+
* @param params.accountType {BrokerDataAccountTypeEnum} (optional) Filter by account type (e.g., 'margin', 'cash', 'crypto_wallet', 'live', 'sim')
|
|
2582
|
+
* @param params.status {AccountStatus} (optional) Filter by account status (e.g., 'active', 'inactive')
|
|
2583
|
+
* @param params.currency {string} (optional) Filter by currency (e.g., 'USD', 'EUR')
|
|
2584
|
+
* @param params.limit {number} (optional) Maximum number of accounts to return
|
|
2585
|
+
* @param params.offset {number} (optional) Number of accounts to skip for pagination
|
|
2586
|
+
* @param params.includeMetadata {boolean} (optional) Include connection metadata in response (excluded by default for FDX compliance)
|
|
2587
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerAccount>>>} Standard response with success/Error/Warning structure
|
|
2261
2588
|
*
|
|
2262
2589
|
* Generated from: GET /api/v1/brokers/data/accounts
|
|
2263
2590
|
* @methodId get_accounts_api_v1_brokers_data_accounts_get
|
|
@@ -2265,7 +2592,7 @@ class BrokersWrapper {
|
|
|
2265
2592
|
* @example
|
|
2266
2593
|
* ```typescript-client
|
|
2267
2594
|
* // Example with no parameters
|
|
2268
|
-
* const result = await finatic.getAccounts();
|
|
2595
|
+
* const result = await finatic.getAccounts({});
|
|
2269
2596
|
*
|
|
2270
2597
|
* // Access the response data
|
|
2271
2598
|
* if (result.success) {
|
|
@@ -2275,7 +2602,11 @@ class BrokersWrapper {
|
|
|
2275
2602
|
* @example
|
|
2276
2603
|
* ```typescript-client
|
|
2277
2604
|
* // Full example with optional parameters
|
|
2278
|
-
* const result = await finatic.getAccounts(
|
|
2605
|
+
* const result = await finatic.getAccounts({
|
|
2606
|
+
brokerId: 'alpaca',
|
|
2607
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2608
|
+
accountType: 'margin'
|
|
2609
|
+
* });
|
|
2279
2610
|
*
|
|
2280
2611
|
* // Handle response with warnings
|
|
2281
2612
|
* if (result.success) {
|
|
@@ -2288,19 +2619,16 @@ class BrokersWrapper {
|
|
|
2288
2619
|
* }
|
|
2289
2620
|
* ```
|
|
2290
2621
|
*/
|
|
2291
|
-
async getAccounts(
|
|
2292
|
-
//
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
includeMetadata: includeMetadata
|
|
2302
|
-
}; // Authentication check
|
|
2303
|
-
if (!this.sessionId) {
|
|
2622
|
+
async getAccounts(params) {
|
|
2623
|
+
// Use params object (with default empty object)
|
|
2624
|
+
const resolvedParams = params || {};
|
|
2625
|
+
if (params?.accountType !== undefined) {
|
|
2626
|
+
const coerced = coerceEnumValue(params.accountType, exports.BrokerDataAccountTypeEnum, 'accountType');
|
|
2627
|
+
if (coerced !== undefined) {
|
|
2628
|
+
params.accountType = coerced;
|
|
2629
|
+
}
|
|
2630
|
+
} // Authentication check
|
|
2631
|
+
if (!this.sessionId || !this.companyId) {
|
|
2304
2632
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2305
2633
|
}
|
|
2306
2634
|
// Generate request ID
|
|
@@ -2311,7 +2639,7 @@ class BrokersWrapper {
|
|
|
2311
2639
|
const shouldCache = true;
|
|
2312
2640
|
const cache = getCache(this.sdkConfig);
|
|
2313
2641
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2314
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts',
|
|
2642
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
|
|
2315
2643
|
const cached = cache.get(cacheKey);
|
|
2316
2644
|
if (cached) {
|
|
2317
2645
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2323,12 +2651,12 @@ class BrokersWrapper {
|
|
|
2323
2651
|
request_id: requestId,
|
|
2324
2652
|
method: 'GET',
|
|
2325
2653
|
path: '/api/v1/brokers/data/accounts',
|
|
2326
|
-
params:
|
|
2654
|
+
params: resolvedParams,
|
|
2327
2655
|
action: 'getAccounts'
|
|
2328
2656
|
});
|
|
2329
2657
|
try {
|
|
2330
2658
|
const response = await retryApiCall(async () => {
|
|
2331
|
-
const apiResponse = await this.api.getAccountsApiV1BrokersDataAccountsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountType !== undefined ? { accountType: accountType } : {}), ...(status !== undefined ? { status: status } : {}), ...(currency !== undefined ? { currency: currency } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
2659
|
+
const apiResponse = await this.api.getAccountsApiV1BrokersDataAccountsGet({ ...(resolvedParams.brokerId !== undefined ? { brokerId: resolvedParams.brokerId } : {}), ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.accountType !== undefined ? { accountType: resolvedParams.accountType } : {}), ...(resolvedParams.status !== undefined ? { status: resolvedParams.status } : {}), ...(resolvedParams.currency !== undefined ? { currency: resolvedParams.currency } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { offset: resolvedParams.offset } : {}), ...(resolvedParams.includeMetadata !== undefined ? { 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
2660
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2333
2661
|
}, {}, this.sdkConfig);
|
|
2334
2662
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2337,9 +2665,27 @@ class BrokersWrapper {
|
|
|
2337
2665
|
throw new Error('Unexpected response shape: missing success field');
|
|
2338
2666
|
}
|
|
2339
2667
|
// Convert response to plain object, removing _id fields recursively
|
|
2668
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2340
2669
|
const standardResponse = convertToPlainObject(responseData);
|
|
2670
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2671
|
+
const hasLimit = true;
|
|
2672
|
+
const hasOffset = true;
|
|
2673
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2674
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2675
|
+
// PaginatedData is already imported at top of file
|
|
2676
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2677
|
+
if (paginationMeta) {
|
|
2678
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2679
|
+
has_more: paginationMeta.has_more,
|
|
2680
|
+
next_offset: paginationMeta.next_offset,
|
|
2681
|
+
current_offset: paginationMeta.current_offset,
|
|
2682
|
+
limit: paginationMeta.limit,
|
|
2683
|
+
}, this.getAccounts.bind(this), resolvedParams, this);
|
|
2684
|
+
standardResponse.success.data = paginatedData;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2341
2687
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2342
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts',
|
|
2688
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
|
|
2343
2689
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2344
2690
|
}
|
|
2345
2691
|
this.logger.debug('Get Accounts completed', {
|
|
@@ -2347,6 +2693,7 @@ class BrokersWrapper {
|
|
|
2347
2693
|
action: 'getAccounts'
|
|
2348
2694
|
});
|
|
2349
2695
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2696
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2350
2697
|
return standardResponse;
|
|
2351
2698
|
}
|
|
2352
2699
|
catch (error) {
|
|
@@ -2422,12 +2769,12 @@ class BrokersWrapper {
|
|
|
2422
2769
|
* Get order fills for a specific order.
|
|
2423
2770
|
*
|
|
2424
2771
|
* 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
|
|
2772
|
+
* @param params.orderId {string} Order ID
|
|
2773
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2774
|
+
* @param params.limit {number} (optional) Maximum number of fills to return
|
|
2775
|
+
* @param params.offset {number} (optional) Number of fills to skip for pagination
|
|
2776
|
+
* @param params.includeMetadata {boolean} (optional) Include fill metadata in response (excluded by default for FDX compliance)
|
|
2777
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderFill>>>} Standard response with success/Error/Warning structure
|
|
2431
2778
|
*
|
|
2432
2779
|
* Generated from: GET /api/v1/brokers/data/orders/{order_id}/fills
|
|
2433
2780
|
* @methodId get_order_fills_api_v1_brokers_data_orders__order_id__fills_get
|
|
@@ -2435,7 +2782,9 @@ class BrokersWrapper {
|
|
|
2435
2782
|
* @example
|
|
2436
2783
|
* ```typescript-client
|
|
2437
2784
|
* // Minimal example with required parameters only
|
|
2438
|
-
* const result = await finatic.getOrderFills(
|
|
2785
|
+
* const result = await finatic.getOrderFills({
|
|
2786
|
+
orderId: '00000000-0000-0000-0000-000000000000'
|
|
2787
|
+
* });
|
|
2439
2788
|
*
|
|
2440
2789
|
* // Access the response data
|
|
2441
2790
|
* if (result.success) {
|
|
@@ -2447,7 +2796,12 @@ class BrokersWrapper {
|
|
|
2447
2796
|
* @example
|
|
2448
2797
|
* ```typescript-client
|
|
2449
2798
|
* // Full example with optional parameters
|
|
2450
|
-
* const result = await finatic.getOrderFills(
|
|
2799
|
+
* const result = await finatic.getOrderFills({
|
|
2800
|
+
orderId: '00000000-0000-0000-0000-000000000000',
|
|
2801
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2802
|
+
limit: 100,
|
|
2803
|
+
offset: 0
|
|
2804
|
+
* });
|
|
2451
2805
|
*
|
|
2452
2806
|
* // Handle response with warnings
|
|
2453
2807
|
* if (result.success) {
|
|
@@ -2460,16 +2814,10 @@ class BrokersWrapper {
|
|
|
2460
2814
|
* }
|
|
2461
2815
|
* ```
|
|
2462
2816
|
*/
|
|
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) {
|
|
2817
|
+
async getOrderFills(params) {
|
|
2818
|
+
// Use params object (required parameters present)
|
|
2819
|
+
const resolvedParams = params; // Authentication check
|
|
2820
|
+
if (!this.sessionId || !this.companyId) {
|
|
2473
2821
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2474
2822
|
}
|
|
2475
2823
|
// Generate request ID
|
|
@@ -2480,7 +2828,7 @@ class BrokersWrapper {
|
|
|
2480
2828
|
const shouldCache = true;
|
|
2481
2829
|
const cache = getCache(this.sdkConfig);
|
|
2482
2830
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2483
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2831
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
|
|
2484
2832
|
const cached = cache.get(cacheKey);
|
|
2485
2833
|
if (cached) {
|
|
2486
2834
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2492,12 +2840,12 @@ class BrokersWrapper {
|
|
|
2492
2840
|
request_id: requestId,
|
|
2493
2841
|
method: 'GET',
|
|
2494
2842
|
path: '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2495
|
-
params:
|
|
2843
|
+
params: resolvedParams,
|
|
2496
2844
|
action: 'getOrderFills'
|
|
2497
2845
|
});
|
|
2498
2846
|
try {
|
|
2499
2847
|
const response = await retryApiCall(async () => {
|
|
2500
|
-
const apiResponse = await this.api.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet({ orderId: orderId, ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
2848
|
+
const apiResponse = await this.api.getOrderFillsApiV1BrokersDataOrdersOrderIdFillsGet({ orderId: resolvedParams.orderId ?? null, ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { offset: resolvedParams.offset } : {}), ...(resolvedParams.includeMetadata !== undefined ? { 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
2849
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2502
2850
|
}, {}, this.sdkConfig);
|
|
2503
2851
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2506,9 +2854,27 @@ class BrokersWrapper {
|
|
|
2506
2854
|
throw new Error('Unexpected response shape: missing success field');
|
|
2507
2855
|
}
|
|
2508
2856
|
// Convert response to plain object, removing _id fields recursively
|
|
2857
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2509
2858
|
const standardResponse = convertToPlainObject(responseData);
|
|
2859
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2860
|
+
const hasLimit = true;
|
|
2861
|
+
const hasOffset = true;
|
|
2862
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2863
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2864
|
+
// PaginatedData is already imported at top of file
|
|
2865
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2866
|
+
if (paginationMeta) {
|
|
2867
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2868
|
+
has_more: paginationMeta.has_more,
|
|
2869
|
+
next_offset: paginationMeta.next_offset,
|
|
2870
|
+
current_offset: paginationMeta.current_offset,
|
|
2871
|
+
limit: paginationMeta.limit,
|
|
2872
|
+
}, this.getOrderFills.bind(this), resolvedParams, this);
|
|
2873
|
+
standardResponse.success.data = paginatedData;
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2510
2876
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2511
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2877
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
|
|
2512
2878
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2513
2879
|
}
|
|
2514
2880
|
this.logger.debug('Get Order Fills completed', {
|
|
@@ -2516,6 +2882,7 @@ class BrokersWrapper {
|
|
|
2516
2882
|
action: 'getOrderFills'
|
|
2517
2883
|
});
|
|
2518
2884
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2885
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2519
2886
|
return standardResponse;
|
|
2520
2887
|
}
|
|
2521
2888
|
catch (error) {
|
|
@@ -2591,12 +2958,12 @@ class BrokersWrapper {
|
|
|
2591
2958
|
* Get order events for a specific order.
|
|
2592
2959
|
*
|
|
2593
2960
|
* 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
|
|
2961
|
+
* @param params.orderId {string} Order ID
|
|
2962
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2963
|
+
* @param params.limit {number} (optional) Maximum number of events to return
|
|
2964
|
+
* @param params.offset {number} (optional) Number of events to skip for pagination
|
|
2965
|
+
* @param params.includeMetadata {boolean} (optional) Include event metadata in response (excluded by default for FDX compliance)
|
|
2966
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderEvent>>>} Standard response with success/Error/Warning structure
|
|
2600
2967
|
*
|
|
2601
2968
|
* Generated from: GET /api/v1/brokers/data/orders/{order_id}/events
|
|
2602
2969
|
* @methodId get_order_events_api_v1_brokers_data_orders__order_id__events_get
|
|
@@ -2604,7 +2971,9 @@ class BrokersWrapper {
|
|
|
2604
2971
|
* @example
|
|
2605
2972
|
* ```typescript-client
|
|
2606
2973
|
* // Minimal example with required parameters only
|
|
2607
|
-
* const result = await finatic.getOrderEvents(
|
|
2974
|
+
* const result = await finatic.getOrderEvents({
|
|
2975
|
+
orderId: '00000000-0000-0000-0000-000000000000'
|
|
2976
|
+
* });
|
|
2608
2977
|
*
|
|
2609
2978
|
* // Access the response data
|
|
2610
2979
|
* if (result.success) {
|
|
@@ -2616,7 +2985,12 @@ class BrokersWrapper {
|
|
|
2616
2985
|
* @example
|
|
2617
2986
|
* ```typescript-client
|
|
2618
2987
|
* // Full example with optional parameters
|
|
2619
|
-
* const result = await finatic.getOrderEvents(
|
|
2988
|
+
* const result = await finatic.getOrderEvents({
|
|
2989
|
+
orderId: '00000000-0000-0000-0000-000000000000',
|
|
2990
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2991
|
+
limit: 100,
|
|
2992
|
+
offset: 0
|
|
2993
|
+
* });
|
|
2620
2994
|
*
|
|
2621
2995
|
* // Handle response with warnings
|
|
2622
2996
|
* if (result.success) {
|
|
@@ -2629,16 +3003,10 @@ class BrokersWrapper {
|
|
|
2629
3003
|
* }
|
|
2630
3004
|
* ```
|
|
2631
3005
|
*/
|
|
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) {
|
|
3006
|
+
async getOrderEvents(params) {
|
|
3007
|
+
// Use params object (required parameters present)
|
|
3008
|
+
const resolvedParams = params; // Authentication check
|
|
3009
|
+
if (!this.sessionId || !this.companyId) {
|
|
2642
3010
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2643
3011
|
}
|
|
2644
3012
|
// Generate request ID
|
|
@@ -2649,7 +3017,7 @@ class BrokersWrapper {
|
|
|
2649
3017
|
const shouldCache = true;
|
|
2650
3018
|
const cache = getCache(this.sdkConfig);
|
|
2651
3019
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2652
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events',
|
|
3020
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
|
|
2653
3021
|
const cached = cache.get(cacheKey);
|
|
2654
3022
|
if (cached) {
|
|
2655
3023
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2661,12 +3029,12 @@ class BrokersWrapper {
|
|
|
2661
3029
|
request_id: requestId,
|
|
2662
3030
|
method: 'GET',
|
|
2663
3031
|
path: '/api/v1/brokers/data/orders/{order_id}/events',
|
|
2664
|
-
params:
|
|
3032
|
+
params: resolvedParams,
|
|
2665
3033
|
action: 'getOrderEvents'
|
|
2666
3034
|
});
|
|
2667
3035
|
try {
|
|
2668
3036
|
const response = await retryApiCall(async () => {
|
|
2669
|
-
const apiResponse = await this.api.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet({ orderId: orderId, ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
3037
|
+
const apiResponse = await this.api.getOrderEventsApiV1BrokersDataOrdersOrderIdEventsGet({ orderId: resolvedParams.orderId ?? null, ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { offset: resolvedParams.offset } : {}), ...(resolvedParams.includeMetadata !== undefined ? { 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
3038
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2671
3039
|
}, {}, this.sdkConfig);
|
|
2672
3040
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2675,9 +3043,27 @@ class BrokersWrapper {
|
|
|
2675
3043
|
throw new Error('Unexpected response shape: missing success field');
|
|
2676
3044
|
}
|
|
2677
3045
|
// Convert response to plain object, removing _id fields recursively
|
|
3046
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2678
3047
|
const standardResponse = convertToPlainObject(responseData);
|
|
3048
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3049
|
+
const hasLimit = true;
|
|
3050
|
+
const hasOffset = true;
|
|
3051
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3052
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3053
|
+
// PaginatedData is already imported at top of file
|
|
3054
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3055
|
+
if (paginationMeta) {
|
|
3056
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3057
|
+
has_more: paginationMeta.has_more,
|
|
3058
|
+
next_offset: paginationMeta.next_offset,
|
|
3059
|
+
current_offset: paginationMeta.current_offset,
|
|
3060
|
+
limit: paginationMeta.limit,
|
|
3061
|
+
}, this.getOrderEvents.bind(this), resolvedParams, this);
|
|
3062
|
+
standardResponse.success.data = paginatedData;
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
2679
3065
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2680
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events',
|
|
3066
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
|
|
2681
3067
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2682
3068
|
}
|
|
2683
3069
|
this.logger.debug('Get Order Events completed', {
|
|
@@ -2685,6 +3071,7 @@ class BrokersWrapper {
|
|
|
2685
3071
|
action: 'getOrderEvents'
|
|
2686
3072
|
});
|
|
2687
3073
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3074
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2688
3075
|
return standardResponse;
|
|
2689
3076
|
}
|
|
2690
3077
|
catch (error) {
|
|
@@ -2760,14 +3147,14 @@ class BrokersWrapper {
|
|
|
2760
3147
|
* Get order groups.
|
|
2761
3148
|
*
|
|
2762
3149
|
* 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
|
|
3150
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
3151
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3152
|
+
* @param params.limit {number} (optional) Maximum number of order groups to return
|
|
3153
|
+
* @param params.offset {number} (optional) Number of order groups to skip for pagination
|
|
3154
|
+
* @param params.createdAfter {string} (optional) Filter order groups created after this timestamp
|
|
3155
|
+
* @param params.createdBefore {string} (optional) Filter order groups created before this timestamp
|
|
3156
|
+
* @param params.includeMetadata {boolean} (optional) Include group metadata in response (excluded by default for FDX compliance)
|
|
3157
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderGroup>>>} Standard response with success/Error/Warning structure
|
|
2771
3158
|
*
|
|
2772
3159
|
* Generated from: GET /api/v1/brokers/data/orders/groups
|
|
2773
3160
|
* @methodId get_order_groups_api_v1_brokers_data_orders_groups_get
|
|
@@ -2775,7 +3162,7 @@ class BrokersWrapper {
|
|
|
2775
3162
|
* @example
|
|
2776
3163
|
* ```typescript-client
|
|
2777
3164
|
* // Example with no parameters
|
|
2778
|
-
* const result = await finatic.getOrderGroups();
|
|
3165
|
+
* const result = await finatic.getOrderGroups({});
|
|
2779
3166
|
*
|
|
2780
3167
|
* // Access the response data
|
|
2781
3168
|
* if (result.success) {
|
|
@@ -2785,7 +3172,11 @@ class BrokersWrapper {
|
|
|
2785
3172
|
* @example
|
|
2786
3173
|
* ```typescript-client
|
|
2787
3174
|
* // Full example with optional parameters
|
|
2788
|
-
* const result = await finatic.getOrderGroups(
|
|
3175
|
+
* const result = await finatic.getOrderGroups({
|
|
3176
|
+
brokerId: 'alpaca',
|
|
3177
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3178
|
+
limit: 100
|
|
3179
|
+
* });
|
|
2789
3180
|
*
|
|
2790
3181
|
* // Handle response with warnings
|
|
2791
3182
|
* if (result.success) {
|
|
@@ -2798,18 +3189,10 @@ class BrokersWrapper {
|
|
|
2798
3189
|
* }
|
|
2799
3190
|
* ```
|
|
2800
3191
|
*/
|
|
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) {
|
|
3192
|
+
async getOrderGroups(params) {
|
|
3193
|
+
// Use params object (with default empty object)
|
|
3194
|
+
const resolvedParams = params || {}; // Authentication check
|
|
3195
|
+
if (!this.sessionId || !this.companyId) {
|
|
2813
3196
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2814
3197
|
}
|
|
2815
3198
|
// Generate request ID
|
|
@@ -2820,7 +3203,7 @@ class BrokersWrapper {
|
|
|
2820
3203
|
const shouldCache = true;
|
|
2821
3204
|
const cache = getCache(this.sdkConfig);
|
|
2822
3205
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2823
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups',
|
|
3206
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
|
|
2824
3207
|
const cached = cache.get(cacheKey);
|
|
2825
3208
|
if (cached) {
|
|
2826
3209
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2832,12 +3215,12 @@ class BrokersWrapper {
|
|
|
2832
3215
|
request_id: requestId,
|
|
2833
3216
|
method: 'GET',
|
|
2834
3217
|
path: '/api/v1/brokers/data/orders/groups',
|
|
2835
|
-
params:
|
|
3218
|
+
params: resolvedParams,
|
|
2836
3219
|
action: 'getOrderGroups'
|
|
2837
3220
|
});
|
|
2838
3221
|
try {
|
|
2839
3222
|
const response = await retryApiCall(async () => {
|
|
2840
|
-
const apiResponse = await this.api.getOrderGroupsApiV1BrokersDataOrdersGroupsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}), ...(createdAfter !== undefined ? { createdAfter: createdAfter } : {}), ...(createdBefore !== undefined ? { createdBefore: createdBefore } : {}), ...(includeMetadata !== undefined ? { includeMetadata: includeMetadata } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
3223
|
+
const apiResponse = await this.api.getOrderGroupsApiV1BrokersDataOrdersGroupsGet({ ...(resolvedParams.brokerId !== undefined ? { brokerId: resolvedParams.brokerId } : {}), ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { offset: resolvedParams.offset } : {}), ...(resolvedParams.createdAfter !== undefined ? { createdAfter: resolvedParams.createdAfter } : {}), ...(resolvedParams.createdBefore !== undefined ? { createdBefore: resolvedParams.createdBefore } : {}), ...(resolvedParams.includeMetadata !== undefined ? { 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
3224
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2842
3225
|
}, {}, this.sdkConfig);
|
|
2843
3226
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2846,9 +3229,27 @@ class BrokersWrapper {
|
|
|
2846
3229
|
throw new Error('Unexpected response shape: missing success field');
|
|
2847
3230
|
}
|
|
2848
3231
|
// Convert response to plain object, removing _id fields recursively
|
|
3232
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2849
3233
|
const standardResponse = convertToPlainObject(responseData);
|
|
3234
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3235
|
+
const hasLimit = true;
|
|
3236
|
+
const hasOffset = true;
|
|
3237
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3238
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3239
|
+
// PaginatedData is already imported at top of file
|
|
3240
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3241
|
+
if (paginationMeta) {
|
|
3242
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3243
|
+
has_more: paginationMeta.has_more,
|
|
3244
|
+
next_offset: paginationMeta.next_offset,
|
|
3245
|
+
current_offset: paginationMeta.current_offset,
|
|
3246
|
+
limit: paginationMeta.limit,
|
|
3247
|
+
}, this.getOrderGroups.bind(this), resolvedParams, this);
|
|
3248
|
+
standardResponse.success.data = paginatedData;
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
2850
3251
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2851
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups',
|
|
3252
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
|
|
2852
3253
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2853
3254
|
}
|
|
2854
3255
|
this.logger.debug('Get Order Groups completed', {
|
|
@@ -2856,6 +3257,7 @@ class BrokersWrapper {
|
|
|
2856
3257
|
action: 'getOrderGroups'
|
|
2857
3258
|
});
|
|
2858
3259
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3260
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2859
3261
|
return standardResponse;
|
|
2860
3262
|
}
|
|
2861
3263
|
catch (error) {
|
|
@@ -2932,14 +3334,14 @@ class BrokersWrapper {
|
|
|
2932
3334
|
*
|
|
2933
3335
|
* This endpoint returns tax lots for positions, which are used for tax reporting.
|
|
2934
3336
|
* 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
|
|
3337
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
3338
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3339
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID
|
|
3340
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
3341
|
+
* @param params.positionId {string} (optional) Filter by position ID
|
|
3342
|
+
* @param params.limit {number} (optional) Maximum number of position lots to return
|
|
3343
|
+
* @param params.offset {number} (optional) Number of position lots to skip for pagination
|
|
3344
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLot>>>} Standard response with success/Error/Warning structure
|
|
2943
3345
|
*
|
|
2944
3346
|
* Generated from: GET /api/v1/brokers/data/positions/lots
|
|
2945
3347
|
* @methodId get_position_lots_api_v1_brokers_data_positions_lots_get
|
|
@@ -2947,7 +3349,7 @@ class BrokersWrapper {
|
|
|
2947
3349
|
* @example
|
|
2948
3350
|
* ```typescript-client
|
|
2949
3351
|
* // Example with no parameters
|
|
2950
|
-
* const result = await finatic.getPositionLots();
|
|
3352
|
+
* const result = await finatic.getPositionLots({});
|
|
2951
3353
|
*
|
|
2952
3354
|
* // Access the response data
|
|
2953
3355
|
* if (result.success) {
|
|
@@ -2957,7 +3359,11 @@ class BrokersWrapper {
|
|
|
2957
3359
|
* @example
|
|
2958
3360
|
* ```typescript-client
|
|
2959
3361
|
* // Full example with optional parameters
|
|
2960
|
-
* const result = await finatic.getPositionLots(
|
|
3362
|
+
* const result = await finatic.getPositionLots({
|
|
3363
|
+
brokerId: 'alpaca',
|
|
3364
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3365
|
+
accountId: '123456789'
|
|
3366
|
+
* });
|
|
2961
3367
|
*
|
|
2962
3368
|
* // Handle response with warnings
|
|
2963
3369
|
* if (result.success) {
|
|
@@ -2970,18 +3376,10 @@ class BrokersWrapper {
|
|
|
2970
3376
|
* }
|
|
2971
3377
|
* ```
|
|
2972
3378
|
*/
|
|
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) {
|
|
3379
|
+
async getPositionLots(params) {
|
|
3380
|
+
// Use params object (with default empty object)
|
|
3381
|
+
const resolvedParams = params || {}; // Authentication check
|
|
3382
|
+
if (!this.sessionId || !this.companyId) {
|
|
2985
3383
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2986
3384
|
}
|
|
2987
3385
|
// Generate request ID
|
|
@@ -2992,7 +3390,7 @@ class BrokersWrapper {
|
|
|
2992
3390
|
const shouldCache = true;
|
|
2993
3391
|
const cache = getCache(this.sdkConfig);
|
|
2994
3392
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2995
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots',
|
|
3393
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
|
|
2996
3394
|
const cached = cache.get(cacheKey);
|
|
2997
3395
|
if (cached) {
|
|
2998
3396
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3004,12 +3402,12 @@ class BrokersWrapper {
|
|
|
3004
3402
|
request_id: requestId,
|
|
3005
3403
|
method: 'GET',
|
|
3006
3404
|
path: '/api/v1/brokers/data/positions/lots',
|
|
3007
|
-
params:
|
|
3405
|
+
params: resolvedParams,
|
|
3008
3406
|
action: 'getPositionLots'
|
|
3009
3407
|
});
|
|
3010
3408
|
try {
|
|
3011
3409
|
const response = await retryApiCall(async () => {
|
|
3012
|
-
const apiResponse = await this.api.getPositionLotsApiV1BrokersDataPositionsLotsGet({ ...(brokerId !== undefined ? { brokerId: brokerId } : {}), ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(accountId !== undefined ? { accountId: accountId } : {}), ...(symbol !== undefined ? { symbol: symbol } : {}), ...(positionId !== undefined ? { positionId: positionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
3410
|
+
const apiResponse = await this.api.getPositionLotsApiV1BrokersDataPositionsLotsGet({ ...(resolvedParams.brokerId !== undefined ? { brokerId: resolvedParams.brokerId } : {}), ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.accountId !== undefined ? { accountId: resolvedParams.accountId } : {}), ...(resolvedParams.symbol !== undefined ? { symbol: resolvedParams.symbol } : {}), ...(resolvedParams.positionId !== undefined ? { positionId: resolvedParams.positionId } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { 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
3411
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3014
3412
|
}, {}, this.sdkConfig);
|
|
3015
3413
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3018,9 +3416,27 @@ class BrokersWrapper {
|
|
|
3018
3416
|
throw new Error('Unexpected response shape: missing success field');
|
|
3019
3417
|
}
|
|
3020
3418
|
// Convert response to plain object, removing _id fields recursively
|
|
3419
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3021
3420
|
const standardResponse = convertToPlainObject(responseData);
|
|
3421
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3422
|
+
const hasLimit = true;
|
|
3423
|
+
const hasOffset = true;
|
|
3424
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3425
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3426
|
+
// PaginatedData is already imported at top of file
|
|
3427
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3428
|
+
if (paginationMeta) {
|
|
3429
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3430
|
+
has_more: paginationMeta.has_more,
|
|
3431
|
+
next_offset: paginationMeta.next_offset,
|
|
3432
|
+
current_offset: paginationMeta.current_offset,
|
|
3433
|
+
limit: paginationMeta.limit,
|
|
3434
|
+
}, this.getPositionLots.bind(this), resolvedParams, this);
|
|
3435
|
+
standardResponse.success.data = paginatedData;
|
|
3436
|
+
}
|
|
3437
|
+
}
|
|
3022
3438
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3023
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots',
|
|
3439
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
|
|
3024
3440
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3025
3441
|
}
|
|
3026
3442
|
this.logger.debug('Get Position Lots completed', {
|
|
@@ -3028,6 +3444,7 @@ class BrokersWrapper {
|
|
|
3028
3444
|
action: 'getPositionLots'
|
|
3029
3445
|
});
|
|
3030
3446
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3447
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3031
3448
|
return standardResponse;
|
|
3032
3449
|
}
|
|
3033
3450
|
catch (error) {
|
|
@@ -3103,11 +3520,11 @@ class BrokersWrapper {
|
|
|
3103
3520
|
* Get position lot fills for a specific lot.
|
|
3104
3521
|
*
|
|
3105
3522
|
* 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
|
|
3523
|
+
* @param params.lotId {string} Position lot ID
|
|
3524
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3525
|
+
* @param params.limit {number} (optional) Maximum number of fills to return
|
|
3526
|
+
* @param params.offset {number} (optional) Number of fills to skip for pagination
|
|
3527
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLotFill>>>} Standard response with success/Error/Warning structure
|
|
3111
3528
|
*
|
|
3112
3529
|
* Generated from: GET /api/v1/brokers/data/positions/lots/{lot_id}/fills
|
|
3113
3530
|
* @methodId get_position_lot_fills_api_v1_brokers_data_positions_lots__lot_id__fills_get
|
|
@@ -3115,7 +3532,9 @@ class BrokersWrapper {
|
|
|
3115
3532
|
* @example
|
|
3116
3533
|
* ```typescript-client
|
|
3117
3534
|
* // Minimal example with required parameters only
|
|
3118
|
-
* const result = await finatic.getPositionLotFills(
|
|
3535
|
+
* const result = await finatic.getPositionLotFills({
|
|
3536
|
+
lotId: '00000000-0000-0000-0000-000000000000'
|
|
3537
|
+
* });
|
|
3119
3538
|
*
|
|
3120
3539
|
* // Access the response data
|
|
3121
3540
|
* if (result.success) {
|
|
@@ -3127,7 +3546,12 @@ class BrokersWrapper {
|
|
|
3127
3546
|
* @example
|
|
3128
3547
|
* ```typescript-client
|
|
3129
3548
|
* // Full example with optional parameters
|
|
3130
|
-
* const result = await finatic.getPositionLotFills(
|
|
3549
|
+
* const result = await finatic.getPositionLotFills({
|
|
3550
|
+
lotId: '00000000-0000-0000-0000-000000000000',
|
|
3551
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3552
|
+
limit: 100,
|
|
3553
|
+
offset: 0
|
|
3554
|
+
* });
|
|
3131
3555
|
*
|
|
3132
3556
|
* // Handle response with warnings
|
|
3133
3557
|
* if (result.success) {
|
|
@@ -3140,15 +3564,10 @@ class BrokersWrapper {
|
|
|
3140
3564
|
* }
|
|
3141
3565
|
* ```
|
|
3142
3566
|
*/
|
|
3143
|
-
async getPositionLotFills(
|
|
3144
|
-
//
|
|
3145
|
-
const
|
|
3146
|
-
|
|
3147
|
-
connectionId: connectionId,
|
|
3148
|
-
limit: limit,
|
|
3149
|
-
offset: offset
|
|
3150
|
-
}; // Authentication check
|
|
3151
|
-
if (!this.sessionId) {
|
|
3567
|
+
async getPositionLotFills(params) {
|
|
3568
|
+
// Use params object (required parameters present)
|
|
3569
|
+
const resolvedParams = params; // Authentication check
|
|
3570
|
+
if (!this.sessionId || !this.companyId) {
|
|
3152
3571
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3153
3572
|
}
|
|
3154
3573
|
// Generate request ID
|
|
@@ -3159,7 +3578,7 @@ class BrokersWrapper {
|
|
|
3159
3578
|
const shouldCache = true;
|
|
3160
3579
|
const cache = getCache(this.sdkConfig);
|
|
3161
3580
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3162
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3581
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
|
|
3163
3582
|
const cached = cache.get(cacheKey);
|
|
3164
3583
|
if (cached) {
|
|
3165
3584
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3171,12 +3590,12 @@ class BrokersWrapper {
|
|
|
3171
3590
|
request_id: requestId,
|
|
3172
3591
|
method: 'GET',
|
|
3173
3592
|
path: '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3174
|
-
params:
|
|
3593
|
+
params: resolvedParams,
|
|
3175
3594
|
action: 'getPositionLotFills'
|
|
3176
3595
|
});
|
|
3177
3596
|
try {
|
|
3178
3597
|
const response = await retryApiCall(async () => {
|
|
3179
|
-
const apiResponse = await this.api.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet({ lotId: lotId, ...(connectionId !== undefined ? { connectionId: connectionId } : {}), ...(limit !== undefined ? { limit: limit } : {}), ...(offset !== undefined ? { offset: offset } : {}) }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
3598
|
+
const apiResponse = await this.api.getPositionLotFillsApiV1BrokersDataPositionsLotsLotIdFillsGet({ lotId: resolvedParams.lotId ?? null, ...(resolvedParams.connectionId !== undefined ? { connectionId: resolvedParams.connectionId } : {}), ...(resolvedParams.limit !== undefined ? { limit: resolvedParams.limit } : {}), ...(resolvedParams.offset !== undefined ? { 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
3599
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3181
3600
|
}, {}, this.sdkConfig);
|
|
3182
3601
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3185,9 +3604,27 @@ class BrokersWrapper {
|
|
|
3185
3604
|
throw new Error('Unexpected response shape: missing success field');
|
|
3186
3605
|
}
|
|
3187
3606
|
// Convert response to plain object, removing _id fields recursively
|
|
3607
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3188
3608
|
const standardResponse = convertToPlainObject(responseData);
|
|
3609
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3610
|
+
const hasLimit = true;
|
|
3611
|
+
const hasOffset = true;
|
|
3612
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3613
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3614
|
+
// PaginatedData is already imported at top of file
|
|
3615
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3616
|
+
if (paginationMeta) {
|
|
3617
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3618
|
+
has_more: paginationMeta.has_more,
|
|
3619
|
+
next_offset: paginationMeta.next_offset,
|
|
3620
|
+
current_offset: paginationMeta.current_offset,
|
|
3621
|
+
limit: paginationMeta.limit,
|
|
3622
|
+
}, this.getPositionLotFills.bind(this), resolvedParams, this);
|
|
3623
|
+
standardResponse.success.data = paginatedData;
|
|
3624
|
+
}
|
|
3625
|
+
}
|
|
3189
3626
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3190
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3627
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
|
|
3191
3628
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3192
3629
|
}
|
|
3193
3630
|
this.logger.debug('Get Position Lot Fills completed', {
|
|
@@ -3195,6 +3632,7 @@ class BrokersWrapper {
|
|
|
3195
3632
|
action: 'getPositionLotFills'
|
|
3196
3633
|
});
|
|
3197
3634
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3635
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3198
3636
|
return standardResponse;
|
|
3199
3637
|
}
|
|
3200
3638
|
catch (error) {
|
|
@@ -3307,7 +3745,7 @@ class CompanyWrapper {
|
|
|
3307
3745
|
* Get Company
|
|
3308
3746
|
*
|
|
3309
3747
|
* Get public company details by ID (no user check, no sensitive data).
|
|
3310
|
-
* @param companyId {string}
|
|
3748
|
+
* @param params.companyId {string} Company ID
|
|
3311
3749
|
* @returns {Promise<FinaticResponse<CompanyResponse>>} Standard response with success/Error/Warning structure
|
|
3312
3750
|
*
|
|
3313
3751
|
* Generated from: GET /api/v1/company/{company_id}
|
|
@@ -3316,7 +3754,9 @@ class CompanyWrapper {
|
|
|
3316
3754
|
* @example
|
|
3317
3755
|
* ```typescript-client
|
|
3318
3756
|
* // Minimal example with required parameters only
|
|
3319
|
-
* const result = await finatic.getCompany(
|
|
3757
|
+
* const result = await finatic.getCompany({
|
|
3758
|
+
companyId: '00000000-0000-0000-0000-000000000000'
|
|
3759
|
+
* });
|
|
3320
3760
|
*
|
|
3321
3761
|
* // Access the response data
|
|
3322
3762
|
* if (result.success) {
|
|
@@ -3326,11 +3766,9 @@ class CompanyWrapper {
|
|
|
3326
3766
|
* }
|
|
3327
3767
|
* ```
|
|
3328
3768
|
*/
|
|
3329
|
-
async getCompany(
|
|
3330
|
-
//
|
|
3331
|
-
const
|
|
3332
|
-
companyId: companyId
|
|
3333
|
-
}; // Generate request ID
|
|
3769
|
+
async getCompany(params) {
|
|
3770
|
+
// Use params object (required parameters present)
|
|
3771
|
+
const resolvedParams = params; // Generate request ID
|
|
3334
3772
|
const requestId = this._generateRequestId();
|
|
3335
3773
|
// Input validation (Phase 2B: zod)
|
|
3336
3774
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3338,7 +3776,7 @@ class CompanyWrapper {
|
|
|
3338
3776
|
const shouldCache = true;
|
|
3339
3777
|
const cache = getCache(this.sdkConfig);
|
|
3340
3778
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3341
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}',
|
|
3779
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
|
|
3342
3780
|
const cached = cache.get(cacheKey);
|
|
3343
3781
|
if (cached) {
|
|
3344
3782
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3350,12 +3788,12 @@ class CompanyWrapper {
|
|
|
3350
3788
|
request_id: requestId,
|
|
3351
3789
|
method: 'GET',
|
|
3352
3790
|
path: '/api/v1/company/{company_id}',
|
|
3353
|
-
params:
|
|
3791
|
+
params: resolvedParams,
|
|
3354
3792
|
action: 'getCompany'
|
|
3355
3793
|
});
|
|
3356
3794
|
try {
|
|
3357
3795
|
const response = await retryApiCall(async () => {
|
|
3358
|
-
const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: companyId }, { headers: { 'x-request-id': requestId } });
|
|
3796
|
+
const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: resolvedParams.companyId ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3359
3797
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3360
3798
|
}, {}, this.sdkConfig);
|
|
3361
3799
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3364,9 +3802,15 @@ class CompanyWrapper {
|
|
|
3364
3802
|
throw new Error('Unexpected response shape: missing success field');
|
|
3365
3803
|
}
|
|
3366
3804
|
// Convert response to plain object, removing _id fields recursively
|
|
3805
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3367
3806
|
const standardResponse = convertToPlainObject(responseData);
|
|
3807
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3808
|
+
const hasLimit = false;
|
|
3809
|
+
const hasOffset = false;
|
|
3810
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3811
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3368
3812
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3369
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}',
|
|
3813
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
|
|
3370
3814
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3371
3815
|
}
|
|
3372
3816
|
this.logger.debug('Get Company completed', {
|
|
@@ -3374,6 +3818,7 @@ class CompanyWrapper {
|
|
|
3374
3818
|
action: 'getCompany'
|
|
3375
3819
|
});
|
|
3376
3820
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3821
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3377
3822
|
return standardResponse;
|
|
3378
3823
|
}
|
|
3379
3824
|
catch (error) {
|
|
@@ -3486,7 +3931,7 @@ class SessionWrapper {
|
|
|
3486
3931
|
* Init Session
|
|
3487
3932
|
*
|
|
3488
3933
|
* Initialize a new session with company API key.
|
|
3489
|
-
* @param xApiKey {string}
|
|
3934
|
+
* @param params.xApiKey {string} Company API key
|
|
3490
3935
|
* @returns {Promise<FinaticResponse<TokenResponseData>>} Standard response with success/Error/Warning structure
|
|
3491
3936
|
*
|
|
3492
3937
|
* Generated from: POST /api/v1/session/init
|
|
@@ -3495,7 +3940,7 @@ class SessionWrapper {
|
|
|
3495
3940
|
* @example
|
|
3496
3941
|
* ```typescript-client
|
|
3497
3942
|
* // Example with no parameters
|
|
3498
|
-
* const result = await finatic.initSession();
|
|
3943
|
+
* const result = await finatic.initSession({});
|
|
3499
3944
|
*
|
|
3500
3945
|
* // Access the response data
|
|
3501
3946
|
* if (result.success) {
|
|
@@ -3503,11 +3948,9 @@ class SessionWrapper {
|
|
|
3503
3948
|
* }
|
|
3504
3949
|
* ```
|
|
3505
3950
|
*/
|
|
3506
|
-
async initSession(
|
|
3507
|
-
//
|
|
3508
|
-
const
|
|
3509
|
-
xApiKey: xApiKey
|
|
3510
|
-
}; // Generate request ID
|
|
3951
|
+
async initSession(params) {
|
|
3952
|
+
// Use params object (required parameters present)
|
|
3953
|
+
const resolvedParams = params; // Generate request ID
|
|
3511
3954
|
const requestId = this._generateRequestId();
|
|
3512
3955
|
// Input validation (Phase 2B: zod)
|
|
3513
3956
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3515,7 +3958,7 @@ class SessionWrapper {
|
|
|
3515
3958
|
const shouldCache = true;
|
|
3516
3959
|
const cache = getCache(this.sdkConfig);
|
|
3517
3960
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3518
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/init',
|
|
3961
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
|
|
3519
3962
|
const cached = cache.get(cacheKey);
|
|
3520
3963
|
if (cached) {
|
|
3521
3964
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3527,12 +3970,12 @@ class SessionWrapper {
|
|
|
3527
3970
|
request_id: requestId,
|
|
3528
3971
|
method: 'POST',
|
|
3529
3972
|
path: '/api/v1/session/init',
|
|
3530
|
-
params:
|
|
3973
|
+
params: resolvedParams,
|
|
3531
3974
|
action: 'initSession'
|
|
3532
3975
|
});
|
|
3533
3976
|
try {
|
|
3534
3977
|
const response = await retryApiCall(async () => {
|
|
3535
|
-
const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: xApiKey }, { headers: { 'x-request-id': requestId } });
|
|
3978
|
+
const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: resolvedParams.xApiKey ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3536
3979
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3537
3980
|
}, {}, this.sdkConfig);
|
|
3538
3981
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3541,9 +3984,15 @@ class SessionWrapper {
|
|
|
3541
3984
|
throw new Error('Unexpected response shape: missing success field');
|
|
3542
3985
|
}
|
|
3543
3986
|
// Convert response to plain object, removing _id fields recursively
|
|
3987
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3544
3988
|
const standardResponse = convertToPlainObject(responseData);
|
|
3989
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3990
|
+
const hasLimit = false;
|
|
3991
|
+
const hasOffset = false;
|
|
3992
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3993
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3545
3994
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3546
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/init',
|
|
3995
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
|
|
3547
3996
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3548
3997
|
}
|
|
3549
3998
|
this.logger.debug('Init Session completed', {
|
|
@@ -3551,6 +4000,7 @@ class SessionWrapper {
|
|
|
3551
4000
|
action: 'initSession'
|
|
3552
4001
|
});
|
|
3553
4002
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4003
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3554
4004
|
return standardResponse;
|
|
3555
4005
|
}
|
|
3556
4006
|
catch (error) {
|
|
@@ -3624,8 +4074,8 @@ class SessionWrapper {
|
|
|
3624
4074
|
* Start Session
|
|
3625
4075
|
*
|
|
3626
4076
|
* Start a session with a one-time token.
|
|
3627
|
-
* @param OneTimeToken {string}
|
|
3628
|
-
* @param body {SessionStartRequest}
|
|
4077
|
+
* @param params.OneTimeToken {string} One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
4078
|
+
* @param params.body {SessionStartRequest} Session start request containing optional user ID to associate with the session
|
|
3629
4079
|
* @returns {Promise<FinaticResponse<SessionResponseData>>} Standard response with success/Error/Warning structure
|
|
3630
4080
|
*
|
|
3631
4081
|
* Generated from: POST /api/v1/session/start
|
|
@@ -3634,7 +4084,7 @@ class SessionWrapper {
|
|
|
3634
4084
|
* @example
|
|
3635
4085
|
* ```typescript-client
|
|
3636
4086
|
* // Example with no parameters
|
|
3637
|
-
* const result = await finatic.startSession();
|
|
4087
|
+
* const result = await finatic.startSession({});
|
|
3638
4088
|
*
|
|
3639
4089
|
* // Access the response data
|
|
3640
4090
|
* if (result.success) {
|
|
@@ -3642,12 +4092,9 @@ class SessionWrapper {
|
|
|
3642
4092
|
* }
|
|
3643
4093
|
* ```
|
|
3644
4094
|
*/
|
|
3645
|
-
async startSession(
|
|
3646
|
-
//
|
|
3647
|
-
const
|
|
3648
|
-
OneTimeToken: OneTimeToken,
|
|
3649
|
-
body: body
|
|
3650
|
-
}; // Generate request ID
|
|
4095
|
+
async startSession(params) {
|
|
4096
|
+
// Use params object (required parameters present)
|
|
4097
|
+
const resolvedParams = params; // Generate request ID
|
|
3651
4098
|
const requestId = this._generateRequestId();
|
|
3652
4099
|
// Input validation (Phase 2B: zod)
|
|
3653
4100
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3655,7 +4102,7 @@ class SessionWrapper {
|
|
|
3655
4102
|
const shouldCache = true;
|
|
3656
4103
|
const cache = getCache(this.sdkConfig);
|
|
3657
4104
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3658
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/start',
|
|
4105
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
|
|
3659
4106
|
const cached = cache.get(cacheKey);
|
|
3660
4107
|
if (cached) {
|
|
3661
4108
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3667,12 +4114,12 @@ class SessionWrapper {
|
|
|
3667
4114
|
request_id: requestId,
|
|
3668
4115
|
method: 'POST',
|
|
3669
4116
|
path: '/api/v1/session/start',
|
|
3670
|
-
params:
|
|
4117
|
+
params: resolvedParams,
|
|
3671
4118
|
action: 'startSession'
|
|
3672
4119
|
});
|
|
3673
4120
|
try {
|
|
3674
4121
|
const response = await retryApiCall(async () => {
|
|
3675
|
-
const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: OneTimeToken, sessionStartRequest: body }, { headers: { 'x-request-id': requestId } });
|
|
4122
|
+
const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: resolvedParams.OneTimeToken ?? null, sessionStartRequest: resolvedParams.body ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3676
4123
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3677
4124
|
}, {}, this.sdkConfig);
|
|
3678
4125
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3681,9 +4128,15 @@ class SessionWrapper {
|
|
|
3681
4128
|
throw new Error('Unexpected response shape: missing success field');
|
|
3682
4129
|
}
|
|
3683
4130
|
// Convert response to plain object, removing _id fields recursively
|
|
4131
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3684
4132
|
const standardResponse = convertToPlainObject(responseData);
|
|
4133
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4134
|
+
const hasLimit = false;
|
|
4135
|
+
const hasOffset = false;
|
|
4136
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4137
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3685
4138
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3686
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/start',
|
|
4139
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
|
|
3687
4140
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3688
4141
|
}
|
|
3689
4142
|
this.logger.debug('Start Session completed', {
|
|
@@ -3691,6 +4144,7 @@ class SessionWrapper {
|
|
|
3691
4144
|
action: 'startSession'
|
|
3692
4145
|
});
|
|
3693
4146
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4147
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3694
4148
|
return standardResponse;
|
|
3695
4149
|
}
|
|
3696
4150
|
catch (error) {
|
|
@@ -3767,7 +4221,7 @@ class SessionWrapper {
|
|
|
3767
4221
|
*
|
|
3768
4222
|
* The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device
|
|
3769
4223
|
* that initiated the session. Device info is automatically validated from the request.
|
|
3770
|
-
* @param No parameters required for this method
|
|
4224
|
+
* @param params No parameters required for this method
|
|
3771
4225
|
* @returns {Promise<FinaticResponse<PortalUrlResponse>>} Standard response with success/Error/Warning structure
|
|
3772
4226
|
*
|
|
3773
4227
|
* Generated from: GET /api/v1/session/portal
|
|
@@ -3776,7 +4230,7 @@ class SessionWrapper {
|
|
|
3776
4230
|
* @example
|
|
3777
4231
|
* ```typescript-client
|
|
3778
4232
|
* // Example with no parameters
|
|
3779
|
-
* const result = await finatic.getPortalUrl();
|
|
4233
|
+
* const result = await finatic.getPortalUrl({});
|
|
3780
4234
|
*
|
|
3781
4235
|
* // Access the response data
|
|
3782
4236
|
* if (result.success) {
|
|
@@ -3784,10 +4238,10 @@ class SessionWrapper {
|
|
|
3784
4238
|
* }
|
|
3785
4239
|
* ```
|
|
3786
4240
|
*/
|
|
3787
|
-
async getPortalUrl() {
|
|
4241
|
+
async getPortalUrl(params) {
|
|
3788
4242
|
// No parameters - use empty params object
|
|
3789
|
-
const
|
|
3790
|
-
if (!this.sessionId) {
|
|
4243
|
+
const resolvedParams = params || {}; // Authentication check
|
|
4244
|
+
if (!this.sessionId || !this.companyId) {
|
|
3791
4245
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3792
4246
|
}
|
|
3793
4247
|
// Generate request ID
|
|
@@ -3798,7 +4252,7 @@ class SessionWrapper {
|
|
|
3798
4252
|
const shouldCache = true;
|
|
3799
4253
|
const cache = getCache(this.sdkConfig);
|
|
3800
4254
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3801
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal',
|
|
4255
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
|
|
3802
4256
|
const cached = cache.get(cacheKey);
|
|
3803
4257
|
if (cached) {
|
|
3804
4258
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3810,12 +4264,12 @@ class SessionWrapper {
|
|
|
3810
4264
|
request_id: requestId,
|
|
3811
4265
|
method: 'GET',
|
|
3812
4266
|
path: '/api/v1/session/portal',
|
|
3813
|
-
params:
|
|
4267
|
+
params: resolvedParams,
|
|
3814
4268
|
action: 'getPortalUrl'
|
|
3815
4269
|
});
|
|
3816
4270
|
try {
|
|
3817
4271
|
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
|
|
4272
|
+
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
4273
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3820
4274
|
}, {}, this.sdkConfig);
|
|
3821
4275
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3824,9 +4278,15 @@ class SessionWrapper {
|
|
|
3824
4278
|
throw new Error('Unexpected response shape: missing success field');
|
|
3825
4279
|
}
|
|
3826
4280
|
// Convert response to plain object, removing _id fields recursively
|
|
4281
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3827
4282
|
const standardResponse = convertToPlainObject(responseData);
|
|
4283
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4284
|
+
const hasLimit = false;
|
|
4285
|
+
const hasOffset = false;
|
|
4286
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4287
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3828
4288
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3829
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal',
|
|
4289
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
|
|
3830
4290
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3831
4291
|
}
|
|
3832
4292
|
this.logger.debug('Get Portal Url completed', {
|
|
@@ -3834,6 +4294,7 @@ class SessionWrapper {
|
|
|
3834
4294
|
action: 'getPortalUrl'
|
|
3835
4295
|
});
|
|
3836
4296
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4297
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3837
4298
|
return standardResponse;
|
|
3838
4299
|
}
|
|
3839
4300
|
catch (error) {
|
|
@@ -3918,7 +4379,7 @@ class SessionWrapper {
|
|
|
3918
4379
|
* - Generates fresh tokens (not returning stored ones)
|
|
3919
4380
|
* - Only accessible to authenticated sessions with user_id
|
|
3920
4381
|
* - Validates that header session_id matches path session_id
|
|
3921
|
-
* @param sessionId {string}
|
|
4382
|
+
* @param params.sessionId {string} Session ID
|
|
3922
4383
|
* @returns {Promise<FinaticResponse<SessionUserResponse>>} Standard response with success/Error/Warning structure
|
|
3923
4384
|
*
|
|
3924
4385
|
* Generated from: GET /api/v1/session/{session_id}/user
|
|
@@ -3927,7 +4388,9 @@ class SessionWrapper {
|
|
|
3927
4388
|
* @example
|
|
3928
4389
|
* ```typescript-client
|
|
3929
4390
|
* // Minimal example with required parameters only
|
|
3930
|
-
* const result = await finatic.getSessionUser(
|
|
4391
|
+
* const result = await finatic.getSessionUser({
|
|
4392
|
+
sessionId: 'sess_1234567890abcdef'
|
|
4393
|
+
* });
|
|
3931
4394
|
*
|
|
3932
4395
|
* // Access the response data
|
|
3933
4396
|
* if (result.success) {
|
|
@@ -3937,12 +4400,10 @@ class SessionWrapper {
|
|
|
3937
4400
|
* }
|
|
3938
4401
|
* ```
|
|
3939
4402
|
*/
|
|
3940
|
-
async getSessionUser(
|
|
3941
|
-
//
|
|
3942
|
-
const
|
|
3943
|
-
|
|
3944
|
-
}; // Authentication check
|
|
3945
|
-
if (!this.sessionId) {
|
|
4403
|
+
async getSessionUser(params) {
|
|
4404
|
+
// Use params object (required parameters present)
|
|
4405
|
+
const resolvedParams = params; // Authentication check
|
|
4406
|
+
if (!this.sessionId || !this.companyId) {
|
|
3946
4407
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3947
4408
|
}
|
|
3948
4409
|
// Generate request ID
|
|
@@ -3953,7 +4414,7 @@ class SessionWrapper {
|
|
|
3953
4414
|
const shouldCache = true;
|
|
3954
4415
|
const cache = getCache(this.sdkConfig);
|
|
3955
4416
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3956
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user',
|
|
4417
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
|
|
3957
4418
|
const cached = cache.get(cacheKey);
|
|
3958
4419
|
if (cached) {
|
|
3959
4420
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3965,12 +4426,12 @@ class SessionWrapper {
|
|
|
3965
4426
|
request_id: requestId,
|
|
3966
4427
|
method: 'GET',
|
|
3967
4428
|
path: '/api/v1/session/{session_id}/user',
|
|
3968
|
-
params:
|
|
4429
|
+
params: resolvedParams,
|
|
3969
4430
|
action: 'getSessionUser'
|
|
3970
4431
|
});
|
|
3971
4432
|
try {
|
|
3972
4433
|
const response = await retryApiCall(async () => {
|
|
3973
|
-
const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: sessionId, xSessionId: sessionId }, { headers: { 'x-request-id': requestId } });
|
|
4434
|
+
const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: resolvedParams.sessionId ?? null, xSessionId: resolvedParams.sessionId ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3974
4435
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3975
4436
|
}, {}, this.sdkConfig);
|
|
3976
4437
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3979,9 +4440,15 @@ class SessionWrapper {
|
|
|
3979
4440
|
throw new Error('Unexpected response shape: missing success field');
|
|
3980
4441
|
}
|
|
3981
4442
|
// Convert response to plain object, removing _id fields recursively
|
|
4443
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3982
4444
|
const standardResponse = convertToPlainObject(responseData);
|
|
4445
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4446
|
+
const hasLimit = false;
|
|
4447
|
+
const hasOffset = false;
|
|
4448
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4449
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3983
4450
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3984
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user',
|
|
4451
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
|
|
3985
4452
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3986
4453
|
}
|
|
3987
4454
|
this.logger.debug('Get Session User completed', {
|
|
@@ -3989,6 +4456,7 @@ class SessionWrapper {
|
|
|
3989
4456
|
action: 'getSessionUser'
|
|
3990
4457
|
});
|
|
3991
4458
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4459
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3992
4460
|
return standardResponse;
|
|
3993
4461
|
}
|
|
3994
4462
|
catch (error) {
|
|
@@ -4737,8 +5205,8 @@ const SessionApiAxiosParamCreator = function (configuration) {
|
|
|
4737
5205
|
/**
|
|
4738
5206
|
* Start a session with a one-time token.
|
|
4739
5207
|
* @summary Start Session
|
|
4740
|
-
* @param {string} oneTimeToken
|
|
4741
|
-
* @param {SessionStartRequest} sessionStartRequest
|
|
5208
|
+
* @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
5209
|
+
* @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
|
|
4742
5210
|
* @param {*} [options] Override http request option.
|
|
4743
5211
|
* @throws {RequiredError}
|
|
4744
5212
|
*/
|
|
@@ -4821,8 +5289,8 @@ const SessionApiFp = function (configuration) {
|
|
|
4821
5289
|
/**
|
|
4822
5290
|
* Start a session with a one-time token.
|
|
4823
5291
|
* @summary Start Session
|
|
4824
|
-
* @param {string} oneTimeToken
|
|
4825
|
-
* @param {SessionStartRequest} sessionStartRequest
|
|
5292
|
+
* @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
5293
|
+
* @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
|
|
4826
5294
|
* @param {*} [options] Override http request option.
|
|
4827
5295
|
* @throws {RequiredError}
|
|
4828
5296
|
*/
|
|
@@ -5037,7 +5505,7 @@ const BrokersApiAxiosParamCreator = function (configuration) {
|
|
|
5037
5505
|
* @summary Get Balances
|
|
5038
5506
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5039
5507
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5040
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
5508
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5041
5509
|
* @param {boolean | null} [isEndOfDaySnapshot] Filter by end-of-day snapshot status (true/false)
|
|
5042
5510
|
* @param {number} [limit] Maximum number of balances to return
|
|
5043
5511
|
* @param {number} [offset] Number of balances to skip for pagination
|
|
@@ -5274,9 +5742,9 @@ const BrokersApiAxiosParamCreator = function (configuration) {
|
|
|
5274
5742
|
* @summary Get Orders
|
|
5275
5743
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5276
5744
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5277
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
5745
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5278
5746
|
* @param {string | null} [symbol] Filter by symbol
|
|
5279
|
-
* @param {
|
|
5747
|
+
* @param {string | null} [orderStatus] Filter by order status (e.g., \'filled\', \'pending_new\', \'cancelled\')
|
|
5280
5748
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by order side (e.g., \'buy\', \'sell\')
|
|
5281
5749
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
5282
5750
|
* @param {number} [limit] Maximum number of orders to return
|
|
@@ -5445,7 +5913,7 @@ const BrokersApiAxiosParamCreator = function (configuration) {
|
|
|
5445
5913
|
* @summary Get Positions
|
|
5446
5914
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5447
5915
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5448
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
5916
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5449
5917
|
* @param {string | null} [symbol] Filter by symbol
|
|
5450
5918
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by position side (e.g., \'long\', \'short\')
|
|
5451
5919
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
@@ -5588,7 +6056,7 @@ const BrokersApiFp = function (configuration) {
|
|
|
5588
6056
|
* @summary Get Balances
|
|
5589
6057
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5590
6058
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5591
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
6059
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5592
6060
|
* @param {boolean | null} [isEndOfDaySnapshot] Filter by end-of-day snapshot status (true/false)
|
|
5593
6061
|
* @param {number} [limit] Maximum number of balances to return
|
|
5594
6062
|
* @param {number} [offset] Number of balances to skip for pagination
|
|
@@ -5674,9 +6142,9 @@ const BrokersApiFp = function (configuration) {
|
|
|
5674
6142
|
* @summary Get Orders
|
|
5675
6143
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5676
6144
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5677
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
6145
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5678
6146
|
* @param {string | null} [symbol] Filter by symbol
|
|
5679
|
-
* @param {
|
|
6147
|
+
* @param {string | null} [orderStatus] Filter by order status (e.g., \'filled\', \'pending_new\', \'cancelled\')
|
|
5680
6148
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by order side (e.g., \'buy\', \'sell\')
|
|
5681
6149
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
5682
6150
|
* @param {number} [limit] Maximum number of orders to return
|
|
@@ -5733,7 +6201,7 @@ const BrokersApiFp = function (configuration) {
|
|
|
5733
6201
|
* @summary Get Positions
|
|
5734
6202
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5735
6203
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5736
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
6204
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5737
6205
|
* @param {string | null} [symbol] Filter by symbol
|
|
5738
6206
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by position side (e.g., \'long\', \'short\')
|
|
5739
6207
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
@@ -6357,11 +6825,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6357
6825
|
}
|
|
6358
6826
|
const sessionId = data?.session_id || '';
|
|
6359
6827
|
const companyId = data?.company_id || '';
|
|
6828
|
+
const responseUserId = data?.user_id || '';
|
|
6360
6829
|
// csrf_token is not in SessionResponseData, get from response headers if available
|
|
6361
6830
|
const csrfToken = data?.csrf_token || '';
|
|
6362
6831
|
this.logger.debug?.('_startSession extracted data', {
|
|
6363
6832
|
sessionId,
|
|
6364
6833
|
companyId,
|
|
6834
|
+
responseUserId,
|
|
6365
6835
|
csrfToken,
|
|
6366
6836
|
fullData: data,
|
|
6367
6837
|
dataKeys: data ? Object.keys(data) : []
|
|
@@ -6383,6 +6853,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6383
6853
|
responseKeys: response ? Object.keys(response) : []
|
|
6384
6854
|
});
|
|
6385
6855
|
}
|
|
6856
|
+
// Store userId if present in response (for getUserId() and isAuthed())
|
|
6857
|
+
// Use userId from response if parameter wasn't provided, or if response has a different userId
|
|
6858
|
+
const finalUserId = responseUserId || userId;
|
|
6859
|
+
if (finalUserId) {
|
|
6860
|
+
this.userId = finalUserId;
|
|
6861
|
+
this.logger.debug?.('_startSession set userId', { userId: finalUserId, source: responseUserId ? 'response' : 'parameter' });
|
|
6862
|
+
}
|
|
6386
6863
|
return { session_id: sessionId, company_id: companyId };
|
|
6387
6864
|
}
|
|
6388
6865
|
/**
|
|
@@ -6394,28 +6871,30 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6394
6871
|
*
|
|
6395
6872
|
* @methodId get_portal_url_api_v1_session_portal_get
|
|
6396
6873
|
* @category session
|
|
6397
|
-
* @param
|
|
6398
|
-
* @param
|
|
6399
|
-
* @param
|
|
6400
|
-
* @param
|
|
6874
|
+
* @param params - Optional parameters object
|
|
6875
|
+
* @param params.theme - Optional theme preset or custom theme object
|
|
6876
|
+
* @param params.brokers - Optional array of broker IDs to filter
|
|
6877
|
+
* @param params.email - Optional email address
|
|
6878
|
+
* @param params.mode - Optional mode ('light' or 'dark')
|
|
6401
6879
|
* @returns Portal URL string
|
|
6402
6880
|
* @example
|
|
6403
6881
|
* ```typescript-client
|
|
6404
|
-
* const url = await finatic.getPortalUrl('
|
|
6882
|
+
* const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
|
|
6405
6883
|
* ```
|
|
6406
6884
|
* @example
|
|
6407
6885
|
* ```typescript-server
|
|
6408
|
-
* const url = await finatic.getPortalUrl('
|
|
6886
|
+
* const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
|
|
6409
6887
|
* ```
|
|
6410
6888
|
* @example
|
|
6411
6889
|
* ```python
|
|
6412
|
-
* url = await finatic.get_portal_url('
|
|
6890
|
+
* url = await finatic.get_portal_url(theme='default', brokers=['broker-1'], email='user@example.com', mode='dark')
|
|
6413
6891
|
* ```
|
|
6414
6892
|
*/
|
|
6415
|
-
async getPortalUrl(
|
|
6893
|
+
async getPortalUrl(params) {
|
|
6416
6894
|
if (!this.sessionId) {
|
|
6417
6895
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
6418
6896
|
}
|
|
6897
|
+
const { theme, brokers, email, mode } = params || {};
|
|
6419
6898
|
// Get raw portal URL from SessionApi directly (not a wrapper)
|
|
6420
6899
|
const axiosResponse = await this.sessionApi.getPortalUrlApiV1SessionPortalGet({
|
|
6421
6900
|
sessionId: this.sessionId,
|
|
@@ -6489,29 +6968,35 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6489
6968
|
*
|
|
6490
6969
|
* @methodId open_portal_client_sdk
|
|
6491
6970
|
* @category session
|
|
6492
|
-
* @param
|
|
6493
|
-
* @param
|
|
6494
|
-
* @param
|
|
6495
|
-
* @param
|
|
6971
|
+
* @param params - Optional parameters object
|
|
6972
|
+
* @param params.theme - Optional theme preset or custom theme object
|
|
6973
|
+
* @param params.brokers - Optional array of broker IDs to filter
|
|
6974
|
+
* @param params.email - Optional email address
|
|
6975
|
+
* @param params.mode - Optional mode ('light' or 'dark')
|
|
6496
6976
|
* @param onSuccess - Optional callback when portal authentication succeeds
|
|
6497
6977
|
* @param onError - Optional callback when portal authentication fails
|
|
6498
6978
|
* @param onClose - Optional callback when portal is closed
|
|
6499
6979
|
* @returns Promise that resolves when portal is opened
|
|
6500
6980
|
* @example
|
|
6501
6981
|
* ```typescript-client
|
|
6502
|
-
* await finatic.openPortal(
|
|
6982
|
+
* await finatic.openPortal({
|
|
6983
|
+
* theme: 'default',
|
|
6984
|
+
* brokers: ['broker-1'],
|
|
6985
|
+
* email: 'user@example.com',
|
|
6986
|
+
* mode: 'dark'
|
|
6987
|
+
* },
|
|
6503
6988
|
* (userId) => console.log('User authenticated:', userId),
|
|
6504
6989
|
* (error) => console.error('Portal error:', error),
|
|
6505
6990
|
* () => console.log('Portal closed')
|
|
6506
6991
|
* );
|
|
6507
6992
|
* ```
|
|
6508
6993
|
*/
|
|
6509
|
-
async openPortal(
|
|
6994
|
+
async openPortal(params, onSuccess, onError, onClose) {
|
|
6510
6995
|
if (!this.sessionId) {
|
|
6511
6996
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
6512
6997
|
}
|
|
6513
6998
|
// Get portal URL with all parameters
|
|
6514
|
-
const portalUrl = await this.getPortalUrl(
|
|
6999
|
+
const portalUrl = await this.getPortalUrl(params);
|
|
6515
7000
|
// Create portal UI if not exists
|
|
6516
7001
|
if (!this.portalUI) {
|
|
6517
7002
|
this.portalUI = new PortalUI(this.sdkConfig.baseUrl || 'https://api.finatic.dev');
|
|
@@ -6698,7 +7183,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6698
7183
|
* ```
|
|
6699
7184
|
*/
|
|
6700
7185
|
async getCompany(params) {
|
|
6701
|
-
return await this.company.getCompany(params
|
|
7186
|
+
return await this.company.getCompany(params);
|
|
6702
7187
|
}
|
|
6703
7188
|
/**
|
|
6704
7189
|
* Get Brokers
|
|
@@ -6856,7 +7341,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6856
7341
|
* ```
|
|
6857
7342
|
*/
|
|
6858
7343
|
async disconnectCompanyFromBroker(params) {
|
|
6859
|
-
return await this.brokers.disconnectCompanyFromBroker(params
|
|
7344
|
+
return await this.brokers.disconnectCompanyFromBroker(params);
|
|
6860
7345
|
}
|
|
6861
7346
|
/**
|
|
6862
7347
|
* Get Orders
|
|
@@ -6936,7 +7421,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6936
7421
|
* ```
|
|
6937
7422
|
*/
|
|
6938
7423
|
async getOrders(params) {
|
|
6939
|
-
return await this.brokers.getOrders(params
|
|
7424
|
+
return await this.brokers.getOrders(params);
|
|
6940
7425
|
}
|
|
6941
7426
|
/**
|
|
6942
7427
|
* Get Positions
|
|
@@ -7016,7 +7501,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7016
7501
|
* ```
|
|
7017
7502
|
*/
|
|
7018
7503
|
async getPositions(params) {
|
|
7019
|
-
return await this.brokers.getPositions(params
|
|
7504
|
+
return await this.brokers.getPositions(params);
|
|
7020
7505
|
}
|
|
7021
7506
|
/**
|
|
7022
7507
|
* Get Balances
|
|
@@ -7096,7 +7581,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7096
7581
|
* ```
|
|
7097
7582
|
*/
|
|
7098
7583
|
async getBalances(params) {
|
|
7099
|
-
return await this.brokers.getBalances(params
|
|
7584
|
+
return await this.brokers.getBalances(params);
|
|
7100
7585
|
}
|
|
7101
7586
|
/**
|
|
7102
7587
|
* Get Accounts
|
|
@@ -7176,7 +7661,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7176
7661
|
* ```
|
|
7177
7662
|
*/
|
|
7178
7663
|
async getAccounts(params) {
|
|
7179
|
-
return await this.brokers.getAccounts(params
|
|
7664
|
+
return await this.brokers.getAccounts(params);
|
|
7180
7665
|
}
|
|
7181
7666
|
/**
|
|
7182
7667
|
* Get Order Fills
|
|
@@ -7264,7 +7749,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7264
7749
|
* ```
|
|
7265
7750
|
*/
|
|
7266
7751
|
async getOrderFills(params) {
|
|
7267
|
-
return await this.brokers.getOrderFills(params
|
|
7752
|
+
return await this.brokers.getOrderFills(params);
|
|
7268
7753
|
}
|
|
7269
7754
|
/**
|
|
7270
7755
|
* Get Order Events
|
|
@@ -7352,7 +7837,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7352
7837
|
* ```
|
|
7353
7838
|
*/
|
|
7354
7839
|
async getOrderEvents(params) {
|
|
7355
|
-
return await this.brokers.getOrderEvents(params
|
|
7840
|
+
return await this.brokers.getOrderEvents(params);
|
|
7356
7841
|
}
|
|
7357
7842
|
/**
|
|
7358
7843
|
* Get Order Groups
|
|
@@ -7431,7 +7916,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7431
7916
|
* ```
|
|
7432
7917
|
*/
|
|
7433
7918
|
async getOrderGroups(params) {
|
|
7434
|
-
return await this.brokers.getOrderGroups(params
|
|
7919
|
+
return await this.brokers.getOrderGroups(params);
|
|
7435
7920
|
}
|
|
7436
7921
|
/**
|
|
7437
7922
|
* Get Position Lots
|
|
@@ -7511,7 +7996,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7511
7996
|
* ```
|
|
7512
7997
|
*/
|
|
7513
7998
|
async getPositionLots(params) {
|
|
7514
|
-
return await this.brokers.getPositionLots(params
|
|
7999
|
+
return await this.brokers.getPositionLots(params);
|
|
7515
8000
|
}
|
|
7516
8001
|
/**
|
|
7517
8002
|
* Get Position Lot Fills
|
|
@@ -7599,7 +8084,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7599
8084
|
* ```
|
|
7600
8085
|
*/
|
|
7601
8086
|
async getPositionLotFills(params) {
|
|
7602
|
-
return await this.brokers.getPositionLotFills(params
|
|
8087
|
+
return await this.brokers.getPositionLotFills(params);
|
|
7603
8088
|
}
|
|
7604
8089
|
/**
|
|
7605
8090
|
* Get all Orders across all pages.
|
|
@@ -7670,7 +8155,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7670
8155
|
let lastError = null;
|
|
7671
8156
|
let warnings = [];
|
|
7672
8157
|
while (true) {
|
|
7673
|
-
const response = await this.brokers.getOrders(
|
|
8158
|
+
const response = await this.brokers.getOrders({ ...filterParams, limit, offset });
|
|
7674
8159
|
// Collect warnings from each page
|
|
7675
8160
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7676
8161
|
warnings.push(...response.warning);
|
|
@@ -7680,10 +8165,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7680
8165
|
break;
|
|
7681
8166
|
}
|
|
7682
8167
|
const result = response.success?.data || [];
|
|
7683
|
-
if
|
|
8168
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8169
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8170
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8171
|
+
? result.items
|
|
8172
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8173
|
+
if (!items || items.length === 0)
|
|
7684
8174
|
break;
|
|
7685
|
-
allData.push(...
|
|
7686
|
-
|
|
8175
|
+
allData.push(...items);
|
|
8176
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8177
|
+
if (items.length < limit)
|
|
7687
8178
|
break;
|
|
7688
8179
|
offset += limit;
|
|
7689
8180
|
}
|
|
@@ -7775,7 +8266,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7775
8266
|
let lastError = null;
|
|
7776
8267
|
let warnings = [];
|
|
7777
8268
|
while (true) {
|
|
7778
|
-
const response = await this.brokers.getPositions(
|
|
8269
|
+
const response = await this.brokers.getPositions({ ...filterParams, limit, offset });
|
|
7779
8270
|
// Collect warnings from each page
|
|
7780
8271
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7781
8272
|
warnings.push(...response.warning);
|
|
@@ -7785,10 +8276,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7785
8276
|
break;
|
|
7786
8277
|
}
|
|
7787
8278
|
const result = response.success?.data || [];
|
|
7788
|
-
if
|
|
8279
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8280
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8281
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8282
|
+
? result.items
|
|
8283
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8284
|
+
if (!items || items.length === 0)
|
|
7789
8285
|
break;
|
|
7790
|
-
allData.push(...
|
|
7791
|
-
|
|
8286
|
+
allData.push(...items);
|
|
8287
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8288
|
+
if (items.length < limit)
|
|
7792
8289
|
break;
|
|
7793
8290
|
offset += limit;
|
|
7794
8291
|
}
|
|
@@ -7880,7 +8377,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7880
8377
|
let lastError = null;
|
|
7881
8378
|
let warnings = [];
|
|
7882
8379
|
while (true) {
|
|
7883
|
-
const response = await this.brokers.getBalances(
|
|
8380
|
+
const response = await this.brokers.getBalances({ ...filterParams, limit, offset });
|
|
7884
8381
|
// Collect warnings from each page
|
|
7885
8382
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7886
8383
|
warnings.push(...response.warning);
|
|
@@ -7890,10 +8387,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7890
8387
|
break;
|
|
7891
8388
|
}
|
|
7892
8389
|
const result = response.success?.data || [];
|
|
7893
|
-
if
|
|
8390
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8391
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8392
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8393
|
+
? result.items
|
|
8394
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8395
|
+
if (!items || items.length === 0)
|
|
7894
8396
|
break;
|
|
7895
|
-
allData.push(...
|
|
7896
|
-
|
|
8397
|
+
allData.push(...items);
|
|
8398
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8399
|
+
if (items.length < limit)
|
|
7897
8400
|
break;
|
|
7898
8401
|
offset += limit;
|
|
7899
8402
|
}
|
|
@@ -7985,7 +8488,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7985
8488
|
let lastError = null;
|
|
7986
8489
|
let warnings = [];
|
|
7987
8490
|
while (true) {
|
|
7988
|
-
const response = await this.brokers.getAccounts(
|
|
8491
|
+
const response = await this.brokers.getAccounts({ ...filterParams, limit, offset });
|
|
7989
8492
|
// Collect warnings from each page
|
|
7990
8493
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7991
8494
|
warnings.push(...response.warning);
|
|
@@ -7995,10 +8498,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7995
8498
|
break;
|
|
7996
8499
|
}
|
|
7997
8500
|
const result = response.success?.data || [];
|
|
7998
|
-
if
|
|
8501
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8502
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8503
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8504
|
+
? result.items
|
|
8505
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8506
|
+
if (!items || items.length === 0)
|
|
7999
8507
|
break;
|
|
8000
|
-
allData.push(...
|
|
8001
|
-
|
|
8508
|
+
allData.push(...items);
|
|
8509
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8510
|
+
if (items.length < limit)
|
|
8002
8511
|
break;
|
|
8003
8512
|
offset += limit;
|
|
8004
8513
|
}
|
|
@@ -8089,7 +8598,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8089
8598
|
let lastError = null;
|
|
8090
8599
|
let warnings = [];
|
|
8091
8600
|
while (true) {
|
|
8092
|
-
const response = await this.brokers.getOrderFills(
|
|
8601
|
+
const response = await this.brokers.getOrderFills({ ...filterParams, limit, offset });
|
|
8093
8602
|
// Collect warnings from each page
|
|
8094
8603
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8095
8604
|
warnings.push(...response.warning);
|
|
@@ -8099,10 +8608,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8099
8608
|
break;
|
|
8100
8609
|
}
|
|
8101
8610
|
const result = response.success?.data || [];
|
|
8102
|
-
if
|
|
8611
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8612
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8613
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8614
|
+
? result.items
|
|
8615
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8616
|
+
if (!items || items.length === 0)
|
|
8103
8617
|
break;
|
|
8104
|
-
allData.push(...
|
|
8105
|
-
|
|
8618
|
+
allData.push(...items);
|
|
8619
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8620
|
+
if (items.length < limit)
|
|
8106
8621
|
break;
|
|
8107
8622
|
offset += limit;
|
|
8108
8623
|
}
|
|
@@ -8193,7 +8708,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8193
8708
|
let lastError = null;
|
|
8194
8709
|
let warnings = [];
|
|
8195
8710
|
while (true) {
|
|
8196
|
-
const response = await this.brokers.getOrderEvents(
|
|
8711
|
+
const response = await this.brokers.getOrderEvents({ ...filterParams, limit, offset });
|
|
8197
8712
|
// Collect warnings from each page
|
|
8198
8713
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8199
8714
|
warnings.push(...response.warning);
|
|
@@ -8203,10 +8718,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8203
8718
|
break;
|
|
8204
8719
|
}
|
|
8205
8720
|
const result = response.success?.data || [];
|
|
8206
|
-
if
|
|
8721
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8722
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8723
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8724
|
+
? result.items
|
|
8725
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8726
|
+
if (!items || items.length === 0)
|
|
8207
8727
|
break;
|
|
8208
|
-
allData.push(...
|
|
8209
|
-
|
|
8728
|
+
allData.push(...items);
|
|
8729
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8730
|
+
if (items.length < limit)
|
|
8210
8731
|
break;
|
|
8211
8732
|
offset += limit;
|
|
8212
8733
|
}
|
|
@@ -8298,7 +8819,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8298
8819
|
let lastError = null;
|
|
8299
8820
|
let warnings = [];
|
|
8300
8821
|
while (true) {
|
|
8301
|
-
const response = await this.brokers.getOrderGroups(
|
|
8822
|
+
const response = await this.brokers.getOrderGroups({ ...filterParams, limit, offset });
|
|
8302
8823
|
// Collect warnings from each page
|
|
8303
8824
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8304
8825
|
warnings.push(...response.warning);
|
|
@@ -8308,10 +8829,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8308
8829
|
break;
|
|
8309
8830
|
}
|
|
8310
8831
|
const result = response.success?.data || [];
|
|
8311
|
-
if
|
|
8832
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8833
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8834
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8835
|
+
? result.items
|
|
8836
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8837
|
+
if (!items || items.length === 0)
|
|
8312
8838
|
break;
|
|
8313
|
-
allData.push(...
|
|
8314
|
-
|
|
8839
|
+
allData.push(...items);
|
|
8840
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8841
|
+
if (items.length < limit)
|
|
8315
8842
|
break;
|
|
8316
8843
|
offset += limit;
|
|
8317
8844
|
}
|
|
@@ -8403,7 +8930,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8403
8930
|
let lastError = null;
|
|
8404
8931
|
let warnings = [];
|
|
8405
8932
|
while (true) {
|
|
8406
|
-
const response = await this.brokers.getPositionLots(
|
|
8933
|
+
const response = await this.brokers.getPositionLots({ ...filterParams, limit, offset });
|
|
8407
8934
|
// Collect warnings from each page
|
|
8408
8935
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8409
8936
|
warnings.push(...response.warning);
|
|
@@ -8413,10 +8940,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8413
8940
|
break;
|
|
8414
8941
|
}
|
|
8415
8942
|
const result = response.success?.data || [];
|
|
8416
|
-
if
|
|
8943
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8944
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8945
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8946
|
+
? result.items
|
|
8947
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8948
|
+
if (!items || items.length === 0)
|
|
8417
8949
|
break;
|
|
8418
|
-
allData.push(...
|
|
8419
|
-
|
|
8950
|
+
allData.push(...items);
|
|
8951
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8952
|
+
if (items.length < limit)
|
|
8420
8953
|
break;
|
|
8421
8954
|
offset += limit;
|
|
8422
8955
|
}
|
|
@@ -8506,7 +9039,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8506
9039
|
let lastError = null;
|
|
8507
9040
|
let warnings = [];
|
|
8508
9041
|
while (true) {
|
|
8509
|
-
const response = await this.brokers.getPositionLotFills(
|
|
9042
|
+
const response = await this.brokers.getPositionLotFills({ ...filterParams, limit, offset });
|
|
8510
9043
|
// Collect warnings from each page
|
|
8511
9044
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8512
9045
|
warnings.push(...response.warning);
|
|
@@ -8516,10 +9049,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8516
9049
|
break;
|
|
8517
9050
|
}
|
|
8518
9051
|
const result = response.success?.data || [];
|
|
8519
|
-
if
|
|
9052
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
9053
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
9054
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
9055
|
+
? result.items
|
|
9056
|
+
: (Array.isArray(result) ? result : [result]);
|
|
9057
|
+
if (!items || items.length === 0)
|
|
8520
9058
|
break;
|
|
8521
|
-
allData.push(...
|
|
8522
|
-
|
|
9059
|
+
allData.push(...items);
|
|
9060
|
+
// If we got fewer items than the limit, there are no more pages
|
|
9061
|
+
if (items.length < limit)
|
|
8523
9062
|
break;
|
|
8524
9063
|
offset += limit;
|
|
8525
9064
|
}
|
|
@@ -8579,6 +9118,7 @@ exports.Configuration = Configuration;
|
|
|
8579
9118
|
exports.EventEmitter = EventEmitter;
|
|
8580
9119
|
exports.FinaticConnect = FinaticConnect;
|
|
8581
9120
|
exports.FinaticError = FinaticError;
|
|
9121
|
+
exports.PaginatedData = PaginatedData;
|
|
8582
9122
|
exports.SessionApi = SessionApi;
|
|
8583
9123
|
exports.SessionApiAxiosParamCreator = SessionApiAxiosParamCreator;
|
|
8584
9124
|
exports.SessionApiFactory = SessionApiFactory;
|