@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.
45 lines (44 loc) • 2.31 kB
JavaScript
import { __assign } from "tslib";
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) {
var startDate = format(parseISO(args.startDate), BLOOMBERG_REQUEST_DATE_FORMAT);
var endDate = format(parseISO(args.endDate), BLOOMBERG_REQUEST_DATE_FORMAT);
var requestArgs = __assign(__assign({}, args), { startDate: startDate, endDate: endDate });
var operationArgs = Object.entries(requestArgs).map(function (_a) {
var _b;
var key = _a[0], value = _a[1];
return (_b = {}, _b[key] = value, _b);
});
return operationArgs;
}
var MESSAGE_TYPE = MessageTypes.HistoricalDataResponse;
var 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;
});
var dataHandler = createResponseDataHandler(MESSAGE_TYPE, function getData(message) {
var 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 (function (sessionManager) {
return function (args) {
var operationArgs = convertToOperationArgs(args);
var handlers = {
partialResponseData: dataHandler,
responseData: dataHandler,
responseError: errorHandler,
};
return new NonSubscriptionRequestImpl(sessionManager, getRequestConfig(RequestType.HistoricalData), operationArgs, handlers).api;
};
});
export * from "./request-args";
export * from "./response";