PHPackages                             timirey/xapi-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. timirey/xapi-php

AbandonedArchivedLibrary[API Development](/categories/api)

timirey/xapi-php
================

A PHP wrapper for the X-Trade Brokers (XTB) xStation5 Trading API, supporting real-time streaming and simple commands via socket connection.

6.3.2(1y ago)482MITPHPPHP ^8.3

Since Jun 28Pushed 1y ago1 watchersCompare

[ Source](https://github.com/timirey/xapi-php)[ Packagist](https://packagist.org/packages/timirey/xapi-php)[ RSS](/packages/timirey-xapi-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (37)Used By (0)

[![XTB Online Investing](https://raw.githubusercontent.com/timirey/xapi-php/master/.github/logo.svg)](https://raw.githubusercontent.com/timirey/xapi-php/master/.github/logo.svg)

[![](https://camo.githubusercontent.com/a9b9316b0dd923c93b326ea82f12466136f253ede16b6ff8b787945e0bf17b74/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e74656e616e63652d646570726563617465642d7265642e737667)](https://camo.githubusercontent.com/a9b9316b0dd923c93b326ea82f12466136f253ede16b6ff8b787945e0bf17b74/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e74656e616e63652d646570726563617465642d7265642e737667)[![Tests](https://github.com/timirey/xapi-php/actions/workflows/tests.yml/badge.svg)](https://github.com/timirey/xapi-php/actions)[![Latest Stable Version](https://camo.githubusercontent.com/fa128f10f5fa9b9c12b6809ef668857b5a5d982f5839ed86207c9401e07dd309/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74696d697265792f786170692d706870)](https://packagist.org/packages/timirey/xapi-php)[![Total Downloads](https://camo.githubusercontent.com/6de67407d743079a357b104aec9c1862bbdcf4f94faea85a2c02640f02f37b62/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74696d697265792f786170692d706870)](https://packagist.org/packages/timirey/xapi-php)[![License](https://camo.githubusercontent.com/6f8a8199d019bd1e5fe84b40c10a0fe4b6ae318f57d1286c2c950b64debb2257/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f74696d697265792f786170692d706870)](https://packagist.org/packages/timirey/xapi-php)

This PHP library provides a comprehensive and user-friendly interface for interacting with the X-Trade Brokers (XTB) xStation5 Trading API. It supports a wide range of functionalities, including account management, trade execution, market data retrieval, and real-time streaming commands via socket, making it an ideal tool for developers looking to integrate advanced trading features and live market data into their applications.

DEPRECATED
==========

[](#deprecated)

As of **March 14, 2025**, access to XTB API via `xapi.xtb.com` and `ws.xtb.com` will be disabled.

Table of contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Available commands](#available-commands)
    - [login](#login)
    - [logout](#logout)
- [Available streaming commands](#available-streaming-commands)
    - [fetchBalance](#fetchbalance-getbalance) (getBalance)
    - [fetchCandles](#fetchcandles-getcandles) (getCandles)
    - [fetchKeepAlive](#fetchkeepalive-getkeepalive) (getKeepAlive)
    - [fetchNews](#fetchnews-getnews) (getNews)
    - [fetchProfits](#fetchprofits-getprofits) (getProfits)
    - [fetchTickPrices](#fetchtickprices-gettickprices) (getTickPrices)
    - [fetchTrades](#fetchtrades-gettrades) (getTrades)
    - [fetchTradeStatus](#fetchtradestatus-gettradestatus) (getTradeStatus)
    - [pingStream](#pingstream-ping) (ping)
- [Retrieving trading data](#retrieving-trading-data)
    - [getAllSymbols](#getallsymbols)
    - [getCalendar](#getcalendar)
    - [getChartLastRequest](#getchartlastrequest)
    - [getChartRangeRequest](#getchartrangerequest)
    - [getCommissionDef](#getcommissiondef)
    - [getCurrentUserData](#getcurrentuserdata)
    - [getIbsHistory](#getibshistory)
    - [getMarginLevel](#getmarginlevel)
    - [getMarginTrade](#getmargintrade)
    - [getNews](#getnews)
    - [getProfitCalculation](#getprofitcalculation)
    - [getServerTime](#getservertime)
    - [getStepRules](#getsteprules)
    - [getSymbol](#getsymbol)
    - [getTickPrices](#gettickprices)
    - [getTradeRecords](#gettraderecords)
    - [getTrades](#gettrades)
    - [getTradesHistory](#gettradeshistory)
    - [getTradingHours](#gettradinghours)
    - [getVersion](#getversion)
    - [ping](#ping)
    - [tradeTransaction](#tradetransaction)
    - [tradeTransactionStatus](#tradetransactionstatus)
- [Error handling](#error-handling)
    - [ErrorResponseException](#errorresponseexception)
    - [InvalidResponseException](#invalidresponseexception)
    - [InvalidPayloadException](#invalidpayloadexception)
    - [SocketException](#socketexception)
- [Testing](#testing)
- [License](#license)
- [Reference](#reference)

Installation
------------

[](#installation)

Install the package via Composer.

```
composer require timirey/xapi-php
```

Usage
-----

[](#usage)

Basic usage example.

```
use Timirey\XApi\Client;
use Timirey\XApi\Enums\Host;
use Timirey\XApi\Responses\GetSymbolResponse;

$client = new Client(
    userId: 12345678,
    password: 'password',
    host: Host::DEMO,
    appName: 'My Test App'
);

/**
 * @var $response GetSymbolResponse
 */
$response = $client->getSymbol(
    symbol: 'EURUSD'
);
```

Subscribe to a stream channel.

```
use Timirey\XApi\Client;
use Timirey\XApi\Enums\Host;
use Timirey\XApi\Responses\Data\TickStreamRecord;
use Timirey\XApi\Responses\FetchTickPricesResponse;

$client = new Client(
    userId: 12345678,
    password: 'password',
    host: Host::DEMO,
    appName: 'My Test App'
);

// Meant to be a daemon, run as separate process.
$client->fetchTickPrices(
    symbol: 'EURUSD',
    callback: static function (FetchTickPricesResponse $response): void {
        /**
         * @var TickStreamRecord $record
         */
        $record = $response->tickStreamRecord;
    },
    minArrivalTime: 100,
    maxLevel: 1
);

// Unreachable code.
```

Available commands
------------------

[](#available-commands)

Request-Reply commands are performed on main connection socket. The reply is sent by main connection socket.

### [login](http://developers.xstore.pro/documentation/current#login)

[](#login)

Logs in to the xStation5 API.

```
use Timirey\XApi\Responses\LoginResponse;
use Timirey\XApi\Client;

/**
 * @var LoginResponse $response
 * @var Client $client
 */
$response = $client->login(
    userId: 123456789,
    password: 'password',
    appName: 'My App'
);
```

### [logout](http://developers.xstore.pro/documentation/current#logout)

[](#logout)

Logs out from the xStation5 API.

```
use Timirey\XApi\Responses\LogoutResponse;
use Timirey\XApi\Client;

/**
 * @var LogoutResponse $response
 * @var Client $client
 */
$response = $client->logout();
```

Available streaming commands
----------------------------

[](#available-streaming-commands)

### fetchBalance ([getBalance](http://developers.xstore.pro/documentation/#streamgetBalance))

[](#fetchbalance-getbalance)

Allows to get actual account indicators values in real-time, as soon as they are available in the system.

```
use Timirey\XApi\Responses\Data\BalanceStreamRecord;
use Timirey\XApi\Responses\FetchBalanceResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchBalance(
    callback: static function (FetchBalanceResponse $response): void {
        /**
         * @var BalanceStreamRecord $record
         */
        $record = $response->balanceStreamRecord;
    }
);
```

### fetchCandles ([getCandles](http://developers.xstore.pro/documentation/#streamgetCandles))

[](#fetchcandles-getcandles)

Subscribes for and unsubscribes from API chart candles. The interval of every candle is 1 minute. A new candle arrives every minute.

```
use Timirey\XApi\Responses\Data\CandleStreamRecord;
use Timirey\XApi\Responses\FetchCandlesResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchCandles(
    symbol: 'EURUSD',
    callback: static function (FetchCandlesResponse $response): void {
        /**
         * @var CandleStreamRecord $record
         */
        $record = $response->candleStreamRecord;
    }
);
```

The **getCandles** API operation often fails to subscribe directly to the desired symbol. To reliably listen for candle data, the price history must be requested first.

Before subscribing to candle updates, initiate a request for the symbol's historical price data using **getChartLastRequest**.

```
use DateTime;
use Timirey\XApi\Client;
use Timirey\XApi\Enums\Period;
use Timirey\XApi\Payloads\Data\ChartLastInfoRecord;
use Timirey\XApi\Responses\Data\CandleStreamRecord;
use Timirey\XApi\Responses\FetchCandlesResponse;
use Timirey\XApi\Responses\GetChartLastRequestResponse;

$chartLastInfoRecord = new ChartLastInfoRecord(
    period: Period::PERIOD_M1,
    start: new DateTime(),
    symbol: $symbol
);

/**
 * @var GetChartLastRequestResponse $response
 * @var Client $client
 *
 * The $response is not used anywhere.
 */
$response = $client->getChartLastRequest($chartLastInfoRecord);

/**
 * @var Client $client
 */
$client->fetchCandles(
    symbol: 'EURUSD',
    callback: static function (FetchCandlesResponse $response): void {
        /**
         * @var CandleStreamRecord $record
         */
        $record = $response->candleStreamRecord;
    }
);
```

### fetchKeepAlive ([getKeepAlive](http://developers.xstore.pro/documentation/#streamgetKeepAlive))

[](#fetchkeepalive-getkeepalive)

Subscribes for and unsubscribes from 'keep alive' messages. A new 'keep alive' message is sent by the API every 3 seconds.

```
use Timirey\XApi\Responses\Data\KeepAliveStreamRecord;
use Timirey\XApi\Responses\FetchKeepAliveResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchKeepAlive(
    callback: static function (FetchKeepAliveResponse $response): void {
        /**
         * @var KeepAliveStreamRecord $record
         */
        $record = $response->keepAliveStreamRecord;
    }
);
```

### fetchNews ([getNews](http://developers.xstore.pro/documentation/#streamgetNews))

[](#fetchnews-getnews)

Subscribes for and unsubscribes from news.

```
use Timirey\XApi\Responses\Data\NewsStreamRecord;
use Timirey\XApi\Responses\FetchNewsResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchNews(
    callback: static function (FetchNewsResponse $response): void {
        /**
         * @var NewsStreamRecord $record
         */
        $record = $response->newsStreamRecord;
    }
);
```

### fetchProfits ([getProfits](http://developers.xstore.pro/documentation/#streamgetProfits))

[](#fetchprofits-getprofits)

Subscribes for and unsubscribes from profits.

```
use Timirey\XApi\Responses\Data\ProfitStreamRecord;
use Timirey\XApi\Responses\FetchProfitsResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchProfits(
    callback: static function (FetchProfitsResponse $response): void {
        /**
         * @var ProfitStreamRecord $record
         */
        $record = $response->profitStreamRecord;
    }
);
```

### fetchTickPrices ([getTickPrices](http://developers.xstore.pro/documentation/#streamgetTickPrices))

[](#fetchtickprices-gettickprices)

Establishes subscription for quotations and allows to obtain the relevant information in real-time, as soon as it is available in the system.

```
use Timirey\XApi\Responses\Data\TickStreamRecord;
use Timirey\XApi\Responses\FetchTickPricesResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchTickPrices(
    symbol: 'EURUSD',
    callback: static function (FetchTickPricesResponse $response): void {
        /**
         * @var TickStreamRecord $record
         */
        $record = $response->tickStreamRecord;
    },
    maxLevel: 1,
    minArrivalTime: 200
);
```

### fetchTrades ([getTrades](http://developers.xstore.pro/documentation/#streamgetTrades))

[](#fetchtrades-gettrades)

Establishes subscription for user trade status data and allows to obtain the relevant information in real-time, as soon as it is available in the system.

```
use Timirey\XApi\Responses\Data\TradeStreamRecord;
use Timirey\XApi\Responses\FetchTradesResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchTrades(
    callback: static function (FetchTradesResponse $response): void {
        /**
         * @var TradeStreamRecord $record
         */
        $record = $response->tradeStreamRecord;
    }
);
```

### fetchTradeStatus ([getTradeStatus](http://developers.xstore.pro/documentation/#streamgetTradeStatus))

[](#fetchtradestatus-gettradestatus)

Allows to get status for sent trade requests in real-time, as soon as it is available in the system.

```
use Timirey\XApi\Responses\Data\TradeStatusStreamRecord;
use Timirey\XApi\Responses\FetchTradeStatusResponse;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->fetchTradeStatus(
    callback: static function (FetchTradeStatusResponse $response): void {
        /**
         * @var TradeStatusStreamRecord $record
         */
        $record = $response->tradeStatusStreamRecord;
    }
);
```

### pingStream ([ping](http://developers.xstore.pro/documentation/#streamping))

[](#pingstream-ping)

Regularly calling this function is enough to refresh the internal state of all the components in the system.

```
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client->pingStream();
```

Retrieving trading data
-----------------------

[](#retrieving-trading-data)

### [getAllSymbols](http://developers.xstore.pro/documentation/current#getAllSymbols)

[](#getallsymbols)

Retrieves information about all symbols.

```
use Timirey\XApi\Responses\GetAllSymbolsResponse;
use Timirey\XApi\Client;

/**
 * @var GetAllSymbolsResponse $response
 * @var Client $client
 */
$response = $client->getAllSymbols();
```

### [getCalendar](http://developers.xstore.pro/documentation/current#getCalendar)

[](#getcalendar)

Returns a calendar with market events.

```
use Timirey\XApi\Responses\GetCalendarResponse;
use Timirey\XApi\Client;

/**
 * @var GetCalendarResponse $response
 * @var Client $client
 */
$response = $client->getCalendar();
```

### [getChartLastRequest](http://developers.xstore.pro/documentation/current#getChartLastRequest)

[](#getchartlastrequest)

Returns chart info from the start date to the current time.

```
use Timirey\XApi\Responses\GetChartLastRequestResponse;
use Timirey\XApi\Client;
use Timirey\XApi\Payloads\Data\ChartLastInfoRecord;
use Timirey\XApi\Enums\Period;
use DateTime;

$chartLastInfoRecord = new ChartLastInfoRecord(
    period: Period::PERIOD_M1,
    start: new DateTime('-1 week'),
    symbol: 'EURUSD'
);

/**
 * @var GetChartLastRequestResponse $response
 * @var Client $client
 */
$response = $client->getChartLastRequest(
    chartLastInfoRecord: $chartLastInfoRecord
);
```

### [getChartRangeRequest](http://developers.xstore.pro/documentation/current#getChartRangeRequest)

[](#getchartrangerequest)

Returns chart info from the start date to the current time.

```
use Timirey\XApi\Responses\GetChartRangeRequestResponse;
use Timirey\XApi\Client;
use Timirey\XApi\Payloads\Data\ChartRangeInfoRecord;
use Timirey\XApi\Enums\Period;
use DateTime;

$chartRangeInfoRecord = new ChartRangeInfoRecord(
    period: Period::PERIOD_H1,
    start: new DateTime('-1 month'),
    end: new DateTime(),
    symbol: 'EURUSD',
    ticks: 1000
);

/**
 * @var GetChartRangeRequestResponse $response
 * @var Client $client
 */
$response = $client->getChartRangeRequest(
    chartRangeInfoRecord: $chartRangeInfoRecord
);
```

### [getCommissionDef](http://developers.xstore.pro/documentation/current#getCommissionDef)

[](#getcommissiondef)

Returns the calculation of commission and rate of exchange.

```
use Timirey\XApi\Responses\GetCommissionDefResponse;
use Timirey\XApi\Client;

/**
 * @var GetCommissionDefResponse $response
 * @var Client $client
 */
$response = $client->getCommissionDef(
    symbol: 'EURUSD',
    volume: 1.0
);
```

### [getCurrentUserData](http://developers.xstore.pro/documentation/current#getCurrentUserData)

[](#getcurrentuserdata)

Returns information about account currency and leverage.

```
use Timirey\XApi\Responses\GetCurrentUserDataResponse;
use Timirey\XApi\Client;

/**
 * @var GetCurrentUserDataResponse $response
 * @var Client $client
 */
$response = $client->getCurrentUserData();
```

### [getIbsHistory](http://developers.xstore.pro/documentation/current#getIbsHistory)

[](#getibshistory)

Returns IBs data from the given time range.

```
use Timirey\XApi\Responses\GetIbsHistoryResponse;
use Timirey\XApi\Client;
use DateTime;

/**
 * @var GetIbsHistoryResponse $response
 * @var Client $client
 */
$response = $client->getIbsHistory(
    start: new DateTime('-1 month'),
    end: new DateTime()
);
```

### [getMarginLevel](http://developers.xstore.pro/documentation/current#getMarginLevel)

[](#getmarginlevel)

Returns various account indicators.

```
use Timirey\XApi\Responses\GetMarginLevelResponse;
use Timirey\XApi\Client;

/**
 * @var GetMarginLevelResponse $response
 * @var Client $client
 */
$response = $client->getMarginLevel();
```

### [getMarginTrade](http://developers.xstore.pro/documentation/current#getMarginTrade)

[](#getmargintrade)

Returns expected margin for a given instrument and volume.

```
use Timirey\XApi\Responses\GetMarginTradeResponse;
use Timirey\XApi\Client;

/**
 * @var GetMarginTradeResponse $response
 * @var Client $client
 */
$response = $client->getMarginTrade(
    symbol: 'EURPLN',
    volume: 1.0
);
```

### [getNews](http://developers.xstore.pro/documentation/current#getNews)

[](#getnews)

Returns news from the trading server which were sent within a specified period.

```
use Timirey\XApi\Responses\GetNewsResponse;
use Timirey\XApi\Client;
use DateTime;

/**
 * @var GetNewsResponse $response
 * @var Client $client
 */
$response = $client->getNews(
    start: new DateTime('-1 month'),
    end: new DateTime()
);
```

### [getProfitCalculation](http://developers.xstore.pro/documentation/current#getProfitCalculation)

[](#getprofitcalculation)

Calculates estimated profit for given deal data.

```
use Timirey\XApi\Responses\GetProfitCalculationResponse;
use Timirey\XApi\Client;
use Timirey\XApi\Enums\Cmd;

/**
 * @var GetProfitCalculationResponse $response
 * @var Client $client
 */
$response = $client->getProfitCalculation(
  closePrice: 1.3000,
  cmd: Cmd::BUY,
  openPrice: 1.2233,
  symbol: 'EURPLN',
  volume: 1.0
);
```

### [getServerTime](http://developers.xstore.pro/documentation/current#getServerTime)

[](#getservertime)

Returns the current time on the trading server.

```
use Timirey\XApi\Responses\GetServerTimeResponse;
use Timirey\XApi\Client;

/**
 * @var GetServerTimeResponse $response
 * @var Client $client
 */
$response = $client->getServerTime();
```

### [getStepRules](http://developers.xstore.pro/documentation/current#getStepRules)

[](#getsteprules)

Returns a list of step rules for DMAs.

```
use Timirey\XApi\Responses\GetStepRulesResponse;
use Timirey\XApi\Client;

/**
 * @var GetStepRulesResponse $response
 * @var Client $client
 */
$response = $client->getStepRules();
```

### [getSymbol](http://developers.xstore.pro/documentation/current#getSymbol)

[](#getsymbol)

Retrieves information about a specific symbol.

```
use Timirey\XApi\Responses\GetSymbolResponse;
use Timirey\XApi\Client;

/**
 * @var GetSymbolResponse $response
 * @var Client $client
 */
$response = $client->getSymbol(
    symbol: EURUSD
);
```

### [getTickPrices](http://developers.xstore.pro/documentation/current#getTickPrices)

[](#gettickprices)

Returns an array of current quotations for given symbols.

```
use Timirey\XApi\Responses\GetTickPricesResponse;
use Timirey\XApi\Enums\Level;
use Timirey\XApi\Client;
use DateTime;

/**
 * @var GetTickPricesResponse $response
 * @var Client $client
 */
$response = $client->getTickPrices(
    level: Level::BASE,
    symbols: ['EURPLN', 'AGO.PL'],
    timestamp: new DateTime()
);
```

### [getTradeRecords](http://developers.xstore.pro/documentation/current#getTradeRecords)

[](#gettraderecords)

Returns an array of trades listed in orders argument.

```
use Timirey\XApi\Responses\GetTradeRecordsResponse;
use Timirey\XApi\Client;

/**
 * @var GetTradeRecordsResponse $response
 * @var Client $client
 */
$response = $client->getTradeRecords(
    orders: [7489839, 7489841]
);
```

### [getTrades](http://developers.xstore.pro/documentation/current#getTrades)

[](#gettrades)

Returns an array of user's trades.

```
use Timirey\XApi\Responses\GetTradesResponse;
use Timirey\XApi\Client;

/**
 * @var GetTradesResponse $response
 * @var Client $client
 */
$response = $client->getTrades(
    openedOnly: true
);
```

### [getTradesHistory](http://developers.xstore.pro/documentation/current#getTradesHistory)

[](#gettradeshistory)

Returns an array of user's trades which were closed within a specified period.

```
use Timirey\XApi\Responses\GetTradesHistoryResponse;
use Timirey\XApi\Client;
use DateTime;

/**
 * @var GetTradesHistoryResponse $response
 * @var Client $client
 */
$response = $client->getTradesHistory(
    start: new DateTime('last month'),
    end: new DateTime()
);
```

### [getTradingHours](http://developers.xstore.pro/documentation/current#getTradingHours)

[](#gettradinghours)

Returns quotes and trading times.

```
use Timirey\XApi\Responses\GetTradingHoursResponse;
use Timirey\XApi\Client;

/**
 * @var GetTradingHoursResponse $response
 * @var Client $client
 */
$response = $client->getTradingHours(
    symbols: ['EURPLN', 'AGO.PL']
);
```

### [getVersion](http://developers.xstore.pro/documentation/current#getVersion)

[](#getversion)

Returns the current API version.

```
use Timirey\XApi\Responses\GetVersionResponse;
use Timirey\XApi\Client;

/**
 * @var GetVersionResponse $response
 * @var Client $client
 */
$response = $client->getVersion();
```

### [ping](http://developers.xstore.pro/documentation/current#ping)

[](#ping)

Regularly calling this function is enough to refresh the internal state of all the components in the system.

```
use Timirey\XApi\Responses\PingResponse;
use Timirey\XApi\Client;

/**
 * @var PingResponse $response
 * @var Client $client
 */
$response = $client->ping();
```

### [tradeTransaction](http://developers.xstore.pro/documentation/current#tradeTransaction)

[](#tradetransaction)

Starts a trade transaction.

```
use Timirey\XApi\Responses\TradeTransactionResponse;
use Timirey\XApi\Payloads\Data\TradeTransInfo;
use Timirey\XApi\Client;

$tradeTransInfo = new TradeTransInfo(
    cmd: Cmd::BUY,
    customComment: 'Test trade',
    expiration: new DateTime(),
    offset: 0,
    order: 0,
    price: 1.12345,
    sl: 1.12000,
    symbol: 'EURUSD',
    tp: 1.12500,
    type: Type::OPEN,
    volume: 1.0
);

/**
 * @var TradeTransactionResponse $response
 * @var Client $client
 */
$response = $client->tradeTransaction(
    tradeTransInfo: $tradeTransInfo
);
```

### [tradeTransactionStatus](http://developers.xstore.pro/documentation/current#tradeTransactionStatus)

[](#tradetransactionstatus)

Returns the current transaction status.

```
use Timirey\XApi\Responses\TradeTransactionStatusResponse;
use Timirey\XApi\Client;

/**
 * @var TradeTransactionStatusResponse $response
 * @var Client $client
 */
$response = $client->tradeTransactionStatus(
    order: 123456
);
```

Error handling
--------------

[](#error-handling)

Custom exceptions for handling request errors.

### ErrorResponseException

[](#errorresponseexception)

Thrown when the API returns an error (e.g., invalid password). Provides error code and description.

```
use Timirey\XApi\Exceptions\ResponseException;
use Timirey\XApi\Enums\Host;
use Timirey\XApi\Client;

/**
 * @var Client $client
 */
$client = new Client(
    userId: 123456789,
    password: 'invalidPassword',
    host: Host::DEMO
);

try {
    $client->getVersion();
} catch (ErrorResponseException $e) {
    echo ($e->getErrorCode()); // 'BE005'
    echo ($e->getErrorDescr()); // 'userPasswordCheck: Invalid login or password.'
}
```

All error codes and descriptions can be found in the [official documentation](http://developers.xstore.pro/documentation#error-messages).

### InvalidResponseException

[](#invalidresponseexception)

Thrown when a request fails and the API does not return a proper error response (e.g., invalid or incomplete response).

### InvalidPayloadException

[](#invalidpayloadexception)

Thrown when for some reason the payload is invalid (usually invalid response from the xApi).

### SocketException

[](#socketexception)

Thrown when socket fails to connect/read/write for some reason.

Testing
-------

[](#testing)

This package uses the PestPHP framework for testing.

```
./vendor/bin/pest
```

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](https://github.com/timirey/xapi-php/blob/main/LICENSE.md).

Reference
---------

[](#reference)

For more detailed documentation, please refer to the [XTB xStation5 Trading API Documentation](http://developers.xstore.pro/documentation).

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance42

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

36

Last Release

497d ago

Major Versions

1.2.1 → 2.0.0-alpha2024-07-08

2.0.1 → 3.0.02024-07-16

3.0.0 → 4.0.02024-07-16

4.0.1 → 5.0.02024-07-17

5.0.0 → 6.0.02024-07-30

PHP version history (2 changes)0.7.0PHP ^8.1

3.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dafb7e130f8087f4eed9d8e588b2c6751b7cf20df058c58d11f0fce51032a977?d=identicon)[timirey](/maintainers/timirey)

---

Top Contributors

[![timirey](https://avatars.githubusercontent.com/u/15349915?v=4)](https://github.com/timirey "timirey (263 commits)")

---

Tags

apiclientphptradingwrapperx-trade-brokersxapixstationxtbphpapiclientwrappertradingxAPIxtbxstationx-trade-brokers

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/timirey-xapi-php/health.svg)

```
[![Health](https://phpackages.com/badges/timirey-xapi-php/health.svg)](https://phpackages.com/packages/timirey-xapi-php)
```

###  Alternatives

[kunalvarma05/dropbox-php-sdk

Dropbox PHP API V2 SDK (Unofficial)

3633.0M18](/packages/kunalvarma05-dropbox-php-sdk)[mozex/anthropic-php

Anthropic PHP is a supercharged community-maintained PHP API client that allows you to interact with Anthropic API.

46365.1k13](/packages/mozex-anthropic-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
