PHPackages                             linwj/bitmex - 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. linwj/bitmex

ActiveLibrary[API Development](/categories/api)

linwj/bitmex
============

Bitmex API Like the official document interface, Support for arbitrary extension.

2.1.2(4y ago)157.8k↓22.5%91MITPHPPHP &gt;=7.0

Since Mar 26Pushed 4y ago2 watchersCompare

[ Source](https://github.com/zhouaini528/bitmex-php)[ Packagist](https://packagist.org/packages/linwj/bitmex)[ RSS](/packages/linwj-bitmex/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (3)Versions (32)Used By (1)

### It is recommended that you use the test server first

[](#it-is-recommended-that-you-use-the-test-server-first)

Online interface testing

Address of the test

The official address

All interface methods are initialized the same as those provided by Bitmex. See details [src/api](https://github.com/zhouaini528/bitmex-php/tree/master/src/Api)

Support [Websocket](https://github.com/zhouaini528/bitmex-php/blob/master/README.md#Websocket)

Most of the interface is now complete, and the user can continue to extend it based on my design, working with me to improve it.

[中文文档](https://github.com/zhouaini528/bitmex-php/blob/master/README_CN.md)

### Other exchanges API

[](#other-exchanges-api)

[Exchanges](https://github.com/zhouaini528/exchanges-php) It includes all of the following exchanges and is highly recommended.

[Bitmex](https://github.com/zhouaini528/bitmex-php) Support [Websocket](https://github.com/zhouaini528/bitmex-php/blob/master/README.md#Websocket)

[Okex](https://github.com/zhouaini528/okex-php) Support [Websocket](https://github.com/zhouaini528/okex-php/blob/master/README.md#Websocket)

[Huobi](https://github.com/zhouaini528/huobi-php) Support [Websocket](https://github.com/zhouaini528/huobi-php/blob/master/README.md#Websocket)

[Binance](https://github.com/zhouaini528/binance-php) Support [Websocket](https://github.com/zhouaini528/binance-php/blob/master/README.md#Websocket)

[Kucoin](https://github.com/zhouaini528/kucoin-php)

[Mxc](https://github.com/zhouaini528/Mxc-php)

[Coinbase](https://github.com/zhouaini528/coinbase-php)

[ZB](https://github.com/zhouaini528/zb-php)

[Bitfinex](https://github.com/zhouaini528/bitfinex-php)

[Bittrex](https://github.com/zhouaini528/bittrex-php)

[Kraken](https://github.com/zhouaini528/kraken-php)

[Gate](https://github.com/zhouaini528/gate-php)

[Bigone](https://github.com/zhouaini528/bigone-php)

[Crex24](https://github.com/zhouaini528/crex24-php)

[Bybit](https://github.com/zhouaini528/bybit-php)

[Coinbene](https://github.com/zhouaini528/coinbene-php)

[Bitget](https://github.com/zhouaini528/bitget-php)

[Poloniex](https://github.com/zhouaini528/poloniex-php)

**If you don't find the exchange SDK you want, you can tell me and I'll join them.**

#### Installation

[](#installation)

```
composer require linwj/bitmex

```

Support for more request Settings [More](https://github.com/zhouaini528/bitmex-php/blob/master/tests/proxy.php#L24)

```
$bitmex=new Bitmex();

//You can set special needs
$bitmex->setOptions([
    //Set the request timeout to 60 seconds by default
    'timeout'=>10,
    //https://github.com/guzzle/guzzle
    'proxy'=>[],
    //https://www.php.net/manual/en/book.curl.php
    'curl'=>[],
]);
```

Book Data [More](https://github.com/zhouaini528/bitmex-php/blob/master/tests/position.php)

```
//Get market data
//Book data may be key and secret
try {
    $bitmex=new Bitmex();
    $result=$bitmex->orderBook()->get([
        'symbol'=>'ETHUSD',
        'depth'=>20
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}
```

Order [More](https://github.com/zhouaini528/bitmex-php/blob/master/tests/order.php)

```
//Test API address  default  https://www.bitmex.com
$key='eLB_l505a_cuZL8Cmu5uo7EP';
$secret='wG3ndMquAPl6c-jHUQNhyBQJKGBwdFenIF2QxcgNKE_g8Kz3';
$host='https://testnet.bitmex.com';

$bitmex=new Bitmex($key,$secret,$host);

//bargaining transaction
try {
    $result=$bitmex->order()->post([
        'symbol'=>'XBTUSD',
        'price'=>'100',
        'side'=>'Buy',
        'orderQty'=>'1',
        'ordType'=>'Limit',
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

//track the order
try {
    $result=$bitmex->order()->getOne([
        'symbol'=>'XBTUSD',
        'orderID'=>$result['orderID'],
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

//update the order
try {
    $result=$bitmex->order()->put([
        'symbol'=>'XBTUSD',
        'orderID'=>$result['orderID'],
        'price'=>'200',
        'orderQty'=>'2',
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}

//cancellation of order
try {
    $result=$bitmex->order()->delete([
        'symbol'=>'XBTUSD',
        'orderID'=>$result['orderID'],
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}
```

Postion [More](https://github.com/zhouaini528/bitmex-php/blob/master/tests/position.php)

```
//bargaining transaction
try {
    //Default return all
    $result=$bitmex->position()->get([
        //'filter'=>'{"symbol": "XBTUSD"}',
        //'columns'=>'markPrice',
        //'count'=>1,
    ]);
    print_r($result);
}catch (\Exception $e){
    print_r($e->getMessage());
}
```

[More Test](https://github.com/zhouaini528/bitmex-php/tree/master/tests)

[More API](https://github.com/zhouaini528/bitmex-php/tree/master/src/Api)

### Websocket

[](#websocket)

Websocket has two services, server and client. The server is responsible for dealing with the new connection of the exchange, data receiving, authentication and login. Client is responsible for obtaining and processing data.

Server initialization must be started in Linux CLI mode.

```
use \Lin\Bitmex\BitmexWebSocket;
require __DIR__ .'./vendor/autoload.php';

$bitmex=new BitmexWebSocket();

$bitmex->config([
    //Do you want to enable local logging,default false
    //'log'=>true,
    //Or set the log name
    'log'=>['filename'=>'bitmex'],

    //Daemons address and port,default 0.0.0.0:2211
    //'global'=>'127.0.0.1:2211',

    //Channel subscription monitoring time,2 seconds
    //'listen_time'=>2,

    //Channel data update time,default 0.5 seconds
    //'data_time'=>0.5,

    //Heartbeat time,default 30 seconds
    //'ping_time'=>30,

    //Number of messages WS queue shuold hold, default 100
    //'queue_count'=>100,

    //baseurl host
    //'baseurl'=>'ws://www.bitmex.com/realtime',//default
    //'baseurl'=>'ws://testnet.bitmex.com/realtime',//test
]);

$bitmex->start();
```

If you want to test, you can "php server.php start" immediately outputs the log at the terminal.

If you want to deploy, you can "php server.php start -d" enables resident process mode, and enables "log=&gt;true" to view logs.

[More Test](https://github.com/zhouaini528/bitmex-php/tree/master/tests/websocket)

Client side initialization.

```
$bitmex=new BitmexWebSocket();

$bitmex->config([
    //Do you want to enable local logging,default false
    //'log'=>true,
    //Or set the log name
    'log'=>['filename'=>'bitmex'],

    //Daemons address and port,default 0.0.0.0:2216
    //'global'=>'127.0.0.1:2216',

    //Channel subscription monitoring time,2 seconds
    //'listen_time'=>2,

    //Channel data update time,default 0.5 seconds
    //'data_time'=>0.5,

    //Heartbeat time,default 30 seconds
    //'ping_time'=>30,

    //Number of messages WS queue shuold hold, default 100
    //'queue_count'=>100,

    //私有数据队列默认保存100条
    //'queue_count'=>100,

    //baseurl host
    //'baseurl'=>'ws://www.bitmex.com/realtime',//default
    //'baseurl'=>'ws://testnet.bitmex.com/realtime',//test
]);
```

Subscribe

```
//You can only subscribe to public channels
$bitmex->subscribe([
    //public
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',
]);

//You can also subscribe to both private and public channels.If keysecret() is set, all private channels will be subscribed by default
$bitmex->keysecret([
    'key'=>'xxxxxxxxx',
    'secret'=>'xxxxxxxxx',
]);
$bitmex->subscribe([
    //public
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',

    //private
    "affiliate",
    "execution",
    "order",
    "margin",
    "position",
    "privateNotifications",
    "transact",
    "wallet"
]);
```

Unsubscribe

```
//Unsubscribe from public channels
$bitmex->unsubscribe([
    //public
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',
]);

//Unsubscribe from public and private channels.If keysecret() is set, private channels will be Unsubscribed by default
$bitmex->keysecret([
    'key'=>'xxxxxxxxx',
    'secret'=>'xxxxxxxxx',
]);
$bitmex->unsubscribe([
    //public
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',

    //private
    "affiliate",
    "execution",
    "order",
    "margin",
    "position",
    "privateNotifications",
    "transact",
    "wallet"
]);
```

Get all channel subscription data

```
//The first way
$data=$bitmex->getSubscribe();
print_r(json_encode($data));

//The second way callback
$bitmex->getSubscribe(function($data){
    print_r(json_encode($data));
});

//The third way is to guard the process
$bitmex->getSubscribe(function($data){
    print_r(json_encode($data));
},true);
```

Get partial channel subscription data

```
//The first way
$data=$bitmex->getSubscribe([
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',
]);
print_r(json_encode($data));

//The second way callback
$bitmex->getSubscribe([
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',
],function($data){
    print_r(json_encode($data));
});

//The third way is to guard the process
$bitmex->getSubscribe([
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',
],function($data){
    print_r(json_encode($data));
},true);
```

Get partial private channel subscription data

```
//The first way
$bitmex->keysecret($key_secret);
$data=$bitmex->getSubscribe();//Return all data of private channel
print_r(json_encode($data));

//The second way callback
$bitmex->keysecret($key_secret);
$bitmex->getSubscribe([//Return data private and market
    //public
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',

    //private
    "affiliate",
    "execution",
    "order",
    "margin",
    "position",
    "privateNotifications",
    "transact",
    "wallet"
],function($data){
    print_r(json_encode($data));
});

//The third way is to guard the process
$bitmex->keysecret($key_secret);
$bitmex->getSubscribe([//Resident process to get data return frequency $bitmex->config['data_time']=0.5s
    //public
    'orderBook10:XBTUSD',
    'quoteBin5m:XBTUSD',

    //private
    "affiliate",
    "execution",
    "order",
    "margin",
    "position",
    "privateNotifications",
    "transact",
    "wallet"
],function($data){
    print_r(json_encode($data));
},true);
```

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity66

Established project with proven stability

 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 ~32 days

Recently: every ~24 days

Total

30

Last Release

1701d ago

Major Versions

1.1.9 → 2.0.02020-11-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5442664?v=4)[lin](/maintainers/zhouaini528)[@zhouaini528](https://github.com/zhouaini528)

---

Top Contributors

[![zhouaini528](https://avatars.githubusercontent.com/u/5442664?v=4)](https://github.com/zhouaini528 "zhouaini528 (114 commits)")

---

Tags

binancebitmexexchangeshuobikucoinkumexokexbinanceBitMEXHuobiOKEXkucoinkumex

### Embed Badge

![Health badge](/badges/linwj-bitmex/health.svg)

```
[![Health](https://phpackages.com/badges/linwj-bitmex/health.svg)](https://phpackages.com/packages/linwj-bitmex)
```

###  Alternatives

[linwj/binance

Binance API Like the official document interface, Support for arbitrary extension.

11318.0k1](/packages/linwj-binance)[linwj/bybit

Bybit API Like the official document interface, Support for arbitrary extension.

3110.7k1](/packages/linwj-bybit)[linwj/okex

Okex API Like the official document interface, Support for arbitrary extension.

5212.5k1](/packages/linwj-okex)[linwj/huobi

Huobi API Like the official document interface, Support for arbitrary extension.

4113.5k1](/packages/linwj-huobi)[linwj/mxc

Mexc API Like the official document interface, Support for arbitrary extension.

197.4k1](/packages/linwj-mxc)[linwj/coinbase

Coinbase API Like the official document interface, Support for arbitrary extension.

1311.9k1](/packages/linwj-coinbase)

PHPackages © 2026

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