Method for calculating time-sharing transaction data based on sliding window
By synchronizing the calculation method based on sliding window and CDC technology into the communication water, the existing time-sharing transaction data calculation method cannot support high concurrency and low performance, and high-performance and high-concurrency time-sharing transaction data calculation is realized, which improves the decision-making ability of transaction participants.
Patent Information
- Application Number
- CN202411645994.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-04-01
AI Technical Summary
The existing time-sharing transaction data calculation methods cannot support high concurrency and low performance, making it difficult for trading participants to make rapid trading decisions when facing market fluctuations.
Using a sliding window-based calculation method, CDC technology is used to synchronize the AC water to the peripheral relational database, and multi-threaded packet statistics and high-performance cache middleware to store time-sharing transaction data to realize incremental aggregation calculation.
Improves computing performance, supports high concurrent queries, reduces computing volume, and improves system stability and user experience.
Smart Images

Figure CN119739759A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of securities trading services, and in particular relates to a method for calculating time-sharing transaction data based on a sliding window. Background Art
[0002] With the continuous opening and development of the financial industry, the types of transactions are constantly expanding, such as stocks, commodity futures, index futures, foreign exchange, cryptocurrencies, etc. At the same time, the computerization and networking of financial transactions have rapidly expanded the transaction volume and transaction amount of financial transactions, resulting in increased volatility in trading market conditions, especially in special periods, such as wars, emergencies, and the release of economic data. This will intensify the volatility of trading market conditions, which requires trading participants to make trading decisions quickly when facing market fluctuations. Most trading participants use market analysis software to conduct data graphic analysis, such as K-line charts, in order to make trading decisions. K-line market technology describes the market's price behavior by recording and applying the four data of the highest price, lowest price, opening price and closing price in the market during the analysis period. As the basis for investment transactions, K-line charts are used in various investment software to describe recent stock price trends. Normally, the existing K-lines on the market are basically generated based on L1 snapshots, and the L1 snapshot cycle is relatively long, or there is a certain delay, and the corresponding K-lines generated are of poor quality; and only involve daily K-lines, that is, K-line charts based on trading days, and at most only involve K-lines in fixed time intervals such as K-lines within 1 minute. The K-line chart data for other periodic unit time intervals is insufficient, and it is impossible to judge whether the data is accurate and complete. There is also a lack of important reference data for market analysis, such as transaction volume or average transaction price. The data is not intuitive and comprehensive enough, which leads to errors in the market judgment of trading participants and makes it impossible to make trading decisions that are beneficial to themselves.
[0003] Trading volume or average trading price reflects the degree of recognition of a certain trading price at a certain trading time, and is also an important parameter for measuring the activity of market transactions. At present, intraday trading data includes trading volume and average trading price. There are two mainstream methods for calculating intraday trading data in the industry.
[0004] The first method is that when querying the intraday transaction data, the centralized trading counter will calculate the transaction volume and average transaction price in real time in the memory based on the total transaction volume of investors on that day. In the case of a large number of users, the centralized trading counter will be overloaded, work efficiency will be low, and the core trading functions will be affected. It has been gradually eliminated by the market; The second method is to improve the first method, and produce a second method where the counter only provides the flow, and the peripheral system calculates the full amount in real time, such as the mobile securities system. This method reduces the pressure on the counter and the risk of downtime to a certain extent compared with the first method. However, it will also cause the following technical problems: 1. Repeated query: Each time you query the time-sharing transaction, you need to query the total transaction volume of the counter investors on that day, which increases the query pressure on the counter; 2. Repeated calculation: Every time an investor queries a time-sharing transaction, a full calculation needs to be done in the peripheral system, such as the mobile securities system, which groups and counts all the data up to the calculation point of the day, increasing the peripheral performance load and causing performance waste.
[0005] In summary, the existing method for calculating time-sharing transaction data has a large amount of calculation in existing business scenarios, cannot support high concurrency, and has low performance. Summary of the invention
[0006] The purpose of the present invention is to provide a method for calculating time-sharing transaction data based on a sliding window, which solves the problem that the existing time-sharing transaction data calculation method cannot support high concurrency and has low performance.
[0007] The technical solution adopted by the present invention is a method for calculating time-sharing transaction data based on a sliding window, which is specifically implemented according to the following steps: Step 1, synchronize to AC water; Step 2, get the completion window; Step 3, query the AC water; Step 4, calculate the intraday transaction; Step 5, write cache middleware; Step 6, slide the completion window; Step 7, check the intraday transactions.
[0008] The present invention is also characterized in that: In step 1, the transaction details of the centralized trading counter are synchronized to the surrounding relational database; using the CDC technology based on database logs, the data source of the transaction details of the centralized trading counter uses the slave database of the centralized trading counter. When there is a new transaction water level in the slave database of the centralized trading counter, the transaction water level change is captured in real time, and the new transaction water level is synchronously written into the relational database of the counter's peripheral system.
[0009] Step 2 is as follows: Step 2.1, get the time point when the last calculation was completed, which is the completion window T C , this time only the exchange water after the completion window is calculated; Step 2.2, Complete Window T C The state information is saved in the cache. When the calculation starts, the completion window is obtained from the cache. T C ; When calculating for the first time, there is no completion window in the cache T CWhen setting the transaction start time as T C The initial value of .
[0010] Step 3: Query the relational database of the counter peripheral system for the data that is larger than the completion window. T C The data set is the exchange water S .
[0011] Step 4: Based on the data set in step 3 S , using group calculation in a multi-threaded manner, the total transaction volume and average transaction price are grouped and counted according to customer number, stock code and minute-level transaction time.
[0012] Step 5: The time-sharing transaction data is stored in the high-performance cache middleware in the form of an ordered set, namely the ordered set ZSet, in which the customer number, stock code and transaction date are combined as the primary key of the cache, the minute-level transaction time point is used as the sorting field of the ordered set, and the total time-sharing transaction volume and the average transaction price are used as the cache value.
[0013] After the calculation of this time-sharing transaction is completed in step 6, the completion window will be slid forward to the latest transaction time in the data set calculated this time, so that only the newly added data will be calculated next time.
[0014] When an investor opens the stock quote time-sharing page, he or she can query the transaction return data from the ordered combination of the cache middleware by passing the stock code and customer number, using the stock code, customer number and current date as the primary key.
[0015] Use the scheduled task scheduler to perform distributed scheduled tasks and execute the scheduling calculation logic every minute: Step 7.1, get the completion window from the cache middleware T C If not, the default is the earliest time for water exchange; Step 7.2, query the latest transaction time in the transaction details and record it as T m ; Step 7.3, query time later than T C The transaction records are aggregated and calculated based on investor ID, stock code and transaction time with minute precision. Step 7.4, write the calculation results into the ordered set ZSet storage structure of the cache middleware; Step 7.5 will complete the window T C The value of is updated to T m , And write cache middleware; Step 7.6: When the investor enters the time-sharing market page, the interface is called to query the time-sharing transaction data from the cache middleware.
[0016] When data synchronization is interrupted or the scheduled task scheduler fails, an exception compensation mechanism is used to reset the completion window to a certain point in time and then re-compensate the calculation to correct the intraday transaction data.
[0017] The beneficial effects of the present invention are as follows: the present invention adopts CDC (Change Data Capture) change data capture technology to directly synchronize investors' transaction water from the slave database of the centralized trading counter to the peripheral relational database, and the aggregate calculation is non-invasive to the centralized trading counter system, with high security; the sliding window incremental aggregate calculation of transaction water is adopted, with small amount of calculation each time and high computing performance; the cache middleware is adopted to store time-sharing transaction information, and high concurrent query capability is provided based on the high performance of the cache middleware. The present invention has the advantages of non-invasiveness, high performance, high concurrency, and small amount of calculation, and can effectively improve system stability and user experience, and has high practical value and promotion and application prospects. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] Figure 1 It is a flow chart of a method for calculating time-sharing transaction data based on a sliding window according to the present invention; Figure 2 It is a calculation logic diagram of the method for calculating time-sharing transaction data based on a sliding window in the present invention. DETAILED DESCRIPTION
[0019] The present invention will be further explained below in conjunction with the accompanying drawings and specific embodiments.
[0020] Example 1 The present invention is based on the method of calculating the time-sharing transaction data of the sliding window, the flow chart is as follows Figure 1 As shown, the implementation is carried out according to the following steps: Step 1, synchronize to AC water; Step 2, get the completion window; Step 3, query the AC water; Step 4, calculate the intraday transaction; Step 5, write cache middleware; Step 6, slide the completion window; Step 7, check the intraday transactions.
[0021] Example 2 The method for calculating time-sharing transaction data based on a sliding window of the present invention is specifically implemented according to the following steps: Step 1, synchronize to AC water; Synchronize the transaction details of the centralized trading counter to the surrounding relational database; use CDC (Change Data Capture) technology based on database logs to achieve quasi-real-time synchronization.
[0022] The data source of the transaction details of the centralized trading counter uses the slave database of the centralized trading counter, so as not to affect the performance of the centralized trading counter; when there is new transaction water in the slave database of the centralized trading counter, the transaction water change is captured in real time and the new transaction water is synchronously written into the relational database of the counter's peripheral system.
[0023] Step 2, get the completion window; Step 2.1, get the time point when the last calculation was completed, that is, the completion window T C , this time only the exchange water after the completion window is calculated; Step 2.2, Complete Window T C The state information is saved in the cache. When the calculation starts, the completion window is obtained from the cache. T C ; When calculating for the first time, there is no completion window in the cache T C When setting the transaction start time as T C The initial value of .
[0024] Step 3, query the AC water; Step 4, calculate the intraday transaction; Step 5, write cache middleware; Step 6, slide the completion window; Step 7, check the intraday transactions.
[0025] Example 3 The method for calculating time-sharing transaction data based on a sliding window of the present invention is specifically implemented according to the following steps: Step 1, synchronize to AC water; Synchronize the transaction details of the centralized trading counter to the surrounding relational database; use CDC (Change Data Capture) technology based on database logs to achieve quasi-real-time synchronization.
[0026] The data source of the transaction details of the centralized trading counter uses the slave database of the centralized trading counter, so as not to affect the performance of the centralized trading counter; when there is a new transaction water in the slave database of the centralized trading counter, the transaction water change is captured in real time and the new transaction water is synchronously written into the relational database of the counter's peripheral system.
[0027] Step 2, get the completion window; Step 2.1, get the time point when the last calculation was completed, which is the completion window T C , this time only the exchange water after the completion window is calculated; Step 2.2, Complete Window T C The state information is saved in the cache. When the calculation starts, the completion window is obtained from the cache. T C ; When calculating for the first time, there is no completion window in the cache T C When setting the transaction start time as T C The initial value of .
[0028] Step 3, query the AC water; query the relational database of the counter peripheral system that is greater than the completion window T C The data set is the exchange water S .
[0029] Step 4: Calculate the time-sharing transaction; according to the data set in step 3 S , using group calculation in a multi-threaded manner, the total transaction volume and average transaction price are grouped and counted according to customer number, stock code and minute-level transaction time.
[0030] Step 5, write the time-sharing transaction data obtained in step 4 into the cache middleware; The time-sharing transaction data is stored in the form of an ordered set in a high-performance cache middleware, namely an ordered set ZSet, such as Redis. The customer number, stock code and transaction date are combined as the primary key of the cache, the minute-level transaction time point is used as the sorting field of the ordered set, and the total time-sharing transaction volume and the average transaction price are used as the cache value.
[0031] Step 6, slide the completion window; after the calculation of this time-sharing transaction is completed, slide the completion window forward to the latest transaction time in the data set calculated this time, so that only the newly added data will be calculated next time.
[0032] Step 7, query the time-sharing transactions. When the investor opens the stock market time-sharing page, by passing the stock code and customer number, using the stock code, customer number and current date as the primary key, query the transaction return data from the ordered combination of the cache middleware.
[0033] Example 4 The method for calculating time-sharing transaction data based on a sliding window of the present invention is specifically implemented according to the following steps: Step 1, synchronize to AC water; Synchronize the transaction details of the centralized trading counter to the surrounding relational database; use CDC (Change Data Capture) technology based on database logs to achieve quasi-real-time synchronization. The data source of the transaction details of the centralized trading counter uses the slave database of the centralized trading counter, so as not to affect the performance of the centralized trading counter; when there is a new transaction water in the slave database of the centralized trading counter, the transaction water change is captured in real time and the new transaction water is synchronously written into the relational database of the counter's peripheral system.
[0034] Step 2, get the completion window; Step 2.1, get the time point when the last calculation was completed, which is the completion window T C , this time only the exchange water after the completion window is calculated; Step 2.2, Complete Window T C The state information is saved in the cache. When the calculation starts, the completion window is obtained from the cache. T C ; When calculating for the first time, there is no completion window in the cache T C When setting the transaction start time as T C The initial value of .
[0035] Step 3, query the AC water; query the relational database of the counter peripheral system that is greater than the completion window T C The data set is the exchange water S .
[0036] Step 4: Calculate the time-sharing transaction; according to the data set in step 3 S , using group calculation in a multi-threaded manner, the total transaction volume and average transaction price are grouped and counted according to customer number, stock code and minute-level transaction time.
[0037] Step 5, write the time-sharing transaction data obtained in step 4 into the cache middleware; The time-sharing transaction data is stored in the form of an ordered set in a high-performance cache middleware, namely an ordered set ZSet, such as Redis. The customer number, stock code and transaction date are combined as the primary key of the cache, the minute-level transaction time point is used as the sorting field of the ordered set, and the total time-sharing transaction volume and the average transaction price are used as the cache value.
[0038] Step 6, slide the completion window; after the calculation of this time-sharing transaction is completed, slide the completion window forward to the latest transaction time in the data set calculated this time, so that only the newly added data will be calculated next time.
[0039] Step 7, query the time-sharing transactions. When the investor opens the stock market time-sharing page, by passing the stock code and customer number, using the stock code, customer number and current date as the primary key, query the transaction return data from the ordered combination of the cache middleware.
[0040] Example 5 On the basis of Example 4, a scheduled task scheduler is used to perform distributed scheduled tasks and execute the scheduling calculation logic every minute, such as Figure 2 As shown: Step 7.1, get the completion window from the cache middleware T C If not, the default is the earliest time for water exchange; Step 7.2, query the latest transaction time in the transaction details and record it as T m ; Step 7.3, query time later than T C The transaction records are aggregated and calculated based on investor ID, stock code and transaction time with minute precision. Step 7.4, write the calculation results into the ordered set ZSet storage structure of the cache middleware; Step 7.5 will complete the window T C The value of is updated to T m , And write cache middleware; Step 7.6: When the investor enters the time-sharing market page, the interface is called to query the time-sharing transaction data from the cache middleware.
[0041] Example 6 On the basis of Example 5, in order to cope with abnormal scenarios, when data synchronization is interrupted and the scheduled task scheduler fails, an abnormal compensation mechanism is adopted to correct the intraday transaction data by resetting the completion window to a certain point in time and then re-compensating the calculation.
[0042] The method for calculating time-sharing transaction data based on sliding windows of the present invention is based on the transaction data of investors one by one, with the help of Change Data Caputre technology, relational data and cache middleware, and adopts a sliding window algorithm to regularly calculate the time-sharing transaction data of investors, write it into a high-performance cache, and display it on the market time-sharing chart in the form of buying and selling points, thereby improving the trading experience of investors, and having the advantages of non-intrusion, high performance and high concurrency. Compared with the existing methods, the calculation process is faster, and the calculation results are more precise and accurate. It has a relatively broad application prospect.
Claims
1. A method for calculating time-sharing transaction data based on a sliding window, characterized in that: Follow the steps below to implement it: Step 1, synchronize to AC water; Step 2, get the completion window; Step 3, query the AC water; Step 4, calculate the time-sharing transaction; Step 5, write cache middleware; Step 6, slide the window to complete; Step 7, check the intraday transactions.
2. The method for calculating time-sharing transaction data based on a sliding window according to claim 1, characterized in that: In step 1, the transaction details of the centralized trading counter are synchronized to the surrounding relational database; using the CDC technology based on database logs, the data source of the transaction details of the centralized trading counter uses the slave database of the centralized trading counter. When there is a new transaction water level in the slave database of the centralized trading counter, the transaction water level change is captured in real time, and the new transaction water level is synchronously written into the relational database of the counter's peripheral system.
3. The method for calculating time-sharing transaction data based on a sliding window according to claim 2, characterized in that: Step 2 is as follows: Step 2.1, get the time point when the last calculation was completed, which is the completion window T C , this time only the exchange water after the completion window is calculated; Step 2.2, Complete Window T C The state information is saved in the cache. When the calculation starts, the completion window is obtained from the cache. T C ; When calculating for the first time, there is no completion window in the cache T C When setting the transaction start time as T C The initial value of .
4. The method for calculating time-sharing transaction data based on a sliding window according to claim 3, characterized in that: Step 3: Query the relational database of the counter peripheral system for the data that is larger than the completion window. T C The data set is the exchange water S .
5. The method for calculating time-sharing transaction data based on a sliding window according to claim 4, characterized in that: Step 4: Based on the data set in step 3 S , using group calculation in a multi-threaded manner, the total transaction volume and average transaction price are grouped and counted according to customer number, stock code and minute-level transaction time.
6. The method for calculating time-sharing transaction data based on a sliding window according to claim 5, characterized in that: Step 5: The time-sharing transaction data is stored in the high-performance cache middleware in the form of an ordered set, namely the ordered set ZSet, in which the customer number, stock code and transaction date are combined as the primary key of the cache, the minute-level transaction time point is used as the sorting field of the ordered set, and the total time-sharing transaction volume and the average transaction price are used as the cache value.
7. The method for calculating time-sharing transaction data based on a sliding window according to claim 6, characterized in that: After the calculation of this time-sharing transaction is completed in step 6, the completion window will be slid forward to the latest transaction time in the data set calculated this time, so that only the newly added data will be calculated next time.
8. The method for calculating time-sharing transaction data based on a sliding window according to claim 7, characterized in that: When an investor opens the stock quote time-sharing page, he or she can query the transaction return data from the ordered combination of the cache middleware by passing the stock code and customer number, using the stock code, customer number and current date as the primary key.
9. The method for calculating time-sharing transaction data based on a sliding window according to claim 8, characterized in that: Use the scheduled task scheduler to perform distributed scheduled tasks and execute the scheduling calculation logic every minute: Step 7.1, get the completion window from the cache middleware T C If not, the default is the earliest time for water exchange; Step 7.2, query the latest transaction time in the transaction details and record it as T m ; Step 7.3, query time later than T C The transaction records are aggregated and calculated based on investor ID, stock code and transaction time with minute precision. Step 7.4, write the calculation results into the ordered set ZSet storage structure of the cache middleware; Step 7.5 will complete the window T C The value of is updated to T m , And write cache middleware; Step 7.6: When the investor enters the time-sharing market page, the interface is called to query the time-sharing transaction data from the cache middleware.
10. The method for calculating time-sharing transaction data based on a sliding window according to claim 9, characterized in that: When data synchronization is interrupted or the scheduled task scheduler fails, an exception compensation mechanism is used to reset the completion window to a certain point in time and then re-compensate the calculation to correct the intraday transaction data.
Citation Information
Cited By
Multi-party secure transaction method based on cross-border e-commerce business rules
CN120689048A