UNPKG

@copytrade/unified-broker

Version:

Unified broker interface library for Indian stock market brokers with plugin architecture

74 lines 2.35 kB
"use strict"; /** * Broker Factory Implementation * Creates broker service instances using dynamic plugin registry * No hardcoded broker references - fully pluggable architecture */ Object.defineProperty(exports, "__esModule", { value: true }); exports.brokerFactory = exports.BrokerFactory = void 0; const BrokerRegistry_1 = require("../registry/BrokerRegistry"); class BrokerFactory { constructor() { this.registry = BrokerRegistry_1.brokerRegistry; } static getInstance() { if (!BrokerFactory.instance) { BrokerFactory.instance = new BrokerFactory(); } return BrokerFactory.instance; } /** * Create a broker service instance * @param brokerName - Name of the broker (e.g., 'shoonya', 'fyers') * @returns IBrokerService instance * @throws Error if broker is not supported */ createBroker(brokerName) { return this.registry.createBroker(brokerName); } /** * Get list of all supported brokers * @returns Array of supported broker names */ getSupportedBrokers() { return this.registry.getAvailableBrokers(); } /** * Check if a broker is supported * @param brokerName - Name of the broker to check * @returns true if broker is supported, false otherwise */ isBrokerSupported(brokerName) { return this.registry.isBrokerAvailable(brokerName); } /** * Register a new broker dynamically * @param brokerName - Name of the broker * @param brokerCreator - Function that creates the broker service instance */ registerBroker(brokerName, brokerCreator) { this.registry.registerPlugin({ name: brokerName, version: '1.0.0', createInstance: brokerCreator }); } /** * Unregister a broker * @param brokerName - Name of the broker to unregister */ unregisterBroker(brokerName) { this.registry.unregisterPlugin(brokerName); } /** * Get the underlying registry instance * @returns BrokerRegistry instance */ getRegistry() { return this.registry; } } exports.BrokerFactory = BrokerFactory; // Export singleton instance for convenience exports.brokerFactory = BrokerFactory.getInstance(); //# sourceMappingURL=BrokerFactory.js.map