Skip to content

Commit e84ce81

Browse files
committed
bug fix when importing stock contract description with empty string as ISIN
1 parent d05d8fb commit e84ce81

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

src/app/components/Portfolio/Report/links.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const ReportLink = {
2-
toIndex: (portfolioId: number | string): string => (portfolioId ? `/portfolio/${portfolioId}/reports/ytd` : "#"),
2+
toIndex: (portfolioId: number | string): string => (portfolioId ? `/portfolio/${portfolioId}/reports/12m/` : "#"),
33
toYtd: (portfolioId: number | string): string => (portfolioId ? `/portfolio/${portfolioId}/reports/ytd` : "#"),
44
to12m: (portfolioId: number | string): string => (portfolioId ? `/portfolio/${portfolioId}/reports/12m` : "#"),
55
toAll: (portfolioId: number | string): string => (portfolioId ? `/portfolio/${portfolioId}/reports/index` : "#"),

src/app/components/Portfolio/Statement/links.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const StatementLink = {
2-
toIndex: (portfolioId: number | string): string => `/portfolio/${portfolioId}/statements/summary/ytd/`,
2+
toIndex: (portfolioId: number | string): string => `/portfolio/${portfolioId}/statements/summary/12m/`,
33
toItem: (portfolioId: number | string, statementId: number | string): string =>
44
`/portfolio/${portfolioId}/statements/id/${statementId}/`,
55
toDate: (portfolioId: number | string, date: Date | string): string => {

src/bots/importer.bot.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ export class ImporterBot extends ITradingBot {
227227
);
228228
return this.findOrCreateContract({ ibContract, force: true }).then(async (contract) => {
229229
if (contract.secType == SecType.STK) {
230-
const contract_data = {
230+
const contract_data: any = {
231231
symbol: element.symbol,
232232
name: element.description,
233233
currency: element.currency,
234-
isin: element.isin,
235-
// isin: "XY0123456789",
234+
// isin: element.isin,
236235
exchange: element.listingExchange,
237236
};
237+
if (element.isin?.length > 0) contract_data.isin = element.isin;
238238
return contract.update(contract_data, {});
239239
} else if (contract.secType == SecType.BOND) {
240240
// IB API does not provide any usefull information for BONDs therefore we update it using XML information
@@ -820,7 +820,8 @@ export class ImporterBot extends ITradingBot {
820820
// idx = (element.description as string).indexOf("(");
821821
// country = (element.description as string).substring(idx + 1, idx + 3);
822822
// }
823-
const country = (element.isin as string).substring(0, 2);
823+
const isin = element.isin as string;
824+
const country = isin && isin.length > 2 ? isin.substring(0, 2) : "XX";
824825
return TaxStatement.findOrCreate({
825826
where: { id: statement.id },
826827
defaults: { id: statement.id, country },
@@ -831,7 +832,8 @@ export class ImporterBot extends ITradingBot {
831832
case StatementTypes.DividendStatement:
832833
{
833834
// console.log(element);
834-
const country = (element.isin as string).substring(0, 2);
835+
const isin = element.isin as string;
836+
const country = isin && isin.length > 2 ? isin.substring(0, 2) : "XX";
835837
return DividendStatement.findOrCreate({
836838
where: { id: statement.id },
837839
defaults: { id: statement.id, country },

src/routers/contracts.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export const optionContractModelToOptionContractEntry = (option: OptionContract)
6363
dte: option.dte,
6464

6565
// Make JSON compatible
66-
createdAt: option.createdAt.getTime(),
67-
updatedAt: option.createdAt.getTime(),
66+
createdAt: option.createdAt?.getTime(),
67+
updatedAt: option.createdAt?.getTime(),
6868

6969
// Associations
7070
contract: undefined,

0 commit comments

Comments
 (0)