bulltrackers-module 1.0.655 → 1.0.656
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.
|
@@ -1277,6 +1277,42 @@ const getComputationResults = async (db, computationName, dateStr, userId = null
|
|
|
1277
1277
|
}
|
|
1278
1278
|
};
|
|
1279
1279
|
|
|
1280
|
+
// 10.4. Find most recent available GlobalAumPerAsset30D data
|
|
1281
|
+
// Looks back up to 7 days to find the most recent available data
|
|
1282
|
+
const findMostRecentGlobalAumData = async (db, startDateStr, maxLookbackDays = 7) => {
|
|
1283
|
+
try {
|
|
1284
|
+
const startDate = new Date(startDateStr);
|
|
1285
|
+
|
|
1286
|
+
// Look back through dates to find the most recent available data
|
|
1287
|
+
for (let i = 0; i < maxLookbackDays; i++) {
|
|
1288
|
+
const checkDate = new Date(startDate);
|
|
1289
|
+
checkDate.setDate(startDate.getDate() - i);
|
|
1290
|
+
const dateKey = checkDate.toISOString().split('T')[0];
|
|
1291
|
+
|
|
1292
|
+
try {
|
|
1293
|
+
const computationData = await getComputationResults(db, 'GlobalAumPerAsset30D', dateKey);
|
|
1294
|
+
|
|
1295
|
+
// If we got valid data (not null/empty), return it
|
|
1296
|
+
if (computationData && typeof computationData === 'object' && Object.keys(computationData).length > 0) {
|
|
1297
|
+
return {
|
|
1298
|
+
date: dateKey,
|
|
1299
|
+
data: computationData
|
|
1300
|
+
};
|
|
1301
|
+
}
|
|
1302
|
+
} catch (error) {
|
|
1303
|
+
// Missing data for this date - continue looking back
|
|
1304
|
+
console.log(`[GlobalAum] No data found for ${dateKey}, checking previous date...`);
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
// No data found in the lookback period
|
|
1309
|
+
return null;
|
|
1310
|
+
} catch (error) {
|
|
1311
|
+
console.error(`[GlobalAum] Error finding most recent data:`, error);
|
|
1312
|
+
throw error;
|
|
1313
|
+
}
|
|
1314
|
+
};
|
|
1315
|
+
|
|
1280
1316
|
// 10.5. Fetch GlobalAumPerAsset30D with 7-day lookback
|
|
1281
1317
|
// Returns the last 7 days of successfully stored data for a specific ticker or all assets
|
|
1282
1318
|
const fetchGlobalAumPerAssetWithLookback = async (db, dateStr, ticker = null, lookbackDays = 7) => {
|
|
@@ -2973,6 +3009,7 @@ const subscribeToAllWatchlistPIs = async (db, userId, watchlistId, alertTypes =
|
|
|
2973
3009
|
module.exports = {
|
|
2974
3010
|
latestUserCentricSnapshot,
|
|
2975
3011
|
pageCollection,
|
|
3012
|
+
findMostRecentGlobalAumData,
|
|
2976
3013
|
fetchGlobalAumPerAssetWithLookback,
|
|
2977
3014
|
getComputationResults,
|
|
2978
3015
|
fetchPopularInvestorMasterList,
|
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
requestPopularInvestorAddition,
|
|
10
10
|
trackPopularInvestorView,
|
|
11
11
|
pageCollection,
|
|
12
|
+
findMostRecentGlobalAumData,
|
|
12
13
|
fetchGlobalAumPerAssetWithLookback
|
|
13
14
|
} = require('../helpers/data-fetchers/firestore.js');
|
|
14
15
|
const { sanitizeCid } = require('../helpers/security_utils.js');
|
|
@@ -275,25 +276,25 @@ router.get('/global-aum', requireFirebaseAuth, async (req, res, next) => {
|
|
|
275
276
|
// Default to today if no date provided
|
|
276
277
|
const targetDate = date || new Date().toISOString().split('T')[0];
|
|
277
278
|
|
|
278
|
-
//
|
|
279
|
-
const
|
|
279
|
+
// Find the most recent available data (looks back up to 7 days if today's data doesn't exist)
|
|
280
|
+
const result = await findMostRecentGlobalAumData(db, targetDate, 7);
|
|
280
281
|
|
|
281
|
-
if (!
|
|
282
|
+
if (!result || !result.data || Object.keys(result.data).length === 0) {
|
|
282
283
|
return res.status(404).json({
|
|
283
284
|
success: false,
|
|
284
|
-
error: 'No AUM data available
|
|
285
|
+
error: 'No AUM data available in the last 7 days'
|
|
285
286
|
});
|
|
286
287
|
}
|
|
287
288
|
|
|
288
289
|
// Convert to array and sort by AUM (descending)
|
|
289
|
-
const assetsArray = Object.entries(
|
|
290
|
+
const assetsArray = Object.entries(result.data)
|
|
290
291
|
.map(([ticker, aum]) => ({ ticker, aum: Number(aum) }))
|
|
291
292
|
.sort((a, b) => b.aum - a.aum)
|
|
292
293
|
.slice(0, parseInt(limit) || 10);
|
|
293
294
|
|
|
294
295
|
res.json({
|
|
295
296
|
success: true,
|
|
296
|
-
date:
|
|
297
|
+
date: result.date, // Return the actual date of the data found
|
|
297
298
|
count: assetsArray.length,
|
|
298
299
|
data: assetsArray
|
|
299
300
|
});
|