Download the PHP package timirey/xapi-php without Composer
On this page you can find all versions of the php package timirey/xapi-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package 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.
Table of contents
- Installation
- Usage
- Available commands
- login
- logout
- Available streaming commands
- fetchBalance (getBalance)
- fetchCandles (getCandles)
- fetchKeepAlive (getKeepAlive)
- fetchNews (getNews)
- fetchProfits (getProfits)
- fetchTickPrices (getTickPrices)
- fetchTrades (getTrades)
- fetchTradeStatus (getTradeStatus)
- pingStream (ping)
- Retrieving trading data
- getAllSymbols
- getCalendar
- getChartLastRequest
- getChartRangeRequest
- getCommissionDef
- getCurrentUserData
- getIbsHistory
- getMarginLevel
- getMarginTrade
- getNews
- getProfitCalculation
- getServerTime
- getStepRules
- getSymbol
- getTickPrices
- getTradeRecords
- getTrades
- getTradesHistory
- getTradingHours
- getVersion
- ping
- tradeTransaction
- tradeTransactionStatus
- Error handling
- ErrorResponseException
- InvalidResponseException
- InvalidPayloadException
- SocketException
- Testing
- License
- Reference
Installation
Install the package via Composer.
Usage
Basic usage example.
Subscribe to a stream channel.
Available commands
Request-Reply commands are performed on main connection socket. The reply is sent by main connection socket.
login
Logs in to the xStation5 API.
logout
Logs out from the xStation5 API.
Available streaming commands
fetchBalance (getBalance)
Allows to get actual account indicators values in real-time, as soon as they are available in the system.
fetchCandles (getCandles)
Subscribes for and unsubscribes from API chart candles. The interval of every candle is 1 minute. A new candle arrives every minute.
fetchKeepAlive (getKeepAlive)
Subscribes for and unsubscribes from 'keep alive' messages. A new 'keep alive' message is sent by the API every 3 seconds.
fetchNews (getNews)
Subscribes for and unsubscribes from news.
fetchProfits (getProfits)
Subscribes for and unsubscribes from profits.
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.
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.
fetchTradeStatus (getTradeStatus)
Allows to get status for sent trade requests in real-time, as soon as it is available in the system.
pingStream (ping)
Regularly calling this function is enough to refresh the internal state of all the components in the system.
Retrieving trading data
getAllSymbols
Retrieves information about all symbols.
getCalendar
Returns a calendar with market events.
getChartLastRequest
Returns chart info from the start date to the current time.
getChartRangeRequest
Returns chart info from the start date to the current time.
getCommissionDef
Returns the calculation of commission and rate of exchange.
getCurrentUserData
Returns information about account currency and leverage.
getIbsHistory
Returns IBs data from the given time range.
getMarginLevel
Returns various account indicators.
getMarginTrade
Returns expected margin for a given instrument and volume.
getNews
Returns news from the trading server which were sent within a specified period.
getProfitCalculation
Calculates estimated profit for given deal data.
getServerTime
Returns the current time on the trading server.
getStepRules
Returns a list of step rules for DMAs.
getSymbol
Retrieves information about a specific symbol.
getTickPrices
Returns an array of current quotations for given symbols.
getTradeRecords
Returns an array of trades listed in orders argument.
getTrades
Returns an array of user's trades.
getTradesHistory
Returns an array of user's trades which were closed within a specified period.
getTradingHours
Returns quotes and trading times.
getVersion
Returns the current API version.
ping
Regularly calling this function is enough to refresh the internal state of all the components in the system.
tradeTransaction
Starts a trade transaction.
tradeTransactionStatus
Returns the current transaction status.
Error handling
Custom exceptions for handling request errors.
ErrorResponseException
Thrown when the API returns an error (e.g., invalid password). Provides error code and description.
All error codes and descriptions can be found in the official documentation.
InvalidResponseException
Thrown when a request fails and the API does not return a proper error response (e.g., invalid or incomplete response).
InvalidPayloadException
Thrown when for some reason the payload is invalid (usually invalid response from the xApi).
SocketException
Thrown when socket fails to connect/read/write for some reason.
Testing
This package uses the PestPHP framework for testing.
License
This library is open-sourced software licensed under the MIT license.
Reference
For more detailed documentation, please refer to the XTB xStation5 Trading API Documentation.