xtb-api-unofficial - v0.1.0
    Preparing search index...

    Class XTBBrowserClient

    Browser automation client for xStation5.

    Connects to an existing Chrome instance via CDP and executes trades by manipulating AngularJS services directly in the browser context. This approach bypasses UI automation and directly calls the same APIs that xStation5 uses internally.

    Requirements:

    • Chrome with remote debugging enabled: --remote-debugging-port=9222
    • xStation5 logged in and loaded at https://xstation5.xtb.com
    • Active session with access to trading services

    ⚠️ Warning: This executes real trades. Always test on demo accounts first.

    # Start Chrome with remote debugging
    google-chrome --remote-debugging-port=9222 https://xstation5.xtb.com
    const client = new XTBBrowserClient({
    cdpUrl: 'ws://127.0.0.1:9222'
    });
    await client.connect();
    const balance = await client.getBalance();
    await client.buy('CIG.PL', 100, { stopLoss: 2.40 });
    Index

    Constructors

    Methods

    • Execute a BUY order using AngularJS trade service.

      ⚠️ WARNING: This executes real trades. Always test on demo accounts first.

      Directly calls the same trading service that xStation5 UI uses, bypassing UI automation for faster and more reliable execution.

      Parameters

      • symbol: string

        Symbol name (e.g., 'CIG.PL', 'AAPL.US')

      • volume: number

        Volume to buy (number of units)

      • Optionaloptions: TradeOptions

        Optional trade parameters (stop loss, take profit)

      Returns Promise<TradeResult>

      Trade execution result with order ID if successful

      Error if AngularJS services are not available or trade fails

    • Connect to Chrome running xStation5.

      Establishes CDP connection and finds the xStation5 tab. The tab must be already loaded and logged in.

      Returns Promise<void>

      Error if Chrome CDP connection fails or xStation5 tab is not found

    • Disconnect from Chrome.

      Cleanly closes the CDP connection and clears references.

      Returns Promise<void>

    • Get the account number from the current xStation5 session.

      Extracts the account number from the page content where it appears as #12345678.

      Returns Promise<number>

      Account number or 0 if not found

    • Get account balance and equity using AngularJS services.

      Retrieves real-time balance data including equity, free margin, and currency. Uses the same service that xStation5 UI uses internally.

      Returns Promise<AccountBalance>

      Account balance information

      Error if AngularJS services are not available or if timeout occurs

    • Get all open positions using AngularJS services.

      Retrieves all currently open trading positions with details like volume, open price, profit/loss, stop loss, take profit, etc.

      Returns Promise<Position[]>

      Array of open positions, empty array if no positions

      Error if AngularJS services are not available

    • Get current quote (bid/ask prices) for a symbol using AngularJS services.

      Retrieves real-time price data including bid, ask, spread, high, low, and timestamp. Automatically resolves symbol names to internal symbol keys.

      Parameters

      Returns Promise<Quote | null>

      Quote data or null if symbol not found or timeout

      Error if AngularJS services are not available

    • Check if connected and xStation5 AngularJS is ready.

      Returns Promise<boolean>

      True if page is connected and AngularJS scope is available

    • Search for financial instruments by name across 11,888+ available instruments.

      Searches through the symbols cache that xStation5 loads into AngularJS scope. Matches against both symbol names and descriptions.

      Parameters

      • query: string

        Search query (e.g., 'Apple', 'CIG', 'EUR/USD')

      Returns Promise<InstrumentSearchResult[]>

      Array of matching instruments (limited to 20 results)

      Error if AngularJS is not available or symbols cache is not loaded

    • Execute a SELL order using AngularJS trade service.

      ⚠️ WARNING: This executes real trades. Always test on demo accounts first.

      Directly calls the same trading service that xStation5 UI uses, bypassing UI automation for faster and more reliable execution.

      Parameters

      • symbol: string

        Symbol name (e.g., 'CIG.PL', 'AAPL.US')

      • volume: number

        Volume to sell (number of units)

      • Optionaloptions: TradeOptions

        Optional trade parameters (stop loss, take profit)

      Returns Promise<TradeResult>

      Trade execution result with order ID if successful

      Error if AngularJS services are not available or trade fails