@copytrade/unified-broker
Version:
Unified broker interface library for Indian stock market brokers with plugin architecture
106 lines • 3.33 kB
TypeScript
/**
* Broker Registry - Core component for dynamic broker registration
* Enables plugin-based architecture for publishable broker library
*/
import { IBrokerService } from '../interfaces/IBrokerService';
export interface BrokerPlugin {
name: string;
version: string;
description?: string;
createInstance: () => IBrokerService;
dependencies?: string[];
}
export interface BrokerRegistryConfig {
autoLoad?: boolean;
pluginPaths?: string[];
enabledBrokers?: string[];
}
export declare class BrokerRegistry {
private static instance;
private plugins;
private instances;
private accountInstances;
private config;
private constructor();
static getInstance(config?: BrokerRegistryConfig): BrokerRegistry;
/**
* Register a broker plugin
* @param plugin - Broker plugin configuration
*/
registerPlugin(plugin: BrokerPlugin): void;
/**
* Unregister a broker plugin
* @param brokerName - Name of the broker to unregister
*/
unregisterPlugin(brokerName: string): void;
/**
* Create a broker instance
* @param brokerName - Name of the broker
* @returns IBrokerService instance
*/
createBroker(brokerName: string): IBrokerService;
/**
* Get or create a singleton broker instance
* @param brokerName - Name of the broker
* @returns IBrokerService instance
* @deprecated Use getBrokerForAccount instead for account-specific instances
*/
getBroker(brokerName: string): IBrokerService;
/**
* Get or create a broker instance for a specific account
* This ensures each account has its own isolated broker service instance
* @param brokerName - Name of the broker
* @param accountId - Account ID for isolation
* @returns IBrokerService instance
*/
getBrokerForAccount(brokerName: string, accountId: string): IBrokerService;
/**
* Remove broker instance for a specific account
* @param brokerName - Name of the broker
* @param accountId - Account ID
*/
removeBrokerForAccount(brokerName: string, accountId: string): void;
/**
* Get list of available broker names
* @returns Array of broker names
*/
getAvailableBrokers(): string[];
/**
* Get list of registered plugins with metadata
* @returns Array of plugin information
*/
getRegisteredPlugins(): Array<{
name: string;
version: string;
description?: string;
}>;
/**
* Check if a broker is available
* @param brokerName - Name of the broker
* @returns true if broker is available
*/
isBrokerAvailable(brokerName: string): boolean;
/**
* Clear all instances (useful for testing)
*/
clearInstances(): void;
/**
* Reset the registry (useful for testing)
*/
reset(): void;
/**
* Load broker plugins from specified paths
* @param paths - Array of paths to load plugins from
*/
loadPlugins(paths?: string[]): Promise<void>;
/**
* Get configuration
*/
getConfig(): BrokerRegistryConfig;
/**
* Update configuration
*/
updateConfig(newConfig: Partial<BrokerRegistryConfig>): void;
}
export declare const brokerRegistry: BrokerRegistry;
//# sourceMappingURL=BrokerRegistry.d.ts.map