PHPackages                             kleninm/binance-api - 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. [API Development](/categories/api)
4. /
5. kleninm/binance-api

ActiveLibrary[API Development](/categories/api)

kleninm/binance-api
===================

Binance API for php

v1.0.0(2y ago)10246↓50%2MITPHPPHP &gt;=8.2CI failing

Since Jul 29Pushed 2y ago1 watchersCompare

[ Source](https://github.com/kleninmaxim/binance-api)[ Packagist](https://packagist.org/packages/kleninm/binance-api)[ RSS](/packages/kleninm-binance-api/feed)WikiDiscussions 1.0 Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (4)Used By (0)

Binance PHP API Client
======================

[](#binance-php-api-client)

[![GitHub Workflow Status (with event)](https://camo.githubusercontent.com/3a7e4456a2ff750fecf7009e231a6c40c3b991ba72f7d8fc29a46a328e71143a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6c656e696e6d6178696d2f62696e616e63652d6170692f74657374732e796d6c3f6c6162656c3d5465737473)](https://camo.githubusercontent.com/3a7e4456a2ff750fecf7009e231a6c40c3b991ba72f7d8fc29a46a328e71143a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6c656e696e6d6178696d2f62696e616e63652d6170692f74657374732e796d6c3f6c6162656c3d5465737473)[![GitHub Workflow Status (with event)](https://camo.githubusercontent.com/74c2124b3b252f6f82a40c39b90b1094f792158ec94ede5de1c13c3a7e9217b3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b6c656e696e6d6178696d2f62696e616e63652d6170692f7374796c652e796d6c3f6c6162656c3d5374796c654349)](https://github.com/kleninmaxim/binance-api/actions/workflows/style.yml)[![Packagist License (custom server)](https://camo.githubusercontent.com/d3609beb481cc36309ddce8f8c391776ecb824a3adad856483a02df5fb90eb3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b6c656e696e6d2f62696e616e63652d6170693f7374796c653d666c61742d737175617265)](https://github.com/kleninmaxim/binance-api#license)[![GitHub release (with filter)](https://camo.githubusercontent.com/3d1f32eb3a842dc061c592d84625b07ea12371a33a4cce965919cd04403fa852/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6b6c656e696e6d6178696d2f62696e616e63652d617069)](https://github.com/kleninmaxim/binance-api/releases)

The purpose of this project is to assist you in creating your own projects that interact with the [Binance SPOT API](https://binance-docs.github.io/apidocs/spot/en/).

Supported in the current version [Wallet Endpoints](https://binance-docs.github.io/apidocs/spot/en/#wallet-endpoints), [Market Data Endpoints](https://binance-docs.github.io/apidocs/spot/en/#market-data-endpoints) and [Spot Account/Trade](https://binance-docs.github.io/apidocs/spot/en/#spot-account-trade)

Introduction
------------

[](#introduction)

This project requires [php](https://www.php.net/) version more or equal 8.2. Also it requires [bcmath](https://www.php.net/manual/en/book.bc.php) extension and [guzzle](https://docs.guzzlephp.org/en/stable/) dependency

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

[](#installation)

```
composer require kleninm/binance-api
```

Quick start
-----------

[](#quick-start)

Every original method's name in `\BinanceApi\Binance` class created by name from url after prefix `v1`, `v2` or `v3`.

For example, by table:

  Link to endpoint   Method name  [Order Book](https://binance-docs.github.io/apidocs/spot/en/#order-book)

 ```
$binance->depth($symbol, $limit);
```

  [Symbol Order Book Ticker](https://binance-docs.github.io/apidocs/spot/en/#symbol-order-book-ticker)

 ```
$binance->tickerBookTicker($symbol);
```

  [24hr Ticker Price Change Statistics](https://binance-docs.github.io/apidocs/spot/en/#24hr-ticker-price-change-statistics)

 ```
$binance->ticker24hr($symbol, $symbols, $type);
```

  [Withdraw History (supporting network)](https://binance-docs.github.io/apidocs/spot/en/#withdraw-history-supporting-network-user_data)

 ```
$binance->capitalWithdrawHistory();
```

 All endpoints and their methods with parameters you can see in phpdoc in `\BinanceApi\Binance` class

Full docs you can find in `documentation` folder of this repository

Look at the [Basic](https://github.com/kleninmaxim/binance-api/tree/1.x/documentation/Basic.md) topic to learn more features

Look at the [Digging deeper](https://github.com/kleninmaxim/binance-api/tree/1.x/documentation/Basic.md) topic if you want to dive deep into the mechanism and add more yourself customizations and scale functionality

You can go to the [Examples and Analogs](https://github.com/kleninmaxim/binance-api/tree/1.x/documentation/ExamplesAndAnalogs.md) topic to see more examples, include what each function returns

Simple start
------------

[](#simple-start)

```
$binance = new \BinanceApi\Binance();

$fullResult = $binance->depth('BTCUSDT', 2);

$orderbook = $fullResult['response']['data'];
```

 View $fullResult variable```
Array
(
   [request] => Array
      (
         [url] => /api/v3/depth
         [headers] => Array
            (
            )
         [query] => Array
            (
               [symbol] => BTCUSDT
               [limit] => 2
            )
         [body] => Array
            (
            )
      )

   [response] => Array
      (
         [data] => Array
            (
               [lastUpdateId] => 37910427874
               [bids] => Array
                  (
                     [0] => Array
                        (
                           [price] => 30319.99000000
                           [amount] => 3.58155000
                        )

                     [1] => Array
                        (
                           [price] => 30319.98000000
                           [amount] => 0.09091000
                        )
                  )
               [asks] => Array
                  (
                     [0] => Array
                        (
                           [price] => 30320.00000000
                           [amount] => 21.24342000
                        )

                     [1] => Array
                        (
                           [price] => 30320.05000000
                           [amount] => 0.00170000
                        )
                  )
            )

         [info] => Array
            (
               [statusCode] => 200
               [reasonPhrase] => OK
               [headers] => Array
                  (
                     [Content-Type] => Array
                        (
                           [0] => application/json;charset=UTF-8
                        )

                     ...

                     [x-mbx-uuid] => Array
                        (
                           [0] => ad6df6c5-903b-451b-904c-5ba90eb4576d
                        )

                     [x-mbx-used-weight] => Array
                        (
                           [0] => 1
                        )

                     [x-mbx-used-weight-1m] => Array
                        (
                           [0] => 1
                        )

                     ...
                  )
            )
      )
)

```

If you want to use [testnet](https://testnet.binance.vision/)
-------------------------------------------------------------

[](#if-you-want-to-use-testnet)

```
$binanceTestNet = new \BinanceApi\Binance(TestNet::BASE_ENDPOINT);

$fullResult = $binance->depth('BTCUSDT', 2);
```

Set api keys
------------

[](#set-api-keys)

Some endpoints will require an API Keys. You can set them like this:

```
$binance->setApiKeys($apiKey, $secretKey);
```

Handle often throws errors:
---------------------------

[](#handle-often-throws-errors)

```
try {
    $result = $binance->depth('BTCUSDT', 2);
} catch (BinanceApi\Exception\BinanceResponseException $e) {
    // This is exception throw, when binance return error message
    // https://binance-docs.github.io/apidocs/spot/en/#error-codes
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // It's about Guzzle exception
    // https://docs.guzzlephp.org/en/stable/quickstart.html#exceptions
}
```

*Full list of errors, you can see in Basic topic*

Rate limits
-----------

[](#rate-limits)

Limits by IP

```
$binance->getAdditional()['limits']['IP']['api'];
```

```
Array
(
    [used] => 2 // By default maximum weight in minute is 1200
    [lastRequest] => Sat, 15 Jul 2023 14:19:01 GMT
)

```

```
$dateTime = new DateTime($binance->getAdditional()['limits']['IP']['api']['lastRequest']);

$dateTime = new DateTime($binance->getAdditional()['limits']['IP']['sapi']['lastRequest']);
```

You know how much weight you use

Binance reset weights by IP (api and sapi) every minute

Binance time
------------

[](#binance-time)

At any places where you need to use time, use a binance microtime format

You can get binance microtime now by function:

```
\BinanceApi\Docs\GeneralInfo\Signed::binanceMicrotime(); //1690113560956
```

More examples
-------------

[](#more-examples)

Common part for all next examples

```
$binance = new \BinanceApi\Binance();

$binance->setApiKeys($apiKey, $secretKey);

// Filter every output. Read more about it in a Basic topic or just use it if you need only a body result from request
$binance->setOutputCallback(function ($output) {
    return $output['response']['data'];
});
```

### Exchange info

[](#exchange-info)

Current exchange trading rules and symbol information

```
$binance->exchangeInfo();
```

### Order book

[](#order-book)

All three methods are identical. Use that you prefer

```
$binance->depth('BTCUSDT', 5);

$binance->orderbook('BTCUSDT', 5);

$binance->orderbookBTCUSDT(5); // "BTCUSDT" you can replace with any market: "ETHUSDT", "BTCBUSD", ...
```

### Trades

[](#trades)

All two methods are identical. Use that you prefer

```
$binance->trades('BTCUSDT', 5);

$binance->tradesETHUSDT(5); // "ETHUSDT" you can replace with any market: "BTCUSDT", "BTCBUSD", ...
```

### Klines/Candlestick

[](#klinescandlestick)

Kline/candlestick bars for a symbol.

```
$binance->klines('BTCUSDT', '1m', limit: 50);

$startTime = (new DateTime('01 Jan 2022 00:00:00 GMT'))->getTimestamp() * 1000;
$binance->klines('BTCUSDT', '1d', $startTime);

$endTime = (new DateTime('01 Jan 2023 00:00:00 GMT'))->getTimestamp() * 1000;
$binance->klines('BTCUSDT', '1d', endTime: $endTime);
```

```
$binance->secondKlines('BTCUSDT');

$binance->minuteKlines('BTCUSDT');

$binance->threeMinuteKlines('BTCUSDT');

$binance->fiveMinuteKlines('BTCUSDT');

$binance->fifteenMinuteKlines('BTCUSDT');

$binance->thirtyMinuteKlines('BTCUSDT');

$binance->hourKlines('BTCUSDT');

$binance->twoHourKlines('BTCUSDT');

$binance->fourHourKlines('BTCUSDT');

$binance->sixHourKlines('BTCUSDT');

$binance->eightHourKlines('BTCUSDT');

$binance->twelveHourKlines('BTCUSDT');

$binance->dayKlines('BTCUSDT');

$binance->threeDayKlines('BTCUSDT');

$binance->weekKlines('BTCUSDT');

$binance->monthKlines('BTCUSDT');
```

```
$startTime = new DateTime('01 Jan 2022 00:00:00 GMT');
$binance->hourKlines('BTCUSDT', $startTime, limit: 24);

$endTime = new DateTime('01 Jan 2022 00:00:00 GMT');
$binance->hourKlines('BTCUSDT', endTime: $endTime, limit: 48);
```

### Prices

[](#prices)

Latest price for a symbol or symbols.

```
$binance->tickerPrice();

$binance->tickerPrice('BTCUSDT');
```

### Limit order

[](#limit-order)

```
$binance->order('BTCUSDT', 'BUY', 'LIMIT', 'GTC', 0.01, price: 20000);

$binance->limitOrder('BTCUSDT', 'BUY', 0.01, price: 21000);
```

### Market order

[](#market-order)

```
$binance->order('BTCUSDT', 'BUY', 'MARKET', quantity: 0.01);

$binance->marketOrder('BTCUSDT', 'SELL', 0.01);
```

### Stop loss order

[](#stop-loss-order)

```
$binance->order('BTCUSDT', 'SELL', 'STOP_LOSS', 'GTC', 0.01, stopPrice: 25000);

$binance->stopLossOrder('BTCUSDT', 'SELL', 0.01, stopPrice: 25000);
```

### Take profit order

[](#take-profit-order)

```
$binance->order('BTCUSDT', 'SELL', 'TAKE_PROFIT', 'GTC', 0.01, stopPrice: 100000);

$binance->takeProfitOrder('BTCUSDT', 'SELL', 0.01, stopPrice: 100000);
```

### Get open orders

[](#get-open-orders)

Get all open orders on a symbol. Careful when accessing this with no symbol.

```
$binance->openOrders('BTCUSDT');

$binance->openOrders();
```

### Get order status

[](#get-order-status)

Check an order's status.

```
$binance->getOrder('BTCUSDT', 8403075);
```

### Cancel order

[](#cancel-order)

Cancel an active order.

```
$binance->cancelOrder('BTCUSDT', 8403075);
```

### Cancel all orders

[](#cancel-all-orders)

Cancels all active orders on a symbol.

```
$binance->cancelOpenOrders('BTCUSDT');
```

### Account Information (Including Balances)

[](#account-information-including-balances)

Get current account information.

```
$binance->account();
```

### Account Trade List

[](#account-trade-list)

Get trades for a specific account and symbol.

```
$binance->myTrades('BTCUSDT');
```

### All Coins' Information

[](#all-coins-information)

Get information of coins (available for deposit and withdraw) for user.

```
$binance->capitalConfigGetall();
```

### Withdraw

[](#withdraw)

Submit a withdraw request.

```
$binance->capitalWithdrawApply('USDT', network: 'TRX', address: 'TNGjavWm7sMjCA4r1YhsEYGfaZtZEkXzNf', amount: 10);

$binance->withdraw('USDT', network: 'TRX', address: 'TNGjavWm7sMjCA4r1YhsEYGfaZtZEkXzNf', amount: 10);
```

### Withdraw History (supporting network)

[](#withdraw-history-supporting-network)

Fetch withdraw history.

```
$binance->capitalWithdrawHistory();
```

### Deposit Address (supporting network)

[](#deposit-address-supporting-network)

Fetch deposit address with network.

```
$binance->capitalDepositAddress('USDT', 'TRX');
```

### Deposit History (supporting network)

[](#deposit-history-supporting-network)

Fetch deposit history.

```
$binance->capitalDepositHisrec();
```

Contributing
============

[](#contributing)

- Please give a star or fork repository 💫
- Create a new issues or pull requests 🤝

License
=======

[](#license)

Binance PHP API Client is licensed under [The MIT License (MIT)](https://github.com/kleninmaxim/binance-api/blob/1.x/LICENSE).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Every ~1 days

Total

3

Last Release

1023d ago

Major Versions

1.0.x-dev → 2.0.x-dev2023-07-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1e897c0591c6b72ed27f7078475df7c789879de8755bd436d606251113bd2b6?d=identicon)[kleninmaxim](/maintainers/kleninmaxim)

---

Top Contributors

[![kleninmaxim](https://avatars.githubusercontent.com/u/54952996?v=4)](https://github.com/kleninmaxim "kleninmaxim (8 commits)")

---

Tags

apibinancecryptocurrencycryptocurrency-exchangesphpapicryptocurrencybinance

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/kleninm-binance-api/health.svg)

```
[![Health](https://phpackages.com/badges/kleninm-binance-api/health.svg)](https://phpackages.com/packages/kleninm-binance-api)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)

PHPackages © 2026

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