In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what is the matchmaking engine in PHP". In the daily operation, I believe that many people have doubts about what the matchmaking engine in PHP is. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what is the matchmaking engine in PHP?" Next, please follow the editor to study!
Laravel Package for Matching Engine
Matching Engine For Laravel (redis-based matchmaking engine), PHP high-performance matchmaking engine
Quick start
Github address
Installation: composer require sting_bo/mengine
Copy profile: php artisan vendor:publish
Dependence
Predis
News flash
Golang micro service has been used to match. Welcome to use and mention issue.
instructions
If a system with existing data uses this library, it can write an initialization script and run the data into the queue first.
The user places an order
After placing an order, deposit it in the database before starting the following steps to instantiate the document object
Use StingBo\ Mengine\ Core\ Order;$uuid = 3; / / user unique ID $oid = 4; / / order unique ID $symbol = 'abc2usdt'; / / transaction pair $transaction =' buy'; / / transaction direction, buy/sale$price = 0.4; / / transaction price will be converted to an integer $volume = 15 depending on the setting precision / / number of transactions, which will be converted to the integer $order = new Order ($uuid, $oid, $symbol, $transaction, $volume, $price) according to the setting precision
The transaction direction and precision can be flexibly set in the configuration file.
Return ['mengine' = > [/ / transaction type, cannot be changed' transaction' = > ['buy',' sale',], / / precision, can be changed 'accuracy' = > 8, / / default' test2usdt_accuracy' = > 4, / / set transaction pair precision to use, otherwise take accuracy],]
Push to the queue. Queue tasks need to be opened manually.
Use StingBo\ Mengine\ Services\ MengineService;$ms = new MengineService (); $ms- > pushQueue ($order)
Open queue tasks: php artisan queue:work-queue=abc2usdt can also use horizon and supervisor to assist, get twice the result with half the effort!
When consuming the queue, you will enter the matchmaking process, and the approximate steps are as follows:
Get matching entrustment order
If there is no matching order, enter the delegate pool and trigger the delegate pool change event, as detailed in point 5
If there is a matching delegate, the program matches and updates the delegate pool data.
A successful transaction will trigger an event, and the developer needs to process the commission order with the transaction in the listener, such as updating database data, WebSocket notification, etc., to register the listener for the event that matches the success in EventServiceProvider:
/ / match success notification. Parameters are: current order, matched documents, transaction quantity event (new MatchEvent ($order, $match_order, $match_volume)); / / registered listener protected $listen = ['StingBo\ Mengine\ Events\ MatchEvent' = > [' App\ Listeners\ YourListener', / / your own listener, which should also be implemented asynchronously],]
If only part of the transaction is completed, the rest goes into the delegate pool and triggers the delegate pool change event, K-line or depth list change notification, etc. The registration listener is as follows:
/ delegate pool data change event event (new PushQueueEvent ($order)); / / register listeners protected $listen = ['StingBo\ Mengine\ Events\ PushQueueEvent' = > [' App\ Listeners\ YourListener', / / your own listeners, which should also be implemented asynchronously],]; users withdraw orders
The order withdrawal process should first query the database to confirm whether it is revocable, then delete the data from redis successfully, and finally update it back to the database.
$order = new Order ($uuid, $oid, $symbol, $transaction, $volume, $price); $ms = new MengineService (); $ms- > deleteOrder ($order)
This matchmaking engine does not implement the locking mechanism like the database. In order to prevent orders from being cancelled when they are brokered, the order is issued and withdrawn in the same queue, ensuring the order. Each transaction pair is an isolated queue, and the efficiency is guaranteed to a certain extent. However, the developer needs to implement the function of asynchronously notifying users. The registration listener is as follows:
/ / notify event (new DeleteOrderSuccEvent ($order)) of cancellation success; / / register listeners protected $listen = ['StingBo\ Mengine\ Events\ DeleteOrderSuccEvent' = > [' App\ Listeners\ YourListener', / / your own listeners, which should also be implemented asynchronously],]; get a list of buy / sell depth of a transaction $symbol = 'abc2cny';$transaction =' buy';$ms = new MengineService (); $ms- > getDepth ($symbol, $transaction);
Tested on local junk notebooks, the average matchmaking speed of deal pairs is 200 / s, and the matchmaking speed will be optimized in the future.
At this point, the study of "what is the matchmaking engine in PHP" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.