Download the PHP package sting_bo/mengine without Composer
On this page you can find all versions of the php package sting_bo/mengine. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package mengine
Laravel Package for Matching Engine
- 中文文档
Quick Start
- Install:
composer require sting_bo/mengine
- Copy configuration file:
php artisan vendor:publish
Dependencies
- predis
News
- Golang Microservice Matching Engine is Now Available,feel free to use and raise issues.
Usage Instructions
-
For existing systems with data, if using this library, you can write an initialization script to first run the data into the queue.
-
Placing an Order
- After placing an order, store it in the database and then instantiate the order object.
Transaction direction
andprecision
can be flexibly set in the configuration file.
- Push to the queue, queue tasks need to be manually started.
Start the queue task:
php artisan queue:work --queue=abc2usdt
You can also use horizon
and supervisor
to assist, making your work more efficient!
When the queue is consumed, it will enter the matching program. The general steps are as follows:
- Get matching delegated orders.
- If there are no matching orders, enter the order pool, triggering the order pool change event, see point 5.
- If there are matching orders, the program matches and updates the order pool data.
-
Successful transactions trigger events. Developers should handle orders with transactions in listeners, such as updating database data, WebSocket notifications, etc. In EventServiceProvider, register listeners for successful matches:
- If only partially filled, the remaining part enters the order pool, triggering the order pool change event, notifying K-line or depth list changes, etc. Register the listener as follows:
-
Canceling an Order
The cancellation process should be to first query the database to confirm if it can be canceled, then successfully delete the data from redis, and finally update the database.
This matching engine does not implement locking mechanisms like databases. To prevent a situation where an order is being matched and a cancellation command is issued, both placing and canceling orders use the same queue to ensure order, and each trading pair has an isolated queue. This ensures efficiency, but developers need to implement asynchronous notification functionality. Register the listener as follows:
-
Obtaining Buy/Sell Depth List for a Trading Pair
Summary
Tested on a local, average matching speed for transactions is around 200 per second. Further optimizations for matching speed are planned for the future.
Technical Support
contact us | detail |
---|---|
QQ Group | 871358160 |
[email protected] |