Skip to content

Commit

Permalink
feat: new instruments Nov 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo4815162342 committed Nov 28, 2024
1 parent cd92729 commit 44f654a
Show file tree
Hide file tree
Showing 8 changed files with 71,382 additions and 45 deletions.
80 changes: 55 additions & 25 deletions src/utils/instrument-meta-data/generate-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,61 @@ const saveFile = promisify(fs.writeFile);

const OUTPUT_FOLDER = path.resolve(__dirname, 'generated');

Promise.all([getActualStartDates(), getRawMetaData()])
.then(([actualStartDates, rawMetaData]) => {
return Promise.all([
saveFile(
path.resolve(OUTPUT_FOLDER, `raw-meta-data-${new Date().toISOString().slice(0, 10)}.json`),
JSON.stringify(rawMetaData, null, 2)
),
generateMeta(
rawMetaData.instruments,
actualStartDates,
path.resolve(OUTPUT_FOLDER, 'instrument-meta-data.json')
),
generateInstrumentEnum(
rawMetaData.instruments,
path.resolve(OUTPUT_FOLDER, 'instrument-enum.ts')
),
generateInstrumentGroupData(
rawMetaData,
path.resolve(OUTPUT_FOLDER, 'instrument-groups.json')
)
]);
})
.then(() => {
console.log('Done');
});
// Promise.all([getActualStartDates(), getRawMetaData()])
// .then(([actualStartDates, rawMetaData]) => {
// return Promise.all([
// saveFile(
// path.resolve(OUTPUT_FOLDER, `raw-meta-data-${new Date().toISOString().slice(0, 10)}.json`),
// JSON.stringify(rawMetaData, null, 2)
// ),
// generateMeta(
// rawMetaData.instruments,
// actualStartDates,
// path.resolve(OUTPUT_FOLDER, 'instrument-meta-data.json')
// ),
// generateInstrumentEnum(
// rawMetaData.instruments,
// path.resolve(OUTPUT_FOLDER, 'instrument-enum.ts')
// ),

// ]);
// })
// .then(() => {
// console.log('Done');
// });


Check failure on line 37 in src/utils/instrument-meta-data/generate-data.ts

View workflow job for this annotation

GitHub Actions / test

Delete `⏎`
async function run() {
const [actualStartDates, rawMetaData] = await Promise.all([getActualStartDates(), getRawMetaData()]);

Check failure on line 39 in src/utils/instrument-meta-data/generate-data.ts

View workflow job for this annotation

GitHub Actions / test

Replace `getActualStartDates(),·getRawMetaData()` with `⏎····getActualStartDates(),⏎····getRawMetaData()⏎··`
await saveFile(
path.resolve(OUTPUT_FOLDER, `raw-meta-data-${new Date().toISOString().slice(0, 10)}.json`),
JSON.stringify(rawMetaData, null, 2)
);

const metaDataFilePath = path.resolve(OUTPUT_FOLDER, 'instrument-meta-data.json');

await generateMeta(

Check failure on line 47 in src/utils/instrument-meta-data/generate-data.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎····rawMetaData.instruments,⏎····actualStartDates,⏎····metaDataFilePath⏎··` with `rawMetaData.instruments,·actualStartDates,·metaDataFilePath`
rawMetaData.instruments,
actualStartDates,
metaDataFilePath
);

await generateInstrumentEnum(

Check failure on line 53 in src/utils/instrument-meta-data/generate-data.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎····metaDataFilePath,⏎····path.resolve(OUTPUT_FOLDER,·'instrument-enum.ts')⏎··);⏎` with `metaDataFilePath,·path.resolve(OUTPUT_FOLDER,·'instrument-enum.ts'));`
metaDataFilePath,
path.resolve(OUTPUT_FOLDER, 'instrument-enum.ts')
);


await generateInstrumentGroupData(
rawMetaData,
path.resolve(OUTPUT_FOLDER, 'instrument-groups.json')
);

console.log('Done');

Check failure on line 64 in src/utils/instrument-meta-data/generate-data.ts

View workflow job for this annotation

GitHub Actions / test

Delete `⏎`

}

run();

async function getActualStartDates(): Promise<ActualStartDates> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
Expand Down
40 changes: 32 additions & 8 deletions src/utils/instrument-meta-data/generate-group-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export function generateInstrumentGroupData(
metadata: MetaDataResponse,
path: string
): Promise<void> {

Check failure on line 17 in src/utils/instrument-meta-data/generate-group-data.ts

View workflow job for this annotation

GitHub Actions / test

Delete `⏎⏎`

const currentGroupDataRaw = fs.readFileSync(path, 'utf8');
const currentGroupData = JSON.parse(currentGroupDataRaw) as GroupData[];

const data = Object.keys(metadata.groups).reduce<GroupData[]>((all, group) => {
const hasInstruments = metadata.groups[group]?.instruments?.length;
if (!hasInstruments) {
Expand All @@ -27,17 +32,36 @@ export function generateInstrumentGroupData(
return all;
}

all.push({
id: group.toLowerCase().replace(/\s/g, '-'),
instruments: metadata.groups[group].instruments
.filter(inst => !!metadata.instruments[inst])
.map(inst => generateIdName(metadata.instruments[inst].historical_filename, inst))
});
const id = group.toLowerCase().replace(/\s/g, '-');

const matchedGroup = currentGroupData.find(item => item.id === id);

if (matchedGroup) {
matchedGroup.instruments = matchedGroup.instruments.concat(
metadata.groups[group].instruments
.filter(inst => !!metadata.instruments[inst])
.map(inst => generateIdName(metadata.instruments[inst].historical_filename, inst))
);
} else {
all.push({
id,
instruments: metadata.groups[group].instruments
.filter(inst => !!metadata.instruments[inst])
.map(inst => generateIdName(metadata.instruments[inst].historical_filename, inst))
});
}

return all;
}, []);
}, currentGroupData);

const dedupedGroups = data.map<GroupData>(item => {
return {
id: item.id,
instruments: Array.from(new Set(item.instruments))
}

Check failure on line 61 in src/utils/instrument-meta-data/generate-group-data.ts

View workflow job for this annotation

GitHub Actions / test

Insert `;`
})

Check failure on line 62 in src/utils/instrument-meta-data/generate-group-data.ts

View workflow job for this annotation

GitHub Actions / test

Insert `;`

return saveFile(path, JSON.stringify(data, null, 2)).then(() => {
return saveFile(path, JSON.stringify(dedupedGroups, null, 2)).then(() => {
console.log('instrument groups generated!', path);
});
}
21 changes: 11 additions & 10 deletions src/utils/instrument-meta-data/generate-instrument-enum.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/* eslint-disable no-console */
import fs from 'fs';
import { promisify } from 'util';
import { MetaDataResponse } from './generate-data.types';
import { generateIdName } from './generate-id-name';
import { InstrumentMetaDataMap } from './generate-meta';
const saveFile = promisify(fs.writeFile);

export function generateInstrumentEnum(

Check failure on line 6 in src/utils/instrument-meta-data/generate-instrument-enum.ts

View workflow job for this annotation

GitHub Actions / test

Replace `⏎··fromPath:·string,⏎··toPath:·string⏎):·Promise<void>·{⏎` with `fromPath:·string,·toPath:·string):·Promise<void>·{`
instruments: MetaDataResponse['instruments'],
path: string
fromPath: string,
toPath: string
): Promise<void> {
const enumKeys = Object.keys(instruments).map(inst => {
const { name, description, historical_filename } = instruments[inst];

const cleanName = generateIdName(historical_filename, inst);
const instrumentsmetaData = fs.readFileSync(fromPath, 'utf8');
const instrumentsMetaData = JSON.parse(instrumentsmetaData) as InstrumentMetaDataMap;

const enumKeys = Object.entries(instrumentsMetaData).map(([cleanName, inst]) => {
const { name, description } = inst;

const key = /^\d/.test(cleanName) ? `'${cleanName}'` : cleanName;

const line = `
Expand All @@ -31,7 +32,7 @@ export function generateInstrumentEnum(
'export type InstrumentType = keyof typeof Instrument;'
].join('\n');

return saveFile(path, strings).then(() => {
console.log('instruments enum generated!', path);
return saveFile(toPath, strings).then(() => {
console.log('instruments enum generated!', toPath);

Check warning on line 36 in src/utils/instrument-meta-data/generate-instrument-enum.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
});
}
10 changes: 8 additions & 2 deletions src/utils/instrument-meta-data/generate-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ const decimalFactorOverride: Record<string, number> = {
lnkusd: 1000
};

type InstrumentMetaDataMap = Record<string, InstrumentMetaData>;

export function generateMeta(
instruments: MetaDataResponse['instruments'],
actualStartDates: ActualStartDates,
path: string
): Promise<void> {
const data = Object.keys(instruments).reduce<Record<string, InstrumentMetaData>>((all, inst) => {

Check failure on line 34 in src/utils/instrument-meta-data/generate-meta.ts

View workflow job for this annotation

GitHub Actions / test

Delete `⏎`
const currentValueFromFile = fs.readFileSync(path, 'utf8');
const currentValue = JSON.parse(currentValueFromFile) as InstrumentMetaDataMap;

const data = Object.keys(instruments).reduce((all, inst) => {
const {
name,
description,
Expand Down Expand Up @@ -66,7 +72,7 @@ export function generateMeta(
};

return all;
}, {});
}, currentValue);

return saveFile(path, JSON.stringify(data, null, 2)).then(() => {
console.log('Meta data generated!', path);
Expand Down
96 changes: 96 additions & 0 deletions src/utils/instrument-meta-data/generated/instrument-enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7601,5 +7601,101 @@ export enum Instrument {
* *ZURN.CH/CHF*
*/
zurnchchf='zurnchchf',

/**
* ### ARK 21Shares Active Bitcoin Ethereum Strategy ETF Fund
* *ARKI.US/USD*
*/
arkiususd='arkiususd',

/**
* ### Global X Cybersecurity UCITS ETF Fund
* *BUGG.GB/GBP*
*/
bugggbgbx='bugggbgbx',

/**
* ### Lyxor Smart Overnight Return - UCITS ETF C-GBP
* *CSH2.GB/GBX*
*/
csh2gbgbx='csh2gbgbx',

/**
* ### WisdomTree Cybersecurity UCITS ETF Fund
* *CYSE.GB/GBX*
*/
cysegbgbx='cysegbgbx',

/**
* ### iShares MSCI Europe Health Care Sector UCITS ETF Fund
* *ESIH.GB/GBP*
*/
esihgbgbx='esihgbgbx',

/**
* ### iShares Physical Gold ETC Fund
* *IGLN.US/USD*
*/
iglnususd='iglnususd',

/**
* ### iShares S&P 500 Financials Sector UCITS ETF
* *IUFS.US/USD*
*/
iufsususd='iufsususd',

/**
* ### iShares MSCI Global Semiconductors UCITS ETF
* *SEMI.GB/GBP*
*/
semigbgbx='semigbgbx',

/**
* ### Invesco Physical Gold ETC Fund
* *SGLD.US/USD*
*/
sgldususd='sgldususd',

/**
* ### VanEck Semiconductor ETF Fund
* *SMH.US/USD*
*/
smhususd='smhususd',

/**
* ### Lyxor Smart Overnight Return - UCITS ETF C-USD
* *SMTC.US/USD*
*/
smtcususd='smtcususd',

/**
* ### Wisdomtree Artificial Intelligence And Innovation Fund
* *WTAI.US/USD*
*/
wtaiususd='wtaiususd',

/**
* ### Xtrackers FTSE Developed Europe Real Estate UCITS ETF
* *XDER.GB/GBX*
*/
xdergbgbx='xdergbgbx',

/**
* ### Xtrackers MSCI World Health Care UCITS ETF Fund
* *XDWH.US/USD*
*/
xdwhususd='xdwhususd',

/**
* ### Xtrackers MSCI World Information Technology UCITS ETF
* *XDWT.US/USD*
*/
xdwtususd='xdwtususd',

/**
* ### Invesco Real Estate S&P US Select Sector UCITS ETF
* *XRES.US/USD*
*/
xresususd='xresususd',
}
export type InstrumentType = keyof typeof Instrument;
21 changes: 21 additions & 0 deletions src/utils/instrument-meta-data/generated/instrument-groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -1439,5 +1439,26 @@
"zsususd",
"ztsususd"
]
},
{
"id": "etf_cfd",
"instruments": [
"arkiususd",
"bugggbgbx",
"csh2gbgbx",
"cysegbgbx",
"esihgbgbx",
"iglnususd",
"iufsususd",
"semigbgbx",
"sgldususd",
"smhususd",
"smtcususd",
"wtaiususd",
"xdergbgbx",
"xdwhususd",
"xdwtususd",
"xresususd"
]
}
]
Loading

0 comments on commit 44f654a

Please sign in to comment.