Skip to content

Installation

Igor Sazonov edited this page Mar 15, 2026 · 1 revision

How to install and configure the OKX PHP SDK.

Requirements

  • PHP: 8.2 or higher
  • Composer: latest version
  • Laravel: 11.x or 12.x (optional)

Installing via Composer

1. Install the package

composer require tigusigalpa/okx-php

2. Verify the installation

composer show tigusigalpa/okx-php

Laravel Setup

1. Publish the configuration file

php artisan vendor:publish --tag=okx-config

This will create config/okx.php.

2. Configure environment variables

Add the following to your .env file:

OKX_API_KEY=your-api-key-here
OKX_SECRET_KEY=your-secret-key-here
OKX_PASSPHRASE=your-passphrase-here
OKX_DEMO=false
OKX_BASE_URL=https://www.okx.com

3. Obtaining API keys

  1. Log in to your account on OKX
  2. Go to AccountAPI
  3. Create a new API key
  4. Save the following credentials:
    • API Key
    • Secret Key
    • Passphrase

⚠️ Important: Never commit your API keys to a public repository.

4. Setting permissions

When creating the API key, grant only the permissions your application needs:

  • Read — Read account data (balances, orders)
  • Trade — Place and manage orders
  • Withdraw — Withdraw funds (optional)

5. IP Whitelist (recommended)

For additional security, add your server IP addresses to the whitelist when creating the API key.

Standalone Setup

Instantiate the client directly without any framework:

use Tigusigalpa\OKX\Client;

$client = new Client(
    apiKey: 'your-api-key',
    secretKey: 'your-secret-key',
    passphrase: 'your-passphrase',
    isDemo: false,  // set to true for demo mode
    baseUrl: 'https://www.okx.com'
);

Demo Mode

Laravel

In .env:

OKX_DEMO=true

Standalone

$client = new Client(
    apiKey: 'demo-api-key',
    secretKey: 'demo-secret-key',
    passphrase: 'demo-passphrase',
    isDemo: true  // enable demo mode
);

Getting demo API keys

  1. Visit OKX Demo Trading
  2. Create a demo account
  3. Generate demo API keys

Configuration

config/okx.php

<?php

return [
    // API key
    'api_key' => env('OKX_API_KEY', ''),
    
    // Secret key
    'secret_key' => env('OKX_SECRET_KEY', ''),
    
    // Passphrase
    'passphrase' => env('OKX_PASSPHRASE', ''),
    
    // Demo mode
    'demo' => env('OKX_DEMO', false),
    
    // Base API URL
    'base_url' => env('OKX_BASE_URL', 'https://www.okx.com'),
];

Verifying the Installation

Laravel

use Tigusigalpa\OKX\Facades\OKX;

Route::get('/test-okx', function () {
    try {
        $time = OKX::publicData()->getTime();
        return response()->json([
            'status' => 'success',
            'server_time' => $time
        ]);
    } catch (\Exception $e) {
        return response()->json([
            'status' => 'error',
            'message' => $e->getMessage()
        ], 500);
    }
});

Standalone

try {
    $time = $client->publicData()->getTime();
    echo "Connection successful! Server time: " . $time[0]['ts'];
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}

Optional Dependencies

Logging (PSR-3)

composer require monolog/monolog

Usage:

use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$logger = new Logger('okx');
$logger->pushHandler(new StreamHandler('okx.log', Logger::DEBUG));

$client = new Client(
    apiKey: 'your-api-key',
    secretKey: 'your-secret-key',
    passphrase: 'your-passphrase',
    logger: $logger
);

Troubleshooting

"Invalid API key"

  • Double-check that the API key, secret, and passphrase are correct
  • Make sure the key is active and has not expired
  • Verify the IP whitelist settings

"Rate limit exceeded"

  • Reduce the frequency of your requests
  • Use WebSocket for real-time data instead of polling

"Insufficient permissions"

  • Review the permissions assigned to your API key
  • Ensure the key has the required access rights for the operation

Updating

composer update tigusigalpa/okx-php

Check the installed version:

composer show tigusigalpa/okx-php

Uninstalling

composer remove tigusigalpa/okx-php

For Laravel, also remove:

  • config/okx.php
  • The OKX_* variables from .env

Next: Quick Start →