定制 linwj/bitmex 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

linwj/bitmex

Composer 安装命令:

composer require linwj/bitmex

包简介

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

README 文档

README

It is recommended that you use the test server first

Online interface testing https://www.bitmex.com/api/explorer/

Address of the test https://testnet.bitmex.com

The official address https://www.bitmex.com

All interface methods are initialized the same as those provided by Bitmex. See details src/api

Support 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.

中文文档

Other exchanges API

Exchanges It includes all of the following exchanges and is highly recommended.

Bitmex Support Websocket

Okex Support Websocket

Huobi Support Websocket

Binance Support Websocket

Kucoin

Mxc

Coinbase

ZB

Bitfinex

Bittrex

Kraken

Gate

Bigone

Crex24

Bybit

Coinbene

Bitget

Poloniex

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

Installation

composer require linwj/bitmex

Support for more request Settings More

$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

//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

//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

//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

More API

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=>true" to view logs.

More Test

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

linwj/bitmex 适用场景与选型建议

linwj/bitmex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.95k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2019 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「binance」 「BitMEX」 「Huobi」 「OKEX」 「kucoin」 「kumex」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 linwj/bitmex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 linwj/bitmex 我们能提供哪些服务?
定制开发 / 二次开发

基于 linwj/bitmex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7.95k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 29
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 2
  • Forks: 9
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-28