@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.mjs
CHANGED
|
@@ -616,7 +616,11 @@ function coerceEnumValue(input, EnumObj, enumName) {
|
|
|
616
616
|
// Direct match by value (case-insensitive)
|
|
617
617
|
const valueMatch = values.find(v => v.toLowerCase() === normalized.toLowerCase());
|
|
618
618
|
if (valueMatch) {
|
|
619
|
-
|
|
619
|
+
// Find the enum key that has this value
|
|
620
|
+
const matchingKey = Object.keys(EnumObj).find(k => EnumObj[k] === valueMatch);
|
|
621
|
+
if (matchingKey) {
|
|
622
|
+
return EnumObj[matchingKey]; // Returns enum member (e.g., BrokerDataOrderStatusEnum.Filled)
|
|
623
|
+
}
|
|
620
624
|
}
|
|
621
625
|
// Match by key name (case-insensitive)
|
|
622
626
|
const keyMatch = Object.keys(EnumObj).find(k => String(k).toLowerCase() === normalized.toLowerCase());
|
|
@@ -764,34 +768,6 @@ var BrokerDataOrderSideEnum;
|
|
|
764
768
|
BrokerDataOrderSideEnum["Sell"] = "sell";
|
|
765
769
|
})(BrokerDataOrderSideEnum || (BrokerDataOrderSideEnum = {}));
|
|
766
770
|
|
|
767
|
-
/* tslint:disable */
|
|
768
|
-
/* eslint-disable */
|
|
769
|
-
/**
|
|
770
|
-
* Finatic FastAPI Backend
|
|
771
|
-
* FinaticAPI REST API
|
|
772
|
-
*
|
|
773
|
-
* The version of the OpenAPI document: 1.0.0
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
777
|
-
* https://openapi-generator.tech
|
|
778
|
-
* Do not edit the class manually.
|
|
779
|
-
*/
|
|
780
|
-
var BrokerDataOrderStatusEnum;
|
|
781
|
-
(function (BrokerDataOrderStatusEnum) {
|
|
782
|
-
BrokerDataOrderStatusEnum["Submitted"] = "submitted";
|
|
783
|
-
BrokerDataOrderStatusEnum["New"] = "new";
|
|
784
|
-
BrokerDataOrderStatusEnum["PartiallyFilled"] = "partially_filled";
|
|
785
|
-
BrokerDataOrderStatusEnum["Filled"] = "filled";
|
|
786
|
-
BrokerDataOrderStatusEnum["PendingCancel"] = "pending_cancel";
|
|
787
|
-
BrokerDataOrderStatusEnum["Cancelled"] = "cancelled";
|
|
788
|
-
BrokerDataOrderStatusEnum["Rejected"] = "rejected";
|
|
789
|
-
BrokerDataOrderStatusEnum["Expired"] = "expired";
|
|
790
|
-
BrokerDataOrderStatusEnum["Created"] = "created";
|
|
791
|
-
BrokerDataOrderStatusEnum["Received"] = "received";
|
|
792
|
-
BrokerDataOrderStatusEnum["Queued"] = "queued";
|
|
793
|
-
})(BrokerDataOrderStatusEnum || (BrokerDataOrderStatusEnum = {}));
|
|
794
|
-
|
|
795
771
|
/* tslint:disable */
|
|
796
772
|
/* eslint-disable */
|
|
797
773
|
/**
|
|
@@ -1209,6 +1185,273 @@ var SessionStatus;
|
|
|
1209
1185
|
SessionStatus["Expired"] = "expired";
|
|
1210
1186
|
})(SessionStatus || (SessionStatus = {}));
|
|
1211
1187
|
|
|
1188
|
+
/**
|
|
1189
|
+
* Pagination utilities for TypeScript SDK.
|
|
1190
|
+
*
|
|
1191
|
+
* Provides PaginatedData class for wrapping paginated responses with helper methods.
|
|
1192
|
+
*/
|
|
1193
|
+
/**
|
|
1194
|
+
* PaginatedData wraps a data array with pagination metadata and helper methods.
|
|
1195
|
+
*
|
|
1196
|
+
* This class behaves like an array, so you can use it directly:
|
|
1197
|
+
* - paginatedData.length returns the number of items
|
|
1198
|
+
* - paginatedData[0] returns the first item
|
|
1199
|
+
* - paginatedData.forEach(...) works directly
|
|
1200
|
+
* - paginatedData.map(...) works directly
|
|
1201
|
+
*
|
|
1202
|
+
* It also provides pagination methods:
|
|
1203
|
+
* - hasMore: Check if there are more pages
|
|
1204
|
+
* - nextPage(): Get the next page
|
|
1205
|
+
* - prevPage(): Get the previous page
|
|
1206
|
+
* - firstPage(): Get the first page
|
|
1207
|
+
* - lastPage(): Get the last page
|
|
1208
|
+
*
|
|
1209
|
+
* @template T - The element type (e.g., FDXBrokerAccount)
|
|
1210
|
+
*
|
|
1211
|
+
* Usage:
|
|
1212
|
+
* ```typescript
|
|
1213
|
+
* const response = await sdk.getAccounts();
|
|
1214
|
+
* const accounts = response.success.data; // Can use directly as array!
|
|
1215
|
+
* console.log(accounts.length); // Works directly
|
|
1216
|
+
* console.log(accounts[0]); // Works directly
|
|
1217
|
+
* accounts.forEach(account => console.log(account)); // Works directly
|
|
1218
|
+
*
|
|
1219
|
+
* if (accounts.hasMore) {
|
|
1220
|
+
* const nextPage = await accounts.nextPage(); // Returns PaginatedData<FDXBrokerAccount>
|
|
1221
|
+
* const nextAccounts = nextPage; // Can use directly as array too!
|
|
1222
|
+
* }
|
|
1223
|
+
* ```
|
|
1224
|
+
*/
|
|
1225
|
+
class PaginatedData {
|
|
1226
|
+
constructor(items, // The actual data array
|
|
1227
|
+
meta,
|
|
1228
|
+
// Use any for method type since it's only called for paginated endpoints
|
|
1229
|
+
// and will return PaginatedData<T> at runtime
|
|
1230
|
+
originalMethod, currentParams, wrapperInstance // Reference to wrapper for method calls
|
|
1231
|
+
) {
|
|
1232
|
+
this.items = items;
|
|
1233
|
+
this.meta = meta;
|
|
1234
|
+
this.originalMethod = originalMethod;
|
|
1235
|
+
this.currentParams = currentParams;
|
|
1236
|
+
this.wrapperInstance = wrapperInstance;
|
|
1237
|
+
// Create a Proxy to allow array-like indexing (paginatedData[0])
|
|
1238
|
+
return new Proxy(this, {
|
|
1239
|
+
get(target, prop) {
|
|
1240
|
+
// Handle numeric indices
|
|
1241
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1242
|
+
return target.items[Number(prop)];
|
|
1243
|
+
}
|
|
1244
|
+
// Handle length property
|
|
1245
|
+
if (prop === 'length') {
|
|
1246
|
+
return target.items.length;
|
|
1247
|
+
}
|
|
1248
|
+
// Handle array methods and other properties
|
|
1249
|
+
return target[prop];
|
|
1250
|
+
},
|
|
1251
|
+
has(target, prop) {
|
|
1252
|
+
// Support 'in' operator
|
|
1253
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1254
|
+
return Number(prop) < target.items.length;
|
|
1255
|
+
}
|
|
1256
|
+
return prop in target;
|
|
1257
|
+
},
|
|
1258
|
+
ownKeys(target) {
|
|
1259
|
+
// Include numeric indices for Object.keys()
|
|
1260
|
+
const keys = Object.keys(target);
|
|
1261
|
+
for (let i = 0; i < target.items.length; i++) {
|
|
1262
|
+
keys.push(String(i));
|
|
1263
|
+
}
|
|
1264
|
+
return keys;
|
|
1265
|
+
},
|
|
1266
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
1267
|
+
if (typeof prop === 'string' && /^\d+$/.test(prop)) {
|
|
1268
|
+
const index = Number(prop);
|
|
1269
|
+
if (index < target.items.length) {
|
|
1270
|
+
return {
|
|
1271
|
+
enumerable: true,
|
|
1272
|
+
configurable: true,
|
|
1273
|
+
value: target.items[index],
|
|
1274
|
+
};
|
|
1275
|
+
}
|
|
1276
|
+
}
|
|
1277
|
+
return Object.getOwnPropertyDescriptor(target, prop);
|
|
1278
|
+
},
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
/**
|
|
1282
|
+
* Get the number of items (allows paginatedData.length).
|
|
1283
|
+
*/
|
|
1284
|
+
get length() {
|
|
1285
|
+
return this.items.length;
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Check if there are more pages available.
|
|
1289
|
+
*/
|
|
1290
|
+
get hasMore() {
|
|
1291
|
+
return this.meta.has_more;
|
|
1292
|
+
}
|
|
1293
|
+
// Array-like methods - delegate to items array
|
|
1294
|
+
/**
|
|
1295
|
+
* Calls a function for each element in the array.
|
|
1296
|
+
*/
|
|
1297
|
+
forEach(callbackfn, thisArg) {
|
|
1298
|
+
return this.items.forEach(callbackfn, thisArg);
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Creates a new array with the results of calling a function for every array element.
|
|
1302
|
+
*/
|
|
1303
|
+
map(callbackfn, thisArg) {
|
|
1304
|
+
return this.items.map(callbackfn, thisArg);
|
|
1305
|
+
}
|
|
1306
|
+
/**
|
|
1307
|
+
* Returns the elements of an array that meet the condition specified in a callback function.
|
|
1308
|
+
*/
|
|
1309
|
+
filter(callbackfn, thisArg) {
|
|
1310
|
+
return this.items.filter(callbackfn, thisArg);
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* Returns the value of the first element in the array where predicate is true.
|
|
1314
|
+
*/
|
|
1315
|
+
find(predicate, thisArg) {
|
|
1316
|
+
return this.items.find(predicate, thisArg);
|
|
1317
|
+
}
|
|
1318
|
+
/**
|
|
1319
|
+
* Returns the index of the first element in the array where predicate is true.
|
|
1320
|
+
*/
|
|
1321
|
+
findIndex(predicate, thisArg) {
|
|
1322
|
+
return this.items.findIndex(predicate, thisArg);
|
|
1323
|
+
}
|
|
1324
|
+
/**
|
|
1325
|
+
* Returns a section of an array.
|
|
1326
|
+
*/
|
|
1327
|
+
slice(start, end) {
|
|
1328
|
+
return this.items.slice(start, end);
|
|
1329
|
+
}
|
|
1330
|
+
/**
|
|
1331
|
+
* Determines whether an array includes a certain element.
|
|
1332
|
+
*/
|
|
1333
|
+
includes(searchElement, fromIndex) {
|
|
1334
|
+
return this.items.includes(searchElement, fromIndex);
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Returns the index of the first occurrence of a value in an array.
|
|
1338
|
+
*/
|
|
1339
|
+
indexOf(searchElement, fromIndex) {
|
|
1340
|
+
return this.items.indexOf(searchElement, fromIndex);
|
|
1341
|
+
}
|
|
1342
|
+
/**
|
|
1343
|
+
* Returns a string representation of an array.
|
|
1344
|
+
*/
|
|
1345
|
+
toString() {
|
|
1346
|
+
return this.items.toString();
|
|
1347
|
+
}
|
|
1348
|
+
/**
|
|
1349
|
+
* Returns a string representation of an array.
|
|
1350
|
+
*/
|
|
1351
|
+
toLocaleString() {
|
|
1352
|
+
return this.items.toLocaleString();
|
|
1353
|
+
}
|
|
1354
|
+
/**
|
|
1355
|
+
* Convert to JSON - returns just the items array for serialization.
|
|
1356
|
+
* This allows clean serialization without exposing internal methods.
|
|
1357
|
+
*
|
|
1358
|
+
* @returns The items array
|
|
1359
|
+
*
|
|
1360
|
+
* @example
|
|
1361
|
+
* ```typescript
|
|
1362
|
+
* const orders = await sdk.getOrders();
|
|
1363
|
+
* console.log(orders); // Shows full PaginatedData with methods
|
|
1364
|
+
* console.log(orders.toJSON()); // Shows just the items array
|
|
1365
|
+
* JSON.stringify(orders); // Automatically uses toJSON()
|
|
1366
|
+
* ```
|
|
1367
|
+
*/
|
|
1368
|
+
toJSON() {
|
|
1369
|
+
return this.items;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Get the next page of data.
|
|
1373
|
+
* @returns Promise<PaginatedData<T>> - The next page (not wrapped in FinaticResponse)
|
|
1374
|
+
* @throws Error if no more pages are available
|
|
1375
|
+
*/
|
|
1376
|
+
async nextPage() {
|
|
1377
|
+
if (!this.hasMore) {
|
|
1378
|
+
throw new Error('No more pages available');
|
|
1379
|
+
}
|
|
1380
|
+
if (this.meta.next_offset === null) {
|
|
1381
|
+
throw new Error('Next offset is null');
|
|
1382
|
+
}
|
|
1383
|
+
const newParams = {
|
|
1384
|
+
...this.currentParams,
|
|
1385
|
+
offset: this.meta.next_offset,
|
|
1386
|
+
};
|
|
1387
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1388
|
+
if (!response.success) {
|
|
1389
|
+
throw new Error(response.error?.message || 'Failed to fetch next page');
|
|
1390
|
+
}
|
|
1391
|
+
return response.success.data; // Return PaginatedData directly
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Get the previous page of data.
|
|
1395
|
+
* @returns Promise<PaginatedData<T>> - The previous page (not wrapped in FinaticResponse)
|
|
1396
|
+
* @throws Error if fetch fails
|
|
1397
|
+
*/
|
|
1398
|
+
async prevPage() {
|
|
1399
|
+
const prevOffset = Math.max(0, this.meta.current_offset - this.meta.limit);
|
|
1400
|
+
const newParams = {
|
|
1401
|
+
...this.currentParams,
|
|
1402
|
+
offset: prevOffset,
|
|
1403
|
+
};
|
|
1404
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1405
|
+
if (!response.success) {
|
|
1406
|
+
throw new Error(response.error?.message || 'Failed to fetch previous page');
|
|
1407
|
+
}
|
|
1408
|
+
return response.success.data; // Return PaginatedData directly
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Get the first page of data.
|
|
1412
|
+
* @returns Promise<PaginatedData<T>> - The first page (not wrapped in FinaticResponse)
|
|
1413
|
+
* @throws Error if fetch fails
|
|
1414
|
+
*/
|
|
1415
|
+
async firstPage() {
|
|
1416
|
+
const newParams = {
|
|
1417
|
+
...this.currentParams,
|
|
1418
|
+
offset: 0,
|
|
1419
|
+
};
|
|
1420
|
+
const response = await this.originalMethod.call(this.wrapperInstance, newParams);
|
|
1421
|
+
if (!response.success) {
|
|
1422
|
+
throw new Error(response.error?.message || 'Failed to fetch first page');
|
|
1423
|
+
}
|
|
1424
|
+
return response.success.data; // Return PaginatedData directly
|
|
1425
|
+
}
|
|
1426
|
+
/**
|
|
1427
|
+
* Get the last page of data.
|
|
1428
|
+
* Uses iterative approach to find the last page.
|
|
1429
|
+
* @returns Promise<PaginatedData<T>> - The last page (not wrapped in FinaticResponse)
|
|
1430
|
+
* @throws Error if fetch fails
|
|
1431
|
+
*/
|
|
1432
|
+
async lastPage() {
|
|
1433
|
+
// Iterative approach to find last page
|
|
1434
|
+
let currentOffset = this.meta.current_offset;
|
|
1435
|
+
let lastValidData = null;
|
|
1436
|
+
while (true) {
|
|
1437
|
+
const testParams = { ...this.currentParams, offset: currentOffset };
|
|
1438
|
+
const response = await this.originalMethod.call(this.wrapperInstance, testParams);
|
|
1439
|
+
if (!response.success) {
|
|
1440
|
+
break;
|
|
1441
|
+
}
|
|
1442
|
+
lastValidData = response.success.data;
|
|
1443
|
+
if (!lastValidData || !lastValidData.hasMore) {
|
|
1444
|
+
break;
|
|
1445
|
+
}
|
|
1446
|
+
currentOffset += this.meta.limit;
|
|
1447
|
+
}
|
|
1448
|
+
if (!lastValidData) {
|
|
1449
|
+
throw new Error('Failed to fetch last page');
|
|
1450
|
+
}
|
|
1451
|
+
return lastValidData; // Return PaginatedData directly
|
|
1452
|
+
}
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1212
1455
|
/**
|
|
1213
1456
|
* Generated wrapper functions for brokers operations (Phase 2A).
|
|
1214
1457
|
*
|
|
@@ -1258,7 +1501,7 @@ class BrokersWrapper {
|
|
|
1258
1501
|
* -------
|
|
1259
1502
|
* FinaticResponse[list[BrokerInfo]]
|
|
1260
1503
|
* list of available brokers with their metadata.
|
|
1261
|
-
* @param No parameters required for this method
|
|
1504
|
+
* @param params No parameters required for this method
|
|
1262
1505
|
* @returns {Promise<FinaticResponse<BrokerInfo[]>>} Standard response with success/Error/Warning structure
|
|
1263
1506
|
*
|
|
1264
1507
|
* Generated from: GET /api/v1/brokers/
|
|
@@ -1267,7 +1510,7 @@ class BrokersWrapper {
|
|
|
1267
1510
|
* @example
|
|
1268
1511
|
* ```typescript-client
|
|
1269
1512
|
* // Example with no parameters
|
|
1270
|
-
* const result = await finatic.getBrokers();
|
|
1513
|
+
* const result = await finatic.getBrokers({});
|
|
1271
1514
|
*
|
|
1272
1515
|
* // Access the response data
|
|
1273
1516
|
* if (result.success) {
|
|
@@ -1275,9 +1518,9 @@ class BrokersWrapper {
|
|
|
1275
1518
|
* }
|
|
1276
1519
|
* ```
|
|
1277
1520
|
*/
|
|
1278
|
-
async getBrokers() {
|
|
1521
|
+
async getBrokers(params) {
|
|
1279
1522
|
// No parameters - use empty params object
|
|
1280
|
-
const
|
|
1523
|
+
const resolvedParams = params || {}; // Generate request ID
|
|
1281
1524
|
const requestId = this._generateRequestId();
|
|
1282
1525
|
// Input validation (Phase 2B: zod)
|
|
1283
1526
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -1285,7 +1528,7 @@ class BrokersWrapper {
|
|
|
1285
1528
|
const shouldCache = true;
|
|
1286
1529
|
const cache = getCache(this.sdkConfig);
|
|
1287
1530
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1288
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/',
|
|
1531
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
|
|
1289
1532
|
const cached = cache.get(cacheKey);
|
|
1290
1533
|
if (cached) {
|
|
1291
1534
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1297,7 +1540,7 @@ class BrokersWrapper {
|
|
|
1297
1540
|
request_id: requestId,
|
|
1298
1541
|
method: 'GET',
|
|
1299
1542
|
path: '/api/v1/brokers/',
|
|
1300
|
-
params:
|
|
1543
|
+
params: resolvedParams,
|
|
1301
1544
|
action: 'getBrokers'
|
|
1302
1545
|
});
|
|
1303
1546
|
try {
|
|
@@ -1311,9 +1554,15 @@ class BrokersWrapper {
|
|
|
1311
1554
|
throw new Error('Unexpected response shape: missing success field');
|
|
1312
1555
|
}
|
|
1313
1556
|
// Convert response to plain object, removing _id fields recursively
|
|
1557
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1314
1558
|
const standardResponse = convertToPlainObject(responseData);
|
|
1559
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1560
|
+
const hasLimit = false;
|
|
1561
|
+
const hasOffset = false;
|
|
1562
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1563
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1315
1564
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1316
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/',
|
|
1565
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/', resolvedParams, this.sdkConfig);
|
|
1317
1566
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1318
1567
|
}
|
|
1319
1568
|
this.logger.debug('Get Brokers completed', {
|
|
@@ -1321,6 +1570,7 @@ class BrokersWrapper {
|
|
|
1321
1570
|
action: 'getBrokers'
|
|
1322
1571
|
});
|
|
1323
1572
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1573
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1324
1574
|
return standardResponse;
|
|
1325
1575
|
}
|
|
1326
1576
|
catch (error) {
|
|
@@ -1398,7 +1648,7 @@ class BrokersWrapper {
|
|
|
1398
1648
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1399
1649
|
* Returns connections that the user has any permissions for, including the current
|
|
1400
1650
|
* company's permissions (read/write) for each connection.
|
|
1401
|
-
* @param No parameters required for this method
|
|
1651
|
+
* @param params No parameters required for this method
|
|
1402
1652
|
* @returns {Promise<FinaticResponse<UserBrokerConnectionWithPermissions[]>>} Standard response with success/Error/Warning structure
|
|
1403
1653
|
*
|
|
1404
1654
|
* Generated from: GET /api/v1/brokers/connections
|
|
@@ -1407,7 +1657,7 @@ class BrokersWrapper {
|
|
|
1407
1657
|
* @example
|
|
1408
1658
|
* ```typescript-client
|
|
1409
1659
|
* // Example with no parameters
|
|
1410
|
-
* const result = await finatic.getBrokerConnections();
|
|
1660
|
+
* const result = await finatic.getBrokerConnections({});
|
|
1411
1661
|
*
|
|
1412
1662
|
* // Access the response data
|
|
1413
1663
|
* if (result.success) {
|
|
@@ -1415,10 +1665,10 @@ class BrokersWrapper {
|
|
|
1415
1665
|
* }
|
|
1416
1666
|
* ```
|
|
1417
1667
|
*/
|
|
1418
|
-
async getBrokerConnections() {
|
|
1668
|
+
async getBrokerConnections(params) {
|
|
1419
1669
|
// No parameters - use empty params object
|
|
1420
|
-
const
|
|
1421
|
-
if (!this.sessionId) {
|
|
1670
|
+
const resolvedParams = params || {}; // Authentication check
|
|
1671
|
+
if (!this.sessionId || !this.companyId) {
|
|
1422
1672
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1423
1673
|
}
|
|
1424
1674
|
// Generate request ID
|
|
@@ -1429,7 +1679,7 @@ class BrokersWrapper {
|
|
|
1429
1679
|
const shouldCache = true;
|
|
1430
1680
|
const cache = getCache(this.sdkConfig);
|
|
1431
1681
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1432
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections',
|
|
1682
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
|
|
1433
1683
|
const cached = cache.get(cacheKey);
|
|
1434
1684
|
if (cached) {
|
|
1435
1685
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1441,12 +1691,12 @@ class BrokersWrapper {
|
|
|
1441
1691
|
request_id: requestId,
|
|
1442
1692
|
method: 'GET',
|
|
1443
1693
|
path: '/api/v1/brokers/connections',
|
|
1444
|
-
params:
|
|
1694
|
+
params: resolvedParams,
|
|
1445
1695
|
action: 'getBrokerConnections'
|
|
1446
1696
|
});
|
|
1447
1697
|
try {
|
|
1448
1698
|
const response = await retryApiCall(async () => {
|
|
1449
|
-
const apiResponse = await this.api.listBrokerConnectionsApiV1BrokersConnectionsGet({ headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
1699
|
+
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 } : {}) } : {}) } });
|
|
1450
1700
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1451
1701
|
}, {}, this.sdkConfig);
|
|
1452
1702
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1455,9 +1705,15 @@ class BrokersWrapper {
|
|
|
1455
1705
|
throw new Error('Unexpected response shape: missing success field');
|
|
1456
1706
|
}
|
|
1457
1707
|
// Convert response to plain object, removing _id fields recursively
|
|
1708
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1458
1709
|
const standardResponse = convertToPlainObject(responseData);
|
|
1710
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1711
|
+
const hasLimit = false;
|
|
1712
|
+
const hasOffset = false;
|
|
1713
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1714
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1459
1715
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1460
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections',
|
|
1716
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/connections', resolvedParams, this.sdkConfig);
|
|
1461
1717
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1462
1718
|
}
|
|
1463
1719
|
this.logger.debug('List Broker Connections completed', {
|
|
@@ -1465,6 +1721,7 @@ class BrokersWrapper {
|
|
|
1465
1721
|
action: 'getBrokerConnections'
|
|
1466
1722
|
});
|
|
1467
1723
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1724
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1468
1725
|
return standardResponse;
|
|
1469
1726
|
}
|
|
1470
1727
|
catch (error) {
|
|
@@ -1541,7 +1798,7 @@ class BrokersWrapper {
|
|
|
1541
1798
|
*
|
|
1542
1799
|
* If the company is the only one with access, the entire connection is deleted.
|
|
1543
1800
|
* If other companies have access, only the company's access is removed.
|
|
1544
|
-
* @param connectionId {string}
|
|
1801
|
+
* @param params.connectionId {string} Connection ID
|
|
1545
1802
|
* @returns {Promise<FinaticResponse<DisconnectActionResult>>} Standard response with success/Error/Warning structure
|
|
1546
1803
|
*
|
|
1547
1804
|
* Generated from: DELETE /api/v1/brokers/disconnect-company/{connection_id}
|
|
@@ -1550,7 +1807,9 @@ class BrokersWrapper {
|
|
|
1550
1807
|
* @example
|
|
1551
1808
|
* ```typescript-client
|
|
1552
1809
|
* // Minimal example with required parameters only
|
|
1553
|
-
* const result = await finatic.disconnectCompanyFromBroker(
|
|
1810
|
+
* const result = await finatic.disconnectCompanyFromBroker({
|
|
1811
|
+
connectionId: '00000000-0000-0000-0000-000000000000'
|
|
1812
|
+
* });
|
|
1554
1813
|
*
|
|
1555
1814
|
* // Access the response data
|
|
1556
1815
|
* if (result.success) {
|
|
@@ -1560,12 +1819,10 @@ class BrokersWrapper {
|
|
|
1560
1819
|
* }
|
|
1561
1820
|
* ```
|
|
1562
1821
|
*/
|
|
1563
|
-
async disconnectCompanyFromBroker(
|
|
1564
|
-
//
|
|
1565
|
-
const
|
|
1566
|
-
|
|
1567
|
-
}; // Authentication check
|
|
1568
|
-
if (!this.sessionId) {
|
|
1822
|
+
async disconnectCompanyFromBroker(params) {
|
|
1823
|
+
// Use params object (required parameters present)
|
|
1824
|
+
const resolvedParams = params; // Authentication check
|
|
1825
|
+
if (!this.sessionId || !this.companyId) {
|
|
1569
1826
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1570
1827
|
}
|
|
1571
1828
|
// Generate request ID
|
|
@@ -1576,7 +1833,7 @@ class BrokersWrapper {
|
|
|
1576
1833
|
const shouldCache = true;
|
|
1577
1834
|
const cache = getCache(this.sdkConfig);
|
|
1578
1835
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1579
|
-
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1836
|
+
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
|
|
1580
1837
|
const cached = cache.get(cacheKey);
|
|
1581
1838
|
if (cached) {
|
|
1582
1839
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1588,12 +1845,12 @@ class BrokersWrapper {
|
|
|
1588
1845
|
request_id: requestId,
|
|
1589
1846
|
method: 'DELETE',
|
|
1590
1847
|
path: '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1591
|
-
params:
|
|
1848
|
+
params: resolvedParams,
|
|
1592
1849
|
action: 'disconnectCompanyFromBroker'
|
|
1593
1850
|
});
|
|
1594
1851
|
try {
|
|
1595
1852
|
const response = await retryApiCall(async () => {
|
|
1596
|
-
const apiResponse = await this.api.disconnectCompanyFromBrokerApiV1BrokersDisconnectCompanyConnectionIdDelete({ connectionId: connectionId }, { headers: { 'x-session-id': this.sessionId, 'x-company-id': this.companyId, 'x-csrf-token': this.csrfToken
|
|
1853
|
+
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 } : {}) } : {}) } });
|
|
1597
1854
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1598
1855
|
}, {}, this.sdkConfig);
|
|
1599
1856
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1602,9 +1859,15 @@ class BrokersWrapper {
|
|
|
1602
1859
|
throw new Error('Unexpected response shape: missing success field');
|
|
1603
1860
|
}
|
|
1604
1861
|
// Convert response to plain object, removing _id fields recursively
|
|
1862
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1605
1863
|
const standardResponse = convertToPlainObject(responseData);
|
|
1864
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
1865
|
+
const hasLimit = false;
|
|
1866
|
+
const hasOffset = false;
|
|
1867
|
+
const hasPagination = hasLimit && hasOffset;
|
|
1868
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
1606
1869
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1607
|
-
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}',
|
|
1870
|
+
const cacheKey = generateCacheKey('DELETE', '/api/v1/brokers/disconnect-company/{connection_id}', resolvedParams, this.sdkConfig);
|
|
1608
1871
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1609
1872
|
}
|
|
1610
1873
|
this.logger.debug('Disconnect Company From Broker completed', {
|
|
@@ -1612,6 +1875,7 @@ class BrokersWrapper {
|
|
|
1612
1875
|
action: 'disconnectCompanyFromBroker'
|
|
1613
1876
|
});
|
|
1614
1877
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
1878
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1615
1879
|
return standardResponse;
|
|
1616
1880
|
}
|
|
1617
1881
|
catch (error) {
|
|
@@ -1688,19 +1952,19 @@ class BrokersWrapper {
|
|
|
1688
1952
|
*
|
|
1689
1953
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1690
1954
|
* Returns orders from connections the company has read access to.
|
|
1691
|
-
* @param brokerId {string} (optional)
|
|
1692
|
-
* @param connectionId {string} (optional)
|
|
1693
|
-
* @param accountId {string} (optional)
|
|
1694
|
-
* @param symbol {string} (optional)
|
|
1695
|
-
* @param orderStatus {
|
|
1696
|
-
* @param side {BrokerDataOrderSideEnum} (optional)
|
|
1697
|
-
* @param assetType {BrokerDataAssetTypeEnum} (optional)
|
|
1698
|
-
* @param limit {number} (optional)
|
|
1699
|
-
* @param offset {number} (optional)
|
|
1700
|
-
* @param createdAfter {string} (optional)
|
|
1701
|
-
* @param createdBefore {string} (optional)
|
|
1702
|
-
* @param includeMetadata {boolean} (optional)
|
|
1703
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrder
|
|
1955
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
1956
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
1957
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID or internal account UUID
|
|
1958
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
1959
|
+
* @param params.orderStatus {string} (optional) Filter by order status (e.g., 'filled', 'pending_new', 'cancelled')
|
|
1960
|
+
* @param params.side {BrokerDataOrderSideEnum} (optional) Filter by order side (e.g., 'buy', 'sell')
|
|
1961
|
+
* @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
|
|
1962
|
+
* @param params.limit {number} (optional) Maximum number of orders to return
|
|
1963
|
+
* @param params.offset {number} (optional) Number of orders to skip for pagination
|
|
1964
|
+
* @param params.createdAfter {string} (optional) Filter orders created after this timestamp
|
|
1965
|
+
* @param params.createdBefore {string} (optional) Filter orders created before this timestamp
|
|
1966
|
+
* @param params.includeMetadata {boolean} (optional) Include order metadata in response (excluded by default for FDX compliance)
|
|
1967
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrder>>>} Standard response with success/Error/Warning structure
|
|
1704
1968
|
*
|
|
1705
1969
|
* Generated from: GET /api/v1/brokers/data/orders
|
|
1706
1970
|
* @methodId get_orders_api_v1_brokers_data_orders_get
|
|
@@ -1708,7 +1972,7 @@ class BrokersWrapper {
|
|
|
1708
1972
|
* @example
|
|
1709
1973
|
* ```typescript-client
|
|
1710
1974
|
* // Example with no parameters
|
|
1711
|
-
* const result = await finatic.getOrders();
|
|
1975
|
+
* const result = await finatic.getOrders({});
|
|
1712
1976
|
*
|
|
1713
1977
|
* // Access the response data
|
|
1714
1978
|
* if (result.success) {
|
|
@@ -1718,7 +1982,11 @@ class BrokersWrapper {
|
|
|
1718
1982
|
* @example
|
|
1719
1983
|
* ```typescript-client
|
|
1720
1984
|
* // Full example with optional parameters
|
|
1721
|
-
* const result = await finatic.getOrders(
|
|
1985
|
+
* const result = await finatic.getOrders({
|
|
1986
|
+
brokerId: 'alpaca',
|
|
1987
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
1988
|
+
accountId: '123456789'
|
|
1989
|
+
* });
|
|
1722
1990
|
*
|
|
1723
1991
|
* // Handle response with warnings
|
|
1724
1992
|
* if (result.success) {
|
|
@@ -1731,23 +1999,22 @@ class BrokersWrapper {
|
|
|
1731
1999
|
* }
|
|
1732
2000
|
* ```
|
|
1733
2001
|
*/
|
|
1734
|
-
async getOrders(
|
|
1735
|
-
//
|
|
1736
|
-
const
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
if (!this.sessionId) {
|
|
2002
|
+
async getOrders(params) {
|
|
2003
|
+
// Use params object (with default empty object)
|
|
2004
|
+
const resolvedParams = params || {};
|
|
2005
|
+
if (params?.side !== undefined) {
|
|
2006
|
+
const coerced = coerceEnumValue(params.side, BrokerDataOrderSideEnum, 'side');
|
|
2007
|
+
if (coerced !== undefined) {
|
|
2008
|
+
params.side = coerced;
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if (params?.assetType !== undefined) {
|
|
2012
|
+
const coerced = coerceEnumValue(params.assetType, BrokerDataAssetTypeEnum, 'assetType');
|
|
2013
|
+
if (coerced !== undefined) {
|
|
2014
|
+
params.assetType = coerced;
|
|
2015
|
+
}
|
|
2016
|
+
} // Authentication check
|
|
2017
|
+
if (!this.sessionId || !this.companyId) {
|
|
1751
2018
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1752
2019
|
}
|
|
1753
2020
|
// Generate request ID
|
|
@@ -1758,7 +2025,7 @@ class BrokersWrapper {
|
|
|
1758
2025
|
const shouldCache = true;
|
|
1759
2026
|
const cache = getCache(this.sdkConfig);
|
|
1760
2027
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1761
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders',
|
|
2028
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
|
|
1762
2029
|
const cached = cache.get(cacheKey);
|
|
1763
2030
|
if (cached) {
|
|
1764
2031
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1770,12 +2037,12 @@ class BrokersWrapper {
|
|
|
1770
2037
|
request_id: requestId,
|
|
1771
2038
|
method: 'GET',
|
|
1772
2039
|
path: '/api/v1/brokers/data/orders',
|
|
1773
|
-
params:
|
|
2040
|
+
params: resolvedParams,
|
|
1774
2041
|
action: 'getOrders'
|
|
1775
2042
|
});
|
|
1776
2043
|
try {
|
|
1777
2044
|
const response = await retryApiCall(async () => {
|
|
1778
|
-
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
|
|
2045
|
+
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 } : {}) } : {}) } });
|
|
1779
2046
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1780
2047
|
}, {}, this.sdkConfig);
|
|
1781
2048
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1784,9 +2051,27 @@ class BrokersWrapper {
|
|
|
1784
2051
|
throw new Error('Unexpected response shape: missing success field');
|
|
1785
2052
|
}
|
|
1786
2053
|
// Convert response to plain object, removing _id fields recursively
|
|
2054
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1787
2055
|
const standardResponse = convertToPlainObject(responseData);
|
|
2056
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2057
|
+
const hasLimit = true;
|
|
2058
|
+
const hasOffset = true;
|
|
2059
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2060
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2061
|
+
// PaginatedData is already imported at top of file
|
|
2062
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2063
|
+
if (paginationMeta) {
|
|
2064
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2065
|
+
has_more: paginationMeta.has_more,
|
|
2066
|
+
next_offset: paginationMeta.next_offset,
|
|
2067
|
+
current_offset: paginationMeta.current_offset,
|
|
2068
|
+
limit: paginationMeta.limit,
|
|
2069
|
+
}, this.getOrders.bind(this), resolvedParams, this);
|
|
2070
|
+
standardResponse.success.data = paginatedData;
|
|
2071
|
+
}
|
|
2072
|
+
}
|
|
1788
2073
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1789
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders',
|
|
2074
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders', resolvedParams, this.sdkConfig);
|
|
1790
2075
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1791
2076
|
}
|
|
1792
2077
|
this.logger.debug('Get Orders completed', {
|
|
@@ -1794,6 +2079,7 @@ class BrokersWrapper {
|
|
|
1794
2079
|
action: 'getOrders'
|
|
1795
2080
|
});
|
|
1796
2081
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2082
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1797
2083
|
return standardResponse;
|
|
1798
2084
|
}
|
|
1799
2085
|
catch (error) {
|
|
@@ -1870,19 +2156,19 @@ class BrokersWrapper {
|
|
|
1870
2156
|
*
|
|
1871
2157
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
1872
2158
|
* Returns positions from connections the company has read access to.
|
|
1873
|
-
* @param brokerId {string} (optional)
|
|
1874
|
-
* @param connectionId {string} (optional)
|
|
1875
|
-
* @param accountId {string} (optional)
|
|
1876
|
-
* @param symbol {string} (optional)
|
|
1877
|
-
* @param side {BrokerDataOrderSideEnum} (optional)
|
|
1878
|
-
* @param assetType {BrokerDataAssetTypeEnum} (optional)
|
|
1879
|
-
* @param positionStatus {BrokerDataPositionStatusEnum} (optional)
|
|
1880
|
-
* @param limit {number} (optional)
|
|
1881
|
-
* @param offset {number} (optional)
|
|
1882
|
-
* @param updatedAfter {string} (optional)
|
|
1883
|
-
* @param updatedBefore {string} (optional)
|
|
1884
|
-
* @param includeMetadata {boolean} (optional)
|
|
1885
|
-
* @returns {Promise<FinaticResponse<FDXBrokerPosition
|
|
2159
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2160
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2161
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID or internal account UUID
|
|
2162
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
2163
|
+
* @param params.side {BrokerDataOrderSideEnum} (optional) Filter by position side (e.g., 'long', 'short')
|
|
2164
|
+
* @param params.assetType {BrokerDataAssetTypeEnum} (optional) Filter by asset type (e.g., 'stock', 'option', 'crypto', 'future')
|
|
2165
|
+
* @param params.positionStatus {BrokerDataPositionStatusEnum} (optional) Filter by position status: 'open' (quantity > 0) or 'closed' (quantity = 0)
|
|
2166
|
+
* @param params.limit {number} (optional) Maximum number of positions to return
|
|
2167
|
+
* @param params.offset {number} (optional) Number of positions to skip for pagination
|
|
2168
|
+
* @param params.updatedAfter {string} (optional) Filter positions updated after this timestamp
|
|
2169
|
+
* @param params.updatedBefore {string} (optional) Filter positions updated before this timestamp
|
|
2170
|
+
* @param params.includeMetadata {boolean} (optional) Include position metadata in response (excluded by default for FDX compliance)
|
|
2171
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPosition>>>} Standard response with success/Error/Warning structure
|
|
1886
2172
|
*
|
|
1887
2173
|
* Generated from: GET /api/v1/brokers/data/positions
|
|
1888
2174
|
* @methodId get_positions_api_v1_brokers_data_positions_get
|
|
@@ -1890,7 +2176,7 @@ class BrokersWrapper {
|
|
|
1890
2176
|
* @example
|
|
1891
2177
|
* ```typescript-client
|
|
1892
2178
|
* // Example with no parameters
|
|
1893
|
-
* const result = await finatic.getPositions();
|
|
2179
|
+
* const result = await finatic.getPositions({});
|
|
1894
2180
|
*
|
|
1895
2181
|
* // Access the response data
|
|
1896
2182
|
* if (result.success) {
|
|
@@ -1900,7 +2186,11 @@ class BrokersWrapper {
|
|
|
1900
2186
|
* @example
|
|
1901
2187
|
* ```typescript-client
|
|
1902
2188
|
* // Full example with optional parameters
|
|
1903
|
-
* const result = await finatic.getPositions(
|
|
2189
|
+
* const result = await finatic.getPositions({
|
|
2190
|
+
brokerId: 'alpaca',
|
|
2191
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2192
|
+
accountId: '123456789'
|
|
2193
|
+
* });
|
|
1904
2194
|
*
|
|
1905
2195
|
* // Handle response with warnings
|
|
1906
2196
|
* if (result.success) {
|
|
@@ -1913,23 +2203,28 @@ class BrokersWrapper {
|
|
|
1913
2203
|
* }
|
|
1914
2204
|
* ```
|
|
1915
2205
|
*/
|
|
1916
|
-
async getPositions(
|
|
1917
|
-
//
|
|
1918
|
-
const
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
2206
|
+
async getPositions(params) {
|
|
2207
|
+
// Use params object (with default empty object)
|
|
2208
|
+
const resolvedParams = params || {};
|
|
2209
|
+
if (params?.side !== undefined) {
|
|
2210
|
+
const coerced = coerceEnumValue(params.side, BrokerDataOrderSideEnum, 'side');
|
|
2211
|
+
if (coerced !== undefined) {
|
|
2212
|
+
params.side = coerced;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
if (params?.assetType !== undefined) {
|
|
2216
|
+
const coerced = coerceEnumValue(params.assetType, BrokerDataAssetTypeEnum, 'assetType');
|
|
2217
|
+
if (coerced !== undefined) {
|
|
2218
|
+
params.assetType = coerced;
|
|
2219
|
+
}
|
|
2220
|
+
}
|
|
2221
|
+
if (params?.positionStatus !== undefined) {
|
|
2222
|
+
const coerced = coerceEnumValue(params.positionStatus, BrokerDataPositionStatusEnum, 'positionStatus');
|
|
2223
|
+
if (coerced !== undefined) {
|
|
2224
|
+
params.positionStatus = coerced;
|
|
2225
|
+
}
|
|
2226
|
+
} // Authentication check
|
|
2227
|
+
if (!this.sessionId || !this.companyId) {
|
|
1933
2228
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
1934
2229
|
}
|
|
1935
2230
|
// Generate request ID
|
|
@@ -1940,7 +2235,7 @@ class BrokersWrapper {
|
|
|
1940
2235
|
const shouldCache = true;
|
|
1941
2236
|
const cache = getCache(this.sdkConfig);
|
|
1942
2237
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1943
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions',
|
|
2238
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
|
|
1944
2239
|
const cached = cache.get(cacheKey);
|
|
1945
2240
|
if (cached) {
|
|
1946
2241
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -1952,12 +2247,12 @@ class BrokersWrapper {
|
|
|
1952
2247
|
request_id: requestId,
|
|
1953
2248
|
method: 'GET',
|
|
1954
2249
|
path: '/api/v1/brokers/data/positions',
|
|
1955
|
-
params:
|
|
2250
|
+
params: resolvedParams,
|
|
1956
2251
|
action: 'getPositions'
|
|
1957
2252
|
});
|
|
1958
2253
|
try {
|
|
1959
2254
|
const response = await retryApiCall(async () => {
|
|
1960
|
-
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
|
|
2255
|
+
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 } : {}) } : {}) } });
|
|
1961
2256
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
1962
2257
|
}, {}, this.sdkConfig);
|
|
1963
2258
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -1966,9 +2261,27 @@ class BrokersWrapper {
|
|
|
1966
2261
|
throw new Error('Unexpected response shape: missing success field');
|
|
1967
2262
|
}
|
|
1968
2263
|
// Convert response to plain object, removing _id fields recursively
|
|
2264
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
1969
2265
|
const standardResponse = convertToPlainObject(responseData);
|
|
2266
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2267
|
+
const hasLimit = true;
|
|
2268
|
+
const hasOffset = true;
|
|
2269
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2270
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2271
|
+
// PaginatedData is already imported at top of file
|
|
2272
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2273
|
+
if (paginationMeta) {
|
|
2274
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2275
|
+
has_more: paginationMeta.has_more,
|
|
2276
|
+
next_offset: paginationMeta.next_offset,
|
|
2277
|
+
current_offset: paginationMeta.current_offset,
|
|
2278
|
+
limit: paginationMeta.limit,
|
|
2279
|
+
}, this.getPositions.bind(this), resolvedParams, this);
|
|
2280
|
+
standardResponse.success.data = paginatedData;
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
1970
2283
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
1971
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions',
|
|
2284
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions', resolvedParams, this.sdkConfig);
|
|
1972
2285
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
1973
2286
|
}
|
|
1974
2287
|
this.logger.debug('Get Positions completed', {
|
|
@@ -1976,6 +2289,7 @@ class BrokersWrapper {
|
|
|
1976
2289
|
action: 'getPositions'
|
|
1977
2290
|
});
|
|
1978
2291
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2292
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
1979
2293
|
return standardResponse;
|
|
1980
2294
|
}
|
|
1981
2295
|
catch (error) {
|
|
@@ -2052,16 +2366,16 @@ class BrokersWrapper {
|
|
|
2052
2366
|
*
|
|
2053
2367
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
2054
2368
|
* Returns balances from connections the company has read access to.
|
|
2055
|
-
* @param brokerId {string} (optional)
|
|
2056
|
-
* @param connectionId {string} (optional)
|
|
2057
|
-
* @param accountId {string} (optional)
|
|
2058
|
-
* @param isEndOfDaySnapshot {boolean} (optional)
|
|
2059
|
-
* @param limit {number} (optional)
|
|
2060
|
-
* @param offset {number} (optional)
|
|
2061
|
-
* @param balanceCreatedAfter {string} (optional)
|
|
2062
|
-
* @param balanceCreatedBefore {string} (optional)
|
|
2063
|
-
* @param includeMetadata {boolean} (optional)
|
|
2064
|
-
* @returns {Promise<FinaticResponse<FDXBrokerBalance
|
|
2369
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2370
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2371
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID or internal account UUID
|
|
2372
|
+
* @param params.isEndOfDaySnapshot {boolean} (optional) Filter by end-of-day snapshot status (true/false)
|
|
2373
|
+
* @param params.limit {number} (optional) Maximum number of balances to return
|
|
2374
|
+
* @param params.offset {number} (optional) Number of balances to skip for pagination
|
|
2375
|
+
* @param params.balanceCreatedAfter {string} (optional) Filter balances created after this timestamp
|
|
2376
|
+
* @param params.balanceCreatedBefore {string} (optional) Filter balances created before this timestamp
|
|
2377
|
+
* @param params.includeMetadata {boolean} (optional) Include balance metadata in response (excluded by default for FDX compliance)
|
|
2378
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerBalance>>>} Standard response with success/Error/Warning structure
|
|
2065
2379
|
*
|
|
2066
2380
|
* Generated from: GET /api/v1/brokers/data/balances
|
|
2067
2381
|
* @methodId get_balances_api_v1_brokers_data_balances_get
|
|
@@ -2069,7 +2383,7 @@ class BrokersWrapper {
|
|
|
2069
2383
|
* @example
|
|
2070
2384
|
* ```typescript-client
|
|
2071
2385
|
* // Example with no parameters
|
|
2072
|
-
* const result = await finatic.getBalances();
|
|
2386
|
+
* const result = await finatic.getBalances({});
|
|
2073
2387
|
*
|
|
2074
2388
|
* // Access the response data
|
|
2075
2389
|
* if (result.success) {
|
|
@@ -2079,7 +2393,11 @@ class BrokersWrapper {
|
|
|
2079
2393
|
* @example
|
|
2080
2394
|
* ```typescript-client
|
|
2081
2395
|
* // Full example with optional parameters
|
|
2082
|
-
* const result = await finatic.getBalances(
|
|
2396
|
+
* const result = await finatic.getBalances({
|
|
2397
|
+
brokerId: 'alpaca',
|
|
2398
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2399
|
+
accountId: '123456789'
|
|
2400
|
+
* });
|
|
2083
2401
|
*
|
|
2084
2402
|
* // Handle response with warnings
|
|
2085
2403
|
* if (result.success) {
|
|
@@ -2092,20 +2410,10 @@ class BrokersWrapper {
|
|
|
2092
2410
|
* }
|
|
2093
2411
|
* ```
|
|
2094
2412
|
*/
|
|
2095
|
-
async getBalances(
|
|
2096
|
-
//
|
|
2097
|
-
const
|
|
2098
|
-
|
|
2099
|
-
connectionId: connectionId,
|
|
2100
|
-
accountId: accountId,
|
|
2101
|
-
isEndOfDaySnapshot: isEndOfDaySnapshot,
|
|
2102
|
-
limit: limit,
|
|
2103
|
-
offset: offset,
|
|
2104
|
-
balanceCreatedAfter: balanceCreatedAfter,
|
|
2105
|
-
balanceCreatedBefore: balanceCreatedBefore,
|
|
2106
|
-
includeMetadata: includeMetadata
|
|
2107
|
-
}; // Authentication check
|
|
2108
|
-
if (!this.sessionId) {
|
|
2413
|
+
async getBalances(params) {
|
|
2414
|
+
// Use params object (with default empty object)
|
|
2415
|
+
const resolvedParams = params || {}; // Authentication check
|
|
2416
|
+
if (!this.sessionId || !this.companyId) {
|
|
2109
2417
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2110
2418
|
}
|
|
2111
2419
|
// Generate request ID
|
|
@@ -2116,7 +2424,7 @@ class BrokersWrapper {
|
|
|
2116
2424
|
const shouldCache = true;
|
|
2117
2425
|
const cache = getCache(this.sdkConfig);
|
|
2118
2426
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2119
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances',
|
|
2427
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
|
|
2120
2428
|
const cached = cache.get(cacheKey);
|
|
2121
2429
|
if (cached) {
|
|
2122
2430
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2128,12 +2436,12 @@ class BrokersWrapper {
|
|
|
2128
2436
|
request_id: requestId,
|
|
2129
2437
|
method: 'GET',
|
|
2130
2438
|
path: '/api/v1/brokers/data/balances',
|
|
2131
|
-
params:
|
|
2439
|
+
params: resolvedParams,
|
|
2132
2440
|
action: 'getBalances'
|
|
2133
2441
|
});
|
|
2134
2442
|
try {
|
|
2135
2443
|
const response = await retryApiCall(async () => {
|
|
2136
|
-
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
|
|
2444
|
+
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 } : {}) } : {}) } });
|
|
2137
2445
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2138
2446
|
}, {}, this.sdkConfig);
|
|
2139
2447
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2142,9 +2450,27 @@ class BrokersWrapper {
|
|
|
2142
2450
|
throw new Error('Unexpected response shape: missing success field');
|
|
2143
2451
|
}
|
|
2144
2452
|
// Convert response to plain object, removing _id fields recursively
|
|
2453
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2145
2454
|
const standardResponse = convertToPlainObject(responseData);
|
|
2455
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2456
|
+
const hasLimit = true;
|
|
2457
|
+
const hasOffset = true;
|
|
2458
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2459
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2460
|
+
// PaginatedData is already imported at top of file
|
|
2461
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2462
|
+
if (paginationMeta) {
|
|
2463
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2464
|
+
has_more: paginationMeta.has_more,
|
|
2465
|
+
next_offset: paginationMeta.next_offset,
|
|
2466
|
+
current_offset: paginationMeta.current_offset,
|
|
2467
|
+
limit: paginationMeta.limit,
|
|
2468
|
+
}, this.getBalances.bind(this), resolvedParams, this);
|
|
2469
|
+
standardResponse.success.data = paginatedData;
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2146
2472
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2147
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances',
|
|
2473
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/balances', resolvedParams, this.sdkConfig);
|
|
2148
2474
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2149
2475
|
}
|
|
2150
2476
|
this.logger.debug('Get Balances completed', {
|
|
@@ -2152,6 +2478,7 @@ class BrokersWrapper {
|
|
|
2152
2478
|
action: 'getBalances'
|
|
2153
2479
|
});
|
|
2154
2480
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2481
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2155
2482
|
return standardResponse;
|
|
2156
2483
|
}
|
|
2157
2484
|
catch (error) {
|
|
@@ -2228,15 +2555,15 @@ class BrokersWrapper {
|
|
|
2228
2555
|
*
|
|
2229
2556
|
* This endpoint is accessible from the portal and uses session-only authentication.
|
|
2230
2557
|
* Returns accounts from connections the company has read access to.
|
|
2231
|
-
* @param brokerId {string} (optional)
|
|
2232
|
-
* @param connectionId {string} (optional)
|
|
2233
|
-
* @param accountType {BrokerDataAccountTypeEnum} (optional)
|
|
2234
|
-
* @param status {AccountStatus} (optional)
|
|
2235
|
-
* @param currency {string} (optional)
|
|
2236
|
-
* @param limit {number} (optional)
|
|
2237
|
-
* @param offset {number} (optional)
|
|
2238
|
-
* @param includeMetadata {boolean} (optional)
|
|
2239
|
-
* @returns {Promise<FinaticResponse<FDXBrokerAccount
|
|
2558
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
2559
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2560
|
+
* @param params.accountType {BrokerDataAccountTypeEnum} (optional) Filter by account type (e.g., 'margin', 'cash', 'crypto_wallet', 'live', 'sim')
|
|
2561
|
+
* @param params.status {AccountStatus} (optional) Filter by account status (e.g., 'active', 'inactive')
|
|
2562
|
+
* @param params.currency {string} (optional) Filter by currency (e.g., 'USD', 'EUR')
|
|
2563
|
+
* @param params.limit {number} (optional) Maximum number of accounts to return
|
|
2564
|
+
* @param params.offset {number} (optional) Number of accounts to skip for pagination
|
|
2565
|
+
* @param params.includeMetadata {boolean} (optional) Include connection metadata in response (excluded by default for FDX compliance)
|
|
2566
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerAccount>>>} Standard response with success/Error/Warning structure
|
|
2240
2567
|
*
|
|
2241
2568
|
* Generated from: GET /api/v1/brokers/data/accounts
|
|
2242
2569
|
* @methodId get_accounts_api_v1_brokers_data_accounts_get
|
|
@@ -2244,7 +2571,7 @@ class BrokersWrapper {
|
|
|
2244
2571
|
* @example
|
|
2245
2572
|
* ```typescript-client
|
|
2246
2573
|
* // Example with no parameters
|
|
2247
|
-
* const result = await finatic.getAccounts();
|
|
2574
|
+
* const result = await finatic.getAccounts({});
|
|
2248
2575
|
*
|
|
2249
2576
|
* // Access the response data
|
|
2250
2577
|
* if (result.success) {
|
|
@@ -2254,7 +2581,11 @@ class BrokersWrapper {
|
|
|
2254
2581
|
* @example
|
|
2255
2582
|
* ```typescript-client
|
|
2256
2583
|
* // Full example with optional parameters
|
|
2257
|
-
* const result = await finatic.getAccounts(
|
|
2584
|
+
* const result = await finatic.getAccounts({
|
|
2585
|
+
brokerId: 'alpaca',
|
|
2586
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2587
|
+
accountType: 'margin'
|
|
2588
|
+
* });
|
|
2258
2589
|
*
|
|
2259
2590
|
* // Handle response with warnings
|
|
2260
2591
|
* if (result.success) {
|
|
@@ -2267,19 +2598,16 @@ class BrokersWrapper {
|
|
|
2267
2598
|
* }
|
|
2268
2599
|
* ```
|
|
2269
2600
|
*/
|
|
2270
|
-
async getAccounts(
|
|
2271
|
-
//
|
|
2272
|
-
const
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
includeMetadata: includeMetadata
|
|
2281
|
-
}; // Authentication check
|
|
2282
|
-
if (!this.sessionId) {
|
|
2601
|
+
async getAccounts(params) {
|
|
2602
|
+
// Use params object (with default empty object)
|
|
2603
|
+
const resolvedParams = params || {};
|
|
2604
|
+
if (params?.accountType !== undefined) {
|
|
2605
|
+
const coerced = coerceEnumValue(params.accountType, BrokerDataAccountTypeEnum, 'accountType');
|
|
2606
|
+
if (coerced !== undefined) {
|
|
2607
|
+
params.accountType = coerced;
|
|
2608
|
+
}
|
|
2609
|
+
} // Authentication check
|
|
2610
|
+
if (!this.sessionId || !this.companyId) {
|
|
2283
2611
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2284
2612
|
}
|
|
2285
2613
|
// Generate request ID
|
|
@@ -2290,7 +2618,7 @@ class BrokersWrapper {
|
|
|
2290
2618
|
const shouldCache = true;
|
|
2291
2619
|
const cache = getCache(this.sdkConfig);
|
|
2292
2620
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2293
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts',
|
|
2621
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
|
|
2294
2622
|
const cached = cache.get(cacheKey);
|
|
2295
2623
|
if (cached) {
|
|
2296
2624
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2302,12 +2630,12 @@ class BrokersWrapper {
|
|
|
2302
2630
|
request_id: requestId,
|
|
2303
2631
|
method: 'GET',
|
|
2304
2632
|
path: '/api/v1/brokers/data/accounts',
|
|
2305
|
-
params:
|
|
2633
|
+
params: resolvedParams,
|
|
2306
2634
|
action: 'getAccounts'
|
|
2307
2635
|
});
|
|
2308
2636
|
try {
|
|
2309
2637
|
const response = await retryApiCall(async () => {
|
|
2310
|
-
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
|
|
2638
|
+
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 } : {}) } : {}) } });
|
|
2311
2639
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2312
2640
|
}, {}, this.sdkConfig);
|
|
2313
2641
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2316,9 +2644,27 @@ class BrokersWrapper {
|
|
|
2316
2644
|
throw new Error('Unexpected response shape: missing success field');
|
|
2317
2645
|
}
|
|
2318
2646
|
// Convert response to plain object, removing _id fields recursively
|
|
2647
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2319
2648
|
const standardResponse = convertToPlainObject(responseData);
|
|
2649
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2650
|
+
const hasLimit = true;
|
|
2651
|
+
const hasOffset = true;
|
|
2652
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2653
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2654
|
+
// PaginatedData is already imported at top of file
|
|
2655
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2656
|
+
if (paginationMeta) {
|
|
2657
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2658
|
+
has_more: paginationMeta.has_more,
|
|
2659
|
+
next_offset: paginationMeta.next_offset,
|
|
2660
|
+
current_offset: paginationMeta.current_offset,
|
|
2661
|
+
limit: paginationMeta.limit,
|
|
2662
|
+
}, this.getAccounts.bind(this), resolvedParams, this);
|
|
2663
|
+
standardResponse.success.data = paginatedData;
|
|
2664
|
+
}
|
|
2665
|
+
}
|
|
2320
2666
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2321
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts',
|
|
2667
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/accounts', resolvedParams, this.sdkConfig);
|
|
2322
2668
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2323
2669
|
}
|
|
2324
2670
|
this.logger.debug('Get Accounts completed', {
|
|
@@ -2326,6 +2672,7 @@ class BrokersWrapper {
|
|
|
2326
2672
|
action: 'getAccounts'
|
|
2327
2673
|
});
|
|
2328
2674
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2675
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2329
2676
|
return standardResponse;
|
|
2330
2677
|
}
|
|
2331
2678
|
catch (error) {
|
|
@@ -2401,12 +2748,12 @@ class BrokersWrapper {
|
|
|
2401
2748
|
* Get order fills for a specific order.
|
|
2402
2749
|
*
|
|
2403
2750
|
* This endpoint returns all execution fills for the specified order.
|
|
2404
|
-
* @param orderId {string}
|
|
2405
|
-
* @param connectionId {string} (optional)
|
|
2406
|
-
* @param limit {number} (optional)
|
|
2407
|
-
* @param offset {number} (optional)
|
|
2408
|
-
* @param includeMetadata {boolean} (optional)
|
|
2409
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrderFill
|
|
2751
|
+
* @param params.orderId {string} Order ID
|
|
2752
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2753
|
+
* @param params.limit {number} (optional) Maximum number of fills to return
|
|
2754
|
+
* @param params.offset {number} (optional) Number of fills to skip for pagination
|
|
2755
|
+
* @param params.includeMetadata {boolean} (optional) Include fill metadata in response (excluded by default for FDX compliance)
|
|
2756
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderFill>>>} Standard response with success/Error/Warning structure
|
|
2410
2757
|
*
|
|
2411
2758
|
* Generated from: GET /api/v1/brokers/data/orders/{order_id}/fills
|
|
2412
2759
|
* @methodId get_order_fills_api_v1_brokers_data_orders__order_id__fills_get
|
|
@@ -2414,7 +2761,9 @@ class BrokersWrapper {
|
|
|
2414
2761
|
* @example
|
|
2415
2762
|
* ```typescript-client
|
|
2416
2763
|
* // Minimal example with required parameters only
|
|
2417
|
-
* const result = await finatic.getOrderFills(
|
|
2764
|
+
* const result = await finatic.getOrderFills({
|
|
2765
|
+
orderId: '00000000-0000-0000-0000-000000000000'
|
|
2766
|
+
* });
|
|
2418
2767
|
*
|
|
2419
2768
|
* // Access the response data
|
|
2420
2769
|
* if (result.success) {
|
|
@@ -2426,7 +2775,12 @@ class BrokersWrapper {
|
|
|
2426
2775
|
* @example
|
|
2427
2776
|
* ```typescript-client
|
|
2428
2777
|
* // Full example with optional parameters
|
|
2429
|
-
* const result = await finatic.getOrderFills(
|
|
2778
|
+
* const result = await finatic.getOrderFills({
|
|
2779
|
+
orderId: '00000000-0000-0000-0000-000000000000',
|
|
2780
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2781
|
+
limit: 100,
|
|
2782
|
+
offset: 0
|
|
2783
|
+
* });
|
|
2430
2784
|
*
|
|
2431
2785
|
* // Handle response with warnings
|
|
2432
2786
|
* if (result.success) {
|
|
@@ -2439,16 +2793,10 @@ class BrokersWrapper {
|
|
|
2439
2793
|
* }
|
|
2440
2794
|
* ```
|
|
2441
2795
|
*/
|
|
2442
|
-
async getOrderFills(
|
|
2443
|
-
//
|
|
2444
|
-
const
|
|
2445
|
-
|
|
2446
|
-
connectionId: connectionId,
|
|
2447
|
-
limit: limit,
|
|
2448
|
-
offset: offset,
|
|
2449
|
-
includeMetadata: includeMetadata
|
|
2450
|
-
}; // Authentication check
|
|
2451
|
-
if (!this.sessionId) {
|
|
2796
|
+
async getOrderFills(params) {
|
|
2797
|
+
// Use params object (required parameters present)
|
|
2798
|
+
const resolvedParams = params; // Authentication check
|
|
2799
|
+
if (!this.sessionId || !this.companyId) {
|
|
2452
2800
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2453
2801
|
}
|
|
2454
2802
|
// Generate request ID
|
|
@@ -2459,7 +2807,7 @@ class BrokersWrapper {
|
|
|
2459
2807
|
const shouldCache = true;
|
|
2460
2808
|
const cache = getCache(this.sdkConfig);
|
|
2461
2809
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2462
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2810
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
|
|
2463
2811
|
const cached = cache.get(cacheKey);
|
|
2464
2812
|
if (cached) {
|
|
2465
2813
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2471,12 +2819,12 @@ class BrokersWrapper {
|
|
|
2471
2819
|
request_id: requestId,
|
|
2472
2820
|
method: 'GET',
|
|
2473
2821
|
path: '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2474
|
-
params:
|
|
2822
|
+
params: resolvedParams,
|
|
2475
2823
|
action: 'getOrderFills'
|
|
2476
2824
|
});
|
|
2477
2825
|
try {
|
|
2478
2826
|
const response = await retryApiCall(async () => {
|
|
2479
|
-
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
|
|
2827
|
+
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 } : {}) } : {}) } });
|
|
2480
2828
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2481
2829
|
}, {}, this.sdkConfig);
|
|
2482
2830
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2485,9 +2833,27 @@ class BrokersWrapper {
|
|
|
2485
2833
|
throw new Error('Unexpected response shape: missing success field');
|
|
2486
2834
|
}
|
|
2487
2835
|
// Convert response to plain object, removing _id fields recursively
|
|
2836
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2488
2837
|
const standardResponse = convertToPlainObject(responseData);
|
|
2838
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
2839
|
+
const hasLimit = true;
|
|
2840
|
+
const hasOffset = true;
|
|
2841
|
+
const hasPagination = hasLimit && hasOffset;
|
|
2842
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
2843
|
+
// PaginatedData is already imported at top of file
|
|
2844
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
2845
|
+
if (paginationMeta) {
|
|
2846
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
2847
|
+
has_more: paginationMeta.has_more,
|
|
2848
|
+
next_offset: paginationMeta.next_offset,
|
|
2849
|
+
current_offset: paginationMeta.current_offset,
|
|
2850
|
+
limit: paginationMeta.limit,
|
|
2851
|
+
}, this.getOrderFills.bind(this), resolvedParams, this);
|
|
2852
|
+
standardResponse.success.data = paginatedData;
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2489
2855
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2490
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills',
|
|
2856
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/fills', resolvedParams, this.sdkConfig);
|
|
2491
2857
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2492
2858
|
}
|
|
2493
2859
|
this.logger.debug('Get Order Fills completed', {
|
|
@@ -2495,6 +2861,7 @@ class BrokersWrapper {
|
|
|
2495
2861
|
action: 'getOrderFills'
|
|
2496
2862
|
});
|
|
2497
2863
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
2864
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2498
2865
|
return standardResponse;
|
|
2499
2866
|
}
|
|
2500
2867
|
catch (error) {
|
|
@@ -2570,12 +2937,12 @@ class BrokersWrapper {
|
|
|
2570
2937
|
* Get order events for a specific order.
|
|
2571
2938
|
*
|
|
2572
2939
|
* This endpoint returns all lifecycle events for the specified order.
|
|
2573
|
-
* @param orderId {string}
|
|
2574
|
-
* @param connectionId {string} (optional)
|
|
2575
|
-
* @param limit {number} (optional)
|
|
2576
|
-
* @param offset {number} (optional)
|
|
2577
|
-
* @param includeMetadata {boolean} (optional)
|
|
2578
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrderEvent
|
|
2940
|
+
* @param params.orderId {string} Order ID
|
|
2941
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
2942
|
+
* @param params.limit {number} (optional) Maximum number of events to return
|
|
2943
|
+
* @param params.offset {number} (optional) Number of events to skip for pagination
|
|
2944
|
+
* @param params.includeMetadata {boolean} (optional) Include event metadata in response (excluded by default for FDX compliance)
|
|
2945
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderEvent>>>} Standard response with success/Error/Warning structure
|
|
2579
2946
|
*
|
|
2580
2947
|
* Generated from: GET /api/v1/brokers/data/orders/{order_id}/events
|
|
2581
2948
|
* @methodId get_order_events_api_v1_brokers_data_orders__order_id__events_get
|
|
@@ -2583,7 +2950,9 @@ class BrokersWrapper {
|
|
|
2583
2950
|
* @example
|
|
2584
2951
|
* ```typescript-client
|
|
2585
2952
|
* // Minimal example with required parameters only
|
|
2586
|
-
* const result = await finatic.getOrderEvents(
|
|
2953
|
+
* const result = await finatic.getOrderEvents({
|
|
2954
|
+
orderId: '00000000-0000-0000-0000-000000000000'
|
|
2955
|
+
* });
|
|
2587
2956
|
*
|
|
2588
2957
|
* // Access the response data
|
|
2589
2958
|
* if (result.success) {
|
|
@@ -2595,7 +2964,12 @@ class BrokersWrapper {
|
|
|
2595
2964
|
* @example
|
|
2596
2965
|
* ```typescript-client
|
|
2597
2966
|
* // Full example with optional parameters
|
|
2598
|
-
* const result = await finatic.getOrderEvents(
|
|
2967
|
+
* const result = await finatic.getOrderEvents({
|
|
2968
|
+
orderId: '00000000-0000-0000-0000-000000000000',
|
|
2969
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
2970
|
+
limit: 100,
|
|
2971
|
+
offset: 0
|
|
2972
|
+
* });
|
|
2599
2973
|
*
|
|
2600
2974
|
* // Handle response with warnings
|
|
2601
2975
|
* if (result.success) {
|
|
@@ -2608,16 +2982,10 @@ class BrokersWrapper {
|
|
|
2608
2982
|
* }
|
|
2609
2983
|
* ```
|
|
2610
2984
|
*/
|
|
2611
|
-
async getOrderEvents(
|
|
2612
|
-
//
|
|
2613
|
-
const
|
|
2614
|
-
|
|
2615
|
-
connectionId: connectionId,
|
|
2616
|
-
limit: limit,
|
|
2617
|
-
offset: offset,
|
|
2618
|
-
includeMetadata: includeMetadata
|
|
2619
|
-
}; // Authentication check
|
|
2620
|
-
if (!this.sessionId) {
|
|
2985
|
+
async getOrderEvents(params) {
|
|
2986
|
+
// Use params object (required parameters present)
|
|
2987
|
+
const resolvedParams = params; // Authentication check
|
|
2988
|
+
if (!this.sessionId || !this.companyId) {
|
|
2621
2989
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2622
2990
|
}
|
|
2623
2991
|
// Generate request ID
|
|
@@ -2628,7 +2996,7 @@ class BrokersWrapper {
|
|
|
2628
2996
|
const shouldCache = true;
|
|
2629
2997
|
const cache = getCache(this.sdkConfig);
|
|
2630
2998
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2631
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events',
|
|
2999
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
|
|
2632
3000
|
const cached = cache.get(cacheKey);
|
|
2633
3001
|
if (cached) {
|
|
2634
3002
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2640,12 +3008,12 @@ class BrokersWrapper {
|
|
|
2640
3008
|
request_id: requestId,
|
|
2641
3009
|
method: 'GET',
|
|
2642
3010
|
path: '/api/v1/brokers/data/orders/{order_id}/events',
|
|
2643
|
-
params:
|
|
3011
|
+
params: resolvedParams,
|
|
2644
3012
|
action: 'getOrderEvents'
|
|
2645
3013
|
});
|
|
2646
3014
|
try {
|
|
2647
3015
|
const response = await retryApiCall(async () => {
|
|
2648
|
-
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
|
|
3016
|
+
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 } : {}) } : {}) } });
|
|
2649
3017
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2650
3018
|
}, {}, this.sdkConfig);
|
|
2651
3019
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2654,9 +3022,27 @@ class BrokersWrapper {
|
|
|
2654
3022
|
throw new Error('Unexpected response shape: missing success field');
|
|
2655
3023
|
}
|
|
2656
3024
|
// Convert response to plain object, removing _id fields recursively
|
|
3025
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2657
3026
|
const standardResponse = convertToPlainObject(responseData);
|
|
3027
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3028
|
+
const hasLimit = true;
|
|
3029
|
+
const hasOffset = true;
|
|
3030
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3031
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3032
|
+
// PaginatedData is already imported at top of file
|
|
3033
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3034
|
+
if (paginationMeta) {
|
|
3035
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3036
|
+
has_more: paginationMeta.has_more,
|
|
3037
|
+
next_offset: paginationMeta.next_offset,
|
|
3038
|
+
current_offset: paginationMeta.current_offset,
|
|
3039
|
+
limit: paginationMeta.limit,
|
|
3040
|
+
}, this.getOrderEvents.bind(this), resolvedParams, this);
|
|
3041
|
+
standardResponse.success.data = paginatedData;
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
2658
3044
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2659
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events',
|
|
3045
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/{order_id}/events', resolvedParams, this.sdkConfig);
|
|
2660
3046
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2661
3047
|
}
|
|
2662
3048
|
this.logger.debug('Get Order Events completed', {
|
|
@@ -2664,6 +3050,7 @@ class BrokersWrapper {
|
|
|
2664
3050
|
action: 'getOrderEvents'
|
|
2665
3051
|
});
|
|
2666
3052
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3053
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2667
3054
|
return standardResponse;
|
|
2668
3055
|
}
|
|
2669
3056
|
catch (error) {
|
|
@@ -2739,14 +3126,14 @@ class BrokersWrapper {
|
|
|
2739
3126
|
* Get order groups.
|
|
2740
3127
|
*
|
|
2741
3128
|
* This endpoint returns order groups that contain multiple orders.
|
|
2742
|
-
* @param brokerId {string} (optional)
|
|
2743
|
-
* @param connectionId {string} (optional)
|
|
2744
|
-
* @param limit {number} (optional)
|
|
2745
|
-
* @param offset {number} (optional)
|
|
2746
|
-
* @param createdAfter {string} (optional)
|
|
2747
|
-
* @param createdBefore {string} (optional)
|
|
2748
|
-
* @param includeMetadata {boolean} (optional)
|
|
2749
|
-
* @returns {Promise<FinaticResponse<FDXBrokerOrderGroup
|
|
3129
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
3130
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3131
|
+
* @param params.limit {number} (optional) Maximum number of order groups to return
|
|
3132
|
+
* @param params.offset {number} (optional) Number of order groups to skip for pagination
|
|
3133
|
+
* @param params.createdAfter {string} (optional) Filter order groups created after this timestamp
|
|
3134
|
+
* @param params.createdBefore {string} (optional) Filter order groups created before this timestamp
|
|
3135
|
+
* @param params.includeMetadata {boolean} (optional) Include group metadata in response (excluded by default for FDX compliance)
|
|
3136
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerOrderGroup>>>} Standard response with success/Error/Warning structure
|
|
2750
3137
|
*
|
|
2751
3138
|
* Generated from: GET /api/v1/brokers/data/orders/groups
|
|
2752
3139
|
* @methodId get_order_groups_api_v1_brokers_data_orders_groups_get
|
|
@@ -2754,7 +3141,7 @@ class BrokersWrapper {
|
|
|
2754
3141
|
* @example
|
|
2755
3142
|
* ```typescript-client
|
|
2756
3143
|
* // Example with no parameters
|
|
2757
|
-
* const result = await finatic.getOrderGroups();
|
|
3144
|
+
* const result = await finatic.getOrderGroups({});
|
|
2758
3145
|
*
|
|
2759
3146
|
* // Access the response data
|
|
2760
3147
|
* if (result.success) {
|
|
@@ -2764,7 +3151,11 @@ class BrokersWrapper {
|
|
|
2764
3151
|
* @example
|
|
2765
3152
|
* ```typescript-client
|
|
2766
3153
|
* // Full example with optional parameters
|
|
2767
|
-
* const result = await finatic.getOrderGroups(
|
|
3154
|
+
* const result = await finatic.getOrderGroups({
|
|
3155
|
+
brokerId: 'alpaca',
|
|
3156
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3157
|
+
limit: 100
|
|
3158
|
+
* });
|
|
2768
3159
|
*
|
|
2769
3160
|
* // Handle response with warnings
|
|
2770
3161
|
* if (result.success) {
|
|
@@ -2777,18 +3168,10 @@ class BrokersWrapper {
|
|
|
2777
3168
|
* }
|
|
2778
3169
|
* ```
|
|
2779
3170
|
*/
|
|
2780
|
-
async getOrderGroups(
|
|
2781
|
-
//
|
|
2782
|
-
const
|
|
2783
|
-
|
|
2784
|
-
connectionId: connectionId,
|
|
2785
|
-
limit: limit,
|
|
2786
|
-
offset: offset,
|
|
2787
|
-
createdAfter: createdAfter,
|
|
2788
|
-
createdBefore: createdBefore,
|
|
2789
|
-
includeMetadata: includeMetadata
|
|
2790
|
-
}; // Authentication check
|
|
2791
|
-
if (!this.sessionId) {
|
|
3171
|
+
async getOrderGroups(params) {
|
|
3172
|
+
// Use params object (with default empty object)
|
|
3173
|
+
const resolvedParams = params || {}; // Authentication check
|
|
3174
|
+
if (!this.sessionId || !this.companyId) {
|
|
2792
3175
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2793
3176
|
}
|
|
2794
3177
|
// Generate request ID
|
|
@@ -2799,7 +3182,7 @@ class BrokersWrapper {
|
|
|
2799
3182
|
const shouldCache = true;
|
|
2800
3183
|
const cache = getCache(this.sdkConfig);
|
|
2801
3184
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2802
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups',
|
|
3185
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
|
|
2803
3186
|
const cached = cache.get(cacheKey);
|
|
2804
3187
|
if (cached) {
|
|
2805
3188
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2811,12 +3194,12 @@ class BrokersWrapper {
|
|
|
2811
3194
|
request_id: requestId,
|
|
2812
3195
|
method: 'GET',
|
|
2813
3196
|
path: '/api/v1/brokers/data/orders/groups',
|
|
2814
|
-
params:
|
|
3197
|
+
params: resolvedParams,
|
|
2815
3198
|
action: 'getOrderGroups'
|
|
2816
3199
|
});
|
|
2817
3200
|
try {
|
|
2818
3201
|
const response = await retryApiCall(async () => {
|
|
2819
|
-
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
|
|
3202
|
+
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 } : {}) } : {}) } });
|
|
2820
3203
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2821
3204
|
}, {}, this.sdkConfig);
|
|
2822
3205
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2825,9 +3208,27 @@ class BrokersWrapper {
|
|
|
2825
3208
|
throw new Error('Unexpected response shape: missing success field');
|
|
2826
3209
|
}
|
|
2827
3210
|
// Convert response to plain object, removing _id fields recursively
|
|
3211
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
2828
3212
|
const standardResponse = convertToPlainObject(responseData);
|
|
3213
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3214
|
+
const hasLimit = true;
|
|
3215
|
+
const hasOffset = true;
|
|
3216
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3217
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3218
|
+
// PaginatedData is already imported at top of file
|
|
3219
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3220
|
+
if (paginationMeta) {
|
|
3221
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3222
|
+
has_more: paginationMeta.has_more,
|
|
3223
|
+
next_offset: paginationMeta.next_offset,
|
|
3224
|
+
current_offset: paginationMeta.current_offset,
|
|
3225
|
+
limit: paginationMeta.limit,
|
|
3226
|
+
}, this.getOrderGroups.bind(this), resolvedParams, this);
|
|
3227
|
+
standardResponse.success.data = paginatedData;
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
2829
3230
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2830
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups',
|
|
3231
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/orders/groups', resolvedParams, this.sdkConfig);
|
|
2831
3232
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
2832
3233
|
}
|
|
2833
3234
|
this.logger.debug('Get Order Groups completed', {
|
|
@@ -2835,6 +3236,7 @@ class BrokersWrapper {
|
|
|
2835
3236
|
action: 'getOrderGroups'
|
|
2836
3237
|
});
|
|
2837
3238
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3239
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
2838
3240
|
return standardResponse;
|
|
2839
3241
|
}
|
|
2840
3242
|
catch (error) {
|
|
@@ -2911,14 +3313,14 @@ class BrokersWrapper {
|
|
|
2911
3313
|
*
|
|
2912
3314
|
* This endpoint returns tax lots for positions, which are used for tax reporting.
|
|
2913
3315
|
* Each lot tracks when a position was opened/closed and at what prices.
|
|
2914
|
-
* @param brokerId {string} (optional)
|
|
2915
|
-
* @param connectionId {string} (optional)
|
|
2916
|
-
* @param accountId {string} (optional)
|
|
2917
|
-
* @param symbol {string} (optional)
|
|
2918
|
-
* @param positionId {string} (optional)
|
|
2919
|
-
* @param limit {number} (optional)
|
|
2920
|
-
* @param offset {number} (optional)
|
|
2921
|
-
* @returns {Promise<FinaticResponse<FDXBrokerPositionLot
|
|
3316
|
+
* @param params.brokerId {string} (optional) Filter by broker ID
|
|
3317
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3318
|
+
* @param params.accountId {string} (optional) Filter by broker provided account ID
|
|
3319
|
+
* @param params.symbol {string} (optional) Filter by symbol
|
|
3320
|
+
* @param params.positionId {string} (optional) Filter by position ID
|
|
3321
|
+
* @param params.limit {number} (optional) Maximum number of position lots to return
|
|
3322
|
+
* @param params.offset {number} (optional) Number of position lots to skip for pagination
|
|
3323
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLot>>>} Standard response with success/Error/Warning structure
|
|
2922
3324
|
*
|
|
2923
3325
|
* Generated from: GET /api/v1/brokers/data/positions/lots
|
|
2924
3326
|
* @methodId get_position_lots_api_v1_brokers_data_positions_lots_get
|
|
@@ -2926,7 +3328,7 @@ class BrokersWrapper {
|
|
|
2926
3328
|
* @example
|
|
2927
3329
|
* ```typescript-client
|
|
2928
3330
|
* // Example with no parameters
|
|
2929
|
-
* const result = await finatic.getPositionLots();
|
|
3331
|
+
* const result = await finatic.getPositionLots({});
|
|
2930
3332
|
*
|
|
2931
3333
|
* // Access the response data
|
|
2932
3334
|
* if (result.success) {
|
|
@@ -2936,7 +3338,11 @@ class BrokersWrapper {
|
|
|
2936
3338
|
* @example
|
|
2937
3339
|
* ```typescript-client
|
|
2938
3340
|
* // Full example with optional parameters
|
|
2939
|
-
* const result = await finatic.getPositionLots(
|
|
3341
|
+
* const result = await finatic.getPositionLots({
|
|
3342
|
+
brokerId: 'alpaca',
|
|
3343
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3344
|
+
accountId: '123456789'
|
|
3345
|
+
* });
|
|
2940
3346
|
*
|
|
2941
3347
|
* // Handle response with warnings
|
|
2942
3348
|
* if (result.success) {
|
|
@@ -2949,18 +3355,10 @@ class BrokersWrapper {
|
|
|
2949
3355
|
* }
|
|
2950
3356
|
* ```
|
|
2951
3357
|
*/
|
|
2952
|
-
async getPositionLots(
|
|
2953
|
-
//
|
|
2954
|
-
const
|
|
2955
|
-
|
|
2956
|
-
connectionId: connectionId,
|
|
2957
|
-
accountId: accountId,
|
|
2958
|
-
symbol: symbol,
|
|
2959
|
-
positionId: positionId,
|
|
2960
|
-
limit: limit,
|
|
2961
|
-
offset: offset
|
|
2962
|
-
}; // Authentication check
|
|
2963
|
-
if (!this.sessionId) {
|
|
3358
|
+
async getPositionLots(params) {
|
|
3359
|
+
// Use params object (with default empty object)
|
|
3360
|
+
const resolvedParams = params || {}; // Authentication check
|
|
3361
|
+
if (!this.sessionId || !this.companyId) {
|
|
2964
3362
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
2965
3363
|
}
|
|
2966
3364
|
// Generate request ID
|
|
@@ -2971,7 +3369,7 @@ class BrokersWrapper {
|
|
|
2971
3369
|
const shouldCache = true;
|
|
2972
3370
|
const cache = getCache(this.sdkConfig);
|
|
2973
3371
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
2974
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots',
|
|
3372
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
|
|
2975
3373
|
const cached = cache.get(cacheKey);
|
|
2976
3374
|
if (cached) {
|
|
2977
3375
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -2983,12 +3381,12 @@ class BrokersWrapper {
|
|
|
2983
3381
|
request_id: requestId,
|
|
2984
3382
|
method: 'GET',
|
|
2985
3383
|
path: '/api/v1/brokers/data/positions/lots',
|
|
2986
|
-
params:
|
|
3384
|
+
params: resolvedParams,
|
|
2987
3385
|
action: 'getPositionLots'
|
|
2988
3386
|
});
|
|
2989
3387
|
try {
|
|
2990
3388
|
const response = await retryApiCall(async () => {
|
|
2991
|
-
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
|
|
3389
|
+
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 } : {}) } : {}) } });
|
|
2992
3390
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
2993
3391
|
}, {}, this.sdkConfig);
|
|
2994
3392
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -2997,9 +3395,27 @@ class BrokersWrapper {
|
|
|
2997
3395
|
throw new Error('Unexpected response shape: missing success field');
|
|
2998
3396
|
}
|
|
2999
3397
|
// Convert response to plain object, removing _id fields recursively
|
|
3398
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3000
3399
|
const standardResponse = convertToPlainObject(responseData);
|
|
3400
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3401
|
+
const hasLimit = true;
|
|
3402
|
+
const hasOffset = true;
|
|
3403
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3404
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3405
|
+
// PaginatedData is already imported at top of file
|
|
3406
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3407
|
+
if (paginationMeta) {
|
|
3408
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3409
|
+
has_more: paginationMeta.has_more,
|
|
3410
|
+
next_offset: paginationMeta.next_offset,
|
|
3411
|
+
current_offset: paginationMeta.current_offset,
|
|
3412
|
+
limit: paginationMeta.limit,
|
|
3413
|
+
}, this.getPositionLots.bind(this), resolvedParams, this);
|
|
3414
|
+
standardResponse.success.data = paginatedData;
|
|
3415
|
+
}
|
|
3416
|
+
}
|
|
3001
3417
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3002
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots',
|
|
3418
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots', resolvedParams, this.sdkConfig);
|
|
3003
3419
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3004
3420
|
}
|
|
3005
3421
|
this.logger.debug('Get Position Lots completed', {
|
|
@@ -3007,6 +3423,7 @@ class BrokersWrapper {
|
|
|
3007
3423
|
action: 'getPositionLots'
|
|
3008
3424
|
});
|
|
3009
3425
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3426
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3010
3427
|
return standardResponse;
|
|
3011
3428
|
}
|
|
3012
3429
|
catch (error) {
|
|
@@ -3082,11 +3499,11 @@ class BrokersWrapper {
|
|
|
3082
3499
|
* Get position lot fills for a specific lot.
|
|
3083
3500
|
*
|
|
3084
3501
|
* This endpoint returns all fills associated with a specific position lot.
|
|
3085
|
-
* @param lotId {string}
|
|
3086
|
-
* @param connectionId {string} (optional)
|
|
3087
|
-
* @param limit {number} (optional)
|
|
3088
|
-
* @param offset {number} (optional)
|
|
3089
|
-
* @returns {Promise<FinaticResponse<FDXBrokerPositionLotFill
|
|
3502
|
+
* @param params.lotId {string} Position lot ID
|
|
3503
|
+
* @param params.connectionId {string} (optional) Filter by connection ID
|
|
3504
|
+
* @param params.limit {number} (optional) Maximum number of fills to return
|
|
3505
|
+
* @param params.offset {number} (optional) Number of fills to skip for pagination
|
|
3506
|
+
* @returns {Promise<FinaticResponse<PaginatedData<FDXBrokerPositionLotFill>>>} Standard response with success/Error/Warning structure
|
|
3090
3507
|
*
|
|
3091
3508
|
* Generated from: GET /api/v1/brokers/data/positions/lots/{lot_id}/fills
|
|
3092
3509
|
* @methodId get_position_lot_fills_api_v1_brokers_data_positions_lots__lot_id__fills_get
|
|
@@ -3094,7 +3511,9 @@ class BrokersWrapper {
|
|
|
3094
3511
|
* @example
|
|
3095
3512
|
* ```typescript-client
|
|
3096
3513
|
* // Minimal example with required parameters only
|
|
3097
|
-
* const result = await finatic.getPositionLotFills(
|
|
3514
|
+
* const result = await finatic.getPositionLotFills({
|
|
3515
|
+
lotId: '00000000-0000-0000-0000-000000000000'
|
|
3516
|
+
* });
|
|
3098
3517
|
*
|
|
3099
3518
|
* // Access the response data
|
|
3100
3519
|
* if (result.success) {
|
|
@@ -3106,7 +3525,12 @@ class BrokersWrapper {
|
|
|
3106
3525
|
* @example
|
|
3107
3526
|
* ```typescript-client
|
|
3108
3527
|
* // Full example with optional parameters
|
|
3109
|
-
* const result = await finatic.getPositionLotFills(
|
|
3528
|
+
* const result = await finatic.getPositionLotFills({
|
|
3529
|
+
lotId: '00000000-0000-0000-0000-000000000000',
|
|
3530
|
+
connectionId: '00000000-0000-0000-0000-000000000000',
|
|
3531
|
+
limit: 100,
|
|
3532
|
+
offset: 0
|
|
3533
|
+
* });
|
|
3110
3534
|
*
|
|
3111
3535
|
* // Handle response with warnings
|
|
3112
3536
|
* if (result.success) {
|
|
@@ -3119,15 +3543,10 @@ class BrokersWrapper {
|
|
|
3119
3543
|
* }
|
|
3120
3544
|
* ```
|
|
3121
3545
|
*/
|
|
3122
|
-
async getPositionLotFills(
|
|
3123
|
-
//
|
|
3124
|
-
const
|
|
3125
|
-
|
|
3126
|
-
connectionId: connectionId,
|
|
3127
|
-
limit: limit,
|
|
3128
|
-
offset: offset
|
|
3129
|
-
}; // Authentication check
|
|
3130
|
-
if (!this.sessionId) {
|
|
3546
|
+
async getPositionLotFills(params) {
|
|
3547
|
+
// Use params object (required parameters present)
|
|
3548
|
+
const resolvedParams = params; // Authentication check
|
|
3549
|
+
if (!this.sessionId || !this.companyId) {
|
|
3131
3550
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3132
3551
|
}
|
|
3133
3552
|
// Generate request ID
|
|
@@ -3138,7 +3557,7 @@ class BrokersWrapper {
|
|
|
3138
3557
|
const shouldCache = true;
|
|
3139
3558
|
const cache = getCache(this.sdkConfig);
|
|
3140
3559
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3141
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3560
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
|
|
3142
3561
|
const cached = cache.get(cacheKey);
|
|
3143
3562
|
if (cached) {
|
|
3144
3563
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3150,12 +3569,12 @@ class BrokersWrapper {
|
|
|
3150
3569
|
request_id: requestId,
|
|
3151
3570
|
method: 'GET',
|
|
3152
3571
|
path: '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3153
|
-
params:
|
|
3572
|
+
params: resolvedParams,
|
|
3154
3573
|
action: 'getPositionLotFills'
|
|
3155
3574
|
});
|
|
3156
3575
|
try {
|
|
3157
3576
|
const response = await retryApiCall(async () => {
|
|
3158
|
-
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
|
|
3577
|
+
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 } : {}) } : {}) } });
|
|
3159
3578
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3160
3579
|
}, {}, this.sdkConfig);
|
|
3161
3580
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3164,9 +3583,27 @@ class BrokersWrapper {
|
|
|
3164
3583
|
throw new Error('Unexpected response shape: missing success field');
|
|
3165
3584
|
}
|
|
3166
3585
|
// Convert response to plain object, removing _id fields recursively
|
|
3586
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3167
3587
|
const standardResponse = convertToPlainObject(responseData);
|
|
3588
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3589
|
+
const hasLimit = true;
|
|
3590
|
+
const hasOffset = true;
|
|
3591
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3592
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) {
|
|
3593
|
+
// PaginatedData is already imported at top of file
|
|
3594
|
+
const paginationMeta = standardResponse.success.meta?.pagination;
|
|
3595
|
+
if (paginationMeta) {
|
|
3596
|
+
const paginatedData = new PaginatedData(standardResponse.success.data, {
|
|
3597
|
+
has_more: paginationMeta.has_more,
|
|
3598
|
+
next_offset: paginationMeta.next_offset,
|
|
3599
|
+
current_offset: paginationMeta.current_offset,
|
|
3600
|
+
limit: paginationMeta.limit,
|
|
3601
|
+
}, this.getPositionLotFills.bind(this), resolvedParams, this);
|
|
3602
|
+
standardResponse.success.data = paginatedData;
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3168
3605
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3169
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills',
|
|
3606
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/brokers/data/positions/lots/{lot_id}/fills', resolvedParams, this.sdkConfig);
|
|
3170
3607
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3171
3608
|
}
|
|
3172
3609
|
this.logger.debug('Get Position Lot Fills completed', {
|
|
@@ -3174,6 +3611,7 @@ class BrokersWrapper {
|
|
|
3174
3611
|
action: 'getPositionLotFills'
|
|
3175
3612
|
});
|
|
3176
3613
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3614
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3177
3615
|
return standardResponse;
|
|
3178
3616
|
}
|
|
3179
3617
|
catch (error) {
|
|
@@ -3286,7 +3724,7 @@ class CompanyWrapper {
|
|
|
3286
3724
|
* Get Company
|
|
3287
3725
|
*
|
|
3288
3726
|
* Get public company details by ID (no user check, no sensitive data).
|
|
3289
|
-
* @param companyId {string}
|
|
3727
|
+
* @param params.companyId {string} Company ID
|
|
3290
3728
|
* @returns {Promise<FinaticResponse<CompanyResponse>>} Standard response with success/Error/Warning structure
|
|
3291
3729
|
*
|
|
3292
3730
|
* Generated from: GET /api/v1/company/{company_id}
|
|
@@ -3295,7 +3733,9 @@ class CompanyWrapper {
|
|
|
3295
3733
|
* @example
|
|
3296
3734
|
* ```typescript-client
|
|
3297
3735
|
* // Minimal example with required parameters only
|
|
3298
|
-
* const result = await finatic.getCompany(
|
|
3736
|
+
* const result = await finatic.getCompany({
|
|
3737
|
+
companyId: '00000000-0000-0000-0000-000000000000'
|
|
3738
|
+
* });
|
|
3299
3739
|
*
|
|
3300
3740
|
* // Access the response data
|
|
3301
3741
|
* if (result.success) {
|
|
@@ -3305,11 +3745,9 @@ class CompanyWrapper {
|
|
|
3305
3745
|
* }
|
|
3306
3746
|
* ```
|
|
3307
3747
|
*/
|
|
3308
|
-
async getCompany(
|
|
3309
|
-
//
|
|
3310
|
-
const
|
|
3311
|
-
companyId: companyId
|
|
3312
|
-
}; // Generate request ID
|
|
3748
|
+
async getCompany(params) {
|
|
3749
|
+
// Use params object (required parameters present)
|
|
3750
|
+
const resolvedParams = params; // Generate request ID
|
|
3313
3751
|
const requestId = this._generateRequestId();
|
|
3314
3752
|
// Input validation (Phase 2B: zod)
|
|
3315
3753
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3317,7 +3755,7 @@ class CompanyWrapper {
|
|
|
3317
3755
|
const shouldCache = true;
|
|
3318
3756
|
const cache = getCache(this.sdkConfig);
|
|
3319
3757
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3320
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}',
|
|
3758
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
|
|
3321
3759
|
const cached = cache.get(cacheKey);
|
|
3322
3760
|
if (cached) {
|
|
3323
3761
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3329,12 +3767,12 @@ class CompanyWrapper {
|
|
|
3329
3767
|
request_id: requestId,
|
|
3330
3768
|
method: 'GET',
|
|
3331
3769
|
path: '/api/v1/company/{company_id}',
|
|
3332
|
-
params:
|
|
3770
|
+
params: resolvedParams,
|
|
3333
3771
|
action: 'getCompany'
|
|
3334
3772
|
});
|
|
3335
3773
|
try {
|
|
3336
3774
|
const response = await retryApiCall(async () => {
|
|
3337
|
-
const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: companyId }, { headers: { 'x-request-id': requestId } });
|
|
3775
|
+
const apiResponse = await this.api.getCompanyApiV1CompanyCompanyIdGet({ companyId: resolvedParams.companyId ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3338
3776
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3339
3777
|
}, {}, this.sdkConfig);
|
|
3340
3778
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3343,9 +3781,15 @@ class CompanyWrapper {
|
|
|
3343
3781
|
throw new Error('Unexpected response shape: missing success field');
|
|
3344
3782
|
}
|
|
3345
3783
|
// Convert response to plain object, removing _id fields recursively
|
|
3784
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3346
3785
|
const standardResponse = convertToPlainObject(responseData);
|
|
3786
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3787
|
+
const hasLimit = false;
|
|
3788
|
+
const hasOffset = false;
|
|
3789
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3790
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3347
3791
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3348
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}',
|
|
3792
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/company/{company_id}', resolvedParams, this.sdkConfig);
|
|
3349
3793
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3350
3794
|
}
|
|
3351
3795
|
this.logger.debug('Get Company completed', {
|
|
@@ -3353,6 +3797,7 @@ class CompanyWrapper {
|
|
|
3353
3797
|
action: 'getCompany'
|
|
3354
3798
|
});
|
|
3355
3799
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3800
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3356
3801
|
return standardResponse;
|
|
3357
3802
|
}
|
|
3358
3803
|
catch (error) {
|
|
@@ -3465,7 +3910,7 @@ class SessionWrapper {
|
|
|
3465
3910
|
* Init Session
|
|
3466
3911
|
*
|
|
3467
3912
|
* Initialize a new session with company API key.
|
|
3468
|
-
* @param xApiKey {string}
|
|
3913
|
+
* @param params.xApiKey {string} Company API key
|
|
3469
3914
|
* @returns {Promise<FinaticResponse<TokenResponseData>>} Standard response with success/Error/Warning structure
|
|
3470
3915
|
*
|
|
3471
3916
|
* Generated from: POST /api/v1/session/init
|
|
@@ -3474,7 +3919,7 @@ class SessionWrapper {
|
|
|
3474
3919
|
* @example
|
|
3475
3920
|
* ```typescript-client
|
|
3476
3921
|
* // Example with no parameters
|
|
3477
|
-
* const result = await finatic.initSession();
|
|
3922
|
+
* const result = await finatic.initSession({});
|
|
3478
3923
|
*
|
|
3479
3924
|
* // Access the response data
|
|
3480
3925
|
* if (result.success) {
|
|
@@ -3482,11 +3927,9 @@ class SessionWrapper {
|
|
|
3482
3927
|
* }
|
|
3483
3928
|
* ```
|
|
3484
3929
|
*/
|
|
3485
|
-
async initSession(
|
|
3486
|
-
//
|
|
3487
|
-
const
|
|
3488
|
-
xApiKey: xApiKey
|
|
3489
|
-
}; // Generate request ID
|
|
3930
|
+
async initSession(params) {
|
|
3931
|
+
// Use params object (required parameters present)
|
|
3932
|
+
const resolvedParams = params; // Generate request ID
|
|
3490
3933
|
const requestId = this._generateRequestId();
|
|
3491
3934
|
// Input validation (Phase 2B: zod)
|
|
3492
3935
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3494,7 +3937,7 @@ class SessionWrapper {
|
|
|
3494
3937
|
const shouldCache = true;
|
|
3495
3938
|
const cache = getCache(this.sdkConfig);
|
|
3496
3939
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3497
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/init',
|
|
3940
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
|
|
3498
3941
|
const cached = cache.get(cacheKey);
|
|
3499
3942
|
if (cached) {
|
|
3500
3943
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3506,12 +3949,12 @@ class SessionWrapper {
|
|
|
3506
3949
|
request_id: requestId,
|
|
3507
3950
|
method: 'POST',
|
|
3508
3951
|
path: '/api/v1/session/init',
|
|
3509
|
-
params:
|
|
3952
|
+
params: resolvedParams,
|
|
3510
3953
|
action: 'initSession'
|
|
3511
3954
|
});
|
|
3512
3955
|
try {
|
|
3513
3956
|
const response = await retryApiCall(async () => {
|
|
3514
|
-
const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: xApiKey }, { headers: { 'x-request-id': requestId } });
|
|
3957
|
+
const apiResponse = await this.api.initSessionApiV1SessionInitPost({ xApiKey: resolvedParams.xApiKey ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3515
3958
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3516
3959
|
}, {}, this.sdkConfig);
|
|
3517
3960
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3520,9 +3963,15 @@ class SessionWrapper {
|
|
|
3520
3963
|
throw new Error('Unexpected response shape: missing success field');
|
|
3521
3964
|
}
|
|
3522
3965
|
// Convert response to plain object, removing _id fields recursively
|
|
3966
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3523
3967
|
const standardResponse = convertToPlainObject(responseData);
|
|
3968
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
3969
|
+
const hasLimit = false;
|
|
3970
|
+
const hasOffset = false;
|
|
3971
|
+
const hasPagination = hasLimit && hasOffset;
|
|
3972
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3524
3973
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3525
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/init',
|
|
3974
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/init', resolvedParams, this.sdkConfig);
|
|
3526
3975
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3527
3976
|
}
|
|
3528
3977
|
this.logger.debug('Init Session completed', {
|
|
@@ -3530,6 +3979,7 @@ class SessionWrapper {
|
|
|
3530
3979
|
action: 'initSession'
|
|
3531
3980
|
});
|
|
3532
3981
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
3982
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3533
3983
|
return standardResponse;
|
|
3534
3984
|
}
|
|
3535
3985
|
catch (error) {
|
|
@@ -3603,8 +4053,8 @@ class SessionWrapper {
|
|
|
3603
4053
|
* Start Session
|
|
3604
4054
|
*
|
|
3605
4055
|
* Start a session with a one-time token.
|
|
3606
|
-
* @param OneTimeToken {string}
|
|
3607
|
-
* @param body {SessionStartRequest}
|
|
4056
|
+
* @param params.OneTimeToken {string} One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
4057
|
+
* @param params.body {SessionStartRequest} Session start request containing optional user ID to associate with the session
|
|
3608
4058
|
* @returns {Promise<FinaticResponse<SessionResponseData>>} Standard response with success/Error/Warning structure
|
|
3609
4059
|
*
|
|
3610
4060
|
* Generated from: POST /api/v1/session/start
|
|
@@ -3613,7 +4063,7 @@ class SessionWrapper {
|
|
|
3613
4063
|
* @example
|
|
3614
4064
|
* ```typescript-client
|
|
3615
4065
|
* // Example with no parameters
|
|
3616
|
-
* const result = await finatic.startSession();
|
|
4066
|
+
* const result = await finatic.startSession({});
|
|
3617
4067
|
*
|
|
3618
4068
|
* // Access the response data
|
|
3619
4069
|
* if (result.success) {
|
|
@@ -3621,12 +4071,9 @@ class SessionWrapper {
|
|
|
3621
4071
|
* }
|
|
3622
4072
|
* ```
|
|
3623
4073
|
*/
|
|
3624
|
-
async startSession(
|
|
3625
|
-
//
|
|
3626
|
-
const
|
|
3627
|
-
OneTimeToken: OneTimeToken,
|
|
3628
|
-
body: body
|
|
3629
|
-
}; // Generate request ID
|
|
4074
|
+
async startSession(params) {
|
|
4075
|
+
// Use params object (required parameters present)
|
|
4076
|
+
const resolvedParams = params; // Generate request ID
|
|
3630
4077
|
const requestId = this._generateRequestId();
|
|
3631
4078
|
// Input validation (Phase 2B: zod)
|
|
3632
4079
|
if (this.sdkConfig?.validationEnabled) ;
|
|
@@ -3634,7 +4081,7 @@ class SessionWrapper {
|
|
|
3634
4081
|
const shouldCache = true;
|
|
3635
4082
|
const cache = getCache(this.sdkConfig);
|
|
3636
4083
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3637
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/start',
|
|
4084
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
|
|
3638
4085
|
const cached = cache.get(cacheKey);
|
|
3639
4086
|
if (cached) {
|
|
3640
4087
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3646,12 +4093,12 @@ class SessionWrapper {
|
|
|
3646
4093
|
request_id: requestId,
|
|
3647
4094
|
method: 'POST',
|
|
3648
4095
|
path: '/api/v1/session/start',
|
|
3649
|
-
params:
|
|
4096
|
+
params: resolvedParams,
|
|
3650
4097
|
action: 'startSession'
|
|
3651
4098
|
});
|
|
3652
4099
|
try {
|
|
3653
4100
|
const response = await retryApiCall(async () => {
|
|
3654
|
-
const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: OneTimeToken, sessionStartRequest: body }, { headers: { 'x-request-id': requestId } });
|
|
4101
|
+
const apiResponse = await this.api.startSessionApiV1SessionStartPost({ oneTimeToken: resolvedParams.OneTimeToken ?? null, sessionStartRequest: resolvedParams.body ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3655
4102
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3656
4103
|
}, {}, this.sdkConfig);
|
|
3657
4104
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3660,9 +4107,15 @@ class SessionWrapper {
|
|
|
3660
4107
|
throw new Error('Unexpected response shape: missing success field');
|
|
3661
4108
|
}
|
|
3662
4109
|
// Convert response to plain object, removing _id fields recursively
|
|
4110
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3663
4111
|
const standardResponse = convertToPlainObject(responseData);
|
|
4112
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4113
|
+
const hasLimit = false;
|
|
4114
|
+
const hasOffset = false;
|
|
4115
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4116
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3664
4117
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3665
|
-
const cacheKey = generateCacheKey('POST', '/api/v1/session/start',
|
|
4118
|
+
const cacheKey = generateCacheKey('POST', '/api/v1/session/start', resolvedParams, this.sdkConfig);
|
|
3666
4119
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3667
4120
|
}
|
|
3668
4121
|
this.logger.debug('Start Session completed', {
|
|
@@ -3670,6 +4123,7 @@ class SessionWrapper {
|
|
|
3670
4123
|
action: 'startSession'
|
|
3671
4124
|
});
|
|
3672
4125
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4126
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3673
4127
|
return standardResponse;
|
|
3674
4128
|
}
|
|
3675
4129
|
catch (error) {
|
|
@@ -3746,7 +4200,7 @@ class SessionWrapper {
|
|
|
3746
4200
|
*
|
|
3747
4201
|
* The session must be in ACTIVE or AUTHENTICATING state and the request must come from the same device
|
|
3748
4202
|
* that initiated the session. Device info is automatically validated from the request.
|
|
3749
|
-
* @param No parameters required for this method
|
|
4203
|
+
* @param params No parameters required for this method
|
|
3750
4204
|
* @returns {Promise<FinaticResponse<PortalUrlResponse>>} Standard response with success/Error/Warning structure
|
|
3751
4205
|
*
|
|
3752
4206
|
* Generated from: GET /api/v1/session/portal
|
|
@@ -3755,7 +4209,7 @@ class SessionWrapper {
|
|
|
3755
4209
|
* @example
|
|
3756
4210
|
* ```typescript-client
|
|
3757
4211
|
* // Example with no parameters
|
|
3758
|
-
* const result = await finatic.getPortalUrl();
|
|
4212
|
+
* const result = await finatic.getPortalUrl({});
|
|
3759
4213
|
*
|
|
3760
4214
|
* // Access the response data
|
|
3761
4215
|
* if (result.success) {
|
|
@@ -3763,10 +4217,10 @@ class SessionWrapper {
|
|
|
3763
4217
|
* }
|
|
3764
4218
|
* ```
|
|
3765
4219
|
*/
|
|
3766
|
-
async getPortalUrl() {
|
|
4220
|
+
async getPortalUrl(params) {
|
|
3767
4221
|
// No parameters - use empty params object
|
|
3768
|
-
const
|
|
3769
|
-
if (!this.sessionId) {
|
|
4222
|
+
const resolvedParams = params || {}; // Authentication check
|
|
4223
|
+
if (!this.sessionId || !this.companyId) {
|
|
3770
4224
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3771
4225
|
}
|
|
3772
4226
|
// Generate request ID
|
|
@@ -3777,7 +4231,7 @@ class SessionWrapper {
|
|
|
3777
4231
|
const shouldCache = true;
|
|
3778
4232
|
const cache = getCache(this.sdkConfig);
|
|
3779
4233
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3780
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal',
|
|
4234
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
|
|
3781
4235
|
const cached = cache.get(cacheKey);
|
|
3782
4236
|
if (cached) {
|
|
3783
4237
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3789,12 +4243,12 @@ class SessionWrapper {
|
|
|
3789
4243
|
request_id: requestId,
|
|
3790
4244
|
method: 'GET',
|
|
3791
4245
|
path: '/api/v1/session/portal',
|
|
3792
|
-
params:
|
|
4246
|
+
params: resolvedParams,
|
|
3793
4247
|
action: 'getPortalUrl'
|
|
3794
4248
|
});
|
|
3795
4249
|
try {
|
|
3796
4250
|
const response = await retryApiCall(async () => {
|
|
3797
|
-
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
|
|
4251
|
+
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 } : {}) } : {}) } });
|
|
3798
4252
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3799
4253
|
}, {}, this.sdkConfig);
|
|
3800
4254
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3803,9 +4257,15 @@ class SessionWrapper {
|
|
|
3803
4257
|
throw new Error('Unexpected response shape: missing success field');
|
|
3804
4258
|
}
|
|
3805
4259
|
// Convert response to plain object, removing _id fields recursively
|
|
4260
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3806
4261
|
const standardResponse = convertToPlainObject(responseData);
|
|
4262
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4263
|
+
const hasLimit = false;
|
|
4264
|
+
const hasOffset = false;
|
|
4265
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4266
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3807
4267
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3808
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal',
|
|
4268
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/portal', resolvedParams, this.sdkConfig);
|
|
3809
4269
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3810
4270
|
}
|
|
3811
4271
|
this.logger.debug('Get Portal Url completed', {
|
|
@@ -3813,6 +4273,7 @@ class SessionWrapper {
|
|
|
3813
4273
|
action: 'getPortalUrl'
|
|
3814
4274
|
});
|
|
3815
4275
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4276
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3816
4277
|
return standardResponse;
|
|
3817
4278
|
}
|
|
3818
4279
|
catch (error) {
|
|
@@ -3897,7 +4358,7 @@ class SessionWrapper {
|
|
|
3897
4358
|
* - Generates fresh tokens (not returning stored ones)
|
|
3898
4359
|
* - Only accessible to authenticated sessions with user_id
|
|
3899
4360
|
* - Validates that header session_id matches path session_id
|
|
3900
|
-
* @param sessionId {string}
|
|
4361
|
+
* @param params.sessionId {string} Session ID
|
|
3901
4362
|
* @returns {Promise<FinaticResponse<SessionUserResponse>>} Standard response with success/Error/Warning structure
|
|
3902
4363
|
*
|
|
3903
4364
|
* Generated from: GET /api/v1/session/{session_id}/user
|
|
@@ -3906,7 +4367,9 @@ class SessionWrapper {
|
|
|
3906
4367
|
* @example
|
|
3907
4368
|
* ```typescript-client
|
|
3908
4369
|
* // Minimal example with required parameters only
|
|
3909
|
-
* const result = await finatic.getSessionUser(
|
|
4370
|
+
* const result = await finatic.getSessionUser({
|
|
4371
|
+
sessionId: 'sess_1234567890abcdef'
|
|
4372
|
+
* });
|
|
3910
4373
|
*
|
|
3911
4374
|
* // Access the response data
|
|
3912
4375
|
* if (result.success) {
|
|
@@ -3916,12 +4379,10 @@ class SessionWrapper {
|
|
|
3916
4379
|
* }
|
|
3917
4380
|
* ```
|
|
3918
4381
|
*/
|
|
3919
|
-
async getSessionUser(
|
|
3920
|
-
//
|
|
3921
|
-
const
|
|
3922
|
-
|
|
3923
|
-
}; // Authentication check
|
|
3924
|
-
if (!this.sessionId) {
|
|
4382
|
+
async getSessionUser(params) {
|
|
4383
|
+
// Use params object (required parameters present)
|
|
4384
|
+
const resolvedParams = params; // Authentication check
|
|
4385
|
+
if (!this.sessionId || !this.companyId) {
|
|
3925
4386
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
3926
4387
|
}
|
|
3927
4388
|
// Generate request ID
|
|
@@ -3932,7 +4393,7 @@ class SessionWrapper {
|
|
|
3932
4393
|
const shouldCache = true;
|
|
3933
4394
|
const cache = getCache(this.sdkConfig);
|
|
3934
4395
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3935
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user',
|
|
4396
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
|
|
3936
4397
|
const cached = cache.get(cacheKey);
|
|
3937
4398
|
if (cached) {
|
|
3938
4399
|
this.logger.debug('Cache hit', { request_id: requestId, cache_key: cacheKey });
|
|
@@ -3944,12 +4405,12 @@ class SessionWrapper {
|
|
|
3944
4405
|
request_id: requestId,
|
|
3945
4406
|
method: 'GET',
|
|
3946
4407
|
path: '/api/v1/session/{session_id}/user',
|
|
3947
|
-
params:
|
|
4408
|
+
params: resolvedParams,
|
|
3948
4409
|
action: 'getSessionUser'
|
|
3949
4410
|
});
|
|
3950
4411
|
try {
|
|
3951
4412
|
const response = await retryApiCall(async () => {
|
|
3952
|
-
const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: sessionId, xSessionId: sessionId }, { headers: { 'x-request-id': requestId } });
|
|
4413
|
+
const apiResponse = await this.api.getSessionUserApiV1SessionSessionIdUserGet({ sessionId: resolvedParams.sessionId ?? null, xSessionId: resolvedParams.sessionId ?? null }, { headers: { 'x-request-id': requestId } });
|
|
3953
4414
|
return await applyResponseInterceptors(apiResponse, this.sdkConfig);
|
|
3954
4415
|
}, {}, this.sdkConfig);
|
|
3955
4416
|
// Unwrap axios response immediately - get FinaticResponse object
|
|
@@ -3958,9 +4419,15 @@ class SessionWrapper {
|
|
|
3958
4419
|
throw new Error('Unexpected response shape: missing success field');
|
|
3959
4420
|
}
|
|
3960
4421
|
// Convert response to plain object, removing _id fields recursively
|
|
4422
|
+
// Use 'any' for initial type to allow PaginatedData assignment, then assert final type
|
|
3961
4423
|
const standardResponse = convertToPlainObject(responseData);
|
|
4424
|
+
// Phase 2: Wrap paginated responses with PaginatedData
|
|
4425
|
+
const hasLimit = false;
|
|
4426
|
+
const hasOffset = false;
|
|
4427
|
+
const hasPagination = hasLimit && hasOffset;
|
|
4428
|
+
if (hasPagination && standardResponse.success?.data && Array.isArray(standardResponse.success.data) && standardResponse.success.meta) ;
|
|
3962
4429
|
if (cache && this.sdkConfig?.cacheEnabled && shouldCache) {
|
|
3963
|
-
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user',
|
|
4430
|
+
const cacheKey = generateCacheKey('GET', '/api/v1/session/{session_id}/user', resolvedParams, this.sdkConfig);
|
|
3964
4431
|
cache.set(cacheKey, standardResponse, this.sdkConfig.cacheTtl || 300);
|
|
3965
4432
|
}
|
|
3966
4433
|
this.logger.debug('Get Session User completed', {
|
|
@@ -3968,6 +4435,7 @@ class SessionWrapper {
|
|
|
3968
4435
|
action: 'getSessionUser'
|
|
3969
4436
|
});
|
|
3970
4437
|
// Phase 2C: Return standard response structure (plain objects with _id fields removed)
|
|
4438
|
+
// Type assertion to final return type (handles both paginated and non-paginated responses)
|
|
3971
4439
|
return standardResponse;
|
|
3972
4440
|
}
|
|
3973
4441
|
catch (error) {
|
|
@@ -4716,8 +5184,8 @@ const SessionApiAxiosParamCreator = function (configuration) {
|
|
|
4716
5184
|
/**
|
|
4717
5185
|
* Start a session with a one-time token.
|
|
4718
5186
|
* @summary Start Session
|
|
4719
|
-
* @param {string} oneTimeToken
|
|
4720
|
-
* @param {SessionStartRequest} sessionStartRequest
|
|
5187
|
+
* @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
5188
|
+
* @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
|
|
4721
5189
|
* @param {*} [options] Override http request option.
|
|
4722
5190
|
* @throws {RequiredError}
|
|
4723
5191
|
*/
|
|
@@ -4800,8 +5268,8 @@ const SessionApiFp = function (configuration) {
|
|
|
4800
5268
|
/**
|
|
4801
5269
|
* Start a session with a one-time token.
|
|
4802
5270
|
* @summary Start Session
|
|
4803
|
-
* @param {string} oneTimeToken
|
|
4804
|
-
* @param {SessionStartRequest} sessionStartRequest
|
|
5271
|
+
* @param {string} oneTimeToken One-time use token obtained from init_session endpoint to authenticate and start the session
|
|
5272
|
+
* @param {SessionStartRequest} sessionStartRequest Session start request containing optional user ID to associate with the session
|
|
4805
5273
|
* @param {*} [options] Override http request option.
|
|
4806
5274
|
* @throws {RequiredError}
|
|
4807
5275
|
*/
|
|
@@ -5016,7 +5484,7 @@ const BrokersApiAxiosParamCreator = function (configuration) {
|
|
|
5016
5484
|
* @summary Get Balances
|
|
5017
5485
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5018
5486
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5019
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
5487
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5020
5488
|
* @param {boolean | null} [isEndOfDaySnapshot] Filter by end-of-day snapshot status (true/false)
|
|
5021
5489
|
* @param {number} [limit] Maximum number of balances to return
|
|
5022
5490
|
* @param {number} [offset] Number of balances to skip for pagination
|
|
@@ -5253,9 +5721,9 @@ const BrokersApiAxiosParamCreator = function (configuration) {
|
|
|
5253
5721
|
* @summary Get Orders
|
|
5254
5722
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5255
5723
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5256
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
5724
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5257
5725
|
* @param {string | null} [symbol] Filter by symbol
|
|
5258
|
-
* @param {
|
|
5726
|
+
* @param {string | null} [orderStatus] Filter by order status (e.g., \'filled\', \'pending_new\', \'cancelled\')
|
|
5259
5727
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by order side (e.g., \'buy\', \'sell\')
|
|
5260
5728
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
5261
5729
|
* @param {number} [limit] Maximum number of orders to return
|
|
@@ -5424,7 +5892,7 @@ const BrokersApiAxiosParamCreator = function (configuration) {
|
|
|
5424
5892
|
* @summary Get Positions
|
|
5425
5893
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5426
5894
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5427
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
5895
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5428
5896
|
* @param {string | null} [symbol] Filter by symbol
|
|
5429
5897
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by position side (e.g., \'long\', \'short\')
|
|
5430
5898
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
@@ -5567,7 +6035,7 @@ const BrokersApiFp = function (configuration) {
|
|
|
5567
6035
|
* @summary Get Balances
|
|
5568
6036
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5569
6037
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5570
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
6038
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5571
6039
|
* @param {boolean | null} [isEndOfDaySnapshot] Filter by end-of-day snapshot status (true/false)
|
|
5572
6040
|
* @param {number} [limit] Maximum number of balances to return
|
|
5573
6041
|
* @param {number} [offset] Number of balances to skip for pagination
|
|
@@ -5653,9 +6121,9 @@ const BrokersApiFp = function (configuration) {
|
|
|
5653
6121
|
* @summary Get Orders
|
|
5654
6122
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5655
6123
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5656
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
6124
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5657
6125
|
* @param {string | null} [symbol] Filter by symbol
|
|
5658
|
-
* @param {
|
|
6126
|
+
* @param {string | null} [orderStatus] Filter by order status (e.g., \'filled\', \'pending_new\', \'cancelled\')
|
|
5659
6127
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by order side (e.g., \'buy\', \'sell\')
|
|
5660
6128
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
5661
6129
|
* @param {number} [limit] Maximum number of orders to return
|
|
@@ -5712,7 +6180,7 @@ const BrokersApiFp = function (configuration) {
|
|
|
5712
6180
|
* @summary Get Positions
|
|
5713
6181
|
* @param {string | null} [brokerId] Filter by broker ID
|
|
5714
6182
|
* @param {string | null} [connectionId] Filter by connection ID
|
|
5715
|
-
* @param {string | null} [accountId] Filter by broker provided account ID
|
|
6183
|
+
* @param {string | null} [accountId] Filter by broker provided account ID or internal account UUID
|
|
5716
6184
|
* @param {string | null} [symbol] Filter by symbol
|
|
5717
6185
|
* @param {BrokerDataOrderSideEnum | null} [side] Filter by position side (e.g., \'long\', \'short\')
|
|
5718
6186
|
* @param {BrokerDataAssetTypeEnum | null} [assetType] Filter by asset type (e.g., \'stock\', \'option\', \'crypto\', \'future\')
|
|
@@ -6336,11 +6804,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6336
6804
|
}
|
|
6337
6805
|
const sessionId = data?.session_id || '';
|
|
6338
6806
|
const companyId = data?.company_id || '';
|
|
6807
|
+
const responseUserId = data?.user_id || '';
|
|
6339
6808
|
// csrf_token is not in SessionResponseData, get from response headers if available
|
|
6340
6809
|
const csrfToken = data?.csrf_token || '';
|
|
6341
6810
|
this.logger.debug?.('_startSession extracted data', {
|
|
6342
6811
|
sessionId,
|
|
6343
6812
|
companyId,
|
|
6813
|
+
responseUserId,
|
|
6344
6814
|
csrfToken,
|
|
6345
6815
|
fullData: data,
|
|
6346
6816
|
dataKeys: data ? Object.keys(data) : []
|
|
@@ -6362,6 +6832,13 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6362
6832
|
responseKeys: response ? Object.keys(response) : []
|
|
6363
6833
|
});
|
|
6364
6834
|
}
|
|
6835
|
+
// Store userId if present in response (for getUserId() and isAuthed())
|
|
6836
|
+
// Use userId from response if parameter wasn't provided, or if response has a different userId
|
|
6837
|
+
const finalUserId = responseUserId || userId;
|
|
6838
|
+
if (finalUserId) {
|
|
6839
|
+
this.userId = finalUserId;
|
|
6840
|
+
this.logger.debug?.('_startSession set userId', { userId: finalUserId, source: responseUserId ? 'response' : 'parameter' });
|
|
6841
|
+
}
|
|
6365
6842
|
return { session_id: sessionId, company_id: companyId };
|
|
6366
6843
|
}
|
|
6367
6844
|
/**
|
|
@@ -6373,28 +6850,30 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6373
6850
|
*
|
|
6374
6851
|
* @methodId get_portal_url_api_v1_session_portal_get
|
|
6375
6852
|
* @category session
|
|
6376
|
-
* @param
|
|
6377
|
-
* @param
|
|
6378
|
-
* @param
|
|
6379
|
-
* @param
|
|
6853
|
+
* @param params - Optional parameters object
|
|
6854
|
+
* @param params.theme - Optional theme preset or custom theme object
|
|
6855
|
+
* @param params.brokers - Optional array of broker IDs to filter
|
|
6856
|
+
* @param params.email - Optional email address
|
|
6857
|
+
* @param params.mode - Optional mode ('light' or 'dark')
|
|
6380
6858
|
* @returns Portal URL string
|
|
6381
6859
|
* @example
|
|
6382
6860
|
* ```typescript-client
|
|
6383
|
-
* const url = await finatic.getPortalUrl('
|
|
6861
|
+
* const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
|
|
6384
6862
|
* ```
|
|
6385
6863
|
* @example
|
|
6386
6864
|
* ```typescript-server
|
|
6387
|
-
* const url = await finatic.getPortalUrl('
|
|
6865
|
+
* const url = await finatic.getPortalUrl({ theme: 'default', brokers: ['broker-1'], email: 'user@example.com', mode: 'dark' });
|
|
6388
6866
|
* ```
|
|
6389
6867
|
* @example
|
|
6390
6868
|
* ```python
|
|
6391
|
-
* url = await finatic.get_portal_url('
|
|
6869
|
+
* url = await finatic.get_portal_url(theme='default', brokers=['broker-1'], email='user@example.com', mode='dark')
|
|
6392
6870
|
* ```
|
|
6393
6871
|
*/
|
|
6394
|
-
async getPortalUrl(
|
|
6872
|
+
async getPortalUrl(params) {
|
|
6395
6873
|
if (!this.sessionId) {
|
|
6396
6874
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
6397
6875
|
}
|
|
6876
|
+
const { theme, brokers, email, mode } = params || {};
|
|
6398
6877
|
// Get raw portal URL from SessionApi directly (not a wrapper)
|
|
6399
6878
|
const axiosResponse = await this.sessionApi.getPortalUrlApiV1SessionPortalGet({
|
|
6400
6879
|
sessionId: this.sessionId,
|
|
@@ -6468,29 +6947,35 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6468
6947
|
*
|
|
6469
6948
|
* @methodId open_portal_client_sdk
|
|
6470
6949
|
* @category session
|
|
6471
|
-
* @param
|
|
6472
|
-
* @param
|
|
6473
|
-
* @param
|
|
6474
|
-
* @param
|
|
6950
|
+
* @param params - Optional parameters object
|
|
6951
|
+
* @param params.theme - Optional theme preset or custom theme object
|
|
6952
|
+
* @param params.brokers - Optional array of broker IDs to filter
|
|
6953
|
+
* @param params.email - Optional email address
|
|
6954
|
+
* @param params.mode - Optional mode ('light' or 'dark')
|
|
6475
6955
|
* @param onSuccess - Optional callback when portal authentication succeeds
|
|
6476
6956
|
* @param onError - Optional callback when portal authentication fails
|
|
6477
6957
|
* @param onClose - Optional callback when portal is closed
|
|
6478
6958
|
* @returns Promise that resolves when portal is opened
|
|
6479
6959
|
* @example
|
|
6480
6960
|
* ```typescript-client
|
|
6481
|
-
* await finatic.openPortal(
|
|
6961
|
+
* await finatic.openPortal({
|
|
6962
|
+
* theme: 'default',
|
|
6963
|
+
* brokers: ['broker-1'],
|
|
6964
|
+
* email: 'user@example.com',
|
|
6965
|
+
* mode: 'dark'
|
|
6966
|
+
* },
|
|
6482
6967
|
* (userId) => console.log('User authenticated:', userId),
|
|
6483
6968
|
* (error) => console.error('Portal error:', error),
|
|
6484
6969
|
* () => console.log('Portal closed')
|
|
6485
6970
|
* );
|
|
6486
6971
|
* ```
|
|
6487
6972
|
*/
|
|
6488
|
-
async openPortal(
|
|
6973
|
+
async openPortal(params, onSuccess, onError, onClose) {
|
|
6489
6974
|
if (!this.sessionId) {
|
|
6490
6975
|
throw new Error('Session not initialized. Call startSession() first.');
|
|
6491
6976
|
}
|
|
6492
6977
|
// Get portal URL with all parameters
|
|
6493
|
-
const portalUrl = await this.getPortalUrl(
|
|
6978
|
+
const portalUrl = await this.getPortalUrl(params);
|
|
6494
6979
|
// Create portal UI if not exists
|
|
6495
6980
|
if (!this.portalUI) {
|
|
6496
6981
|
this.portalUI = new PortalUI(this.sdkConfig.baseUrl || 'https://api.finatic.dev');
|
|
@@ -6677,7 +7162,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6677
7162
|
* ```
|
|
6678
7163
|
*/
|
|
6679
7164
|
async getCompany(params) {
|
|
6680
|
-
return await this.company.getCompany(params
|
|
7165
|
+
return await this.company.getCompany(params);
|
|
6681
7166
|
}
|
|
6682
7167
|
/**
|
|
6683
7168
|
* Get Brokers
|
|
@@ -6835,7 +7320,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6835
7320
|
* ```
|
|
6836
7321
|
*/
|
|
6837
7322
|
async disconnectCompanyFromBroker(params) {
|
|
6838
|
-
return await this.brokers.disconnectCompanyFromBroker(params
|
|
7323
|
+
return await this.brokers.disconnectCompanyFromBroker(params);
|
|
6839
7324
|
}
|
|
6840
7325
|
/**
|
|
6841
7326
|
* Get Orders
|
|
@@ -6915,7 +7400,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6915
7400
|
* ```
|
|
6916
7401
|
*/
|
|
6917
7402
|
async getOrders(params) {
|
|
6918
|
-
return await this.brokers.getOrders(params
|
|
7403
|
+
return await this.brokers.getOrders(params);
|
|
6919
7404
|
}
|
|
6920
7405
|
/**
|
|
6921
7406
|
* Get Positions
|
|
@@ -6995,7 +7480,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
6995
7480
|
* ```
|
|
6996
7481
|
*/
|
|
6997
7482
|
async getPositions(params) {
|
|
6998
|
-
return await this.brokers.getPositions(params
|
|
7483
|
+
return await this.brokers.getPositions(params);
|
|
6999
7484
|
}
|
|
7000
7485
|
/**
|
|
7001
7486
|
* Get Balances
|
|
@@ -7075,7 +7560,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7075
7560
|
* ```
|
|
7076
7561
|
*/
|
|
7077
7562
|
async getBalances(params) {
|
|
7078
|
-
return await this.brokers.getBalances(params
|
|
7563
|
+
return await this.brokers.getBalances(params);
|
|
7079
7564
|
}
|
|
7080
7565
|
/**
|
|
7081
7566
|
* Get Accounts
|
|
@@ -7155,7 +7640,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7155
7640
|
* ```
|
|
7156
7641
|
*/
|
|
7157
7642
|
async getAccounts(params) {
|
|
7158
|
-
return await this.brokers.getAccounts(params
|
|
7643
|
+
return await this.brokers.getAccounts(params);
|
|
7159
7644
|
}
|
|
7160
7645
|
/**
|
|
7161
7646
|
* Get Order Fills
|
|
@@ -7243,7 +7728,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7243
7728
|
* ```
|
|
7244
7729
|
*/
|
|
7245
7730
|
async getOrderFills(params) {
|
|
7246
|
-
return await this.brokers.getOrderFills(params
|
|
7731
|
+
return await this.brokers.getOrderFills(params);
|
|
7247
7732
|
}
|
|
7248
7733
|
/**
|
|
7249
7734
|
* Get Order Events
|
|
@@ -7331,7 +7816,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7331
7816
|
* ```
|
|
7332
7817
|
*/
|
|
7333
7818
|
async getOrderEvents(params) {
|
|
7334
|
-
return await this.brokers.getOrderEvents(params
|
|
7819
|
+
return await this.brokers.getOrderEvents(params);
|
|
7335
7820
|
}
|
|
7336
7821
|
/**
|
|
7337
7822
|
* Get Order Groups
|
|
@@ -7410,7 +7895,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7410
7895
|
* ```
|
|
7411
7896
|
*/
|
|
7412
7897
|
async getOrderGroups(params) {
|
|
7413
|
-
return await this.brokers.getOrderGroups(params
|
|
7898
|
+
return await this.brokers.getOrderGroups(params);
|
|
7414
7899
|
}
|
|
7415
7900
|
/**
|
|
7416
7901
|
* Get Position Lots
|
|
@@ -7490,7 +7975,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7490
7975
|
* ```
|
|
7491
7976
|
*/
|
|
7492
7977
|
async getPositionLots(params) {
|
|
7493
|
-
return await this.brokers.getPositionLots(params
|
|
7978
|
+
return await this.brokers.getPositionLots(params);
|
|
7494
7979
|
}
|
|
7495
7980
|
/**
|
|
7496
7981
|
* Get Position Lot Fills
|
|
@@ -7578,7 +8063,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7578
8063
|
* ```
|
|
7579
8064
|
*/
|
|
7580
8065
|
async getPositionLotFills(params) {
|
|
7581
|
-
return await this.brokers.getPositionLotFills(params
|
|
8066
|
+
return await this.brokers.getPositionLotFills(params);
|
|
7582
8067
|
}
|
|
7583
8068
|
/**
|
|
7584
8069
|
* Get all Orders across all pages.
|
|
@@ -7649,7 +8134,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7649
8134
|
let lastError = null;
|
|
7650
8135
|
let warnings = [];
|
|
7651
8136
|
while (true) {
|
|
7652
|
-
const response = await this.brokers.getOrders(
|
|
8137
|
+
const response = await this.brokers.getOrders({ ...filterParams, limit, offset });
|
|
7653
8138
|
// Collect warnings from each page
|
|
7654
8139
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7655
8140
|
warnings.push(...response.warning);
|
|
@@ -7659,10 +8144,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7659
8144
|
break;
|
|
7660
8145
|
}
|
|
7661
8146
|
const result = response.success?.data || [];
|
|
7662
|
-
if
|
|
8147
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8148
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8149
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8150
|
+
? result.items
|
|
8151
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8152
|
+
if (!items || items.length === 0)
|
|
7663
8153
|
break;
|
|
7664
|
-
allData.push(...
|
|
7665
|
-
|
|
8154
|
+
allData.push(...items);
|
|
8155
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8156
|
+
if (items.length < limit)
|
|
7666
8157
|
break;
|
|
7667
8158
|
offset += limit;
|
|
7668
8159
|
}
|
|
@@ -7754,7 +8245,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7754
8245
|
let lastError = null;
|
|
7755
8246
|
let warnings = [];
|
|
7756
8247
|
while (true) {
|
|
7757
|
-
const response = await this.brokers.getPositions(
|
|
8248
|
+
const response = await this.brokers.getPositions({ ...filterParams, limit, offset });
|
|
7758
8249
|
// Collect warnings from each page
|
|
7759
8250
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7760
8251
|
warnings.push(...response.warning);
|
|
@@ -7764,10 +8255,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7764
8255
|
break;
|
|
7765
8256
|
}
|
|
7766
8257
|
const result = response.success?.data || [];
|
|
7767
|
-
if
|
|
8258
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8259
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8260
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8261
|
+
? result.items
|
|
8262
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8263
|
+
if (!items || items.length === 0)
|
|
7768
8264
|
break;
|
|
7769
|
-
allData.push(...
|
|
7770
|
-
|
|
8265
|
+
allData.push(...items);
|
|
8266
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8267
|
+
if (items.length < limit)
|
|
7771
8268
|
break;
|
|
7772
8269
|
offset += limit;
|
|
7773
8270
|
}
|
|
@@ -7859,7 +8356,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7859
8356
|
let lastError = null;
|
|
7860
8357
|
let warnings = [];
|
|
7861
8358
|
while (true) {
|
|
7862
|
-
const response = await this.brokers.getBalances(
|
|
8359
|
+
const response = await this.brokers.getBalances({ ...filterParams, limit, offset });
|
|
7863
8360
|
// Collect warnings from each page
|
|
7864
8361
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7865
8362
|
warnings.push(...response.warning);
|
|
@@ -7869,10 +8366,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7869
8366
|
break;
|
|
7870
8367
|
}
|
|
7871
8368
|
const result = response.success?.data || [];
|
|
7872
|
-
if
|
|
8369
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8370
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8371
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8372
|
+
? result.items
|
|
8373
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8374
|
+
if (!items || items.length === 0)
|
|
7873
8375
|
break;
|
|
7874
|
-
allData.push(...
|
|
7875
|
-
|
|
8376
|
+
allData.push(...items);
|
|
8377
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8378
|
+
if (items.length < limit)
|
|
7876
8379
|
break;
|
|
7877
8380
|
offset += limit;
|
|
7878
8381
|
}
|
|
@@ -7964,7 +8467,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7964
8467
|
let lastError = null;
|
|
7965
8468
|
let warnings = [];
|
|
7966
8469
|
while (true) {
|
|
7967
|
-
const response = await this.brokers.getAccounts(
|
|
8470
|
+
const response = await this.brokers.getAccounts({ ...filterParams, limit, offset });
|
|
7968
8471
|
// Collect warnings from each page
|
|
7969
8472
|
if (response.warning && Array.isArray(response.warning)) {
|
|
7970
8473
|
warnings.push(...response.warning);
|
|
@@ -7974,10 +8477,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
7974
8477
|
break;
|
|
7975
8478
|
}
|
|
7976
8479
|
const result = response.success?.data || [];
|
|
7977
|
-
if
|
|
8480
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8481
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8482
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8483
|
+
? result.items
|
|
8484
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8485
|
+
if (!items || items.length === 0)
|
|
7978
8486
|
break;
|
|
7979
|
-
allData.push(...
|
|
7980
|
-
|
|
8487
|
+
allData.push(...items);
|
|
8488
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8489
|
+
if (items.length < limit)
|
|
7981
8490
|
break;
|
|
7982
8491
|
offset += limit;
|
|
7983
8492
|
}
|
|
@@ -8068,7 +8577,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8068
8577
|
let lastError = null;
|
|
8069
8578
|
let warnings = [];
|
|
8070
8579
|
while (true) {
|
|
8071
|
-
const response = await this.brokers.getOrderFills(
|
|
8580
|
+
const response = await this.brokers.getOrderFills({ ...filterParams, limit, offset });
|
|
8072
8581
|
// Collect warnings from each page
|
|
8073
8582
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8074
8583
|
warnings.push(...response.warning);
|
|
@@ -8078,10 +8587,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8078
8587
|
break;
|
|
8079
8588
|
}
|
|
8080
8589
|
const result = response.success?.data || [];
|
|
8081
|
-
if
|
|
8590
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8591
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8592
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8593
|
+
? result.items
|
|
8594
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8595
|
+
if (!items || items.length === 0)
|
|
8082
8596
|
break;
|
|
8083
|
-
allData.push(...
|
|
8084
|
-
|
|
8597
|
+
allData.push(...items);
|
|
8598
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8599
|
+
if (items.length < limit)
|
|
8085
8600
|
break;
|
|
8086
8601
|
offset += limit;
|
|
8087
8602
|
}
|
|
@@ -8172,7 +8687,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8172
8687
|
let lastError = null;
|
|
8173
8688
|
let warnings = [];
|
|
8174
8689
|
while (true) {
|
|
8175
|
-
const response = await this.brokers.getOrderEvents(
|
|
8690
|
+
const response = await this.brokers.getOrderEvents({ ...filterParams, limit, offset });
|
|
8176
8691
|
// Collect warnings from each page
|
|
8177
8692
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8178
8693
|
warnings.push(...response.warning);
|
|
@@ -8182,10 +8697,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8182
8697
|
break;
|
|
8183
8698
|
}
|
|
8184
8699
|
const result = response.success?.data || [];
|
|
8185
|
-
if
|
|
8700
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8701
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8702
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8703
|
+
? result.items
|
|
8704
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8705
|
+
if (!items || items.length === 0)
|
|
8186
8706
|
break;
|
|
8187
|
-
allData.push(...
|
|
8188
|
-
|
|
8707
|
+
allData.push(...items);
|
|
8708
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8709
|
+
if (items.length < limit)
|
|
8189
8710
|
break;
|
|
8190
8711
|
offset += limit;
|
|
8191
8712
|
}
|
|
@@ -8277,7 +8798,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8277
8798
|
let lastError = null;
|
|
8278
8799
|
let warnings = [];
|
|
8279
8800
|
while (true) {
|
|
8280
|
-
const response = await this.brokers.getOrderGroups(
|
|
8801
|
+
const response = await this.brokers.getOrderGroups({ ...filterParams, limit, offset });
|
|
8281
8802
|
// Collect warnings from each page
|
|
8282
8803
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8283
8804
|
warnings.push(...response.warning);
|
|
@@ -8287,10 +8808,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8287
8808
|
break;
|
|
8288
8809
|
}
|
|
8289
8810
|
const result = response.success?.data || [];
|
|
8290
|
-
if
|
|
8811
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8812
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8813
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8814
|
+
? result.items
|
|
8815
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8816
|
+
if (!items || items.length === 0)
|
|
8291
8817
|
break;
|
|
8292
|
-
allData.push(...
|
|
8293
|
-
|
|
8818
|
+
allData.push(...items);
|
|
8819
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8820
|
+
if (items.length < limit)
|
|
8294
8821
|
break;
|
|
8295
8822
|
offset += limit;
|
|
8296
8823
|
}
|
|
@@ -8382,7 +8909,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8382
8909
|
let lastError = null;
|
|
8383
8910
|
let warnings = [];
|
|
8384
8911
|
while (true) {
|
|
8385
|
-
const response = await this.brokers.getPositionLots(
|
|
8912
|
+
const response = await this.brokers.getPositionLots({ ...filterParams, limit, offset });
|
|
8386
8913
|
// Collect warnings from each page
|
|
8387
8914
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8388
8915
|
warnings.push(...response.warning);
|
|
@@ -8392,10 +8919,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8392
8919
|
break;
|
|
8393
8920
|
}
|
|
8394
8921
|
const result = response.success?.data || [];
|
|
8395
|
-
if
|
|
8922
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
8923
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
8924
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
8925
|
+
? result.items
|
|
8926
|
+
: (Array.isArray(result) ? result : [result]);
|
|
8927
|
+
if (!items || items.length === 0)
|
|
8396
8928
|
break;
|
|
8397
|
-
allData.push(...
|
|
8398
|
-
|
|
8929
|
+
allData.push(...items);
|
|
8930
|
+
// If we got fewer items than the limit, there are no more pages
|
|
8931
|
+
if (items.length < limit)
|
|
8399
8932
|
break;
|
|
8400
8933
|
offset += limit;
|
|
8401
8934
|
}
|
|
@@ -8485,7 +9018,7 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8485
9018
|
let lastError = null;
|
|
8486
9019
|
let warnings = [];
|
|
8487
9020
|
while (true) {
|
|
8488
|
-
const response = await this.brokers.getPositionLotFills(
|
|
9021
|
+
const response = await this.brokers.getPositionLotFills({ ...filterParams, limit, offset });
|
|
8489
9022
|
// Collect warnings from each page
|
|
8490
9023
|
if (response.warning && Array.isArray(response.warning)) {
|
|
8491
9024
|
warnings.push(...response.warning);
|
|
@@ -8495,10 +9028,16 @@ let FinaticConnect$1 = class FinaticConnect extends EventEmitter {
|
|
|
8495
9028
|
break;
|
|
8496
9029
|
}
|
|
8497
9030
|
const result = response.success?.data || [];
|
|
8498
|
-
if
|
|
9031
|
+
// Extract items from PaginatedData if it's a PaginatedData object, otherwise use as-is
|
|
9032
|
+
// PaginatedData has array-like behavior but we extract items for getAll* methods
|
|
9033
|
+
const items = result && typeof result === 'object' && 'items' in result && Array.isArray(result.items)
|
|
9034
|
+
? result.items
|
|
9035
|
+
: (Array.isArray(result) ? result : [result]);
|
|
9036
|
+
if (!items || items.length === 0)
|
|
8499
9037
|
break;
|
|
8500
|
-
allData.push(...
|
|
8501
|
-
|
|
9038
|
+
allData.push(...items);
|
|
9039
|
+
// If we got fewer items than the limit, there are no more pages
|
|
9040
|
+
if (items.length < limit)
|
|
8502
9041
|
break;
|
|
8503
9042
|
offset += limit;
|
|
8504
9043
|
}
|
|
@@ -8543,5 +9082,5 @@ class FinaticConnect extends FinaticConnect$1 {
|
|
|
8543
9082
|
// Marker to verify custom class is being used
|
|
8544
9083
|
FinaticConnect.__CUSTOM_CLASS__ = true;
|
|
8545
9084
|
|
|
8546
|
-
export { AccountStatus, ApiError, BrokerDataAccountTypeEnum, BrokerDataAssetTypeEnum, BrokerDataOrderSideEnum,
|
|
9085
|
+
export { AccountStatus, ApiError, BrokerDataAccountTypeEnum, BrokerDataAssetTypeEnum, BrokerDataOrderSideEnum, BrokerDataPositionStatusEnum, BrokersApi, BrokersApiAxiosParamCreator, BrokersApiFactory, BrokersApiFp, BrokersWrapper, CompanyApi, CompanyApiAxiosParamCreator, CompanyApiFactory, CompanyApiFp, CompanyWrapper, Configuration, EventEmitter, FDXAccountStatus, FDXAccountType, FDXAssetType, FDXBalanceType, FDXOrderClass, FDXOrderEventType, FDXOrderGroupType, FDXOrderSide, FDXOrderStatus, FDXOrderType, FDXPositionSide, FDXPositionStatus, FDXSecurityIdType, FDXTimeInForce, FinaticConnect, FinaticError, PaginatedData, SessionApi, SessionApiAxiosParamCreator, SessionApiFactory, SessionApiFp, SessionStatus, SessionWrapper, ValidationError, addErrorInterceptor, addRequestInterceptor, addResponseInterceptor, appendBrokerFilterToURL, appendThemeToURL, applyErrorInterceptors, applyRequestInterceptors, applyResponseInterceptors, coerceEnumValue, convertToPlainObject, defaultConfig, generateCacheKey, generateRequestId, getCache, getConfig, getLogger, handleError, numberSchema, retryApiCall, stringSchema, unwrapAxiosResponse, validateParams };
|
|
8547
9086
|
//# sourceMappingURL=index.mjs.map
|