private HistoricalTimeSeries doGetHistoricalTimeSeries( ExternalIdBundle identifiers, String dataSource, String dataProvider, String field, LocalDate startDate, LocalDate endDate, Integer maxPoints) { ArgumentChecker.notNull(identifiers, "identifiers"); ArgumentChecker.notNull(field, "field"); ArgumentChecker.notNull(startDate, "startDate"); ArgumentChecker.notNull(endDate, "endDate"); Validate.isTrue( ObjectUtils.equals(dataSource, BLOOMBERG_DATA_SOURCE_NAME), getClass().getName() + "cannot support " + dataSource); if (maxPoints != null && maxPoints > 0) { throw new UnsupportedOperationException( "Fetching a bounded number of points from the start of a Bloomberg time-series is unsupported"); } s_logger.info("Getting HistoricalTimeSeries for security {}", identifiers); ensureStarted(); if (endDate.isBefore(startDate)) { throw new IllegalArgumentException("endDate must be after startDate"); } ExternalId dsid = BloombergDomainIdentifierResolver.resolvePreferredIdentifier(identifiers); String bbgKey = BloombergDomainIdentifierResolver.toBloombergKeyWithDataProvider(dsid, dataProvider); Request request = composeRequest(bbgKey, dataSource, dataProvider, field, startDate, endDate, maxPoints); _statistics.gotFields(Collections.singleton(bbgKey), Collections.singleton(field)); LocalDateDoubleTimeSeries timeSeries = processRequest(bbgKey, request, field); return new SimpleHistoricalTimeSeries(UID_SUPPLIER.get(), timeSeries); }
@Override public Map<JmsTopicNameResolveRequest, String> resolve( Collection<JmsTopicNameResolveRequest> requests) { Map<JmsTopicNameResolveRequest, String> returnValue = new HashMap<JmsTopicNameResolveRequest, String>(); Map<String, Collection<JmsTopicNameResolveRequest>> lookupKey2Requests = new HashMap<String, Collection<JmsTopicNameResolveRequest>>(); for (JmsTopicNameResolveRequest request : requests) { ExternalId marketDataUniqueId = request.getMarketDataUniqueId(); if (!marketDataUniqueId.getScheme().equals(SecurityUtils.BLOOMBERG_BUID)) { s_logger.info("No Bloomberg BUID found, was given: " + marketDataUniqueId); returnValue.put(request, null); continue; } String lookupKey = BloombergDomainIdentifierResolver.toBloombergKey(marketDataUniqueId); Collection<JmsTopicNameResolveRequest> requestsForLookupKey = lookupKey2Requests.get(lookupKey); if (requestsForLookupKey == null) { requestsForLookupKey = new ArrayList<JmsTopicNameResolveRequest>(); lookupKey2Requests.put(lookupKey, requestsForLookupKey); } requestsForLookupKey.add(request); } if (!lookupKey2Requests.keySet().isEmpty()) { ReferenceDataResult referenceData = _referenceDataProvider.getFields( lookupKey2Requests.keySet(), BloombergConstants.JMS_TOPIC_NAME_RESOLVER_FIELDS); for (Map.Entry<String, Collection<JmsTopicNameResolveRequest>> entry : lookupKey2Requests.entrySet()) { String lookupKey = entry.getKey(); PerSecurityReferenceDataResult result = referenceData.getResult(lookupKey); for (JmsTopicNameResolveRequest request : entry.getValue()) { String jmsTopicName = getJmsTopicName(request, result); returnValue.put(request, jmsTopicName); } } } return returnValue; }
// ------------------------------------------------------------------------- @Override public Map<ExternalIdBundle, HistoricalTimeSeries> getHistoricalTimeSeries( Set<ExternalIdBundle> identifierSet, String dataSource, String dataProvider, String dataField, LocalDate start, boolean includeStart, LocalDate end, boolean includeEnd) { ArgumentChecker.notNull(identifierSet, "identifierSet"); ArgumentChecker.notNull(dataField, "dataField"); ArgumentChecker.notNull(start, "start"); ArgumentChecker.notNull(end, "end"); Validate.isTrue( ObjectUtils.equals(dataSource, BLOOMBERG_DATA_SOURCE_NAME), getClass().getName() + "cannot support " + dataSource); if (end.isBefore(start)) { throw new IllegalArgumentException("end must be after start"); } ensureStarted(); s_logger.debug("Getting historical data for {}", identifierSet); if (identifierSet.isEmpty()) { s_logger.info("Historical data request for empty identifier set"); return Collections.emptyMap(); } Map<String, ExternalIdBundle> bbgSecDomainMap = new HashMap<String, ExternalIdBundle>(); Request request = getRefDataService().createRequest(BLOOMBERG_HISTORICAL_DATA_REQUEST); Element securitiesElem = request.getElement(BLOOMBERG_SECURITIES_REQUEST); for (ExternalIdBundle identifiers : identifierSet) { ExternalId preferredIdentifier = BloombergDomainIdentifierResolver.resolvePreferredIdentifier(identifiers); s_logger.debug( "Resolved preferred identifier {} from identifier bundle {}", preferredIdentifier, identifiers); String bbgKey = BloombergDomainIdentifierResolver.toBloombergKeyWithDataProvider( preferredIdentifier, dataProvider); securitiesElem.appendValue(bbgKey); bbgSecDomainMap.put(bbgKey, identifiers); } Element fieldElem = request.getElement(BLOOMBERG_FIELDS_REQUEST); fieldElem.appendValue(dataField); // TODO: inclusive start / exclusive end request.set("periodicityAdjustment", "ACTUAL"); request.set("periodicitySelection", "DAILY"); request.set("startDate", printYYYYMMDD(start)); request.set("endDate", printYYYYMMDD(end)); request.set("adjustmentSplit", true); _statistics.gotFields(bbgSecDomainMap.keySet(), Collections.singleton(dataField)); CorrelationID cid = submitBloombergRequest(request); BlockingQueue<Element> resultElements = getResultElement(cid); if (resultElements == null || resultElements.isEmpty()) { s_logger.warn("Unable to get historical data for {}", identifierSet); return null; } // REVIEW simon 2011/11/01: should this be deduped with the single case? Map<ExternalIdBundle, HistoricalTimeSeries> result = new HashMap<ExternalIdBundle, HistoricalTimeSeries>(); for (Element resultElem : resultElements) { if (resultElem.hasElement(RESPONSE_ERROR)) { s_logger.warn("Response error"); processError(resultElem.getElement(RESPONSE_ERROR)); continue; } Element securityElem = resultElem.getElement(SECURITY_DATA); if (securityElem.hasElement(SECURITY_ERROR)) { processError(securityElem.getElement(SECURITY_ERROR)); } if (securityElem.hasElement(FIELD_EXCEPTIONS)) { Element fieldExceptions = securityElem.getElement(FIELD_EXCEPTIONS); for (int i = 0; i < fieldExceptions.numValues(); i++) { Element fieldException = fieldExceptions.getValueAsElement(i); String fieldId = fieldException.getElementAsString(FIELD_ID); s_logger.warn("Field error on {}", fieldId); Element errorInfo = fieldException.getElement(ERROR_INFO); processError(errorInfo); } } if (securityElem.hasElement(FIELD_DATA)) { processFieldData(securityElem, dataField, bbgSecDomainMap, result); } } if (identifierSet.size() != result.size()) { s_logger.warn( "Failed to get time series results for ({}/{}) {}", new Object[] { identifierSet.size() - result.size(), identifierSet.size(), Sets.difference(identifierSet, result.keySet()) }); } return result; }