Example #1
0
session.on('ReferenceDataResponse', function(m) {
    //c.log(m);
    // At this point, m.correlations[0].value will equal:
    // 100 -> ReferenceDataResponse for option chain
    // 101 -> ReferenceDataResponse for LAST_PRICE of individual options
    if (m.correlations[0].value === 100) {
        var chain = m.data.securityData[0].fieldData.CHAIN_FULL;
        for (i in chain) {
            var strike = chain[i];
            var call = strike['Call Ticker'] + " Equity";
            var put = strike['Put Ticker'] + " Equity";
            options.push(call, put);
        }
        if (m.eventType === 'RESPONSE') {
            session.request('//blp/refdata', 'ReferenceDataRequest',
                { securities: options, fields: ['LAST_PRICE'] }, 101);
        }
    } else if (m.correlations[0].value === 101) {
        for (i in m.data.securityData) {
            var data = m.data.securityData[i];
            console.log(data.security, '=>', data.fieldData.LAST_PRICE);
        }
        if (m.eventType === 'RESPONSE') {
            session.stop();
        }
    }
});
session.on('AuthorizationFailure', function(m) {
    // Match correlation identifier used when authorizing
    if (m.correlations[0].value == request_apiauth) {
        console.log('Authorization response failure.');
        session.stop();
    }
});
session.on('AuthorizationSuccess', function(m) {
    // Match correlation identifier used when authorizing
    if (m.correlations[0].value == request_apiauth) {
        console.log('Authorization successful.');
        session.stop();
    }
});
session.on('ServiceOpened', function(m) {
    // Check to ensure the opened service is the apiauth service
    if (m.correlations[0].value == service_apiauth) {
        try {
            session.authorize('//blp/apiauth', request_apiauth);
        } catch(e) {
            console.log('Authorization request failure:', e);
            session.stop();
        }
    }
});
session.on('fieldResponse', function(m) {
    //c.log(m);
    // At this point, m.correlations[0].value will equal:
    // 100 -> FieldResponse for the free-form FieldSearchRequest
    if (m.correlations[0].value == 100) {
        if (results < limit) {
            for (var i in m.data.fieldData) {
                var fd = m.data.fieldData[i];
                console.log(fd.fieldInfo.mnemonic, "=>",
                            fd.fieldInfo.description);
                results++;
                if (results === limit)
                    break;
            }
        }
        // Stop once the final response is received
        if (m.eventType === 'RESPONSE') {
            session.stop();
        }
    }
});
function checkStop() {
    responses++;
    // Signal stop once all final responses have been received
    if (responses == 3)
        session.stop();
}
	function checkStop() {
	    responses++;
	    if (responses === 2) // 1st for ReferenceDataRequest, 2nd for HistoricalDataRequest
	        session.stop();
	}