Method, system and device for quickly realizing order simulation matching
Through multi-threaded model and three-dimensional storage structure, the order simulation matching problem is solved, and the problem of slow restoration of the market order book and back-test deviation is achieved, fast order simulation matching and efficient data processing are achieved.
Patent Information
- Application Number
- CN202411163890.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-08-23
AI Technical Summary
In the existing order simulation matching technology, the market order book is restored slowly, there is a large deviation between backtesting and actual transactions, and the in-memory database makes the market replay take a long time, so it is impossible to apply to large-scale data scenarios.
The market order book is positioned using a multi-threaded model, and the market order book is quickly positioned through primary and secondary indexes. The market data is classified and stored using a three-dimensional storage structure, and the appropriate matching method is selected according to the transaction type and stage for simulation matching.
It significantly improves the restoration speed of the market order book and the effectiveness of strategic backtesting, reduces the deviation between backtesting and actual transactions, and is suitable for large-scale data scenarios.
Smart Images

Figure CN118674531B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a method, system and device for quickly implementing order simulation matching. Background Art
[0002] In the existing order simulation matching, historical transaction quotes are generally used as basic data. The quotation order book is updated and restored for new transaction orders, order cancellations, and completed transaction quotes in strict accordance with their respective business logic in the order in which the quotes were generated. In the process of restoring the quotation order book, user strategy orders are connected to simulate the matching of user strategy orders with real-time quotation orders.
[0003] The following problems may arise in the existing practices:
[0004] The order book restore is slow: when backtesting a strategy for a certain period of time (such as the historical tick-by-tick market data for the past year), the amount of historical tick-by-tick data is very large, so when updating the order book, it is very time-consuming to find and locate the specific location of the orders involved in the tick-by-tick market in the order book;
[0005] The limited matching support function will lead to a large deviation between backtesting and actual trading: the matching rules for different trading stages and different transaction types of auction transactions are different, the business logic is complex, and the support is insufficient;
[0006] Using an in-memory database as the basic data structure will result in a long time-consuming insertion and playback of market information, and is not suitable for matching scenarios with huge market information playback volumes and only simple indexes. Summary of the invention
[0007] In view of the shortcomings of the prior art, the present invention provides a method, system and device for quickly realizing order simulation matching.
[0008] In order to solve the above technical problems, the present invention is solved by the following technical solutions:
[0009] A method for quickly implementing simulated order matching includes the following steps:
[0010] Based on the time sequence of each transaction order, the transaction orders are obtained and parsed to obtain transaction order information, wherein the transaction order information at least includes transaction type, transaction direction, transaction price, transaction number and transaction target code;
[0011] The corresponding market order book is located through a multi-threaded model, and the transaction order information is stored in the corresponding market order book;
[0012] Matching corresponding restoration logic based on the transaction type of the transaction order, and updating the market order book through the restoration logic to form a new market order book;
[0013] Obtaining the pending simulated matching orders, judging the validity of the pending simulated matching orders, and obtaining the judgment results, wherein the pending simulated matching order information includes the transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price;
[0014] If the order to be simulated matched is a valid order, the new market order book is located according to the transaction target code, the transaction stage involved in the order to be simulated matched is determined according to the update time, and simulated matching is performed in the transaction stage through the corresponding matching method according to the transaction type to obtain the matching result.
[0015] As an implementable method, locating the corresponding market order book through a multi-threaded model includes the following steps:
[0016] The multi-threaded model includes a primary index, a secondary index and a market order book;
[0017] The primary index is a thread pool index, the index value of the thread pool index is a processing thread, and the processing thread is a result obtained by taking a modulus of the data of the transaction target code;
[0018] The secondary index is an order book index, the index value of the order book index is a hash value, and the hash value is a result of hashing the data of the transaction target code;
[0019] The data of the transaction target code is modulo, the corresponding processing thread is initially matched, the transaction target code is hashed, and the corresponding market order book is matched through the hash value.
[0020] As an implementable embodiment, the market order book is provided with a storage structure of at least three dimensions;
[0021] The first dimension of the storage structure is used to store data sets that classify market data by transaction direction;
[0022] The second dimension of the storage structure is used to store a data set that classifies the data set of the first dimension according to the transaction price level;
[0023] The third dimension of the storage structure is used to store the entrustment queue data of the second dimension data set that is unique by transaction number.
[0024] As an implementable method, the transaction type in the transaction order information includes a first entrustment type and a first transaction type;
[0025] The first order type includes a new transaction order and a first cancellation order; the first transaction type includes a first transaction direction order, a second transaction direction order and a third transaction direction order;
[0026] The updating of the quotation order book includes the following steps:
[0027] When it is a new transaction order, the market data of the transaction direction of the corresponding market order book is matched according to the transaction target code and the transaction direction, and then the corresponding transaction price level is matched according to the transaction target price, and the entrustment queue under the corresponding level is obtained, and the new transaction order information is inserted at the end of the entrustment queue;
[0028] When it is the first cancellation order, the market data of the transaction direction of the corresponding market order book is matched according to the transaction target code and the transaction direction, and then the corresponding transaction price level is matched according to the transaction target price, and the entrustment queue under the corresponding level is obtained, and the transaction number of the first cancellation order is searched in the entrustment queue based on the binary search method and deleted from the queue;
[0029] When it is an order for the first transaction direction, locate the corresponding market order book according to the transaction target code, find the corresponding transaction price level in the selling market data according to the transaction transaction price, and obtain the entrustment queue under the corresponding level. The first transaction order in the entrustment queue is the current transaction order. If the remaining quantity of the order minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, delete the current transaction order from the order queue.
[0030] When it is an order for the second transaction direction, locate the corresponding market order book according to the transaction target code, find the corresponding transaction price level in the buy market data according to the transaction transaction price, obtain the entrustment queue under the corresponding level, and the first transaction order in the entrustment queue is the current transaction order. If the remaining quantity of the order minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, delete the current transaction order from the order queue;
[0031] When it is an order for the third transaction direction, the orders of both parties of the third transaction direction are judged. If it is an order for the first transaction direction, the corresponding market order book is located according to the transaction target code, and the corresponding transaction price level is found in the buy market data according to the transaction transaction price. The entrustment queue under the corresponding level is obtained, and the first transaction order of the entrustment queue is judged according to the transaction number whether it is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continued to be judged until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, The current transaction order will be deleted from the order queue; if it is an order for the second transaction direction, the corresponding market order book will be located according to the transaction target code, and the corresponding transaction price level will be found in the selling market data according to the transaction transaction price, and the entrustment queue under the corresponding level will be obtained. According to the transaction number, it is judged whether the first transaction order in the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels will be taken for judgment until the transaction order is obtained. If the remaining quantity of the order minus the transaction quantity of the current transaction order is greater than 0, the remaining quantity of the current transaction order will be updated. If all transactions are completed, the current transaction order will be deleted from the order queue.
[0032] As an implementable method, the transaction type in the transaction order information further includes a second entrustment type and a second transaction type, the second entrustment type includes a limit transaction order, a best transaction order and a market price transaction order; the second transaction type includes a transaction order and a second cancellation order;
[0033] The updating of the quotation order book includes the following steps:
[0034] When it is a limit order, locate the market data of the transaction direction of the market order book according to the transaction target code and transaction direction, and then match the corresponding transaction price level according to the transaction target price, obtain the entrustment queue under the corresponding level, and insert the current limit order at the end of the entrustment queue;
[0035] When it is the best trading order, locate the market data of the trading direction of the market order book according to the trading target code and the trading direction, obtain the best trading price in the corresponding market data, convert the current trading order into a limit trading order with the best trading price as the trading target price, obtain the entrustment queue under the corresponding gear based on the trading price level corresponding to the limit trading order, and insert the corresponding current best trading order at the end of the entrustment queue;
[0036] When it is a market price trading order, locate the market data of the corresponding market order book trading direction according to the trading target code and the trading direction, obtain the entrustment queue under the corresponding level at the market price level of the corresponding market data, and insert the current market price trading order into the entrustment queue;
[0037] When it is a completed order, the orders of both parties of the completed order are judged. If it is the first completed order, the corresponding market order book is located according to the transaction target code, and the entrustment queue is obtained under the market price level of the buy market data. The market price transaction order is matched according to the transaction number. If the match is unsuccessful, the corresponding transaction price level is found in the buy market data according to the transaction transaction price, and the entrustment queue under the corresponding level is obtained. According to the transaction number, it is judged whether the first transaction order in the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continued to be judged until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, the current The transaction order is deleted from the order queue; if it is the second executed order, the corresponding market order book is located according to the transaction target code, the entrustment queue is obtained under the market price level of the selling market data, and the market price transaction order is matched according to the transaction number. If the match is unsuccessful, the corresponding transaction price level is found in the selling market data according to the transaction transaction price, and the entrustment queue under the corresponding level is obtained. According to the transaction number, it is judged whether the first transaction order of the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continuously obtained for judgment until the transaction order is obtained. If the remaining order quantity minus the current transaction order execution quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, the current transaction order is deleted from the order queue;
[0038] When it is the second cancellation order, the market data of the transaction direction of the corresponding market order book is located according to the transaction target code and the transaction direction, and the market price transaction level is obtained. The entrustment queue under the level matches the market price transaction order according to the transaction number. If the match is successful, the current transaction order is deleted from the order queue; if the match is unsuccessful, it is not a market price transaction order, and the corresponding transaction price level is matched according to the transaction target price, the entrustment queue under the corresponding level is obtained, and the transaction number of the second cancellation order is searched in the entrustment queue based on the binary search method and deleted from the queue.
[0039] As an implementable method, the trading stages of the order matching to be simulated include a call auction stage and a continuous auction stage, and the trading types include a limit trading type, a first part transaction type, a second part transaction type, a first conversion type, a second conversion type, all operation types and an instant operation type.
[0040] As an implementable method, triggering the corresponding matching method according to the transaction stage and transaction type and then performing simulated matching to obtain the matching result includes the following steps:
[0041] During the call auction phase, no simulated matching is performed on new trading orders to be simulated. For limit price trading orders to be simulated, the pending order data of the pending order book to be simulated is located according to the trading target code and trading direction. Then, the corresponding price level is matched according to the trading target price, and the pending order queue under the corresponding level is obtained. The pending order to be simulated is inserted at the end of the pending order queue. The pending order to be traded at the call auction triggers the simulated matching of the pending order book to be simulated and the market order book.
[0042] During the continuous bidding phase, new trading orders to be simulated and matched are simulated with the market order book based on price priority and time priority. Different transaction types are allowed to match different price levels and remaining quantity processing;
[0043] When it is a limit transaction type, if the transaction target price of the buy order to be simulated matched is not less than the latest transaction price, the market order book is located according to the transaction target code, the sell market data is obtained, and then the corresponding price level is matched according to the latest transaction price, the entrustment queue under the corresponding level is obtained, the entrustment queue is traversed, and simulated matching is performed with the current limit transaction order; if all the market orders of the current price level are simulated matched and the limit transaction order is not completely executed, the entrustment queue under the adjacent price level will continue to be simulated matched until the buy transaction target price is less than the sell transaction price or the transaction target quantity is fully executed. ; If it is a sell order to be simulated, if the target price of the sell order is not greater than the latest transaction price, locate the market order book according to the transaction target code, obtain the buy market data, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding level, traverse the entrustment queue, and simulate matching with the current limit order; if all the market orders at this price level are simulated, and the limit order is not completely executed, continue to take the entrustment queue under the adjacent price level for simulated matching until the sell transaction target price is greater than the buy transaction price or the transaction target quantity is fully executed;
[0044] When it is the first part of the transaction type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and simulate matching with the market price transaction order. If the transaction order is not completely executed, continue to obtain the entrustment queue under the adjacent price level for simulated matching until the transaction price is reasonable or the transaction target quantity is fully executed. If the transaction target quantity is not fully executed, the remaining quantity will be automatically cancelled;
[0045] When it is the second part of the transaction type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and simulate matching with the market price transaction order. If the transaction order is not completely executed, continue to obtain the entrustment queue under the adjacent price level for simulated matching until the transaction price is reasonable or the transaction target quantity is fully executed. If the transaction target quantity is not fully executed, the remaining quantity will be converted into a limit transaction order with the most recent matching transaction price as the transaction target price;
[0046] When it is the first conversion type, locate the market order book according to the transaction target code, obtain market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price to obtain the entrustment queue under the corresponding price level. If there is no order in the entrustment queue, continue to obtain the entrustment queue under the adjacent price level until there is an order record in the entrustment queue, and convert it into a limit transaction order with the transaction price of the current price level as the transaction target price;
[0047] When it is the second conversion type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, if there is no order in the entrustment queue, continue to obtain the entrustment queue under the adjacent price level, until there is an order record in the entrustment queue, traverse the entrustment queue and simulate matching with the market price transaction order, if the transaction order is not completely executed, the remaining quantity is converted into a limit price transaction order with the most recent matching transaction price as the transaction target price;
[0048] When it is the all operation type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and determine whether the market price transaction order can be fully matched and executed. If not all transactions are completed, continue to obtain the entrustment queue under the next price level, and determine whether the uncompleted part can be fully matched and executed, until the price level is obtained to a reasonable price level or is fully matched and executed. If it is determined that all transactions can be matched and executed, they will be matched in sequence according to the above logical order, otherwise the order will be automatically cancelled;
[0049] When it is an instant operation type, the market order book is located according to the transaction target code, the counterparty market data is obtained according to the transaction direction, and then the corresponding price level is matched according to the latest transaction price, the entrustment queue under the corresponding price level is obtained, the entrustment queue is traversed, and the market price transaction order is simulated and matched. If all transactions are not completed, the entrustment queue under the adjacent price level will continue to be simulated and matched until the price level is obtained at a reasonable price level or all transactions are matched and completed. If there is a remaining quantity of the market price transaction order, the remaining quantity will be converted into a limit price transaction order with the most recent matching transaction price as the transaction target price.
[0050] As an implementable method, when the order to be simulated and matched is a new transaction order, the following steps are included:
[0051] The information of the new transaction order shall at least include: transaction number, transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price;
[0052] Locate the corresponding market order book by the transaction target code, and locate the counterparty market data by the transaction direction;
[0053] Simulate matching of market data with new trading orders based on price priority and time priority;
[0054] If the limit order meets the preset conditions, it will be matched and traded; the best trading order of our party takes the best price level trading price of our party's market data as the trading target price and is converted into a limit order; the market price trading order is limited to the matching price level and the remaining quantity processing method according to the specific trading order type;
[0055] If there is still a remaining quantity after the simulated matching, the remaining number of new trading orders will be inserted into the pending order book to be simulated matched. Among them, the pending order price of the market price trading order that has not been automatically cancelled is determined according to the specific transaction type; for the pending orders that have not been executed, the market data of the transaction direction of the market order book is recorded, and the last transaction number of the entrustment queue under the price level is matched with the pending order price, which is used to count the number of quotes that are better than the current pending order at the same price level when matching pending orders.
[0056] As an implementable method, when the order to be simulated is a pending transaction order, the following steps are included:
[0057] The information of pending order includes transaction number, transaction target code, transaction direction, transaction target price, remaining quantity, and market transaction number;
[0058] Locate the corresponding pending order book to be simulated based on the transaction target code of the transaction order, and locate the counterparty pending order data based on the transaction direction of the transaction order;
[0059] The pending order data is simulated matched with the transaction order in the order of price priority and time priority. Specifically, the matching quantity of this transaction order = the number of transaction orders - the number of quotes that are better than the pending order to be simulated matched. When the matching quantity of this quote is greater than 0, simulated matching is performed. The number of quotes that are better than the pending order to be simulated matched includes the number of all quotes whose prices are better than the pending order to be simulated matched and the number of all quotes whose times are better than the pending order to be simulated matched at this price level.
[0060] A system for quickly realizing order simulation matching, comprising an order acquisition module, a positioning storage module, a matching update module, an acquisition judgment module and a matching determination module;
[0061] The order acquisition module acquires and analyzes the transaction orders one by one based on the time sequence of the transaction orders, and obtains transaction order information, wherein the transaction order information at least includes the transaction type, transaction direction, transaction price, transaction number and transaction target code;
[0062] The positioning storage module locates the corresponding market order book through a multi-threaded model, and stores the transaction order information in the corresponding market order book;
[0063] The matching and updating module matches the corresponding restoration logic based on the transaction type of each transaction order, and updates the market order book through the restoration logic to form a new market order book;
[0064] The acquisition and judgment module is used to obtain the matching order to be simulated, judge the validity of the matching order to be simulated, and obtain the judgment result, wherein the matching order information to be simulated includes the transaction target code, transaction direction, transaction type, transaction target quantity and transaction target price;
[0065] The matching determination module is configured to: if the order to be simulated matching is a valid order, locate the new market order book according to the transaction target code, determine the transaction stage involved in the order to be simulated matching according to the update time, and perform simulated matching in the transaction stage through the corresponding matching method according to the transaction type to obtain the matching result.
[0066] As an implementable embodiment, the positioning storage module is configured as follows:
[0067] The multi-threaded model includes a primary index, a secondary index and a market order book;
[0068] The primary index is a thread pool index, the index value of the thread pool index is a processing thread, and the processing thread is a result obtained by taking a modulus of the data of the transaction target code;
[0069] The secondary index is an order book index, the index value of the order book index is a hash value, and the hash value is a result of hashing the data of the transaction target code;
[0070] The data of the transaction target code is modulo, the corresponding processing thread is initially matched, the transaction target code is hashed, and the corresponding market order book is matched through the hash value.
[0071] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following method is implemented:
[0072] Based on the time sequence of each transaction order, the transaction orders are obtained and parsed to obtain transaction order information, wherein the transaction order information at least includes transaction type, transaction direction, transaction price, transaction number and transaction target code;
[0073] The corresponding market order book is located through a multi-threaded model, and the transaction order information is stored in the corresponding market order book;
[0074] Matching corresponding restoration logic based on the transaction type of the transaction order, and updating the market order book through the restoration logic to form a new market order book;
[0075] Obtaining the pending simulated matching orders, judging the validity of the pending simulated matching orders, and obtaining the judgment results, wherein the pending simulated matching order information includes the transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price;
[0076] If the order to be simulated matched is a valid order, the new market order book is located according to the transaction target code, the transaction stage involved in the order to be simulated matched is determined according to the update time, and simulated matching is performed in the transaction stage through the corresponding matching method according to the transaction type to obtain the matching result.
[0077] A device for quickly implementing simulated order matching includes a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor implements the following method when executing the computer program:
[0078] Based on the time sequence of each transaction order, the transaction orders are obtained and parsed to obtain transaction order information, wherein the transaction order information at least includes transaction type, transaction direction, transaction price, transaction number and transaction target code;
[0079] The corresponding market order book is located through a multi-threaded model, and the transaction order information is stored in the corresponding market order book;
[0080] Matching corresponding restoration logic based on the transaction type of the transaction order, and updating the market order book through the restoration logic to form a new market order book;
[0081] Obtaining the pending simulated matching orders, judging the validity of the pending simulated matching orders, and obtaining the judgment results, wherein the pending simulated matching order information includes the transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price;
[0082] If the order to be simulated matched is a valid order, the new market order book is located according to the transaction target code, the transaction stage involved in the order to be simulated matched is determined according to the update time, and simulated matching is performed in the transaction stage through the corresponding matching method according to the transaction type to obtain the matching result.
[0083] The present invention has significant technical effects due to the adoption of the above technical solution:
[0084] The present invention locates the corresponding market order book through a multi-threaded model, and can quickly complete the restoration and update of the market order book; different simulation matching methods are provided at different stages to improve the effectiveness of strategy backtesting. BRIEF DESCRIPTION OF THE DRAWINGS
[0085] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0086] Figure 1 It is a schematic flow diagram of the method of the present invention;
[0087] Figure 2 It is a schematic diagram of the multi-threaded model of the present invention;
[0088] Figure 3 is a schematic diagram of a market order book of the present invention;
[0089] Figure 4-Figure 5 They are schematic diagrams of the restoration logic of the present invention;
[0090] Figure 6 It is a structural schematic diagram of the system of the present invention. DETAILED DESCRIPTION
[0091] The present invention is further described in detail below in conjunction with embodiments. The following embodiments are for explanation of the present invention but the present invention is not limited to the following embodiments.
[0092] Embodiment 1:
[0093] A method to quickly realize order simulation matching, such as Figure 1 As shown, the following steps are included:
[0094] S100, based on the time sequence of the generation of the transaction orders, obtain and parse the transaction orders one by one to obtain transaction order information, wherein the transaction order information at least includes transaction type, transaction direction, transaction price, transaction number and transaction target code;
[0095] S200, locating the corresponding market order book through the multi-threaded model, and storing the transaction order information in the corresponding market order book;
[0096] S300, matching corresponding restoration logic based on the transaction type of each transaction order, and updating the market order book through the restoration logic to form a new market order book;
[0097] S400, obtaining the order to be simulated, judging the validity of the order to be simulated, and obtaining a judgment result, wherein the information of the order to be simulated includes the transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price;
[0098] S500: If the order to be simulated is a valid order, locate the new market order book according to the transaction target code, determine the transaction stage involved in the order to be simulated according to the update time, perform simulated matching in the transaction stage by the corresponding matching method according to the transaction type, and obtain the matching result.
[0099] In step S200, the corresponding market order book is located through the multi-threaded model, including the following steps:
[0100] The multi-threaded model includes a primary index, a secondary index and a market order book;
[0101] The primary index is a thread pool index, the index value of the thread pool index is a processing thread, and the processing thread is a result obtained by taking a modulus of the data of the transaction target code;
[0102] The secondary index is an order book index, the index value of the order book index is a hash value, and the hash value is a result of hashing the data of the transaction target code;
[0103] The data of the transaction target code is modulo, the corresponding processing thread is initially matched, the transaction target code is hashed, and the corresponding market order book is matched through the hash value.
[0104] Attached Figure 2 As shown, the present invention can quickly realize order simulation matching by relying on locating the corresponding market order book through a multi-threaded model. The multi-threaded model locates the market order book through a paging index. The primary index is a thread pool index. The index value of the thread pool index is a processing thread, which is the result obtained by taking the data of the transaction target code modulo; the secondary index is an order book index. The index value of the order book index is a hash value, which is the result obtained by hashing the data of the transaction target code. The specific market order book can be quickly located through the secondary index, and the query time is short and the complexity is low.
[0105] like Figure 3 As shown, since the basic parameters of the transaction target code (which can be the securities code in this embodiment) are the price limit and the minimum price difference, the daily highest and lowest buying and selling prices of the corresponding stocks and the minimum price difference of the transaction price will be limited. Therefore, a three-dimensional storage structure is constructed for the market order book. The first dimension of the storage structure is distinguished by the buying and selling direction. The first dimension of the storage structure is used to store data sets classified by transaction direction, and the second dimension is an array data set with price level as the subscript. The length of the first and second dimension arrays is determined, and memory can be pre-allocated and initialized; the third dimension is a self-incrementing loop array, which stores the unique entrustment queue data of the transaction number. When receiving a transaction order by transaction, the transaction order to be processed can be quickly located in the market order book with a three-dimensional storage structure according to the transaction direction, transaction price and transaction number of the transaction order information.
[0106] In layman's terms, the first dimension is the direction of buying and selling, through which the market order book is classified into buying and selling markets; the second dimension is the price level, through which a classification is made in the buying and selling markets by price; the third dimension is the entrustment queue details with the buying and selling directions and price classifications, and the entrustment is unique by transaction number. The market order book is updated by the market transaction; the pending order book is the new orders to be simulated matching that failed to be fully executed after the first matching, and the remaining part is converted into pending orders to be simulated and inserted into the pending order book. When the subsequent market transactions enter the system, it will try to match with the pending orders to be simulated in the pending order book. If these pending orders can be fully matched, they will be deleted from the pending order book, or the user can initiate a cancellation order and delete it from the pending order book. The storage structure of the pending order book is the same as that of the market order book, that is, the data inside, one is the pending order data to be simulated, and the other is the transaction transaction data of the exchange.
[0107] In one embodiment, the transaction type includes a first entrustment type and a first transaction type;
[0108] The first order type includes a new transaction order and a first cancellation order; the first transaction type includes a first transaction direction order, a second transaction direction order and a third transaction direction order;
[0109] The updating of the quotation order book includes the following steps:
[0110] When it is a new transaction order, the market data of the transaction direction of the corresponding market order book is matched according to the transaction target code and the transaction direction, and then the corresponding transaction price level is matched according to the transaction target price, and the entrustment queue under the corresponding level is obtained, and the new transaction order information is inserted at the end of the entrustment queue;
[0111] When it is the first cancellation order, the market data of the transaction direction of the corresponding market order book is matched according to the transaction target code and the transaction direction, and then the corresponding transaction price level is matched according to the transaction target price, and the entrustment queue under the corresponding level is obtained, and the transaction number of the first cancellation order is searched in the entrustment queue based on the binary search method and deleted from the queue;
[0112] When it is an order for the first transaction direction, locate the corresponding market order book according to the transaction target code, find the corresponding transaction price level in the selling market data according to the transaction transaction price, and obtain the entrustment queue under the corresponding level. The first transaction order in the entrustment queue is the current transaction order. If the remaining quantity of the order minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, delete the current transaction order from the order queue.
[0113] When it is an order for the second transaction direction, locate the corresponding market order book according to the transaction target code, find the corresponding transaction price level in the buy market data according to the transaction transaction price, obtain the entrustment queue under the corresponding level, and the first transaction order in the entrustment queue is the current transaction order. If the remaining quantity of the order minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, delete the current transaction order from the order queue;
[0114] When it is an order for the third transaction direction, the orders of both parties of the third transaction direction are judged. If it is an order for the first transaction direction, the corresponding market order book is located according to the transaction target code, and the corresponding transaction price level is found in the buy market data according to the transaction transaction price. The entrustment queue under the corresponding level is obtained, and the first transaction order of the entrustment queue is judged according to the transaction number whether it is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continued to be judged until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, The current transaction order will be deleted from the order queue; if it is an order for the second transaction direction, the corresponding market order book will be located according to the transaction target code, and the corresponding transaction price level will be found in the selling market data according to the transaction transaction price, and the entrustment queue under the corresponding level will be obtained. According to the transaction number, it is judged whether the first transaction order in the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels will be taken for judgment until the transaction order is obtained. If the remaining quantity of the order minus the transaction quantity of the current transaction order is greater than 0, the remaining quantity of the current transaction order will be updated. If all transactions are completed, the current transaction order will be deleted from the order queue.
[0115] See a specific embodiment, such as Figure 4 As shown, the first entrustment type of this process is matched to the current transaction-by-transaction entrustment of a certain A exchange, the first transaction type is matched to the current transaction-by-transaction of a certain A exchange, the transaction target code is the security code, the transaction direction is the buy and sell direction, and the transaction target price is the entrustment price. The specific operations are as follows:
[0116] A Exchange's order-by-order - new trading order: quickly locate the market data of the corresponding market order book in the buying and selling directions according to the securities code and buying and selling directions of the order-by-order, and then locate the corresponding price level according to the order price, obtain the order queue under the corresponding level, and insert the new trading order at the end of the order queue.
[0117] A Exchange's Order-by-Order-First Cancelled Order: Quickly locate the market data of the corresponding market order book's buy and sell directions based on the securities code and buy and sell directions of the order-by-order, and then locate the corresponding price level based on the order price to obtain the order queue under the corresponding level. Because the transaction number of the order-by-order-new transaction order is incremental, the transaction number in the order queue under the corresponding price level of the market order book restored in chronological order is incremental (but not necessarily continuous). The binary search method can be used in the queue to find the canceled transaction number, find the first canceled order and delete it from the queue.
[0118] A Exchange Transaction by Transaction - The first transaction direction order is the buy active transaction order: locate the corresponding market order book according to the stock code. According to the transaction price, find the entrustment queue under the corresponding price level in the sell market data of the market order book. The first order in the queue is the transaction order of this time (the matching method is price priority and time priority, so under the same price, the time priority order will be executed first). If the remaining quantity of the order - the current transaction quantity > 0, the remaining quantity of this order is updated. If all transactions are completed, the order will be deleted from the entrustment queue.
[0119] A Exchange's transaction by transaction - the second transaction direction order is the active selling transaction order: locate the corresponding market order book according to the stock code. According to the transaction price, find the entrustment queue under the corresponding price level in the buy market data of the market order book. The first order in the queue is the transaction order of this time (the matching method is price priority and time priority, so under the same price, the time priority order will be executed first). If the remaining quantity of the order - the current transaction quantity > 0, the remaining quantity of this order will be updated. If all transactions are completed, the order will be deleted from the entrustment queue.
[0120] A Exchange Transaction by Transaction - Third Transaction Direction Orders, i.e., unknown orders of the active transaction party: judge the transaction parties separately. If it is a buyer transaction, locate the corresponding market order book according to the securities code, find the corresponding transaction price level in the buy market data according to the transaction price, obtain the entrustment queue under the corresponding level, and judge whether the first transaction order in the entrustment queue is the current transaction order according to the transaction number. If not, continue to take the first transaction order in the entrustment queue under other price levels for judgment until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If If all transactions are completed, the current transaction order will be deleted from the order queue. If it is a seller transaction, locate the corresponding quotation order book according to the securities code, find the corresponding transaction price level in the selling quotation data according to the transaction price, obtain the entrustment queue under the corresponding level, and determine whether the first transaction order in the entrustment queue is the current transaction order according to the transaction number. If not, continue to obtain the first transaction order in the entrustment queue under other price levels for judgment until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, delete the current transaction order from the order queue.
[0121] In one embodiment, the transaction type further includes a second entrustment type and a second transaction type, the second entrustment type includes a limit transaction order, a best transaction order and a market price transaction order; the second transaction type includes a transaction order and a second cancellation order;
[0122] The updating of the quotation order book includes the following steps:
[0123] When it is a limit order, locate the market data of the transaction direction of the market order book according to the transaction target code and transaction direction, and then match the corresponding transaction price level according to the transaction target price, obtain the entrustment queue under the corresponding level, and insert the current limit order at the end of the entrustment queue;
[0124] When it is the best trading order, locate the market data of the trading direction of the market order book according to the trading target code and the trading direction, obtain the best trading price in the market order book, convert the current trading order into a limit trading order with the best trading price as the trading target price, obtain the entrustment queue under the corresponding gear based on the trading price level corresponding to the trading target price, and insert the corresponding current best trading order at the end of the entrustment queue;
[0125] When it is a market price trading order, locate the market data of the corresponding market order book trading direction according to the trading target code and the trading direction, obtain the entrustment queue under the corresponding level at the market price level of the corresponding market data, and insert the current market price trading order into the entrustment queue;
[0126] When it is a completed order, the orders of both parties of the completed order are judged. If it is the first completed order, the corresponding market order book is located according to the transaction target code, and the entrustment queue is obtained under the market price level of the buy market data. The market price transaction order is matched according to the transaction number. If the match is unsuccessful, the corresponding transaction price level is found in the buy market data according to the transaction transaction price, and the entrustment queue under the corresponding level is obtained. According to the transaction number, it is judged whether the first transaction order in the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continued to be judged until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, the current The transaction order is deleted from the order queue; if it is the second executed order, the corresponding market order book is located according to the transaction target code, the entrustment queue is obtained under the market price level of the selling market data, and the market price transaction order is matched according to the transaction number. If the match is unsuccessful, the corresponding transaction price level is found in the selling market data according to the transaction transaction price, and the entrustment queue under the corresponding level is obtained. According to the transaction number, it is judged whether the first transaction order of the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continuously obtained for judgment until the transaction order is obtained. If the remaining order quantity minus the current transaction order execution quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, the current transaction order is deleted from the order queue;
[0127] When it is the second cancellation order, the market data of the transaction direction of the corresponding market order book is located according to the transaction target code and the transaction direction, and the market price transaction level is obtained. The entrustment queue under the level matches the market price transaction order according to the transaction number. If the match is successful, the current transaction order is deleted from the entrustment queue; if the match is unsuccessful, it is not a market price transaction order, and the corresponding transaction price level is matched according to the transaction target price, the entrustment queue under the corresponding level is obtained, and the transaction number of the second cancellation order is searched in the entrustment queue based on the binary search method and deleted from the queue.
[0128] See a specific embodiment, such as Figure 5As shown, the second entrustment type of this process is matched to the current individual entrustment of a certain B exchange, and the second transaction type is matched to the current individual transaction of a certain B exchange. The transaction target code is the security code, the transaction direction is the buy and sell direction, and the transaction target price is the entrustment price. The specific operations are as follows:
[0129] B Exchange's individual entrustment - limit order: quickly locate the market data of the corresponding market order book in the buying and selling directions according to the securities code and buying and selling directions of the individual entrustment, and then locate the corresponding price level according to the entrustment price, obtain the entrustment queue under the corresponding level, and insert the new transaction order at the end of the queue.
[0130] B Exchange's best order for each transaction - that is, the best transaction order of the party: quickly locate the market data of the corresponding market order book in the buy and sell direction according to the security code and the buy and sell direction, obtain the best price of the party, convert the current order into a limit order with the best price of the party as the commission price, obtain the commission queue under the corresponding price level based on the commission price corresponding to the transaction price level, and insert the new transaction order at the end of the commission queue.
[0131] B Exchange's order-by-order - market price trading order: quickly locate the market data of the corresponding market order book in the buying and selling directions according to the security code and the buying and selling directions, obtain the market price level, and insert the new trading order into the order queue under the level.
[0132] B Exchange trades one by one - traded orders: judge the two parties of the transaction respectively. If it is a buyer's transaction, locate the corresponding market order book according to the security code, obtain the entrustment queue under the market price level of the buy market data, match the market price transaction order according to the transaction number, if the match is unsuccessful, find the corresponding transaction price level in the buy market data according to the transaction price, obtain the entrustment queue under the corresponding level, and judge whether the first transaction order in the entrustment queue is the current transaction order according to the transaction number. If not, continue to take the first transaction order in the entrustment queue under other price levels for judgment until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, the current The transaction order is deleted from the order queue; if it is a seller transaction, the corresponding market order book is located according to the securities code, the entrustment queue is obtained under the market price level of the selling market data, and the market price transaction order is matched according to the transaction number. If the match is unsuccessful, the corresponding transaction price level is found in the selling market data according to the transaction price, and the entrustment queue under the corresponding level is obtained. According to the transaction number, it is judged whether the first transaction order in the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continued to be judged until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, the current transaction order will be deleted from the order queue.
[0133] B Exchange's transaction-by-transaction - second cancellation order: quickly locate the market data of the corresponding market order book in the buying and selling direction according to the security code and the buying and selling direction, obtain the market price level, and match the transaction number of the cancelled order to the entrustment queue under the market price level (there is only one order in the entrustment queue at the same time). If the match is successful, the second cancellation order is deleted from the queue. If the match is unsuccessful, it is a non-market price transaction order. The corresponding transaction price level is matched according to the entrustment price, and the entrustment queue under the corresponding level is obtained. The transaction number of the second cancellation order is searched in the entrustment queue based on the binary search method and deleted from the queue.
[0134] In one embodiment, the transaction phase includes a call auction phase and a continuous auction phase, and the transaction types include a limit transaction type, a first part transaction type, a second part transaction type, a first conversion type, a second conversion type, all operation types, and an instant operation type. Then, triggering a corresponding matching method according to the transaction phase and transaction type and then performing simulated matching to obtain a matching result includes the following steps:
[0135] During the call auction phase, no simulated matching is performed on new trading orders to be simulated. For limit price trading orders to be simulated, the pending order data of the pending order book to be simulated is located according to the trading target code and trading direction. Then, the corresponding price level is matched according to the trading target price, and the pending order queue under the corresponding level is obtained. The pending order to be simulated is inserted at the end of the pending order queue. The pending order to be traded at the call auction triggers the simulated matching of the pending order book to be simulated and the market order book.
[0136] During the continuous bidding phase, new trading orders to be simulated and matched are simulated with the market order book based on price priority and time priority. Different transaction types are allowed to match different price levels and remaining quantity processing;
[0137] When it is a limit transaction type, if the transaction target price of the buy order to be simulated matched is not less than the latest transaction price, the market order book is located according to the transaction target code, the sell market data is obtained, and then the corresponding price level is matched according to the latest transaction price, the entrustment queue under the corresponding level is obtained, the entrustment queue is traversed, and simulated matching is performed with the current limit transaction order; if all the market orders of the current price level are simulated matched and the limit transaction order is not completely executed, the entrustment queue under the adjacent price level will continue to be simulated matched until the buy transaction target price is less than the sell transaction price or the transaction target quantity is fully executed. ; If it is a sell order to be simulated, if the target price of the sell order is not greater than the latest transaction price, locate the market order book according to the transaction target code, obtain the buy market data, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding level, traverse the entrustment queue, and simulate matching with the current limit order; if all the market orders at this price level are simulated, and the limit order is not completely executed, continue to take the entrustment queue under the adjacent price level for simulated matching until the sell transaction target price is greater than the buy transaction price or the transaction target quantity is fully executed;
[0138] When it is the first part of the transaction type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and simulate matching with the market price transaction order. If the transaction order is not fully executed, continue to obtain the entrustment queue under the adjacent price level for simulated matching until the transaction price is reasonable or the transaction target quantity is fully executed. If the transaction target quantity is not fully executed, the remaining quantity will be automatically cancelled;
[0139] When it is the second part of the transaction phase, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and simulate matching with the market price transaction order. If the transaction order is not completely executed, continue to take the entrustment queue under the adjacent price level for simulated matching until the transaction price is reasonable or the transaction target quantity is fully executed. If the transaction target quantity is not fully executed, the remaining quantity will be converted into a limit transaction order with the most recent matching transaction price as the transaction target price;
[0140] When it is the first conversion type, locate the market order book according to the transaction target code, obtain market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price to obtain the entrustment queue under the corresponding price level. If there is no order in the entrustment queue, continue to obtain the entrustment queue under the adjacent price level until there is an order record in the entrustment queue, and convert it into a limit transaction order with the transaction price of the current price level as the transaction target price;
[0141] When it is the second conversion type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, if there is no order in the entrustment queue, continue to obtain the entrustment queue under the adjacent price level, until there is an order record in the entrustment queue, traverse the entrustment queue and simulate matching with the market price transaction order, if the transaction order is not completely executed, the remaining quantity is converted into a limit price transaction order with the most recent matching transaction price as the transaction target price;
[0142] When it is the all operation type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and determine whether the market price transaction order can be fully matched and executed. If not all transactions are completed, continue to obtain the entrustment queue under the next price level, and determine whether the uncompleted part can be fully matched and executed, until the price level is obtained to a reasonable price level or is fully matched and executed. If it is determined that all transactions can be matched and executed, they will be matched in sequence according to the above logical order, otherwise the order will be automatically cancelled;
[0143] When it is an instant operation type, the market order book is located according to the transaction target code, the counterparty market data is obtained according to the transaction direction, and then the corresponding price level is matched according to the latest transaction price, the entrustment queue under the corresponding price level is obtained, the entrustment queue is traversed, and the market price transaction order is simulated and matched. If all transactions are not completed, the entrustment queue under the adjacent price level will continue to be simulated and matched until the price level is obtained at a reasonable price level or all transactions are matched and completed. If there is a remaining quantity of the market price transaction order, the remaining quantity will be converted into a limit price transaction order with the most recent matching transaction price as the transaction target price.
[0144] The above transaction stages are combined with specific implementation examples, and the detailed process is as follows:
[0145] During the call auction stage, only limit orders are allowed for new trading orders. No simulated matching will be performed for new trading orders to be simulated. For limit trading orders to be simulated, the order data in the buy and sell directions of the order book to be simulated are located according to the security code and the buy and sell directions. Then, the corresponding price level is matched according to the entrusted price, and the order queue under the corresponding level is obtained. The order to be simulated is inserted at the end of the order queue, and the call auction transaction order triggers the simulated matching of the order book to be simulated and the market order book.
[0146] In the continuous bidding phase, new trading orders to be simulated and matched are simulated and matched with the real-time market order book in the order of price priority and time priority. Different order types allow different price levels and remaining quantity processing.
[0147] Limit price is the limit price trading type: if the commission price of the buy order to be simulated is greater than or equal to the latest market price, locate the market order book according to the security code, obtain the sell market data, and then match the corresponding price level according to the latest transaction price, obtain the commission queue under the corresponding level, traverse the commission queue, and simulate matching with the current limit price trading order; if all the market orders at this price level are simulated, and the limit price trading order is not completely executed, continue to simulate matching with the commission queue under the adjacent price level until the commission price < the market selling price or the commission quantity is fully executed. The sell order is the opposite.
[0148] The best five-level instant transaction and the remaining cancellation are the first part of the transaction type: for simulated matching buy (sell) orders, locate the market order book according to the security code, sell (buy) market data in the market order book, traverse the price levels from the first price to the fifth price, obtain the entrustment queue under the corresponding level, and simulate matching with the market order. According to the above logic, the best five-level price matching is carried out. If there is a remaining quantity of the market order, the remaining quantity of trading orders will be automatically cancelled.
[0149] The remaining amount of the best five-level instant transaction is converted to a limit price, which is the second part of the transaction type: for simulated matching buy (sell) orders, locate the market order book according to the security code, sell (buy) market data in the market order book, traverse the price levels from the first price to the fifth price, obtain the entrustment queue under the corresponding level, and simulate matching with the market order. According to the above logic, the best five-level price matching is carried out. If there is a remaining quantity of the market order, the remaining quantity is converted to a limit order with the most recent simulated matching transaction price as the entrustment price.
[0150] The first conversion type is the best price to limit price conversion: for simulated matching buy (sell) orders, locate the market order book according to the security code, buy (sell) market data in the market order book, take the first buy (sell) price as the entrustment price and convert it into a limit order.
[0151] The counterparty's best price submission is the second conversion type: for simulated matching buy (sell) orders, locate the market order book according to the security code, sell (buy) market data in the market order book, take the sell (buy) first price as the entrustment price to convert it into a limit order, and traverse and match it with the entrustment list under the sell (buy) first price level in the sell (buy) market data in the market order book.
[0152] Full transaction or cancellation means all operation types: for simulated matching buy (sell) orders, locate the market order book according to the security code, sell (buy) market data in the market order book, traverse all price levels from the first selling (buying) price, obtain the order list under the corresponding level, and determine whether the market order can be fully matched and executed. If so, simulate matching in sequence according to the above logical order, otherwise the order will be automatically cancelled.
[0153] Instant transaction remaining cancellation is instant operation type: for simulated matching buy (sell) orders, locate the market order book according to the security code, sell (buy) market data in the market order book, traverse all price levels from the first selling (buying) price, obtain the entrustment list under the corresponding level, and simulate matching with the market order. If the market order has remaining quantity, the remaining quantity will be converted into a limit order with the most recent simulated matching transaction price as the entrustment price.
[0154] In one embodiment, when the order to be simulated is a new transaction order, the following steps are included:
[0155] The information of the new transaction order shall at least include: transaction number, transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price;
[0156] Locate the corresponding market order book through the transaction target code, and locate the counterparty's market order data through the transaction direction;
[0157] Simulate matching of market data with new trading orders based on price priority and time priority;
[0158] If the limit order meets the preset conditions, it will be matched and traded; the best trading order of our party takes the best trading price level of our market data as the entrustment price and is converted into a limit order; the market price trading order is limited to the matching price level and the remaining quantity processing method according to the specific trading order type;
[0159] If there is still a remaining quantity after the simulated matching, the remaining number of new trading orders will be inserted into the pending order book to be simulated matched. Among them, the pending order price of the market price trading order that has not been automatically cancelled is determined according to the specific transaction type; for the pending order that has not been executed, the last transaction number of the entrustment queue under the price level that matches the pending order price in the market data of the market order book is recorded, which is used to count the number of quotes that are better than the current pending order at the same price level when matching pending orders.
[0160] In one embodiment, when the order to be simulated is a pending transaction order, the following steps are included:
[0161] The information of pending order includes transaction number, transaction target code, transaction direction, transaction target price, remaining quantity, and market transaction number;
[0162] The corresponding order book to be simulated matching is located according to the transaction target code of the transaction order, and the counterparty order data is located according to the transaction direction of the transaction order.
[0163] The pending order data is simulated and matched with the transaction orders in the order of price priority and time priority.
[0164] The number of quotes that can be matched for this quote order = the number of transaction orders - the number of quotes that are better than the pending order to be simulated matched. When the number of quotes that can be matched for this quote is greater than 0, simulated matching is performed. The number of quotes that are better than the pending order to be simulated matched includes the number of all quotes whose prices are better than the pending order to be simulated matched and the number of all quotes whose time at this price level is better than the pending order to be simulated matched.
[0165] Embodiment 2:
[0166] A system for quickly implementing order simulation matching, such as Figure 6 As shown, it includes an order acquisition module 100, a positioning storage module 200, a matching update module 300, an acquisition judgment module 400 and a matching determination module 500;
[0167] The order acquisition module 100 acquires and parses the transaction orders one by one based on the time sequence of the transaction orders, and obtains transaction order information, wherein the transaction order information at least includes the transaction type, transaction direction, transaction price, transaction number and transaction target code;
[0168] The positioning storage module 200 locates the corresponding market order book through a multi-threaded model, and stores the transaction order information in the corresponding market order book;
[0169] The matching and updating module 300 matches the corresponding restoration logic based on the transaction type of each transaction order, and updates the market order book through the restoration logic to form a new market order book;
[0170] The acquisition and judgment module 400 is used to obtain the order to be simulated, judge the validity of the order to be simulated, and obtain the judgment result, wherein the information of the order to be simulated includes the transaction target code, transaction direction, transaction type, transaction target quantity and transaction target price;
[0171] The matching determination module 500 is configured to: if the order to be simulated matching is a valid order, locate the new market order book according to the transaction target code, determine the transaction stage involved in the order to be simulated matching according to the update time, and perform simulated matching in the transaction stage through the corresponding matching method according to the transaction type to obtain the matching result.
[0172] In one embodiment, the positioning storage module 200 is configured to:
[0173] The multi-threaded model includes a primary index, a secondary index and a market order book;
[0174] The primary index is a thread pool index, the index value of the thread pool index is a processing thread, and the processing thread is a result obtained by taking a modulus of the data of the transaction target code;
[0175] The secondary index is an order book index, the index value of the order book index is a hash value, and the hash value is a result of hashing the data of the transaction target code;
[0176] The data of the transaction target code is modulo, the corresponding processing thread is initially matched, the transaction target code is hashed, and the corresponding market order book is matched through the hash value.
[0177] In one embodiment, the market order book is provided with a storage structure of at least three dimensions;
[0178] The first dimension of the storage structure is used to store data sets that classify market data by transaction direction;
[0179] The second dimension of the storage structure is used to store a data set classified by transaction price level based on the data set of the first dimension;
[0180] The third dimension of the storage structure is used to store unique entrustment queue data by transaction number based on the second dimension data set.
[0181] Various changes and modifications can be made without departing from the spirit and scope of the present invention, and all equivalent technical solutions also belong to the scope of the present invention.
[0182] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0183] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods, devices or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0184] The present invention is described with reference to the flowcharts and / or block diagrams of the method, terminal device (system), and computer program product according to the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0185] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0186] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0187] It should be noted that:
[0188] The "one embodiment" or "embodiment" mentioned in the specification means that the specific features, structures or characteristics described in conjunction with the embodiment are included in at least one embodiment of the present invention. Therefore, the phrases "one embodiment" or "embodiment" appearing in various places throughout the specification do not necessarily refer to the same embodiment.
[0189] In addition, it should be noted that the shapes and names of the parts and components of the specific embodiments described in this specification may be different. Any equivalent or simple changes made based on the structure, features and principles described in the patent concept of the present invention are included in the protection scope of the patent of the present invention. The technicians in the technical field of the present invention can make various modifications or supplements to the specific embodiments described or replace them in a similar manner, as long as they do not deviate from the structure of the present invention or exceed the scope defined by the claims, they should all fall within the protection scope of the present invention.
Claims
1. A method for quickly implementing simulated order matching. It is characterized in that The following steps are involved: Based on the time sequence of each transaction order, the transaction orders are obtained and parsed to obtain transaction order information, wherein the transaction order information at least includes transaction type, transaction direction, transaction price, transaction number and transaction target code; The corresponding market order book is located through a multi-threaded model, and the transaction order information is stored in the corresponding market order book; Matching corresponding restoration logic based on the transaction type of the transaction order, and updating the market order book through the restoration logic to form a new market order book; Obtaining the pending simulated matching orders, judging the validity of the pending simulated matching orders, and obtaining the judgment results, wherein the pending simulated matching order information includes the transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price; If the order to be simulated is a valid order, locate the new market order book according to the transaction target code, determine the transaction stage involved in the order to be simulated according to the update time, and perform simulated matching in the transaction stage according to the corresponding matching method according to the transaction type to obtain the matching result; Among them, locating the corresponding market order book through the multi-threaded model includes the following steps: The multi-threaded model includes a primary index, a secondary index and a market order book; The primary index is a thread pool index, the index value of the thread pool index is a processing thread, and the processing thread is a result obtained by taking a modulus of the data of the transaction target code; The secondary index is an order book index, the index value of the order book index is a hash value, and the hash value is a result of hashing the data of the transaction target code; The data of the transaction target code is modulo, the corresponding processing thread is initially matched, the transaction target code is hashed, and the corresponding market order book is matched through the hash value.
2. The method for quickly achieving order simulation matching according to claim 1, It is characterized in that The market order book is provided with a storage structure of at least three dimensions; The first dimension of the storage structure is used to store data sets that classify market data by transaction direction; The second dimension of the storage structure is used to store a data set that classifies the data set of the first dimension according to the transaction price level; The third dimension of the storage structure is used to store the entrustment queue data of the second dimension data set that is unique by transaction number.
3. The method for quickly achieving order simulation matching according to claim 1, It is characterized in that The transaction type in the transaction order information includes a first entrustment type and a first transaction type; The first order type includes a new transaction order and a first cancellation order; the first transaction type includes a first transaction direction order, a second transaction direction order and a third transaction direction order; The updating of the market order book includes the following steps: When it is a new transaction order, the market data of the transaction direction of the corresponding market order book is matched according to the transaction target code and the transaction direction, and then the corresponding transaction price level is matched according to the transaction target price, and the entrustment queue under the corresponding level is obtained, and the new transaction order information is inserted at the end of the entrustment queue; When it is the first cancellation order, the market data of the transaction direction of the corresponding market order book is matched according to the transaction target code and the transaction direction, and then the corresponding transaction price level is matched according to the transaction target price, and the entrustment queue under the corresponding level is obtained, and the transaction number of the first cancellation order is searched in the entrustment queue based on the binary search method and deleted from the queue; When it is an order for the first transaction direction, locate the corresponding market order book according to the transaction target code, find the corresponding transaction price level in the selling market data according to the transaction transaction price, and obtain the entrustment queue under the corresponding level. The first transaction order in the entrustment queue is the current transaction order. If the remaining quantity of the order minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, delete the current transaction order from the order queue. When it is an order for the second transaction direction, locate the corresponding market order book according to the transaction target code, find the corresponding transaction price level in the buy market data according to the transaction transaction price, obtain the entrustment queue under the corresponding level, and the first transaction order in the entrustment queue is the current transaction order. If the remaining quantity of the order minus the current transaction order transaction quantity is greater than 0, update the remaining quantity of the current transaction order. If all transactions are completed, delete the current transaction order from the order queue; When it is an order for the third transaction direction, the orders of both parties of the third transaction direction are judged. If it is an order for the first transaction direction, the corresponding market order book is located according to the transaction target code, and the corresponding transaction price level is found in the buy market data according to the transaction transaction price. The entrustment queue under the corresponding level is obtained, and the first transaction order of the entrustment queue is judged according to the transaction number whether it is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continued to be judged until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, The current transaction order will be deleted from the order queue; if it is an order for the second transaction direction, the corresponding market order book will be located according to the transaction target code, and the corresponding transaction price level will be found in the selling market data according to the transaction transaction price, and the entrustment queue under the corresponding level will be obtained. According to the transaction number, it is judged whether the first transaction order in the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels will be taken for judgment until the transaction order is obtained. If the remaining quantity of the order minus the transaction quantity of the current transaction order is greater than 0, the remaining quantity of the current transaction order will be updated. If all transactions are completed, the current transaction order will be deleted from the order queue.
4. The method for rapidly achieving order simulation matching according to claim 1, It is characterized in that The transaction type in the transaction order information further includes a second entrustment type and a second transaction type, wherein the second entrustment type includes a limit transaction order, a best transaction order and a market price transaction order; and the second transaction type includes a transaction order and a second cancellation order; The updating of the market order book includes the following steps: When it is a limit order, locate the market data of the transaction direction of the market order book according to the transaction target code and transaction direction, and then match the corresponding transaction price level according to the transaction target price, obtain the entrustment queue under the corresponding level, and insert the current limit order at the end of the entrustment queue; When it is the best trading order, locate the market data of the trading direction of the market order book according to the trading target code and the trading direction, obtain the best trading price in the corresponding market data, convert the current trading order into a limit trading order with the best trading price as the trading target price, obtain the entrustment queue under the corresponding gear based on the trading price level corresponding to the limit trading order, and insert the corresponding current best trading order at the end of the entrustment queue; When it is a market price trading order, locate the market data of the corresponding market order book trading direction according to the trading target code and the trading direction, obtain the entrustment queue under the corresponding level at the market price level of the corresponding market data, and insert the current market price trading order into the entrustment queue; When it is a completed order, the orders of both parties of the completed order are judged. If it is the first completed order, the corresponding market order book is located according to the transaction target code, and the entrustment queue is obtained under the market price level of the buy market data. The market price transaction order is matched according to the transaction number. If the match is unsuccessful, the corresponding transaction price level is found in the buy market data according to the transaction transaction price, and the entrustment queue under the corresponding level is obtained. According to the transaction number, it is judged whether the first transaction order in the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continued to be judged until the transaction order is obtained. If the remaining order quantity minus the current transaction order transaction quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, the current The transaction order is deleted from the order queue; if it is the second executed order, the corresponding market order book is located according to the transaction target code, the entrustment queue is obtained under the market price level of the selling market data, and the market price transaction order is matched according to the transaction number. If the match is unsuccessful, the corresponding transaction price level is found in the selling market data according to the transaction transaction price, and the entrustment queue under the corresponding level is obtained. According to the transaction number, it is judged whether the first transaction order of the entrustment queue is the current transaction order. If not, the first transaction order of the entrustment queue under other price levels is continuously obtained for judgment until the transaction order is obtained. If the remaining order quantity minus the current transaction order execution quantity is greater than 0, the remaining quantity of the current transaction order is updated. If all transactions are completed, the current transaction order is deleted from the order queue; When it is the second cancellation order, the market data of the transaction direction of the corresponding market order book is located according to the transaction target code and the transaction direction, and the market price transaction level is obtained. The entrustment queue under the level matches the market price transaction order according to the transaction number. If the match is successful, the current transaction order is deleted from the order queue; if the match is unsuccessful, it is not a market price transaction order, and the corresponding transaction price level is matched according to the transaction target price, the entrustment queue under the corresponding level is obtained, and the transaction number of the second cancellation order is searched in the entrustment queue based on the binary search method and deleted from the queue.
5. The method for rapidly achieving order simulation matching according to claim 1, It is characterized in that The transaction stages of the order matching to be simulated include a call auction stage and a continuous auction stage, and the transaction types include a limit transaction type, a first part transaction type, a second part transaction type, a first conversion type, a second conversion type, all operation types and an instant operation type.
6. The method for rapidly achieving simulated order matching according to claim 5, It is characterized in that According to the transaction stage and transaction type, the corresponding matching method is triggered to perform simulated matching and obtain the matching result, including the following steps: During the call auction phase, no simulated matching is performed on new trading orders to be simulated. For limit price trading orders to be simulated, the pending order data of the pending order book to be simulated is located according to the trading target code and trading direction. Then, the corresponding price level is matched according to the trading target price, and the pending order queue under the corresponding level is obtained. The pending order to be simulated is inserted at the end of the pending order queue. The pending order to be traded at the call auction triggers the simulated matching of the pending order book to be simulated and the market order book. During the continuous bidding phase, new trading orders to be simulated and matched are simulated with the market order book based on price priority and time priority. Different transaction types are allowed to match different price levels and remaining quantity processing; When it is a limit transaction type, if the transaction target price of the buy order to be simulated matched is not less than the latest transaction price, the market order book is located according to the transaction target code, the sell market data is obtained, and then the corresponding price level is matched according to the latest transaction price, the entrustment queue under the corresponding level is obtained, the entrustment queue is traversed, and simulated matching is performed with the current limit transaction order; if all the market orders of the current price level are simulated matched and the limit transaction order is not completely executed, the entrustment queue under the adjacent price level will continue to be simulated matched until the buy transaction target price is less than the sell transaction price or the transaction target quantity is fully executed. ; If it is a sell order to be simulated, if the target price of the sell order is not greater than the latest transaction price, locate the market order book according to the transaction target code, obtain the buy market data, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding level, traverse the entrustment queue, and simulate matching with the current limit order; if all the market orders at this price level are simulated, and the limit order is not completely executed, continue to take the entrustment queue under the adjacent price level for simulated matching until the sell transaction target price is greater than the buy transaction price or the transaction target quantity is fully executed; When it is the first part of the transaction type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and simulate matching with the market price transaction order. If the transaction order is not completely executed, continue to obtain the entrustment queue under the adjacent price level for simulated matching until the transaction price is reasonable or the transaction target quantity is fully executed. If the transaction target quantity is not fully executed, the remaining quantity will be automatically cancelled; When it is the second part of the transaction type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and simulate matching with the market price transaction order. If the transaction order is not completely executed, continue to obtain the entrustment queue under the adjacent price level for simulated matching until the transaction price is reasonable or the transaction target quantity is fully executed. If the transaction target quantity is not fully executed, the remaining quantity will be converted into a limit transaction order with the most recent matching transaction price as the transaction target price; When it is the first conversion type, locate the market order book according to the transaction target code, obtain market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price to obtain the entrustment queue under the corresponding price level. If there is no order in the entrustment queue, continue to obtain the entrustment queue under the adjacent price level until there is an order record in the entrustment queue, and convert it into a limit transaction order with the transaction price of the current price level as the transaction target price; When it is the second conversion type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, if there is no order in the entrustment queue, continue to obtain the entrustment queue under the adjacent price level, until there is an order record in the entrustment queue, traverse the entrustment queue and simulate matching with the market price transaction order, if the transaction order is not completely executed, the remaining quantity is converted into a limit price transaction order with the most recent matching transaction price as the transaction target price; When it is the all operation type, locate the market order book according to the transaction target code, obtain the counterparty market data according to the transaction direction, and then match the corresponding price level according to the latest transaction price, obtain the entrustment queue under the corresponding price level, traverse the entrustment queue, and determine whether the market price transaction order can be fully matched and executed. If not all transactions are completed, continue to obtain the entrustment queue under the next price level, and determine whether the uncompleted part can be fully matched and executed, until the price level is obtained to a reasonable price level or is fully matched and executed. If it is determined that all transactions can be matched and executed, they will be matched in sequence according to the above logical order, otherwise the order will be automatically cancelled; When it is an instant operation type, the market order book is located according to the transaction target code, the counterparty market data is obtained according to the transaction direction, and then the corresponding price level is matched according to the latest transaction price, the entrustment queue under the corresponding price level is obtained, the entrustment queue is traversed, and the market price transaction order is simulated and matched. If all transactions are not completed, the entrustment queue under the adjacent price level will continue to be simulated and matched until the price level is obtained at a reasonable price level or all transactions are matched and completed. If there is a remaining quantity of the market price transaction order, the remaining quantity will be converted into a limit price transaction order with the most recent matching transaction price as the transaction target price.
7. The method for rapidly achieving order simulation matching according to claim 1, It is characterized in that When the order to be simulated is a new transaction order, the following steps are included: The information of the new transaction order shall at least include: transaction number, transaction target code, transaction direction, transaction type, transaction target quantity, and transaction target price; Locate the corresponding market order book through the transaction target code, and locate the counterparty market data through the transaction direction; Simulate matching of market data with new trading orders based on price priority and time priority; If the limit order meets the preset conditions, it will be matched and traded; the best trading order of our party takes the best price level trading price of our party's market data as the trading target price and is converted into a limit order; the market price trading order is limited to the matching price level and the remaining quantity processing method according to the specific trading order type; If there is still a remaining quantity after the simulated matching, the remaining number of new trading orders will be inserted into the pending order book to be simulated matched. Among them, the pending order price of the market price trading order that has not been automatically cancelled is determined according to the specific transaction type; for the pending orders that have not been executed, the market data of the transaction direction of the market order book is recorded, and the last transaction number of the entrustment queue under the price level is matched with the pending order price, which is used to count the number of quotes that are better than the current pending order at the same price level when matching pending orders.
8. The method for rapidly achieving order simulation matching according to claim 1, It is characterized in that When the order to be simulated is a pending order, the following steps are included: The information of pending order includes transaction number, transaction target code, transaction direction, transaction target price, remaining quantity, and market transaction number; Locate the corresponding pending order book to be simulated based on the transaction target code of the transaction order, and locate the counterparty pending order data based on the transaction direction of the transaction order; The pending order data is simulated matched with the transaction order in the order of price priority and time priority. Specifically, the matching quantity of this transaction order = the number of transaction orders - the number of quotes that are better than the pending order to be simulated matched. When the matching quantity of this quote is greater than 0, simulated matching is performed. The number of quotes that are better than the pending order to be simulated matched includes the number of all quotes whose prices are better than the pending order to be simulated matched and the number of all quotes whose times are better than the pending order to be simulated matched at this price level.
9. A system for quickly implementing simulated order matching. It is characterized in that It includes order acquisition module, positioning storage module, matching update module, acquisition judgment module and matching determination module; The order acquisition module acquires and analyzes the transaction orders one by one based on the time sequence of the transaction orders, and obtains transaction order information, wherein the transaction order information at least includes the transaction type, transaction direction, transaction price, transaction number and transaction target code; The positioning storage module locates the corresponding market order book through a multi-threaded model, and stores the transaction order information in the corresponding market order book; The matching and updating module matches the corresponding restoration logic based on the transaction type of each transaction order, and updates the market order book through the restoration logic to form a new market order book; The acquisition and judgment module is used to obtain the matching order to be simulated, judge the validity of the matching order to be simulated, and obtain the judgment result, wherein the matching order information to be simulated includes the transaction target code, transaction direction, transaction type, transaction target quantity and transaction target price; The matching determination module is configured to: if the order to be simulated matching is a valid order, locate the new market order book according to the transaction target code, determine the transaction stage involved in the order to be simulated matching according to the update time, and simulate matching in the transaction stage according to the corresponding matching method according to the transaction type to obtain the matching result; Wherein, the positioning storage module is configured as: The multi-threaded model includes a primary index, a secondary index and a market order book; The primary index is a thread pool index, the index value of the thread pool index is a processing thread, and the processing thread is a result obtained by taking a modulus of the data of the transaction target code; The secondary index is an order book index, the index value of the order book index is a hash value, and the hash value is a result of hashing the data of the transaction target code; The data of the transaction target code is modulo, the corresponding processing thread is initially matched, the transaction target code is hashed, and the corresponding market order book is matched through the hash value.
10. A computer-readable storage medium storing a computer program. It is characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
11. A device for quickly implementing simulated order matching, comprising a memory, a processor, and a computer program stored in the memory and running on the processor, It is characterized in that When the processor executes the computer program, the method according to any one of claims 1 to 8 is implemented.
