@@ -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 } ,
0 commit comments