This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ProxyAgent } from 'undici'; | |
const SAFE_HTTP_METHODS = ['GET', 'HEAD', 'OPTIONS']; | |
const IDEMPOTENT_HTTP_METHODS = SAFE_HTTP_METHODS.concat(['PUT', 'DELETE']); | |
const HTTP_STATUS_TO_RETRY = [408, 429, 500, 501, 502, 503, 504]; | |
const DEFAULT_TIMEOUT = 20_000; | |
const retryDenyList = new Set([ | |
'ENOTFOUND', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async timestampCreateSeries({ | |
key, | |
retentionInSeconds, | |
labels, | |
}: { | |
key: string; | |
retentionInSeconds: number; | |
labels: string[][]; | |
}) { | |
const args: (string | number)[] = [key, 'RETENTION', retentionInSeconds, 'DUPLICATE_POLICY', 'LAST']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": "1232312323", | |
"name": "Apple", | |
"isin": "US123456890", | |
"marketCap": 1233413233.123, | |
"ipoDate": "2000-01-01", | |
"lastPrice": 123.23, | |
"dividends": [ | |
{ | |
"date": "2022-01-01", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.assets.find({ | |
marketCap: { $gt: 10000 } | |
}, { | |
projection: { isin: 1 } | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = await MongoClient.connect('mongo-url', { | |
// perf optimization - https://github.com/mongodb/node-mongodb-native/releases/tag/v4.3.0 | |
enableUtf8Validation: false, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = await MongoClient.connect('mongodb-url', { | |
minPoolSize: 50, | |
maxPoolSize: 250, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getQuotesForPeriod( | |
assetIdentifier: string, | |
from: Date, | |
to: Date | |
): Promise<Quote[]> { | |
const quotesCollection = await getQuotesCollection(); | |
/** | |
* When fetching multiple years of data, queries are fast, but retrieval not so much. | |
* To improve query performance, we split the interval into a few chunks and query/fetch the data in parallel, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = await MongoClient.connect(mongoConfig().mongoUrl, { | |
compressors: 'snappy', // make sure Snappy is installed | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.assets | |
.find({ ipoDate: { $gt: ISODate('2022-01-01') } }) | |
.readPref('secondaryPreferred') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.holdings.aggregate([ | |
{ | |
$group: { | |
_id: '$portfolio', | |
assetIdentifiers: { | |
$addToSet: '$asset.identifier', | |
}, | |
}, | |
}, | |
{ |
NewerOlder