PHPackages                             tigusigalpa/okx-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tigusigalpa/okx-php

ActiveLibrary

tigusigalpa/okx-php
===================

A production-grade PHP/Laravel SDK for the OKX v5 API.

v1.0.0(1mo ago)00MITPHPPHP ^8.2

Since Mar 15Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/tigusigalpa/okx-php)[ Packagist](https://packagist.org/packages/tigusigalpa/okx-php)[ RSS](/packages/tigusigalpa-okx-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

OKX PHP SDK
===========

[](#okx-php-sdk)

[![OKX PHP client](https://camo.githubusercontent.com/b043dd87349162987c67765eeac6c4701871e424f4c178bdec91ab1b973e2bbd/68747470733a2f2f692e706f7374696d672e63632f534b7372547234382f6f6b782d7068702d62616e6e65722e6a7067)](https://camo.githubusercontent.com/b043dd87349162987c67765eeac6c4701871e424f4c178bdec91ab1b973e2bbd/68747470733a2f2f692e706f7374696d672e63632f534b7372547234382f6f6b782d7068702d62616e6e65722e6a7067)

[![PHP Version](https://camo.githubusercontent.com/962aced9b09d89716dbebf186ff899754a096ff1068b6b7988675c2d9fab9331/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c75652e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

PHP client for the [OKX v5 API](https://www.okx.com/docs-v5/en/). Covers the entire REST API (335 endpoints, 16 categories) and WebSocket API (53 channels). Works standalone or plugs into Laravel 11/12 via a Service Provider.

Go version: [tigusigalpa/okx-go](https://github.com/tigusigalpa/okx-go) | [Wiki](https://github.com/tigusigalpa/okx-php/wiki)

What's inside
-------------

[](#whats-inside)

- 335 REST endpoints grouped into service classes (`account()`, `trade()`, `market()`, etc.)
- WebSocket client with auto-reconnect and ping/pong heartbeat
- HMAC-SHA256 request signing
- Demo trading mode (just flip a flag)
- Typed DTOs for requests and responses; all prices/amounts stay as `string` to avoid float rounding
- Laravel Service Provider, Facade, publishable config
- PSR-3 logging, PSR-12 code style
- PHP 8.2+ (`readonly` classes, named arguments)

Requirements
------------

[](#requirements)

- PHP 8.2+
- Composer
- Laravel 11 or 12 (optional)

Installation
------------

[](#installation)

```
composer require tigusigalpa/okx-php
```

Laravel setup
-------------

[](#laravel-setup)

Publish the config:

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

Add credentials to `.env`:

```
OKX_API_KEY=your-api-key
OKX_SECRET_KEY=your-secret-key
OKX_PASSPHRASE=your-passphrase
OKX_DEMO=false
```

Then use the facade:

```
use Tigusigalpa\OKX\Facades\OKX;

$balance = OKX::account()->getBalance();

$order = OKX::trade()->placeOrder(
    instId: 'BTC-USDT',
    tdMode: 'cash',
    side: 'buy',
    ordType: 'limit',
    sz: '0.01',
    px: '50000'
);

$ticker = OKX::market()->getTicker('BTC-USDT');
```

Standalone usage
----------------

[](#standalone-usage)

```
use Tigusigalpa\OKX\Client;

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

$balance = $client->account()->getBalance();

$order = $client->trade()->placeOrder(
    instId: 'BTC-USDT',
    tdMode: 'cash',
    side: 'buy',
    ordType: 'market',
    sz: '100',
    tgtCcy: 'quote_ccy'
);

$trades = $client->market()->getTrades('BTC-USDT', limit: 100);
```

Configuration
-------------

[](#configuration)

OptionEnv variableDefault`api_key``OKX_API_KEY``''`API key`secret_key``OKX_SECRET_KEY``''`Secret key`passphrase``OKX_PASSPHRASE``''`Passphrase`demo``OKX_DEMO``false`Use demo trading environment`base_url``OKX_BASE_URL``https://www.okx.com`Base URLREST API coverage
-----------------

[](#rest-api-coverage)

335 endpoints across 16 categories:

Category\#DocsAccount53[Trading Account](https://www.okx.com/docs-v5/en/#trading-account-rest-api)Trade32[Order Book Trading](https://www.okx.com/docs-v5/en/#order-book-trading-trade-rest-api)Market24[Market Data](https://www.okx.com/docs-v5/en/#order-book-trading-market-data-rest-api)Public Data24[Public Data](https://www.okx.com/docs-v5/en/#public-data-rest-api)Asset26[Funding Account](https://www.okx.com/docs-v5/en/#funding-account-rest-api)Finance33[Financial Products](https://www.okx.com/docs-v5/en/#financial-product-rest-api)Copy Trading26[Copy Trading](https://www.okx.com/docs-v5/en/#copy-trading-rest-api)Trading Bot44[Trading Bot](https://www.okx.com/docs-v5/en/#trading-bot-grid-trading-rest-api)RFQ20[Block Trading](https://www.okx.com/docs-v5/en/#block-trading-rest-api)Spread Trading13[Spread Trading](https://www.okx.com/docs-v5/en/#spread-trading-rest-api)Rubik15[Trading Statistics](https://www.okx.com/docs-v5/en/#trading-statistics-rest-api)Fiat13[Fiat](https://www.okx.com/docs-v5/en/#fiat-rest-api)Users8[Sub-account](https://www.okx.com/docs-v5/en/#sub-account-rest-api)Support2[Announcements](https://www.okx.com/docs-v5/en/#announcement-rest-api)System Status1[Status](https://www.okx.com/docs-v5/en/#status-rest-api)Affiliate1[Affiliate](https://www.okx.com/docs-v5/en/#affiliate-rest-api)WebSocket
---------

[](#websocket)

Public channel:

```
use Tigusigalpa\OKX\WebsocketClient;

$ws = new WebsocketClient(
    apiKey: 'your-api-key',
    secretKey: 'your-secret-key',
    passphrase: 'your-passphrase'
);

$ws->connectPublic();

$ws->subscribe('tickers', ['instId' => 'BTC-USDT'], function ($data) {
    echo "BTC-USDT: " . $data['data'][0]['last'] . PHP_EOL;
});

$ws->run();
```

Private channel (authenticated automatically on connect):

```
$ws->connectPrivate();

$ws->subscribe('account', ['ccy' => 'BTC'], function ($data) {
    foreach ($data['data'] as $account) {
        echo "Balance: {$account['bal']} {$account['ccy']}" . PHP_EOL;
    }
});

$ws->run();
```

Public channels include `tickers`, `books`, `books5`, `trades`, `candle*`, `index-tickers`, `mark-price`, `funding-rate`, `open-interest`, `liquidation-orders`, and others.

Private channels include `account`, `positions`, `orders`, `orders-algo`, `fills`, `balance_and_position`, `liquidation-warning`, `deposit-info`, `withdrawal-info`, and others.

Demo trading
------------

[](#demo-trading)

Set `OKX_DEMO=true` in `.env`, or pass `isDemo: true` to the constructor. Same API, sandbox environment, no real money involved.

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

Examples
--------

[](#examples)

Order with TP/SL:

```
$order = $client->trade()->placeOrder(
    instId: 'BTC-USDT',
    tdMode: 'cross',
    side: 'buy',
    ordType: 'limit',
    sz: '0.1',
    px: '50000',
    tpTriggerPx: '55000',
    tpOrdPx: '-1',
    slTriggerPx: '48000',
    slOrdPx: '-1'
);
```

Batch orders:

```
$orders = $client->trade()->batchOrders([
    [
        'instId' => 'BTC-USDT',
        'tdMode' => 'cash',
        'side' => 'buy',
        'ordType' => 'limit',
        'sz' => '0.01',
        'px' => '50000'
    ],
    [
        'instId' => 'ETH-USDT',
        'tdMode' => 'cash',
        'side' => 'buy',
        'ordType' => 'limit',
        'sz' => '0.1',
        'px' => '3000'
    ]
]);
```

Set leverage:

```
$client->account()->setLeverage(
    lever: '10',
    mgnMode: 'cross',
    instId: 'BTC-USDT-SWAP'
);
```

Historical candles:

```
$candles = $client->market()->getHistoryCandles(
    instId: 'BTC-USDT',
    bar: '1H',
    limit: 100
);
```

Withdrawal:

```
$withdrawal = $client->asset()->withdrawal(
    ccy: 'USDT',
    amt: '100',
    dest: '4',
    toAddr: 'your-wallet-address',
    fee: '1',
    chain: 'USDT-TRC20'
);
```

Error handling
--------------

[](#error-handling)

Each error type has its own exception class. They all extend `OKXException`, which carries the raw OKX error code in `$e->okxCode`.

```
use Tigusigalpa\OKX\Exceptions\AuthenticationException;
use Tigusigalpa\OKX\Exceptions\RateLimitException;
use Tigusigalpa\OKX\Exceptions\InvalidParameterException;
use Tigusigalpa\OKX\Exceptions\InsufficientFundsException;
use Tigusigalpa\OKX\Exceptions\OKXException;

try {
    $balance = $client->account()->getBalance();
} catch (AuthenticationException $e) {
    // bad credentials or signature
} catch (RateLimitException $e) {
    // slow down
} catch (InvalidParameterException $e) {
    // check your request params
} catch (InsufficientFundsException $e) {
    // not enough balance
} catch (OKXException $e) {
    // everything else from OKX
    echo "OKX error [{$e->okxCode}]: " . $e->getMessage();
}
```

Logging
-------

[](#logging)

Pass any PSR-3 logger to the constructor:

```
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
);
```

Credentials are never written to logs.

Testing
-------

[](#testing)

Unit tests:

```
vendor/bin/phpunit
```

Integration tests (needs demo credentials):

```
export OKX_API_KEY=your-demo-api-key
export OKX_SECRET_KEY=your-demo-secret-key
export OKX_PASSPHRASE=your-demo-passphrase
vendor/bin/phpunit -c phpunit.integration.xml
```

Contributing
------------

[](#contributing)

1. Fork it
2. Create a branch (`git checkout -b fix/something`)
3. Make your changes, add tests
4. Push and open a PR

Code must follow PSR-12. Tests must pass.

Security
--------

[](#security)

Found a vulnerability? Email  directly. Don't open a public issue.

License
-------

[](#license)

MIT. See [LICENSE](LICENSE).

Links
-----

[](#links)

- [OKX API v5 docs](https://www.okx.com/docs-v5/en/)
- [Repository](https://github.com/tigusigalpa/okx-php)
- [Issues](https://github.com/tigusigalpa/okx-php/issues)

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance95

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/76c3a1d93c3213a8a22b4b637708d8b66a1ba3a5252624046cae7683a198b3a8?d=identicon)[tigusigalpa](/maintainers/tigusigalpa)

---

Top Contributors

[![tigusigalpa](https://avatars.githubusercontent.com/u/2721390?v=4)](https://github.com/tigusigalpa "tigusigalpa (2 commits)")

---

Tags

bitcoinchainlinkcrypto-exchange-platformcryptocurrencylaravelnear-protocolnearprotocolokxokx-apiokx-laravelokx-walletphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tigusigalpa-okx-php/health.svg)

```
[![Health](https://phpackages.com/badges/tigusigalpa-okx-php/health.svg)](https://phpackages.com/packages/tigusigalpa-okx-php)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[tempest/framework

The PHP framework that gets out of your way.

2.1k23.1k9](/packages/tempest-framework)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
