PHP code example of mehdi9324 / mengine
1. Go to this page and download the library: Download mehdi9324/mengine library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mehdi9324 / mengine example snippets
use StingBo\Mengine\Core\Order;
$uuid = 3; // 用户唯一标识
$oid = 4; // 订单唯一标识
$symbol = 'abc2usdt'; // 交易对
$transaction = 'buy'; // 交易方向,buy/sell
$price = 0.4; // 交易价格,会根据设置精度转化为整数
$volume = 15; // 交易数量,会根据设置精度转化为整数
$order = new Order($uuid, $oid, $symbol, $transaction, $volume, $price);
return [
'mengine' => [
// 交易类型,不可更改
'transaction' => [
'buy',
'sell',
],
// 精度,可更改
'accuracy' => 8, //default
'test2usdt_accuracy' => 4, //设置交易对精度则使用,没有则取accuracy
],
];
use StingBo\Mengine\Services\MengineService;
$ms = new MengineService();
$ms->pushQueue($order);
// 撮合成功通知,参数分别是:当前订单,被匹配的单据,交易数量
event(new MatchEvent($order, $match_order, $match_volume));
// 注册监听器
protected $listen = [
'StingBo\Mengine\Events\MatchEvent' => [
'App\Listeners\YourListener', // 你自己的监听器,应该也使用异步来实现
],
];
// 委托池数据变更事件
event(new PushQueueEvent($order));
// 注册监听器
protected $listen = [
'StingBo\Mengine\Events\PushQueueEvent' => [
'App\Listeners\YourListener', // 你自己的监听器,应该也使用异步来实现
],
];
$order = new Order($uuid, $oid, $symbol, $transaction, $volume, $price);
$ms = new MengineService();
$ms->deleteOrder($order);
// 撤单成功通知
event(new DeleteOrderSuccEvent($order));
// 注册监听器
protected $listen = [
'StingBo\Mengine\Events\DeleteOrderSuccEvent' => [
'App\Listeners\YourListener', // 你自己的监听器,应该也使用异步来实现
],
];
$symbol = 'abc2cny';
$transaction = 'buy';
$ms = new MengineService();
$ms->getDepth($symbol, $transaction);