removed some files
This commit is contained in:
parent
b87a931a2b
commit
cbf002a31a
4 changed files with 2 additions and 247 deletions
|
|
@ -1,93 +0,0 @@
|
|||
import { MongoClient } from 'mongodb';
|
||||
|
||||
async function migratePriceTracking() {
|
||||
const client = new MongoClient('mongodb://localhost:27017');
|
||||
await client.connect();
|
||||
|
||||
const mongodb = client.db('stock');
|
||||
|
||||
try {
|
||||
console.log('Starting price tracking migration...');
|
||||
|
||||
const collection = mongodb.collection('eodSymbols');
|
||||
const batchSize = 100;
|
||||
let processedCount = 0;
|
||||
let hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
// Find documents that need migration
|
||||
const documents = await collection.find({
|
||||
lastPriceUpdate: { $exists: true },
|
||||
'operations.price_update': { $exists: false }
|
||||
}).limit(batchSize).toArray();
|
||||
|
||||
if (documents.length === 0) {
|
||||
hasMore = false;
|
||||
break;
|
||||
}
|
||||
|
||||
// Process each document
|
||||
for (const doc of documents) {
|
||||
// Normalize date to 00:00:00 UTC
|
||||
const lastPriceUpdate = new Date(doc.lastPriceUpdate);
|
||||
const normalizedDate = new Date(Date.UTC(
|
||||
lastPriceUpdate.getUTCFullYear(),
|
||||
lastPriceUpdate.getUTCMonth(),
|
||||
lastPriceUpdate.getUTCDate(),
|
||||
0, 0, 0, 0
|
||||
));
|
||||
|
||||
// Parse lastPriceDate if it exists
|
||||
let lastRecordDate = null;
|
||||
if (doc.lastPriceDate) {
|
||||
try {
|
||||
lastRecordDate = new Date(doc.lastPriceDate);
|
||||
} catch (e) {
|
||||
console.warn(`Failed to parse lastPriceDate for ${doc.Code}: ${doc.lastPriceDate}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the document
|
||||
await collection.updateOne(
|
||||
{ _id: doc._id },
|
||||
{
|
||||
$set: {
|
||||
'operations.price_update': {
|
||||
lastRunAt: normalizedDate,
|
||||
lastSuccessAt: normalizedDate,
|
||||
status: 'success',
|
||||
...(lastRecordDate && { lastRecordDate })
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
processedCount++;
|
||||
if (processedCount % 1000 === 0) {
|
||||
console.log(`Processed ${processedCount} documents...`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Migration completed. Total documents migrated: ${processedCount}`);
|
||||
|
||||
// Optional: Remove old fields
|
||||
const removeOldFields = false; // Set to true to remove old fields
|
||||
if (removeOldFields) {
|
||||
console.log('Removing old fields...');
|
||||
const result = await collection.updateMany(
|
||||
{},
|
||||
{ $unset: { lastPriceUpdate: '', lastPriceDate: '' } }
|
||||
);
|
||||
console.log(`Removed old fields from ${result.modifiedCount} documents`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('Migration failed:', error);
|
||||
} finally {
|
||||
await client.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Run the migration
|
||||
migratePriceTracking().catch(console.error);
|
||||
|
|
@ -329,7 +329,6 @@ export async function fetchIntraday(
|
|||
symbol,
|
||||
exchange,
|
||||
symbolExchange: `${symbol}.${exchange}`,
|
||||
interval,
|
||||
datetime: bar.datetime,
|
||||
timestamp: bar.timestamp,
|
||||
gmtoffset: bar.gmtoffset,
|
||||
|
|
@ -341,12 +340,12 @@ export async function fetchIntraday(
|
|||
source: 'eod'
|
||||
}));
|
||||
|
||||
// Save to MongoDB - use timestamp, symbol, and interval as unique identifier
|
||||
// Save to MongoDB - use timestamp and symbolExchange as unique identifier
|
||||
const collectionName = `eodIntraday${interval.toUpperCase()}`;
|
||||
const result = await this.mongodb.batchUpsert(
|
||||
collectionName,
|
||||
recordsWithMetadata,
|
||||
['timestamp', 'symbolExchange', 'interval']
|
||||
['timestamp', 'symbolExchange']
|
||||
);
|
||||
|
||||
logger.info(`Saved ${result.insertedCount} intraday records`, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue