PHP 8.1+ ~10 min setup
PHP Integration
Access real-time financial data from PHP applications. Includes Guzzle HTTP examples, a Laravel service class with built-in caching, and controller patterns.
Installation
bash
composer require guzzlehttp/guzzle Quick Start with Guzzle
php
<?php
// Install: composer require guzzlehttp/guzzle
require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
$client = new Client([
'base_uri' => 'https://tickatlas.com/v1/',
'headers' => ['X-API-Key' => getenv('CLAW_API_KEY')],
'timeout' => 10,
]);
// Get RSI for EURUSD
try {
$response = $client->get('indicator', [
'query' => [
'symbol' => 'EURUSD',
'indicator' => 'RSI_14',
'timeframe' => 'H1',
],
]);
$data = json_decode($response->getBody(), true);
echo "RSI: {$data['value']} | Signal: {$data['signal']}\n";
} catch (RequestException $e) {
if ($e->getResponse() && $e->getResponse()->getStatusCode() === 429) {
$retryAfter = $e->getResponse()->getHeader('Retry-After')[0] ?? 2;
echo "Rate limited. Retry after {$retryAfter} seconds.\n";
} else {
echo "Error: " . $e->getMessage() . "\n";
}
} Laravel Service Class
A reusable service class with Laravel Cache integration. Responses are cached automatically to reduce API calls:
app/Services/TickAtlasService.php
<?php
// app/Services/TickAtlasService.php
namespace App\Services;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Illuminate\Support\Facades\Cache;
class TickAtlasService
{
private Client $client;
public function __construct()
{
$this->client = new Client([
'base_uri' => 'https://tickatlas.com/v1/',
'headers' => ['X-API-Key' => config('services.tickatlas.key')],
'timeout' => 10,
]);
}
public function indicator(string $symbol, string $indicator, string $tf = 'H1'): array
{
$cacheKey = "claw:{$symbol}:{$indicator}:{$tf}";
return Cache::remember($cacheKey, now()->addSeconds(30), function () use ($symbol, $indicator, $tf) {
$response = $this->client->get('indicator', [
'query' => compact('symbol', 'indicator') + ['timeframe' => $tf],
]);
return json_decode($response->getBody(), true);
});
}
public function indicators(string $symbol, string $tf = 'H1'): array
{
return Cache::remember("claw:all:{$symbol}:{$tf}", 30, function () use ($symbol, $tf) {
$response = $this->client->get('indicators', [
'query' => ['symbol' => $symbol, 'timeframe' => $tf],
]);
return json_decode($response->getBody(), true);
});
}
public function summary(string $symbol, string $tf = 'H1'): array
{
$response = $this->client->get('summary', [
'query' => ['symbol' => $symbol, 'timeframe' => $tf],
]);
return json_decode($response->getBody(), true);
}
public function quote(string $symbol): array
{
$response = $this->client->get('quote', [
'query' => ['symbol' => $symbol],
]);
return json_decode($response->getBody(), true);
}
public function screener(string $indicator, string $tf = 'H1', ?float $max = null): array
{
$query = ['indicator' => $indicator, 'timeframe' => $tf];
if ($max !== null) $query['max'] = $max;
$response = $this->client->get('screener', ['query' => $query]);
return json_decode($response->getBody(), true);
}
public function heatmap(string $tf = 'H1'): array
{
return Cache::remember("claw:heatmap:{$tf}", 60, function () use ($tf) {
$response = $this->client->get('heatmap', [
'query' => ['timeframe' => $tf],
]);
return json_decode($response->getBody(), true);
});
}
} Configuration
Add your API key to the Laravel services config:
config/services.php
<?php
// config/services.php — add to your existing config
return [
// ... other services
'tickatlas' => [
'key' => env('TICKATLAS_API_KEY'),
],
];
// .env
// TICKATLAS_API_KEY=your_api_key_here Controller Example
Use the service in your controllers with dependency injection:
app/Http/Controllers/MarketController.php
<?php
// app/Http/Controllers/MarketController.php
namespace App\Http\Controllers;
use App\Services\TickAtlasService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class MarketController extends Controller
{
public function __construct(
private TickAtlasService $claw
) {}
public function rsi(Request $request): JsonResponse
{
$symbol = $request->input('symbol', 'EURUSD');
$data = $this->claw->indicator($symbol, 'RSI_14', 'H1');
return response()->json([
'symbol' => $data['symbol'],
'rsi' => $data['value'],
'signal' => $data['signal'],
]);
}
public function summary(Request $request): JsonResponse
{
$symbol = $request->input('symbol', 'EURUSD');
$data = $this->claw->summary($symbol, 'H1');
return response()->json([
'bias' => $data['bias'],
'confidence' => $data['confidence'],
'narrative' => $data['narrative'],
]);
}
public function oversold(): JsonResponse
{
$data = $this->claw->screener('RSI_14', 'H1', max: 30);
return response()->json($data['results']);
}
}