import { EventEmitter } from 'events'; type Direction = 'BUY' | 'SELL'; type OrderType = 'LIMIT' | 'STOP'; type DealStatus = 'ACCEPTED' | 'CREATED' | 'EXECUTED' | 'EXPIRED' | 'REJECTED' | 'MODIFIED' | 'MODIFY_REJECT' | 'CANCELLED' | 'CANCEL_REJECT' | 'UNKNOWN'; type ActivitySource = 'CLOSE_OUT' | 'DEALER' | 'SL' | 'SYSTEM' | 'TP' | 'USER'; type ActivityType = 'POSITION' | 'WORKING_ORDER' | 'EDIT_STOP_AND_LIMIT' | 'SWAP' | 'SYSTEM'; type InstrumentType = 'SHARES' | 'CURRENCIES' | 'INDICES' | 'CRYPTOCURRENCIES' | 'COMMODITIES'; type MarketStatus = 'TRADEABLE' | 'CLOSED' | 'EDITS_ONLY'; type Resolution = 'MINUTE' | 'MINUTE_5' | 'MINUTE_15' | 'MINUTE_30' | 'HOUR' | 'HOUR_4' | 'DAY' | 'WEEK'; type TransactionType = 'INACTIVITY_FEE' | 'RESERVE' | 'VOID' | 'UNRESERVE' | 'WRITE_OFF_OR_CREDIT' | 'CREDIT_FACILITY' | 'FX_COMMISSION' | 'COMPLAINT_SETTLEMENT' | 'DEPOSIT' | 'WITHDRAWAL' | 'REFUND' | 'WITHDRAWAL_MONEY_BACK' | 'TRADE' | 'SWAP' | 'TRADE_COMMISSION' | 'TRADE_COMMISSION_GSL' | 'NEGATIVE_BALANCE_PROTECTION' | 'TRADE_CORRECTION' | 'CHARGEBACK' | 'ADJUSTMENT' | 'BONUS' | 'TRANSFER' | 'CORPORATE_ACTION' | 'CONVERSION' | 'REBATE' | 'TRADE_SLIPPAGE_PROTECTION'; interface SessionCredentials { identifier: string; password: string; encryptedPassword?: boolean; } interface ApiConfig { apiKey: string; baseUrl?: string; timeout?: number; } interface EncryptionKeyResponse { encryptionKey: string; timeStamp: number; } interface Balance { balance: number; deposit: number; profitLoss: number; available: number; } interface Account { accountId: string; accountName: string; preferred: boolean; accountType: string; currency: string; symbol: string; balance: Balance; } interface SessionResponse { accountType: string; accountInfo: Balance; currencyIsoCode: string; currencySymbol: string; currentAccountId: string; streamingHost: string; accounts: Account[]; clientId: string; timezoneOffset: number; hasActiveDemoAccounts: boolean; hasActiveLiveAccounts: boolean; trailingStopsEnabled: boolean; } interface SessionDetails { clientId: string; accountId: string; timezoneOffset: number; locale: string; currency: string; streamEndpoint: string; } interface SwitchAccountRequest { accountId: string; } interface SwitchAccountResponse { trailingStopsEnabled: boolean; dealingEnabled: boolean; hasActiveDemoAccounts: boolean; hasActiveLiveAccounts: boolean; } interface AccountsResponse { accounts: Account[]; } interface Leverages { SHARES: number; CURRENCIES: number; INDICES: number; CRYPTOCURRENCIES: number; COMMODITIES: number; } interface AccountPreferences { hedgingMode: boolean; leverages: Leverages; } interface UpdateAccountPreferencesRequest { leverages?: Partial; hedgingMode?: boolean; } interface Activity { epic: string; dealId: string; status: DealStatus; type: ActivityType; source: ActivitySource; date: string; dateUTC: string; description: string; details?: Record; } interface ActivityHistoryResponse { activities: Activity[]; } interface Transaction { reference: string; transactionType: TransactionType; transactionId: string; date: string; dateUTC: string; openLevel: string; closeLevel: string; size: string; currency: string; cash: string; pnl: string; } interface TransactionHistoryResponse { transactions: Transaction[]; } interface TopUpRequest { amount: number; } interface TopUpResponse { successful: boolean; } interface CreatePositionRequest { epic: string; direction: Direction; size: number; guaranteedStop?: boolean; trailingStop?: boolean; stopLevel?: number; stopDistance?: number; stopAmount?: number; profitLevel?: number; profitDistance?: number; profitAmount?: number; } interface CreatePositionResponse { dealReference: string; } interface UpdatePositionRequest { guaranteedStop?: boolean; trailingStop?: boolean; stopLevel?: number; stopDistance?: number; stopAmount?: number; profitLevel?: number; profitDistance?: number; profitAmount?: number; } interface Position { contractSize: number; createdDate: string; createdDateUTC: string; dealId: string; dealReference: string; workingOrderId?: string; size: number; leverage: number; upl: number; direction: Direction; level: number; currency: string; guaranteedStop: boolean; } interface Market { instrumentName: string; expiry: string; marketStatus: MarketStatus; epic: string; symbol: string; instrumentType: InstrumentType; lotSize: number; high: number; low: number; percentageChange: number; netChange: number; bid: number; offer: number; updateTime: string; updateTimeUTC: string; delayTime: number; streamingPricesAvailable: boolean; scalingFactor: number; marketModes: string[]; } interface PositionResponse { position: Position; market: Market; } interface PositionsResponse { positions: PositionResponse[]; } interface CreateWorkingOrderRequest { epic: string; direction: Direction; size: number; level: number; type: OrderType; goodTillDate?: string; guaranteedStop?: boolean; trailingStop?: boolean; stopLevel?: number; stopDistance?: number; stopAmount?: number; profitLevel?: number; profitDistance?: number; profitAmount?: number; } interface UpdateWorkingOrderRequest { level?: number; goodTillDate?: string; guaranteedStop?: boolean; trailingStop?: boolean; stopLevel?: number; stopDistance?: number; stopAmount?: number; profitLevel?: number; profitDistance?: number; profitAmount?: number; } interface WorkingOrder { dealId: string; direction: Direction; epic: string; orderType: OrderType; orderSize: number; orderLevel: number; size?: number; level?: number; leverage?: number; timeInForce: string; goodTillDate?: string; guaranteedStop: boolean; trailingStop: boolean; currencyCode?: string; createdDate: string; createdDateUTC: string; } interface WorkingOrderResponse { workingOrderData: WorkingOrder; marketData: Market; } interface WorkingOrdersResponse { workingOrders: WorkingOrderResponse[]; } interface AffectedDeal { dealId: string; status: string; } interface DealConfirmation { date: string; status: string; dealStatus: DealStatus; epic: string; dealReference: string; dealId: string; affectedDeals: AffectedDeal[]; level: number; size: number; direction: Direction; guaranteedStop: boolean; trailingStop: boolean; } interface NavigationNode { id: string; name: string; } interface NavigationResponse { nodes: NavigationNode[]; } interface OpeningHours { [key: string]: { openTime: string; closeTime: string; }[]; } interface OvernightFee { longPositionFee: number; shortPositionFee: number; } interface Instrument { epic: string; symbol: string; expiry: string; name: string; lotSize: number; type: InstrumentType; guaranteedStopAllowed: boolean; streamingPricesAvailable: boolean; currency: string; marginFactor: number; marginFactorUnit: string; openingHours: OpeningHours; overnightFee: OvernightFee; } interface DealingRuleValue { unit: string; value: number; } interface DealingRules { minStepDistance: DealingRuleValue; minDealSize: DealingRuleValue; maxDealSize: DealingRuleValue; minSizeIncrement: DealingRuleValue; minGuaranteedStopDistance: DealingRuleValue; minStopOrProfitDistance: DealingRuleValue; maxStopOrProfitDistance: DealingRuleValue; marketOrderPreference: string; trailingStopsPreference: string; } interface Snapshot { marketStatus: MarketStatus; netChange: number; percentageChange: number; updateTime: string; delayTime: number; bid: number; offer: number; high: number; low: number; decimalPlacesFactor: number; scalingFactor: number; marketModes: string[]; } interface MarketDetailsResponse { instrument: Instrument; dealingRules: DealingRules; snapshot: Snapshot; } interface MarketsResponse { markets: Market[]; } interface PriceValue { bid: number; ask: number; lastTraded: number | null; } interface PriceSnapshot { snapshotTime: string; snapshotTimeUTC: string; openPrice: PriceValue; closePrice: PriceValue; highPrice: PriceValue; lowPrice: PriceValue; lastTradedVolume: number; } interface HistoricalPricesResponse { prices: PriceSnapshot[]; instrumentType: InstrumentType; } interface ClientSentiment { marketId: string; longPositionPercentage: number; shortPositionPercentage: number; } interface ClientSentimentsResponse { clientSentiments: ClientSentiment[]; } interface Watchlist { id: string; name: string; editable: boolean; deleteable: boolean; } interface WatchlistsResponse { watchlists: Watchlist[]; } interface CreateWatchlistRequest { name: string; epics?: string[]; } interface CreateWatchlistResponse { watchlistId: string; status: string; } interface WatchlistMarketsResponse { markets: Market[]; } interface AddMarketToWatchlistRequest { epic: string; } interface WebSocketMessage { destination: string; correlationId: string; cst: string; securityToken: string; payload?: Record; } interface MarketDataSubscription { epics: string[]; } interface OHLCSubscription { epics: string[]; resolutions?: Resolution[]; type?: 'classic' | 'heikin-ashi'; } interface QuoteData { epic: string; product: string; bid: number; bidQty: number; ofr: number; ofrQty: number; timestamp: number; } interface OHLCData { resolution: Resolution; epic: string; type: string; priceType: string; t: number; h: number; l: number; o: number; c: number; } interface ApiResponse { data?: T; status?: string; error?: string; } interface SuccessResponse { status: 'SUCCESS'; } interface ServerTimeResponse { serverTime: number; } interface PingResponse { status: 'OK'; } interface CapitalAPIConfig { baseUrl?: string; demoMode?: boolean; apiKey?: string; timeout?: number; } interface CapitalWebSocketConfig { cst: string; securityToken: string; streamingUrl?: string; } declare class CapitalWebSocket extends EventEmitter { private ws?; private cst; private securityToken; private streamingUrl; private correlationIdCounter; private reconnectInterval; private maxReconnectAttempts; private reconnectAttempts; private isConnected; private subscriptions; constructor(config: CapitalWebSocketConfig); private getNextCorrelationId; private createMessage; private send; private onMessage; private onError; private onClose; private onOpen; connect(): Promise; disconnect(): void; isConnectedToServer(): boolean; getWebSocketState(): number | undefined; getWebSocketUrl(): string | undefined; subscribeToMarketData(epics: string[]): void; unsubscribeFromMarketData(epics: string[]): void; subscribeToOHLCData(epics: string[], resolutions?: Resolution[], type?: 'classic' | 'heikin-ashi'): void; unsubscribeFromOHLCData(epics: string[], resolutions?: Resolution[], types?: ('classic' | 'heikin-ashi')[]): void; ping(): void; startAutoPing(interval?: number): void; updateTokens(cst: string, securityToken: string): void; } declare class CapitalAPI { private baseUrl; private client; private apiKey?; private cst?; private securityToken?; private webSocket?; constructor(config?: CapitalAPIConfig); private clearSession; private setSessionTokens; setApiKey(apiKey: string): void; isAuthenticated(): boolean; getSessionTokens(): { cst?: string; securityToken?: string; }; private encryptPassword; private requestQueue; private processingQueue; private processQueue; private get; private post; private put; private delete; getServerTime(): Promise; ping(): Promise; getEncryptionKey(): Promise; createSession(credentials: SessionCredentials): Promise; createSessionWithEncryption(identifier: string, password: string): Promise; getSessionDetails(): Promise; switchAccount(request: SwitchAccountRequest): Promise; logout(): Promise; getAllAccounts(): Promise; getAccountPreferences(): Promise; updateAccountPreferences(request: UpdateAccountPreferencesRequest): Promise; getActivityHistory(params?: { from?: string; to?: string; lastPeriod?: number; detailed?: boolean; dealId?: string; filter?: string; }): Promise; getTransactionHistory(params?: { from?: string; to?: string; lastPeriod?: number; type?: string; }): Promise; topUpDemoAccount(request: TopUpRequest): Promise; getDealConfirmation(dealReference: string): Promise; getAllPositions(): Promise; createPosition(request: CreatePositionRequest): Promise; getPosition(dealId: string): Promise; updatePosition(dealId: string, request: UpdatePositionRequest): Promise; closePosition(dealId: string): Promise; getAllWorkingOrders(): Promise; createWorkingOrder(request: CreateWorkingOrderRequest): Promise; updateWorkingOrder(dealId: string, request: UpdateWorkingOrderRequest): Promise; deleteWorkingOrder(dealId: string): Promise; getMarketNavigation(): Promise; getMarketNavigationNode(nodeId: string, limit?: number): Promise; getMarkets(params?: { searchTerm?: string; epics?: string; }): Promise; getMarketDetails(epic: string): Promise; getHistoricalPrices(epic: string, params?: { resolution?: Resolution; max?: number; from?: string; to?: string; }): Promise; getClientSentiment(marketIds?: string): Promise; getClientSentimentForMarket(marketId: string): Promise; getAllWatchlists(): Promise; createWatchlist(request: CreateWatchlistRequest): Promise; getWatchlist(watchlistId: string): Promise; addMarketToWatchlist(watchlistId: string, request: AddMarketToWatchlistRequest): Promise; deleteWatchlist(watchlistId: string): Promise; removeMarketFromWatchlist(watchlistId: string, epic: string): Promise; createWebSocketConnection(config?: Partial): CapitalWebSocket; getWebSocketConnection(): CapitalWebSocket | undefined; connectWebSocket(): Promise; disconnectWebSocket(): void; } export { CapitalAPI, CapitalWebSocket }; export type { Account, AccountPreferences, AccountsResponse, Activity, ActivityHistoryResponse, ActivitySource, ActivityType, AddMarketToWatchlistRequest, AffectedDeal, ApiConfig, ApiResponse, Balance, CapitalAPIConfig, ClientSentiment, ClientSentimentsResponse, CreatePositionRequest, CreatePositionResponse, CreateWatchlistRequest, CreateWatchlistResponse, CreateWorkingOrderRequest, DealConfirmation, DealStatus, DealingRuleValue, DealingRules, Direction, EncryptionKeyResponse, HistoricalPricesResponse, Instrument, InstrumentType, Leverages, Market, MarketDataSubscription, MarketDetailsResponse, MarketStatus, MarketsResponse, NavigationNode, NavigationResponse, OHLCData, OHLCSubscription, OpeningHours, OrderType, OvernightFee, PingResponse, Position, PositionResponse, PositionsResponse, PriceSnapshot, PriceValue, QuoteData, Resolution, ServerTimeResponse, SessionCredentials, SessionDetails, SessionResponse, Snapshot, SuccessResponse, SwitchAccountRequest, SwitchAccountResponse, TopUpRequest, TopUpResponse, Transaction, TransactionHistoryResponse, TransactionType, UpdateAccountPreferencesRequest, UpdatePositionRequest, UpdateWorkingOrderRequest, Watchlist, WatchlistMarketsResponse, WatchlistsResponse, WebSocketMessage, WorkingOrder, WorkingOrderResponse, WorkingOrdersResponse };