timirey/trader-php

PHP wrapper for the trader extension, providing access to technical analysis indicators.

1.0.1 2024-12-20 23:30 UTC

This package is auto-updated.

Last update: 2024-12-20 23:31:26 UTC


README

Trader PHP

Tests Latest Stable Version Total Downloads License

Trader PHP

Trader PHP is a PHP library that serves as a user-friendly wrapper for the Trader Extension. It provides developers with easy access to a wide range of technical analysis indicators and functions, enabling seamless integration of financial analytics into trading and finance applications.

With support for commonly used indicators like Moving Averages (SMA, EMA), Relative Strength Index (RSI), MACD, and more, this library simplifies the process of building financial tools, algorithmic trading systems, and real-time data analysis platforms.

Table of Contents

Features

  • Easy-to-use wrapper around PHP’s Trader Extension.
  • Support for over 30 technical analysis indicators such as SMA, EMA, RSI, MACD, and more.
  • Real-time trading workflows with built-in error handling.
  • Ideal for building financial applications, trading bots, and analytics tools.

Installation

You can easily install the library using Composer:

composer require timirey/trader-php

Make sure that the PHP Trader Extension is installed and enabled on your PHP setup.

Basic Usage

Once installed, you can quickly start using the indicators in your PHP application.

Example 1: Simple Moving Average (SMA)

use Trader\TraderService;

require 'vendor/autoload.php';

// Initialize TraderService
$trader = new TraderService();

// Sample close prices (could be from a stock price feed)
$closePrices = [120.5, 121.0, 121.5, 122.0, 122.5];  // closing prices

// Calculate the Simple Moving Average (SMA) with a period of 3
$sma = $trader->sma($closePrices, 3);

// Display the result
echo "Simple Moving Average (SMA): " . implode(", ", $sma);

Example 2: Relative Strength Index (RSI)

use Trader\TraderService;

require 'vendor/autoload.php';

// Initialize TraderInterface
$trader = new TraderService();

// Sample close prices
$closePrices = [120.5, 121.0, 121.5, 122.0, 122.5];

// Calculate RSI with a period of 14
$rsi = $trader->rsi($closePrices, 14);

// Display the result
echo "Relative Strength Index (RSI): " . implode(", ", $rsi);

Available Indicators

The library provides access to a wide variety of technical analysis functions supported by the PHP Trader extension. Some of the most commonly used indicators include:

  • SMA - Simple Moving Average
  • EMA - Exponential Moving Average
  • RSI - Relative Strength Index
  • MACD - Moving Average Convergence Divergence
  • ADX - Average Directional Index
  • ATR - Average True Range
  • Bollinger Bands
  • CCI - Commodity Channel Index
  • MFI - Money Flow Index
  • OBV - On-Balance Volume
  • Stochastic Oscillator

For a full list of available functions, refer to the official PHP Trader documentation.

Error Handling

To handle errors, you can catch BadFunctionCallException exceptions that occur when invalid data is passed to any indicator.

License

This library is licensed under the MIT License. See the LICENSE file for more information.

Reference

For more detailed documentation, please refer to official PHP Trader documentation.