import ibkr , { EventName } from '@stoqey/ib' ; import IBKRConnection from '../connection/IBKRConnection' ; import { getRadomReqId } from '../_utils/text.utils' ; export interface FundamentalDataContractParams { readonly exchange : string ; readonly primaryExch : string ; readonly secType : string ; readonly symbol : string ; readonly currency ? : string ; } export class FundamentalData { ib : ibkr ; private reqIdToResolver : { [ reqId ] : ( value ? : string | PromiseLike < string > ) => void ; } = { } ; symbolsWithTicker : { tickerId : number ; symbol : string ; } [ ] = [ ] ; private static _instance : FundamentalData ; public static get Instance ( ) : FundamentalData { return this . _instance || ( this . _instance = new this ( ) ) ; } private constructor ( ) { const ib = IBKRConnection . Instance . getIBKR ( ) ; this . ib = ib ; ib . on ( EventName . fundamentalData , ( reqId , xmlText ) => { console . log ( 'onFundamentalData:' , reqId , xmlText ) ; const res = this . reqIdToResolver [ reqId ] ; if ( res ) { delete this . reqIdToResolver [ reqId ] ; res ( xmlText ) ; } } ) ; } param reportType public getFundamentalData ( reportType , contract ) { const reqId = getRadomReqId ( ) ; return new Promise ( ( res ) => { this . reqIdToResolver [ reqId ] = res ; this . ib . reqFundamentalData ( reqId , contract , reportType ) ; } ) ; } } export default FundamentalData ;