@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.
116 lines (115 loc) • 6.38 kB
JavaScript
import { __assign, __awaiter, __generator } from "tslib";
import { generateId } from "../utils";
import { SessionLifetime } from "./types/session-lifetime";
import { Session } from "./types/session";
import { BloombergSession } from "./types";
import { SessionInstance } from "../core/session-instance";
var SessionsManager = (function () {
function SessionsManager(mdfBridge, apiId, libConfigSettings, logger) {
var _a, _b;
this.mdfBridge = mdfBridge;
this.apiId = apiId;
this.libConfigSettings = libConfigSettings;
this.logger = logger;
this.sessionInstanceByName = new Map();
this.libConfigSessionOptions =
((_a = this.libConfigSettings) === null || _a === void 0 ? void 0 : _a.options) != null && typeof this.libConfigSettings.options === "object"
? this.libConfigSettings.options
: undefined;
this.libConfigIdentityOptions =
((_b = this.libConfigSettings) === null || _b === void 0 ? void 0 : _b.identityOptions) != null && typeof this.libConfigSettings.identityOptions === "object"
? this.libConfigSettings.identityOptions
: undefined;
this.dataRequestsSessionImpl = new SessionInstance(this.mdfBridge, this.configureBloombergSession({ name: Session.DataRequests, lifetime: SessionLifetime.Owned }), this.logger);
this.largeHistoricalRequestsSessionImpl = new SessionInstance(this.mdfBridge, this.configureBloombergSession({ name: Session.LargeHistoricalRequests, lifetime: SessionLifetime.Owned }), this.logger);
this.subscriptionsSession = new SessionInstance(this.mdfBridge, this.configureBloombergSession({ name: Session.RealTime, lifetime: SessionLifetime.Owned }), this.logger);
}
Object.defineProperty(SessionsManager.prototype, "all", {
get: function () {
return Array.from(this.sessionInstanceByName.keys());
},
enumerable: false,
configurable: true
});
SessionsManager.prototype.createSession = function (settings) {
return __awaiter(this, void 0, void 0, function () {
var bbgSession;
return __generator(this, function (_a) {
bbgSession = this.configureBloombergSession(__assign(__assign({}, settings), { name: generateId(), lifetime: SessionLifetime.Owned }));
this.sessionInstanceByName.set(bbgSession.name, new SessionInstance(this.mdfBridge, bbgSession, this.logger));
return [2, Promise.resolve(bbgSession)];
});
});
};
SessionsManager.prototype.closeSession = function (sessionName) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!this.sessionInstanceByName.has(sessionName)) {
throw new Error("Either this session was closed or it was not created by this api instance.");
}
return [4, this.mdfBridge.closeSession(sessionName)];
case 1:
_a.sent();
this.sessionInstanceByName.delete(sessionName);
return [2];
}
});
});
};
SessionsManager.prototype.getNonSubscriptionReqSessionInstance = function (providedSession) {
return this.getSessionInstance({
providedSession: providedSession,
requestKind: "non-subscription",
});
};
SessionsManager.prototype.getSubscriptionReqSessionInstance = function (providedSession) {
return this.getSessionInstance({
providedSession: providedSession,
requestKind: "subscription",
});
};
SessionsManager.prototype.getSessionInstance = function (_a) {
var providedSession = _a.providedSession, requestKind = _a.requestKind;
if (providedSession instanceof BloombergSession) {
if (!this.sessionInstanceByName.has(providedSession.name)) {
throw new Error("Either this session was closed or it was not created by this api instance.");
}
return this.sessionInstanceByName.get(providedSession.name);
}
if (providedSession === Session.CreateNew) {
var shortLivedSessionConfig = this.configureBloombergSession({
name: generateId(),
lifetime: SessionLifetime.RefCounted,
});
return new SessionInstance(this.mdfBridge, shortLivedSessionConfig, this.logger);
}
if (requestKind === "non-subscription") {
return providedSession === Session.LargeHistoricalRequests
? this.largeHistoricalRequestsSessionImpl
: this.dataRequestsSessionImpl;
}
return this.subscriptionsSession;
};
SessionsManager.prototype.configureBloombergSession = function (settings) {
var _a, _b;
var name = this.decorateSessionName(settings.name);
var lifetime = (_a = settings === null || settings === void 0 ? void 0 : settings.lifetime) !== null && _a !== void 0 ? _a : SessionLifetime.Owned;
var identityOptions = (settings === null || settings === void 0 ? void 0 : settings.identityOptions) != null && typeof settings.identityOptions === "object"
? settings.identityOptions
: this.libConfigIdentityOptions;
if (identityOptions) {
identityOptions = __assign(__assign({}, identityOptions), { authUser: (_b = identityOptions === null || identityOptions === void 0 ? void 0 : identityOptions.authUser) !== null && _b !== void 0 ? _b : {} });
}
var options = (settings === null || settings === void 0 ? void 0 : settings.options) != null && typeof settings.options === "object"
? settings.options
: this.libConfigSessionOptions;
return new BloombergSession(name, lifetime, options, identityOptions);
};
SessionsManager.prototype.decorateSessionName = function (name) {
return name + "_" + this.apiId;
};
return SessionsManager;
}());
export { SessionsManager };