-
Notifications
You must be signed in to change notification settings - Fork 0
Installation
Igor Sazonov edited this page Mar 15, 2026
·
1 revision
How to install and configure the OKX PHP SDK.
- PHP: 8.2 or higher
- Composer: latest version
- Laravel: 11.x or 12.x (optional)
composer require tigusigalpa/okx-phpcomposer show tigusigalpa/okx-phpphp artisan vendor:publish --tag=okx-configThis will create config/okx.php.
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- Log in to your account on OKX
- Go to Account → API
- Create a new API key
- Save the following credentials:
- API Key
- Secret Key
- Passphrase
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)
For additional security, add your server IP addresses to the whitelist when creating the API key.
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'
);In .env:
OKX_DEMO=true$client = new Client(
apiKey: 'demo-api-key',
secretKey: 'demo-secret-key',
passphrase: 'demo-passphrase',
isDemo: true // enable demo mode
);- Visit OKX Demo Trading
- Create a demo account
- Generate demo API keys
<?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'),
];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);
}
});try {
$time = $client->publicData()->getTime();
echo "Connection successful! Server time: " . $time[0]['ts'];
} catch (\Exception $e) {
echo "Error: " . $e->getMessage();
}composer require monolog/monologUsage:
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
);- 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
- Reduce the frequency of your requests
- Use WebSocket for real-time data instead of polling
- Review the permissions assigned to your API key
- Ensure the key has the required access rights for the operation
composer update tigusigalpa/okx-phpCheck the installed version:
composer show tigusigalpa/okx-phpcomposer remove tigusigalpa/okx-phpFor Laravel, also remove:
config/okx.php- The
OKX_*variables from.env
Next: Quick Start →