@copytrade/unified-broker
Version:
Unified broker interface library for Indian stock market brokers with plugin architecture
118 lines • 4.47 kB
TypeScript
/**
* Unified Broker Response Interface
* Standardizes all broker module responses to eliminate broker-specific logic in unified flow
*/
export type AccountStatus = 'ACTIVE' | 'INACTIVE' | 'PROCEED_TO_OAUTH' | 'TOKEN_EXPIRED' | 'REFRESH_REQUIRED';
export type AuthenticationStep = 'DIRECT_AUTH' | 'OAUTH_REQUIRED' | 'OAUTH_COMPLETION' | 'TOKEN_REFRESH' | 'REAUTH_REQUIRED';
export type BrokerErrorType = 'AUTH_FAILED' | 'AUTH_CODE_EXPIRED' | 'TOKEN_EXPIRED' | 'REFRESH_TOKEN_EXPIRED' | 'NETWORK_ERROR' | 'BROKER_ERROR' | 'VALIDATION_ERROR';
/**
* Standardized Account Information
* All brokers must return account info in this format
*/
export interface UnifiedAccountInfo {
accountId: string;
userName: string;
email?: string;
brokerDisplayName: string;
exchanges: string[];
products: string[];
}
/**
* Standardized Token Information
* Handles token lifecycle for all brokers
*/
export interface UnifiedTokenInfo {
accessToken?: string;
refreshToken?: string;
expiryTime: string | null;
isExpired: boolean;
canRefresh: boolean;
}
/**
* Standardized Authentication Response
* Base response for all authentication operations
*/
export interface UnifiedAuthResponse {
success: boolean;
message: string;
accountStatus: AccountStatus;
authenticationStep: AuthenticationStep;
errorType?: BrokerErrorType;
accountInfo?: UnifiedAccountInfo;
tokenInfo?: UnifiedTokenInfo;
authUrl?: string;
requiresAuthCode?: boolean;
data?: any;
}
/**
* Standardized Connection Response
* Response for initial broker connection attempts
*/
export interface UnifiedConnectionResponse extends UnifiedAuthResponse {
}
/**
* Standardized OAuth Completion Response
* Response for OAuth completion with auth code
*/
export interface UnifiedOAuthResponse extends UnifiedAuthResponse {
}
/**
* Standardized Token Refresh Response
* Response for token refresh operations
*/
export interface UnifiedTokenRefreshResponse extends UnifiedAuthResponse {
}
/**
* Standardized Account Validation Response
* Response for account/session validation
*/
export interface UnifiedValidationResponse {
isValid: boolean;
accountStatus: AccountStatus;
message?: string;
errorType?: BrokerErrorType;
tokenInfo?: UnifiedTokenInfo;
}
/**
* Enhanced Broker Service Interface
* All broker modules must implement this interface
*/
export interface IUnifiedBrokerService {
getBrokerName(): string;
connect(credentials: any): Promise<UnifiedConnectionResponse>;
completeOAuth(authCode: string, credentials: any): Promise<UnifiedOAuthResponse>;
refreshToken(credentials: any): Promise<UnifiedTokenRefreshResponse>;
validateSession(credentials: any): Promise<UnifiedValidationResponse>;
disconnect(): Promise<boolean>;
getAccountInfo(): UnifiedAccountInfo | null;
getTokenInfo(): UnifiedTokenInfo | null;
isConnected(): boolean;
getAccountStatus(): AccountStatus;
placeOrder(orderRequest: any): Promise<any>;
cancelOrder(orderId: string): Promise<any>;
modifyOrder(orderId: string, modifications: any): Promise<any>;
getOrderStatus(accountId: string, orderId: string): Promise<any>;
getOrderHistory(accountId: string): Promise<any>;
getPositions(accountId: string): Promise<any>;
getQuote(symbol: string, exchange: string): Promise<any>;
searchSymbols(query: string, exchange: string): Promise<any>;
}
/**
* Broker Module Factory Interface
* For creating standardized broker instances
*/
export interface IBrokerModuleFactory {
createBroker(brokerName: string): IUnifiedBrokerService;
getSupportedBrokers(): string[];
isBrokerSupported(brokerName: string): boolean;
}
/**
* Helper functions for creating standardized responses
*/
export declare class UnifiedResponseHelper {
static createSuccessResponse(message: string, accountStatus: AccountStatus, authStep: AuthenticationStep, accountInfo?: UnifiedAccountInfo, tokenInfo?: UnifiedTokenInfo, additionalData?: any): UnifiedAuthResponse;
static createErrorResponse(message: string, errorType: BrokerErrorType, accountStatus?: AccountStatus, authStep?: AuthenticationStep): UnifiedAuthResponse;
static createOAuthResponse(authUrl: string, message?: string): UnifiedConnectionResponse;
static createTokenExpiredResponse(canRefresh: boolean, message?: string): UnifiedValidationResponse;
}
//# sourceMappingURL=UnifiedBrokerResponse.d.ts.map