@glue42/bbg-market-data
Version:
A high-level API that wraps existing Glue42 Bloomberg Bridge Market Data interop methods. The API is based on the jBloomberg open source wrapper.
38 lines (37 loc) • 2.15 kB
JavaScript
import { RequestType } from "../../core/request-types";
import { NonSubscriptionRequestImpl } from "../../core/non-subscription-request";
import { getRequestConfig } from "./../../request-configs";
import { createResponseDataHandler, createResponseErrorHandler } from "../../core/helpers";
import { MessageTypes } from "../../core/message-types";
import { parseISO, format } from "date-fns";
import { BLOOMBERG_REQUEST_DATE_FORMAT } from "./../../constants";
function convertToOperationArgs(args) {
const startDate = format(parseISO(args.startDate), BLOOMBERG_REQUEST_DATE_FORMAT);
const endDate = format(parseISO(args.endDate), BLOOMBERG_REQUEST_DATE_FORMAT);
const requestArgs = Object.assign(Object.assign({}, args), { startDate: startDate, endDate: endDate });
const operationArgs = Object.entries(requestArgs).map(([key, value]) => ({ [key]: value }));
return operationArgs;
}
const MESSAGE_TYPE = MessageTypes.HistoricalDataResponse;
const errorHandler = createResponseErrorHandler(MESSAGE_TYPE, function getError(message) {
return message === null || message === void 0 ? void 0 : message.responseError;
}, function test(message) {
return (message === null || message === void 0 ? void 0 : message.responseError) != null;
});
const dataHandler = createResponseDataHandler(MESSAGE_TYPE, function getData(message) {
const securityData = message === null || message === void 0 ? void 0 : message.securityData;
return securityData == null ? [] : Array.isArray(securityData) ? securityData : [securityData];
}, function test(message) {
return (message === null || message === void 0 ? void 0 : message.securityData) != null;
});
export default (sessionManager) => (args) => {
const operationArgs = convertToOperationArgs(args);
const handlers = {
partialResponseData: dataHandler,
responseData: dataHandler,
responseError: errorHandler,
};
return new NonSubscriptionRequestImpl(sessionManager, getRequestConfig(RequestType.HistoricalData), operationArgs, handlers).api;
};
export * from "./request-args";
export * from "./response";