Modern, object-oriented PHP/Laravel library for the taapi.io technical analysis API.
- ✨ Modern PHP 8.1+ with strict types and enums
- 🔄 Fluent Interface for intuitive request building
- 📦 Full API Coverage - GET (Direct), POST (Bulk), and POST (Manual) requests
- 🎯 Type-Safe - Strongly typed responses with DTOs
- 🚀 Laravel Integration - Service Provider, Facade, and configuration
- 🛡️ Error Handling - Custom exceptions for different error types
- âś… Well Tested - Comprehensive unit and integration tests
- đź“– Fully Documented - Complete PHPDoc documentation
Install via Composer:
composer require tigusigalpa/taapi-phpuse Tigusigalpa\TAAPI\TAAPIClient;
$taapi = new TAAPIClient('YOUR_API_SECRET');- Publish the configuration file (optional):
php artisan vendor:publish --tag=taapi-config- Add your API secret to
.env:
TAAPI_SECRET=your_api_secret_here
TAAPI_TIMEOUT=30
TAAPI_DEFAULT_EXCHANGE=binance
TAAPI_DEFAULT_INTERVAL=1h- Use the Facade:
use Tigusigalpa\TAAPI\Laravel\Facades\TAAPI;
// Or with alias
use TAAPI;Get a single indicator value for a specific exchange, symbol, and interval.
use Tigusigalpa\TAAPI\Laravel\Facades\TAAPI;
$rsi = TAAPI::exchange('binance')
->symbol('BTC/USDT')
->interval('1h')
->indicator('rsi')
->get();
echo "RSI Value: " . $rsi->getValue();use Tigusigalpa\TAAPI\Enums\Exchange;
use Tigusigalpa\TAAPI\Enums\Indicator;
use Tigusigalpa\TAAPI\Enums\Interval;
$macd = TAAPI::exchange(Exchange::BINANCE)
->symbol('ETH/USDT')
->interval(Interval::FOUR_HOURS)
->indicator(Indicator::MACD)
->get();
echo "MACD: " . $macd->get('valueMACD');
echo "Signal: " . $macd->get('valueMACDSignal');
echo "Histogram: " . $macd->get('valueMACDHist');$ema = TAAPI::exchange('binance')
->symbol('BTC/USDT')
->interval('1h')
->indicator('ema')
->withParams(['period' => 50])
->get();
echo "EMA(50): " . $ema->getValue();// Get historical data
$rsi = TAAPI::exchange('binance')
->symbol('BTC/USDT')
->interval('1h')
->indicator('rsi')
->backtrack(5)
->get();
// Get multiple historical values
$rsi = TAAPI::exchange('binance')
->symbol('BTC/USDT')
->interval('1h')
->indicator('rsi')
->backtracks(10)
->get();Execute multiple indicator requests in a single API call for better performance.
$results = TAAPI::bulk()
->addConstruct(
TAAPI::construct('binance', 'BTC/USDT', '1h')
->addIndicator('rsi', ['id' => 'btc_rsi'])
->addIndicator('macd', ['id' => 'btc_macd'])
)
->addConstruct(
TAAPI::construct('binance', 'ETH/USDT', '4h')
->addIndicator('sma', ['period' => 200, 'id' => 'eth_sma'])
)
->execute();
// Access results by ID
$btcRsi = $results->findById('btc_rsi');
echo "BTC RSI: " . $btcRsi->getValue();
// Iterate through all results
foreach ($results as $result) {
echo "{$result->indicator}: {$result->getValue()}\n";
}use Tigusigalpa\TAAPI\Enums\Exchange;
use Tigusigalpa\TAAPI\Enums\Interval;
$results = TAAPI::bulk()
->addConstruct(
TAAPI::construct(Exchange::BINANCE, 'BTC/USDT', Interval::ONE_HOUR)
->addIndicator('rsi', ['period' => 14, 'id' => 'rsi_14'])
->addIndicator('rsi', ['period' => 21, 'id' => 'rsi_21'])
->addIndicator('ema', ['period' => 50, 'id' => 'ema_50'])
->addIndicator('ema', ['period' => 200, 'id' => 'ema_200'])
)
->addConstruct(
TAAPI::construct(Exchange::COINBASE, 'ETH/USD', Interval::FOUR_HOURS)
->addIndicator('bbands', ['id' => 'eth_bb'])
->addIndicator('stoch', ['id' => 'eth_stoch'])
)
->execute();
// Filter by indicator type
$rsiResults = $results->filterByIndicator('rsi');
foreach ($rsiResults as $rsi) {
echo "RSI ({$rsi->id}): {$rsi->getValue()}\n";
}Calculate indicators using your own candle data.
$candles = [
[1609459200, 28923.63, 28923.63, 28923.63, 28923.63, 0.00000000],
[1609462800, 29083.37, 29188.78, 28963.64, 29103.37, 1107.05626800],
[1609466400, 29103.38, 29152.98, 28980.01, 29050.00, 978.58108600],
// ... more candles
];
$ema = TAAPI::manual('ema')
->withCandles($candles)
->withParams(['period' => 50])
->execute();
echo "EMA(50): " . $ema->getValue();use Tigusigalpa\TAAPI\Enums\Indicator;
$rsi = TAAPI::manual(Indicator::RSI)
->withCandles($candles)
->withParam('period', 14)
->execute();
echo "RSI: " . $rsi->getValue();All single indicator requests return an IndicatorResponse object:
$response = TAAPI::exchange('binance')
->symbol('BTC/USDT')
->interval('1h')
->indicator('rsi')
->get();
// Get the main value
$value = $response->getValue();
// Access specific fields
$value = $response->get('value');
$value = $response['value'];
$value = $response->value;
// Check if field exists
if ($response->has('value')) {
// ...
}
// Convert to array
$array = $response->toArray();
// JSON serialization
$json = json_encode($response);Bulk requests return a BulkResponse object:
$results = TAAPI::bulk()
->addConstruct(/* ... */)
->execute();
// Count results
$count = count($results);
// Find by ID
$result = $results->findById('my_indicator');
// Filter by indicator
$rsiResults = $results->filterByIndicator('rsi');
// Iterate
foreach ($results as $result) {
echo $result->indicator . ': ' . $result->getValue();
}
// Array access
$first = $results[0];
// Convert to array
$array = $results->toArray();The library provides custom exceptions for different error scenarios:
use Tigusigalpa\TAAPI\Exceptions\InvalidArgumentException;
use Tigusigalpa\TAAPI\Exceptions\ApiException;
use Tigusigalpa\TAAPI\Exceptions\RateLimitException;
try {
$result = TAAPI::exchange('binance')
->symbol('BTC/USDT')
->interval('1h')
->indicator('rsi')
->get();
} catch (InvalidArgumentException $e) {
// Handle invalid parameters
echo "Invalid argument: " . $e->getMessage();
} catch (RateLimitException $e) {
// Handle rate limiting
echo "Rate limit exceeded. Retry after: " . $e->getRetryAfterSeconds() . " seconds";
} catch (ApiException $e) {
// Handle general API errors
echo "API Error [{$e->statusCode}]: " . $e->getMessage();
print_r($e->responseData);
}use Tigusigalpa\TAAPI\Enums\Exchange;
Exchange::BINANCE
Exchange::BINANCEUS
Exchange::BINANCEUSDM
Exchange::BITFINEX
Exchange::BITGET
Exchange::BITMEX
Exchange::BITSTAMP
Exchange::BYBIT
Exchange::COINBASE
Exchange::CRYPTOCOM
Exchange::GATEIO
Exchange::HUOBI
Exchange::KRAKEN
Exchange::KUCOIN
Exchange::MEXC
Exchange::OKX
Exchange::PHEMEX
Exchange::POLONIEXuse Tigusigalpa\TAAPI\Enums\Interval;
Interval::ONE_MINUTE // '1m'
Interval::FIVE_MINUTES // '5m'
Interval::FIFTEEN_MINUTES // '15m'
Interval::THIRTY_MINUTES // '30m'
Interval::ONE_HOUR // '1h'
Interval::TWO_HOURS // '2h'
Interval::FOUR_HOURS // '4h'
Interval::TWELVE_HOURS // '12h'
Interval::ONE_DAY // '1d'
Interval::ONE_WEEK // '1w'use Tigusigalpa\TAAPI\Enums\Indicator;
Indicator::RSI
Indicator::MACD
Indicator::EMA
Indicator::SMA
Indicator::BBANDS
Indicator::STOCH
Indicator::STOCHRSI
Indicator::ATR
Indicator::ADX
Indicator::CCI
// ... and many moreSee the Indicator enum for the complete list.
// Standard PHP
$taapi = new TAAPIClient('YOUR_API_SECRET');
$taapi->setTimeout(60);
// Laravel
TAAPI::setTimeout(60);use Tigusigalpa\TAAPI\TAAPIClient;
class TradingService
{
public function __construct(
private TAAPIClient $taapi
) {}
public function analyzeMarket(string $symbol): array
{
$rsi = $this->taapi
->exchange('binance')
->symbol($symbol)
->interval('1h')
->indicator('rsi')
->get();
return [
'rsi' => $rsi->getValue(),
'signal' => $rsi->getValue() > 70 ? 'overbought' : 'oversold',
];
}
}Run the test suite:
composer testRun tests with coverage:
composer test -- --coverage- PHP 8.1 or higher
- Guzzle HTTP client 7.5+
- Laravel 10.0+ or 11.0+ (for Laravel integration)
This library is open-sourced software licensed under the MIT license.
Igor Sazonov
- Email: sovletig@gmail.com
- GitHub: @tigusigalpa
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please open an issue on GitHub.
