[go: up one dir, main page]

CN118674531B - Method, system and device for quickly realizing order simulation matching - Google Patents

Method, system and device for quickly realizing order simulation matching Download PDF

Info

Publication number
CN118674531B
CN118674531B CN202411163890.8A CN202411163890A CN118674531B CN 118674531 B CN118674531 B CN 118674531B CN 202411163890 A CN202411163890 A CN 202411163890A CN 118674531 B CN118674531 B CN 118674531B
Authority
CN
China
Prior art keywords
transaction
order
price
market
entrustment
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202411163890.8A
Other languages
Chinese (zh)
Other versions
CN118674531A (en
Inventor
童卫
冯杰
余艳玲
李斌
刘士毅
徐雪
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zheshang Securities Co ltd
Original Assignee
Zheshang Securities Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zheshang Securities Co ltd filed Critical Zheshang Securities Co ltd
Priority to CN202411163890.8A priority Critical patent/CN118674531B/en
Publication of CN118674531A publication Critical patent/CN118674531A/en
Application granted granted Critical
Publication of CN118674531B publication Critical patent/CN118674531B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/06Buying, selling or leasing transactions
    • G06Q30/0601Electronic shopping [e-shopping]
    • G06Q30/0633Lists, e.g. purchase orders, compilation or processing
    • G06Q30/0635Processing of requisition or of purchase orders
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02PCLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
    • Y02P90/00Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
    • Y02P90/30Computing systems specially adapted for manufacturing

Landscapes

  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • Development Economics (AREA)
  • Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Physics & Mathematics (AREA)
  • General Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

The invention discloses a method, a system and a device for rapidly realizing order simulation matching, comprising the following steps: based on the time sequence generated by each transaction order, acquiring each transaction order and analyzing to obtain transaction order information; positioning the corresponding market place order book through the multi-thread model and storing the transaction order information in the market place order book; based on the transaction types of the transaction orders, corresponding restoring logic is matched, and the quotation order book is updated through the restoring logic to form a new quotation order book; acquiring a matching order to be simulated, and judging the effectiveness of the matching order to be simulated to obtain a judging result; if the order is an effective order, a new quotation order book is positioned according to a transaction target code, a transaction stage related to the to-be-simulated matching order is determined, and a simulation matching is carried out in a corresponding matching mode to obtain a matching result. According to the invention, the corresponding quotation order book is positioned through the multithread model, so that the reduction and updating of the quotation order book can be completed rapidly; and the strategy return testing effectiveness is improved.

Description

快速实现订单模拟撮合的方法、系统及装置Method, system and device for quickly realizing order simulation matching

技术领域Technical Field

本发明涉及数据处理技术领域,尤其涉及一种快速实现订单模拟撮合的方法、系统及装置。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

在现有的订单模拟撮合中,一般是通过历史逐笔行情作为基础数据,严格按照逐笔行情产生的先后顺序,对新交易订单、撤单、成交的逐笔行情按各自业务逻辑更新还原行情订单簿,进而在还原行情订单簿过程中接入用户策略订单,模拟用户策略订单与实时行情订单仿真撮合。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.

现有的做法中,会出现以下问题:The following problems may arise in the existing practices:

行情订单簿还原较慢:当进行某一个时间段的策略回测时(比如近一年的历史逐笔行情),由于历史逐笔行情的数据量非常大,因此在更新行情订单簿时,查找和定位逐笔行情涉及的订单在行情订单簿的具体位置时非常耗时;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;

由于撮合支持功能有限会导致回测与实际交易有较大偏差:竞价交易不同交易阶段、不同交易类型的撮合规则均不同,业务逻辑复杂,支持度不够;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;

采用内存数据库作为基础数据结构,会导致行情插入回放耗时较大,对行情回放量巨大且只包含简单索引的撮合场景不适用。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

本发明针对现有技术中的缺点,提供了一种快速实现订单模拟撮合的方法、系统及装置。In view of the shortcomings of the prior art, the present invention provides a method, system and device for quickly realizing order simulation matching.

为了解决上述技术问题,本发明通过下述技术方案得以解决:In order to solve the above technical problems, the present invention is solved by the following technical solutions:

一种快速实现订单模拟撮合的方法,包括以下步骤:A method for quickly implementing simulated order matching includes the following steps:

基于逐笔交易订单产生的时间顺序,获取逐笔交易订单并解析,得到交易订单信息,其中,交易订单信息至少包括交易类型、交易成交方向、交易成交价格、交易编号及交易目标代码;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 order to be simulated, judging the validity of the order to be simulated, and obtaining 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;

若待模拟撮合订单为有效订单,则根据交易目标代码定位新行情订单簿,根据更新时间确定待模拟撮合订单涉及的交易阶段,根据交易类型在所述交易阶段通过对应的撮合方式进行模拟撮合,得到撮合结果。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.

作为一种可实施方式,通过多线程模型定位相应的行情订单簿,包括以下步骤:As an implementable method, locating the corresponding market order book through a 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.

作为一种可实施方式,所述行情订单簿设有至少三个维度的存储结构;As an implementable embodiment, 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.

作为一种可实施方式,所述交易订单信息中的交易类型包括第一委托类型和第一成交类型;As an implementable method, 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;

当为第一成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,所述委托队列的第一笔交易订单即为当前交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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.

当为第二成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,所述委托队列的第一笔交易订单即为当前交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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;

当为第三成交方向订单时,对第三成交方向订单的成交双方订单进行判断,若为第一成交方向订单,则根据交易目标代码定位相应的行情订单簿,根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为第二成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除。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.

作为一种可实施方式,所述交易订单信息中的交易类型还包括第二委托类型及第二成交类型,所述第二委托类型包括限价交易订单、最优交易订单及市场价格交易订单;所述第二成交类型包括成交订单及第二撤销订单;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;

则所述对行情订单簿进行更新,包括以下步骤: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;

当为成交订单时,对成交订单的成交双方订单进行判断,若为第一成交订单,则根据交易目标代码定位相应的行情订单簿,在买入行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为第二成交订单时,根据交易目标代码定位相应的行情订单簿,在卖出行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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.

作为一种可实施方式,所述待模拟撮合订单交易阶段包括集合竞价阶段、连续竞价阶段,所述交易类型包括限价交易类型、第一部分成交类型、第二部分成交类型、第一转换类型、第二转换类型、全部操作类型及即时操作类型。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.

作为一种可实施方式,根据交易阶段、交易类型触发相应的撮合方式进而进行模拟撮合,得到撮合结果,包括以下步骤: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:

当集合竞价阶段时,对待模拟撮合新交易订单不进行模拟撮合,对待模拟撮合限价交易订单按交易目标代码、交易成交方向定位待模拟撮合挂单订单簿交易成交方向的挂单数据,进而根据交易目标价格匹配对应价格档位,获取相应档位下的挂单队列,在挂单队列最后插入待模拟撮合挂单,待集合竞价成交订单触发待模拟撮合挂单订单簿与行情订单簿模拟撮合;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.

作为一种可实施方式,所述待模拟撮合订单为新交易订单时,包括以下步骤:As an implementable method, when the order to be simulated and matched 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.

作为一种可实施方式,当待模拟撮合订单为挂单交易订单时,包括以下步骤:As an implementable method, when the order to be simulated is a pending transaction 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;

对挂单数据通过价格优先、时间优先的顺序与逐笔交易订单进行模拟撮合,具体为:本笔逐笔交易订单可撮合数量 = 逐笔交易订单数量-优于待模拟撮合挂单的行情数量,当本笔行情可撮合数量大于0时,进行模拟撮合,其中,优于待模拟撮合挂单的行情数量,包括价格优于本待模拟撮合挂单的所有行情数量、本价格档位上时间优于本待模拟撮合挂单的所有行情数量。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.

一种快速实现订单模拟撮合的系统,包括订单获取模块、定位存储模块、匹配更新模块、获取判断模块及确定撮合模块;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;

所述订单获取模块,基于逐笔交易订单产生的时间顺序,获取逐笔交易订单并解析,得到交易订单信息,其中,交易订单信息至少包括交易类型、交易成交方向、交易成交价格、交易编号及交易目标代码;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 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;

所述确定撮合模块,被设置为:若待模拟撮合订单为有效订单,则根据交易目标代码定位新行情订单簿,根据更新时间确定待模拟撮合订单涉及的交易阶段,根据交易类型在所述交易阶段通过对应的撮合方式进行模拟撮合,得到撮合结果。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.

作为一种可实施方式,所述定位存储模块,被设置为:As an implementable embodiment, the positioning storage module is configured as follows:

所述多线程模型包括一级索引、二级索引及行情订单簿;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.

一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现如下所述的方法:A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following method is implemented:

基于逐笔交易订单产生的时间顺序,获取逐笔交易订单并解析,得到交易订单信息,其中,交易订单信息至少包括交易类型、交易成交方向、交易成交价格、交易编号及交易目标代码;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 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.

一种快速实现订单模拟撮合的装置,包括存储器、处理器以及存储在所述存储器中并在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如下所述的方法: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:

基于逐笔交易订单产生的时间顺序,获取逐笔交易订单并解析,得到交易订单信息,其中,交易订单信息至少包括交易类型、交易成交方向、交易成交价格、交易编号及交易目标代码;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 order to be simulated, judging the validity of the order to be simulated, and obtaining 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;

若待模拟撮合订单为有效订单,则根据交易目标代码定位新行情订单簿,根据更新时间确定待模拟撮合订单涉及的交易阶段,根据交易类型在所述交易阶段通过对应的撮合方式进行模拟撮合,得到撮合结果。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.

本发明由于采用了以上技术方案,具有显著的技术效果:The present invention has significant technical effects due to the adoption of the above technical solution:

本发明通过多线程模型定位相应的行情订单簿,能够快速的完成行情订单簿的还原与更新;不同阶段设有不同的模拟撮合方式,提高策略回测有效性。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

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其他的附图。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.

图1是本发明方法的流程示意图;Fig. 1 is a schematic flow diagram of the method of the present invention;

图2是本发明多线程模型的示意图;FIG2 is a schematic diagram of a multi-threaded model of the present invention;

图3是本发明行情订单簿的示意图;FIG3 is a schematic diagram of a market order book of the present invention;

图4-图5分别是本发明还原逻辑的示意图;4-5 are schematic diagrams of the restoration logic of the present invention;

图6是本发明系统的结构示意图。FIG. 6 is a schematic diagram of the structure of the system of the present invention.

具体实施方式DETAILED DESCRIPTION

下面结合实施例对本发明做进一步的详细说明,以下实施例是对本发明的解释而本发明并不局限于以下实施例。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.

实施例1:Embodiment 1:

一种快速实现订单模拟撮合的方法,如图1所示,包括以下步骤:A method for quickly implementing order simulation matching, as shown in FIG1, includes the following steps:

S100、基于逐笔交易订单产生的时间顺序,获取逐笔交易订单并解析,得到交易订单信息,其中,交易订单信息至少包括交易类型、交易成交方向、交易成交价格、交易编号及交易目标代码;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;

S200、通过多线程模型定位相应的行情订单簿,并将逐笔交易订单信息存储于对应的行情订单簿中;S200, locating the corresponding market order book through the multi-threaded model, and storing the transaction order information in the corresponding market order book;

S300、基于逐笔交易订单的交易类型匹配相应的还原逻辑,通过所述还原逻辑对行情订单簿进行更新以形成新行情订单簿;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;

S400、获取待模拟撮合订单,对待模拟撮合订单的有效性进行判断,得到判断结果,其中,待模拟撮合订单信息包括交易目标代码、交易成交方向、交易类型、交易目标数量及交易目标价格;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;

S500、若待模拟撮合订单为有效订单,则根据交易目标代码定位新行情订单簿,根据更新时间确定待模拟撮合订单涉及的交易阶段,根据交易类型在所述交易阶段通过对应的撮合方式进行模拟撮合,得到撮合结果。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.

在步骤S200通过多线程模型定位相应的行情订单簿,包括以下步骤:In step S200, the corresponding market order book is located through the multi-threaded model, including 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所示,本发明能够快速实现订单模拟撮合是依赖于通过多线程模型定位相应的行情订单簿。多线程模型通过分页索引定位到行情订单簿,一级索引为线程池索引,线程池索引的索引值为处理线程,其为通过对交易目标代码的数据取模得到的结果;二级索引为订单簿索引,订单簿索引的索引值为哈希值,其为对交易目标代码的数据进行哈希处理得到的结果。通过二次索引能快速定位到具体的行情订单簿,查询的时间短并且复杂度低。As shown in Figure 2, 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, and the index value of the thread pool index is a processing thread, which is the result obtained by taking the module of the data of the transaction target code; the secondary index is an order book index, and 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.

如图3所示,由于交易目标代码(本实施例中可以为证券代码)的基本参数为涨跌停价格、最小价差会限制了对应股票的每日最高、最低买卖价格以及交易价格的最小价差。因此,为行情订单簿构建三维存储结构,存储结构的第一维度以买卖方向区分,存储结构的第一维度用于存储按交易成交方向分类的数据集,第二维度为以价格档位为下标的数组数据集。第一维度和第二维度数组长度确定,可以预分配内存并初始化;第三维度为自增循环数组,存储交易编号唯一的委托队列数据。收到逐笔交易订单时,根据交易订单信息的交易成交方向、交易成交价格及交易编号即可在三维存储结构的行情订单簿中快速定位需要处理的交易订单。As shown in Figure 3, 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 maximum and minimum 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 the transaction direction, and the second dimension is an array data set with the 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.

通俗的讲,第一维是买卖方向,通过这一维度将行情订单簿做了个买行情和卖行情的分类;第二维是价格档位,通过这一维度,在买、卖行情中按价格做了一个分类;第三维是做好了买卖方向、价格分类的委托队列明细,委托按交易编号唯一。行情订单簿是通过逐笔行情更新的;挂单订单簿是待模拟撮合新订单在首次撮合后未能全部成交,剩余部分转换为待模拟撮合挂单插入到挂单订单簿中,后续逐笔行情进入系统的时候,会去尝试与挂单订单簿中的待模拟撮合挂单撮合,这部分挂单若能被全部撮合掉会从挂单订单簿中删除,或者用户发起撤单可从挂单订单簿中删除。挂单订单簿的存储结构跟行情订单簿是一样的,就是里面的数据,一个是待模拟撮合的挂单数据,一个是交易所的逐笔行情数据。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.

在一个实施例中,所述交易类型包括第一委托类型和第一成交类型;In one embodiment, the transaction type 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;

当为第一成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,所述委托队列的第一笔交易订单即为当前交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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.

当为第二成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,所述委托队列的第一笔交易订单即为当前交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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;

当为第三成交方向订单时,对第三成交方向订单的成交双方订单进行判断,若为第一成交方向订单,则根据交易目标代码定位相应的行情订单簿,根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为第二成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除。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所示,将此流程的第一委托类型匹配到目前某A交易所的逐笔委托,第一成交类型匹配到目前某A交易所的逐笔成交,交易目标代码即为证券代码、交易成交方向即为买卖方向、交易目标价格即为委托价格,具体操作如下:Referring to a specific embodiment, as shown in FIG4 , the first entrustment type of this process is matched to the current transaction by transaction 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 transaction direction is the buying and selling direction, and the transaction target price is the entrustment price. The specific operations are as follows:

A交易所逐笔委托-新交易订单:根据逐笔委托的证券代码、买卖方向快速定位到相应行情订单簿买卖方向的行情数据,再根据委托价格定位到对应价格档位,获取相应档位下的委托队列,在所述委托队列最后插入本笔新交易订单。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.

A交易所逐笔委托-第一撤销订单:根据逐笔委托的证券代码、买卖方向快速定位相应行情订单簿买卖方向的行情数据,再根据委托价格定位到对应价格档位,获取相应档位下的委托队列。因为逐笔委托-新交易订单的交易编号是递增的,因此按时间顺序还原的行情订单簿对应价格档位下的委托队列中,交易编号是递增的(但不一定连续),可在队列中采用二分法查找被撤销的交易编号,找到第一撤销订单从队列中删除。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.

A交易所逐笔成交-第一成交方向订单即买主动成交订单:根据证券代码定位对应行情订单簿。根据成交价格在行情订单簿的卖出行情数据中,找到对应价格档位下的委托队列,队列的第一笔订单即为本次成交订单(撮合方式为价格优先、时间优先,故相同价格情况下,时间优先的订单会先成交),若订单剩余数量-本次成交数量>0,则更新本笔订单剩余数量,若全部成交则将该订单从委托队列中删除。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.

A交易所逐笔成交-第二成交方向订单即卖主动成交订单:根据证券代码定位对应行情订单簿。根据成交价格在行情订单簿的买入行情数据中,找到对应价格档位下的委托队列,队列的第一笔订单即为本次成交订单(撮合方式为价格优先、时间优先,故相同价格情况下,时间优先的订单会先成交),若订单剩余数量-本次成交数量>0,则更新本笔订单剩余数量,若全部成交则将该订单从委托队列中删除。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.

A交易所逐笔成交-第三成交方向订单即主动成交方未知订单:分别对成交双方进行判断,若为买方成交,则根据证券代码定位相应的行情订单簿,根据成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为卖方成交,根据证券代码定位相应的行情订单簿,根据成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除。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.

在一个实施例中,所述交易类型还包括第二委托类型及第二成交类型,所述第二委托类型包括限价交易订单、最优交易订单及市场价格交易订单;所述第二成交类型包括成交订单及第二撤销订单;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;

则所述对行情订单簿进行更新,包括以下步骤: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 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;

当为市场价格交易订单时,根据交易目标代码、交易成交方向定位对应行情订单簿交易成交方向的行情数据,在相应行情数据的市场价格档位,获取相应档位下的委托队列,在所述委托队列中插入当前市场价格交易订单;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;

当为成交订单时,对成交订单的成交双方订单进行判断,若为第一成交订单,则根据交易目标代码定位相应的行情订单簿,在买入行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为第二成交订单时,根据交易目标代码定位相应的行情订单簿,在卖出行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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 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.

参见一具体的实施例,如图5所示,将此流程的第二委托类型匹配到目前某B交易所的逐笔委托,第二成交类型匹配到目前某B交易所的逐笔成交,交易目标代码即为证券代码、交易成交方向即为买卖方向、交易目标价格即为委托价格,具体操作如下:Referring to a specific embodiment, as shown in FIG5 , the second entrustment type of this process is matched to the current transaction-by-transaction entrustment of a certain B exchange, the second transaction type is matched to the current transaction-by-transaction of a certain B exchange, the transaction target code is the security code, the transaction transaction direction is the buying and selling direction, and the transaction target price is the entrustment price. The specific operations are as follows:

B交易所逐笔委托-限价交易订单:根据逐笔委托的证券代码、买卖方向快速定位到相应的行情订单簿买卖方向的行情数据,再根据委托价格定位到对应价格档位,获取相应档位下的委托队列,在该队列最后插入本笔新交易订单。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.

B交易所逐笔委托-最优交易订单即本方最优交易订单:根据证券代码、买卖方向快速定位到相应行情订单簿买卖方向的行情数据,获取本方最优价,将本订单转换为以本方最优价为委托价格的限价单,基于委托价格对应交易价格档位,获取相应档位下的委托队列,在所述委托队列最后插入本笔新交易订单。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.

B交易所逐笔委托-市场价格交易订单:根据证券代码、买卖方向快速定位到相应行情订单簿买卖方向的行情数据,获取市场价格档位,在该档位下的委托队列中插入本笔新交易订单。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.

B交易所逐笔成交-成交订单:分别对成交双方进行判断,若为买方成交,则根据证券代码定位相应的行情订单簿,在买入行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为卖方成交时,根据证券代码定位相应的行情订单簿,在卖出行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除。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.

B交易所逐笔成交-第二撤销订单:根据证券代码、买卖方向快速定位到相应行情订单簿买卖方向的行情数据,获取市场价格档位,被撤销订单的交易编号先匹配市场价格档位下的委托队列(市场价格档位下委托队列在同一时刻最多只有一笔订单),若匹配成功则从该队列中删除第二撤销订单,若匹配不成功则非市场价格交易订单,则根据委托价格匹配对应的对应交易价格档位,获取相应档位下的委托队列,并基于二分法在所述委托队列中查找第二撤销订单的交易编号并从队列中删除。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.

在一个实施例中,所述交易阶段包括集合竞价阶段、连续竞价阶段,交易类型包括限价交易类型、第一部分成交类型、第二部分成交类型、第一转换类型、第二转换类型、全部操作类型及即时操作类型。则,根据交易阶段、交易类型触发相应的撮合方式进而进行模拟撮合,得到撮合结果,包括以下步骤: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:

当集合竞价阶段时,对待模拟撮合新交易订单不进行模拟撮合,对待模拟撮合限价交易订单按交易目标代码、交易成交方向定位待模拟撮合挂单订单簿交易成交方向的挂单数据,进而根据交易目标价格匹配对应价格档位,获取相应档位下的挂单队列,在挂单队列最后插入待模拟撮合挂单,待集合竞价成交订单触发待模拟撮合挂单订单簿与行情订单簿模拟撮合;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 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;

当为第二部分成交阶段时,根据交易目标代码定位行情订单簿,根据交易成交方向获取对手方行情数据,进而根据最新交易价格匹配对应价格档位,获取相应价格档位下的委托队列,遍历所述委托队列,与市场价格交易订单模拟撮合,若交易订单未完全成交,则继续取相邻档价格档位下的委托队列进行模拟撮合,直至交易价格合理或交易目标数量全部成交,若交易目标数量未全部成交,则剩余数量以最近撮合成交价为交易目标价格转为限价交易订单;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;

当为第一转换类型时,根据交易目标代码定位行情订单簿,根据交易成交方向获取行情数据,进而根据最新交易价格匹配对应价格档位,获取相应价格档位下的委托队列,若委托队列无订单则继续取相邻档价格档位下的委托队列,直至委托队列中存在订单记录,以当前价格档位的交易价格为交易目标价格转为限价交易订单;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.

以上交易阶段结合具体的实施例,详细过程如下:The above transaction stages are combined with specific implementation examples, and the detailed process is as follows:

在集合竞价阶段,新交易订单只允许限价单,对待模拟撮合新交易订单不进行模拟撮合,对待模拟撮合限价交易订单按证券代码、买卖方向定位待模拟撮合挂单订单簿买卖方向的挂单数据,进而根据委托价格匹配对应价格档位,获取相应档位下的挂单队列,在挂单队列最后插入待模拟撮合挂单,待集合竞价成交订单触发待模拟撮合挂单订单簿与行情订单簿模拟撮合。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.

在连续竞价阶段,待模拟撮合新交易订单与实时行情订单簿按价格优先、时间优先顺序模拟撮合。不同订单类型允许撮合的价格档位、剩余数量处理均不相同。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.

限价即限价交易类型:若待模拟撮合买入订单的委托价格>=行情最新价格,则根据证券代码定位行情订单簿,获取卖出行情数据,进而根据最新交易价格匹配对应价格档位,获取相应档位下的委托队列,遍历所述委托队列,与当前限价交易订单进行模拟撮合;若本价格档位的行情订单全部进行模拟撮合,限价交易订单未完全成交,则继续取相邻档价格档位下的委托队列进行模拟撮合,直至委托价格<行情卖出价格或委托数量全部成交。卖出订单与之相反。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.

最优五档即时成交剩余撤销即第一部分成交类型:对待模拟撮合买入(卖出)订单,根据证券代码定位行情订单簿,在行情订单簿卖出(买入)行情数据,依次遍历卖(买)一价至卖(买)五价价格档位,获取相应档位下的委托队列,与该市价订单模拟撮合。按以上逻辑进行最优五档价格撮合,若市价订单有剩余数量,则剩余数量的交易订单按自动撤销处理。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.

最优五档即时成交剩余转限价即第二部分成交类型:对待模拟撮合买入(卖出)订单,根据证券代码定位行情订单簿,在行情订单簿卖出(买入)行情数据,依次遍历卖(买)一价至卖(买)五价价格档位,获取相应档位下的委托队列,与该市价订单模拟撮合。按以上逻辑进行最优五档价格撮合,若市价订单有剩余数量,则剩余数量以最近模拟撮合成交价为委托价格转为限价订单。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.

本方最优价转限价即第一转换类型:对待模拟撮合买入(卖出)订单,根据证券代码定位行情订单簿,在行情订单簿买入(卖出)行情数据,取买(卖)一价为委托价格转为限价订单。Our best price to limit price conversion is the first conversion type: 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.

对手方最优价申报即第二转换类型:对待模拟撮合买入(卖出)订单,根据证券代码定位行情订单簿,在行情订单簿卖出(买入)行情数据,取卖(买)一价为委托价格转为限价订单,与行情订单簿卖出(买入)行情数据中卖(买)一价价格档位下的委托列表遍历撮合。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.

全额成交或撤销即全部操作类型:对待模拟撮合买入(卖出)订单,根据证券代码定位行情订单簿,在行情订单簿卖出(买入)行情数据,从卖(买)一价开始遍历所有价格档位,获取相应档位下的委托列表,判断该市价订单是否能被全部撮合成交,若能,则按以上逻辑顺序依次模拟撮合,否则本订单自动撤销。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.

即时成交剩余撤销即即时操作类型:对待模拟撮合买入(卖出)订单,根据证券代码定位行情订单簿,在行情订单簿卖出(买入)行情数据,从卖(买)一价开始遍历所有价格档位,获取相应档位下的委托列表,与该市价订单模拟撮合。若市价订单有剩余数量,则剩余数量以最近模拟撮合成交价为委托价格转为限价订单。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.

在一个实施例中,所述待模拟撮合订单为新交易订单时,包括以下步骤:In one embodiment, 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's market order 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 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;

若模拟撮合后还存在剩余数量,则将剩余数量的新交易订单插入待模拟撮合挂单订单簿,其中,未自动撤销的市场价格交易订单按具体交易类型确定挂单价格;对无成交的挂单,记录行情订单簿本方行情数据中,以挂单价格匹配价格档位下的委托队列的最后一笔交易编号,用于挂单撮合时统计相同价格档位上优于本挂单的行情数量。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.

在一个实施例中,当待模拟撮合订单为挂单交易订单时,包括以下步骤:In one embodiment, when the order to be simulated is a pending transaction 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;

根据逐笔交易订单的交易目标代码定位相应的待模拟撮合挂单订单簿,通过逐笔交易订单的交易成交方向定位对手方挂单数据。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.

对挂单数据通过价格优先、时间优先的顺序与逐笔交易订单进行模拟撮合。The pending order data is simulated and matched with the transaction orders in the order of price priority and time priority.

本笔行情订单可撮合数量 = 逐笔交易订单数量-优于待模拟撮合挂单的行情数量,当本笔行情可撮合数量大于0时,进行模拟撮合,其中,优于待模拟撮合挂单的行情数量,包括价格优于本待模拟撮合挂单的所有行情数量、本价格档位上时间优于本待模拟撮合挂单的所有行情数量。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 orders 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 orders to be simulated matched includes the number of all quotes whose prices are better than the pending orders to be simulated matched and the number of all quotes whose times at this price level are better than the pending orders to be simulated matched.

实施例2:Embodiment 2:

一种快速实现订单模拟撮合的系统,如图6所示,包括订单获取模块100、定位存储模块200、匹配更新模块300、获取判断模块400及确定撮合模块500;A system for quickly implementing order simulation matching, as shown in FIG6 , 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 ;

所述订单获取模块100,基于逐笔交易订单产生的时间顺序,获取逐笔交易订单并解析,得到交易订单信息,其中,交易订单信息至少包括交易类型、交易成交方向、交易成交价格、交易编号及交易目标代码;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;

所述定位存储模块200,通过多线程模型定位相应的行情订单簿,并将逐笔交易订单信息存储于对应的行情订单簿中;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;

所述匹配更新模块300,基于逐笔交易订单的交易类型匹配相应的还原逻辑,通过所述还原逻辑对行情订单簿进行更新以形成新行情订单簿;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;

所述获取判断模块400,用于获取待模拟撮合订单,对待模拟撮合订单的有效性进行判断,得到判断结果,其中,待模拟撮合订单信息包括交易目标代码、交易成交方向、交易类型、交易目标数量及交易目标价格;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;

所述确定撮合模块500,被设置为:若待模拟撮合订单为有效订单,则根据交易目标代码定位新行情订单簿,根据更新时间确定待模拟撮合订单涉及的交易阶段,根据交易类型在所述交易阶段通过对应的撮合方式进行模拟撮合,得到撮合结果。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.

一个实施例中,所述定位存储模块200,被设置为:In one embodiment, the positioning storage module 200 is configured to:

所述多线程模型包括一级索引、二级索引及行情订单簿;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.

一个实施例中,所述行情订单簿设有至少三个维度的存储结构;In one embodiment, 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 classified by transaction price level based on the data set of the first dimension;

存储结构的第三维度用于存储在第二维度数据集的基础上按交易编号唯一的委托队列数据。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.

在不脱离本发明的精神和范围的情况下做出的各种变化和变型,所有等同的技术方案也属于本发明的范畴。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.

本说明书中的各个实施例均采用递进的方式描述,每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同、相似的部分互相参见即可。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.

本领域内的技术人员应明白,本发明的实施例可提供为方法、装置或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。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.

本发明是参照根据本发明的方法、终端设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理终端设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理终端设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to the flowchart and/or block diagram of the method, terminal device (system), and computer program product according to the present invention. It should be understood that each process and/or box in the flowchart and/or block diagram, as well as the combination of the processes and/or boxes 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 produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device produce a device for implementing the functions specified in one process or multiple processes in the flowchart and/or one box or multiple boxes in the block diagram.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理终端设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory that can direct 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 that implements the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理终端设备上,使得在计算机或其他可编程终端设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程终端设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。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 computer-implemented processing, so that the instructions executed on the computer or other programmable terminal device provide steps for implementing the functions specified in one or more processes in the flowchart and/or one or more boxes in the block diagram.

需要说明的是:It should be noted that:

说明书中提到的“一个实施例”或“实施例”意指结合实施例描述的特定特征、结构或特性包括在本发明的至少一个实施例中。因此,说明书通篇各个地方出现的短语“一个实施例”或“实施例”并不一定均指同一个实施例。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.

此外,需要说明的是,本说明书中所描述的具体实施例,其零、部件的形状、所取名称等可以不同。凡依本发明专利构思所述的构造、特征及原理所做的等效或简单变化,均包括于本发明专利的保护范围内。本发明所属技术领域的技术人员可以对所描述的具体实施例做各种各样的修改或补充或采用类似的方式替代,只要不偏离本发明的结构或者超越本权利要求书所定义的范围,均应属于本发明的保护范围。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 (11)

1.一种快速实现订单模拟撮合的方法,其特征在于,包括以下步骤:1. A method for quickly implementing order simulation matching, characterized by comprising the following steps: 基于逐笔交易订单产生的时间顺序,获取逐笔交易订单并解析,得到交易订单信息,其中,交易订单信息至少包括交易类型、交易成交方向、交易成交价格、交易编号及交易目标代码;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.根据权利要求1所述的快速实现订单模拟撮合的方法,其特征在于,所述行情订单簿设有至少三个维度的存储结构;2. The method for rapidly implementing simulated order matching according to claim 1, 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.根据权利要求1所述的快速实现订单模拟撮合的方法,其特征在于,所述交易订单信息中的交易类型包括第一委托类型和第一成交类型;3. The method for quickly realizing order simulation matching according to claim 1, 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; 当为第一成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,所述委托队列的第一笔交易订单即为当前交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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. 当为第二成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,所述委托队列的第一笔交易订单即为当前交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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; 当为第三成交方向订单时,对第三成交方向订单的成交双方订单进行判断,若为第一成交方向订单,则根据交易目标代码定位相应的行情订单簿,根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为第二成交方向订单时,根据交易目标代码定位相应的行情订单簿,根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除。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.根据权利要求1所述的快速实现订单模拟撮合的方法,其特征在于,所述交易订单信息中的交易类型还包括第二委托类型及第二成交类型,所述第二委托类型包括限价交易订单、最优交易订单及市场价格交易订单;所述第二成交类型包括成交订单及第二撤销订单;4. The method for quickly realizing order simulation matching according to claim 1, characterized in that the transaction type in the transaction order information also 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; 则所述对行情订单簿进行更新,包括以下步骤: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; 当为成交订单时,对成交订单的成交双方订单进行判断,若为第一成交订单,则根据交易目标代码定位相应的行情订单簿,在买入行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据交易成交价格在买入行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;若为第二成交订单时,根据交易目标代码定位相应的行情订单簿,在卖出行情数据的市场价格档位下获取委托队列,根据交易编号匹配市场价格交易订单,若匹配不成功则根据交易成交价格在卖出行情数据中查找对应交易价格档位,获取相应档位下的委托队列,根据交易编号判断所述委托队列的第一笔交易订单是否为当前交易订单,若否,则继续取其他档位价格档位下的委托队列的第一笔交易订单进行判断,直至获取到交易订单,若订单剩余数量减去当前交易订单成交数量大于0,则更新当前交易订单的剩余数量,若全部成交则将当前交易订单从订单队列中删除;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.根据权利要求1所述的快速实现订单模拟撮合的方法,其特征在于,所述待模拟撮合订单交易阶段包括集合竞价阶段、连续竞价阶段,所述交易类型包括限价交易类型、第一部分成交类型、第二部分成交类型、第一转换类型、第二转换类型、全部操作类型及即时操作类型。5. The method for quickly realizing simulated order matching according to claim 1 is characterized in that the trading stages of the order to be simulated matching include a call auction stage and a continuous auction stage, and the trading 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.根据权利要求5所述的快速实现订单模拟撮合的方法,其特征在于,根据交易阶段、交易类型触发相应的撮合方式进而进行模拟撮合,得到撮合结果,包括以下步骤:6. The method for quickly realizing order simulation matching according to claim 5 is characterized in that the corresponding matching method is triggered according to the transaction stage and transaction type, and then the simulated matching is performed to 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.根据权利要求1所述的快速实现订单模拟撮合的方法,其特征在于,所述待模拟撮合订单为新交易订单时,包括以下步骤:7. The method for quickly realizing order simulation matching according to claim 1, characterized in that when the order to be simulated matching is a new transaction order, the method comprises the following steps: 新交易订单的信息至少包括:交易编号、交易目标代码、交易成交方向、交易类型、交易目标数量、交易目标价格;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.根据权利要求1所述的快速实现订单模拟撮合的方法,其特征在于,当待模拟撮合订单为挂单交易订单时,包括以下步骤:8. The method for quickly realizing simulated order matching according to claim 1 is characterized in that when the order to be simulated matched is a pending order, it includes the following steps: 挂单交易订单的信息包括交易编号、交易目标代码、交易成交方向、交易目标价格、剩余数量、行情交易编号;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; 对挂单数据通过价格优先、时间优先的顺序与逐笔交易订单进行模拟撮合,具体为:本笔逐笔交易订单可撮合数量 = 逐笔交易订单数量-优于待模拟撮合挂单的行情数量,当本笔行情可撮合数量大于0时,进行模拟撮合,其中,优于待模拟撮合挂单的行情数量,包括价格优于本待模拟撮合挂单的所有行情数量、本价格档位上时间优于本待模拟撮合挂单的所有行情数量。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.一种快速实现订单模拟撮合的系统,其特征在于,包括订单获取模块、定位存储模块、匹配更新模块、获取判断模块及确定撮合模块;9. A system for quickly implementing order simulation matching, characterized by comprising an order acquisition module, a positioning storage module, a matching update module, an acquisition judgment module and a 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.一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求1至8任意一项所述的方法。10. A computer-readable storage medium storing a computer program, wherein the computer program implements the method according to any one of claims 1 to 8 when executed by a processor. 11.一种快速实现订单模拟撮合的装置,包括存储器、处理器以及存储在所述存储器中并在所述处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现如权利要求1至8任意一项所述的方法。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, wherein the processor implements the method according to any one of claims 1 to 8 when executing the computer program.
CN202411163890.8A 2024-08-23 2024-08-23 Method, system and device for quickly realizing order simulation matching Active CN118674531B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202411163890.8A CN118674531B (en) 2024-08-23 2024-08-23 Method, system and device for quickly realizing order simulation matching

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202411163890.8A CN118674531B (en) 2024-08-23 2024-08-23 Method, system and device for quickly realizing order simulation matching

Publications (2)

Publication Number Publication Date
CN118674531A CN118674531A (en) 2024-09-20
CN118674531B true CN118674531B (en) 2024-11-05

Family

ID=92732931

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202411163890.8A Active CN118674531B (en) 2024-08-23 2024-08-23 Method, system and device for quickly realizing order simulation matching

Country Status (1)

Country Link
CN (1) CN118674531B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110852879A (en) * 2019-07-26 2020-02-28 上海量锐信息科技有限公司 High-frequency quantitative transaction strategy return test certificate method and system
CN117391857A (en) * 2023-10-17 2024-01-12 浙江智臾科技有限公司 Analog matching method, analog matching engine, device and storage medium

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112561664A (en) * 2020-12-28 2021-03-26 中国金融交易中心 Electronic transaction processing system and method based on order combination
CN113962807A (en) * 2021-09-28 2022-01-21 中泰证券股份有限公司 Method for deeply restoring millisecond order book Level2-plus service
CN114549129A (en) * 2022-02-22 2022-05-27 上海金融期货信息技术有限公司 Low-delay high-throughput real-time order book generation method
US20240046294A1 (en) * 2022-08-04 2024-02-08 Melange Technologies, Inc. Continuous Order Book Systems and Methods
CN116402583A (en) * 2023-04-13 2023-07-07 平安银行股份有限公司 Order processing method, device, storage medium and equipment
CN116860481A (en) * 2023-07-18 2023-10-10 中国外汇交易中心(全国银行间同业拆借中心) Transaction matching processing method, device and system
CN118395668A (en) * 2024-03-15 2024-07-26 广西电网有限责任公司电力科学研究院 VPP two-stage game transaction matching method and system based on blockchain architecture

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110852879A (en) * 2019-07-26 2020-02-28 上海量锐信息科技有限公司 High-frequency quantitative transaction strategy return test certificate method and system
CN117391857A (en) * 2023-10-17 2024-01-12 浙江智臾科技有限公司 Analog matching method, analog matching engine, device and storage medium

Also Published As

Publication number Publication date
CN118674531A (en) 2024-09-20

Similar Documents

Publication Publication Date Title
US20220084118A1 (en) Determination of implied orders in a trade matching system
US20230005061A1 (en) Generating implied orders based on electronic requests for quotes
WO2022001131A1 (en) Method and apparatus for reconstructing market quotations based on quote-by-quote data, and device
US7801878B2 (en) Method and system for approximate matching of data records
KR20220063147A (en) Systems and Methods Using Goodness-of-Fitness-Slope Blockchain Consensus
CN111127198A (en) Electric power market transaction server, market main body terminal and matching method
US12164495B2 (en) Optimized data structure
JP2011510382A (en) Method and system for low latency basket calculation
JP2008129984A (en) Transaction support system, transaction support program, and recording medium thereof.
US7937315B2 (en) Portfolio execution and reporting
CN111784435A (en) Energy carbon emission quota trading method and device
US8781948B2 (en) Trade matching platform with variable pricing based on clearing relationships
CN112527402A (en) Settlement method and related device
Falk et al. Economics of NFTs: The value of creator royalties
Hansson Arbitrage in crypto markets: An analysis of primary ethereum blockchain data
CN118674531B (en) Method, system and device for quickly realizing order simulation matching
US20130204769A1 (en) Trade Matching Platform with Variable Pricing Based on Clearing Relationships
CN108198006B (en) Centralized bidding clearing method and system for electric energy market transaction
CN113240422B (en) Financial product transfer method based on block chain and related device
CN114926253A (en) Market snapshot generation method and device and electronic equipment
Tu An application of web‐based data mining: selling strategies for online auctions
CN112529652B (en) Processing method and device for central order book
CN118552307A (en) Ethernet arbitrage transaction detection method and system
US20230117941A1 (en) System and Process For Tracking Liquidity Pool Tokens
US20250014028A1 (en) Private oracle-based trustless smart contract execution

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant