A financial market data subscription management method, device, electronic equipment and program product
Patent Information
- Application Number
- CN202611184489.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-06
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2046-08-06
AI Technical Summary
现有技术中,金融交易客户端软件的各个业务界面模块独立订阅行情数据导致重复订阅、网络带宽浪费、外部行情源压力增加、僵尸订阅和紧耦合的问题。
A market data caching and management module is introduced as an intermediary to uniformly manage subscription relationships. Through reference counting and dynamic grace period mechanisms, a request is sent to the market data access service when subscribing for the first time, cached data is reused when already subscribed, and the grace period is adjusted based on jitter history when unsubscribing.
It eliminates the waste of network bandwidth and pressure on market data sources caused by duplicate subscriptions, avoids zombie subscriptions, improves the modular design and maintainability of the system, and enhances subscription processing efficiency.
Smart Images

Figure CN122679208B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of financial data processing, and more specifically, to a method, apparatus, electronic device, and program product for managing financial market data subscriptions. Background Technology
[0002] Financial trading client software typically includes multiple business function interfaces such as market data browsing, order placement, and risk monitoring. Each business interface may subscribe to real-time market data for one or more securities.
[0003] In existing technologies, each business interface module within the client directly initiates an independent subscription request to the underlying market data access service. Upon receiving the subscription requests from each business interface, the market data access service establishes a data connection with the external market data source accordingly and returns the acquired market data to the business interface module that initiated the request.
[0004] When multiple business interfaces subscribe to the same security simultaneously, the market data access service will send multiple duplicate subscription instructions to external market data sources for that security and obtain multiple identical data streams, resulting in additional network bandwidth consumption and increased connection pressure on external market data sources. Each business interface manages its own subscription status independently, lacking a unified coordination mechanism. If a business interface fails to send a cancel subscription request correctly due to an abnormal exit, the subscription relationship will persist, forming a zombie subscription that continuously occupies the data push channel. Furthermore, the direct interaction between the business interfaces and the market data access service tightly couples the front-end business logic with the underlying data access logic. When the interface protocol of the market data access service changes, each business interface module needs to be adapted and adjusted, which is detrimental to the modular design and subsequent maintenance of the system. Summary of the Invention
[0005] The purpose of this application is to provide a financial market data subscription management method, device, electronic device and program product, which is used to improve the efficiency of market data subscription processing and reduce resource waste.
[0006] To achieve the above objectives, the technical solutions adopted in the embodiments of this application are as follows: In a first aspect, embodiments of this application provide a method for managing financial market data subscriptions, including: The system receives a subscription request from the business interface module and queries the market data cache to see if a corresponding cache record exists based on the target code in the subscription request; the market data cache is used to cache all cached objects. When the target code is subscribed for the first time, a cache object corresponding to the target code is created, the reference count is incremented, and a subscription request is sent to the market data access service to obtain the market data corresponding to the target code; the reference count is used to indicate the number of times the target code has been subscribed. When the target code has been subscribed, the reference count is incremented, and the market data corresponding to the cached target code is reused; Upon receiving the unsubscribe request from the business interface module, decrement the reference count; When the decremented reference count equals 0, a dynamic grace period is determined based on the jitter history of the target code; If a subscription request for the target code is received again during the dynamic grace period, the dynamic grace period is extended and the current cancellation request is cancelled; if the dynamic grace period expires and no new subscription request is received, a cancellation request is initiated to the market data access service.
[0007] Secondly, embodiments of this application provide a financial market data subscription management device, comprising: The market data caching and management module receives subscription requests from the business interface module and queries the market data cache to see if a corresponding cached record exists based on the target code in the subscription request. The market data cache is used to cache all cached objects. When the target code is subscribed for the first time, a cached object corresponding to the target code is created, the reference count is incremented, and a subscription request is sent to the market data access service to obtain the market data corresponding to the target code. The reference count is used to indicate the number of times the target code has been subscribed. When the target code has already been subscribed, the reference count is incremented, and the cached market data corresponding to the target code is reused. The module receives a cancellation request from the business interface module and decrements the reference count. When the decremented reference count equals 0, a dynamic grace period is determined based on the jitter history of the target code. During the dynamic grace period, if another subscription request for the target code is received, the dynamic grace period is extended, and the current cancellation request is cancelled. If the dynamic grace period expires and no new subscription request is received, a cancellation request is sent to the market data access service.
[0008] Thirdly, embodiments of this application provide an electronic device, including: Memory, used to store one or more programs; processor; When the one or more programs are executed by the processor, the method as described in any one of the first aspects above is implemented.
[0009] Fourthly, embodiments of this application provide a program product that, when executed by a processor, implements the method as described in any one of the first aspects above.
[0010] Compared to existing technologies, the financial market data subscription management method, apparatus, electronic device, and program product provided in this application manage subscription relationships uniformly through market data caching and reference counting: Subscription is only initiated to the market data access service for the first subscription; cached market data is reused when already subscribed, and only one subscription channel is maintained for the same target, eliminating bandwidth waste and market data source pressure caused by duplicate subscriptions. The reference count is immediately decremented upon receiving a cancellation request; after the reference count reaches zero, a dynamic grace period is determined based on historical jitter. If a subscription request is received again within the grace period, the grace period is extended and the external cancellation is cancelled, avoiding frequent creation and release of external subscriptions due to fluctuations in subscription demand. A cancellation request is only initiated to the market data access service when the grace period expires and there are no new subscriptions, ensuring that resources are released only after the subscription demand truly disappears. The grace period is dynamically adjusted according to historical jitter, balancing the suppression of subscription jitter with resource recovery efficiency.
[0011] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0012] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 This is a schematic diagram of the existing market data subscription architecture. Figure 2 A flowchart illustrating a financial market data subscription management method provided in an embodiment of the present invention; Figure 3 A flowchart illustrating another financial market data subscription management method provided in an embodiment of the present invention; Figure 4 A schematic diagram of a cache object structure provided in an embodiment of the present invention; Figure 5 A flowchart illustrating another financial market data subscription management method provided in an embodiment of the present invention; Figure 6 A flowchart illustrating another financial market data subscription management method provided in an embodiment of the present invention; Figure 7A flowchart illustrating another financial market data subscription management method provided in an embodiment of the present invention; Figure 8 A flowchart illustrating another financial market data subscription management method provided in an embodiment of the present invention; Figure 9 Signaling interaction diagram of the financial market data subscription management method provided in this embodiment of the invention; Figure 10 A schematic diagram of the structure of a financial market data subscription management device provided in an embodiment of the present invention; Figure 11 This is a schematic structural block diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0014] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. The components of the embodiments of this application described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0015] Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0016] In the description of this application, it should also be noted that, unless otherwise explicitly specified and limited, the terms "set" and "connection" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0017] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0018] Financial trading client software typically includes multiple functional interfaces, such as a market data viewing interface, a trade order placement interface, a risk monitoring interface, and a strategy backtesting interface. Each interface may need to subscribe to real-time market data for one or more financial securities.
[0019] In existing technologies, financial trading client software typically employs a distributed market data subscription architecture. Under this architecture, each business interface module within the client directly connects to the underlying market data access service.
[0020] Specifically, Figure 1 See the diagram for the existing market data subscription architecture. Figure 1 In this scenario, both business interface A and business interface B need to obtain market data for the same security S. Therefore, both interfaces will send subscription requests to the market data access service. Upon receiving the subscription request from business interface A, the market data access service initiates a data retrieval request for security S from the exchange's market data source. Simultaneously, upon receiving the subscription request from business interface B, the market data access service also initiates a data retrieval request for security S from the exchange's market data source. Thus, even though business interfaces A and B are focusing on the same security S, the market data access service will generate two duplicate subscription instructions for that security and obtain two identical data streams from the exchange's market data source.
[0021] Similarly, if business interface C needs to obtain market data for security T, then business interface C directly sends a subscription request for security T to the market data access service, and the market data access service accordingly initiates a data retrieval request for security T from the exchange's market data source.
[0022] The aforementioned subscription process revealed several shortcomings in actual operation. Firstly, there was a waste of resources. Taking the example of business interface A and business interface B simultaneously subscribing to security S, because the market data access service performed two external subscription operations for the same security S, the exchange's market data source needed to continuously push two duplicate market data streams to the client. This directly increased network bandwidth consumption and placed unnecessary connection pressure on the external market data source. In scenarios with large-scale client deployments, if there are many similar situations where business interface A and business interface B simultaneously subscribe to the same security, the resource overhead caused by this duplicate subscription will be drastically amplified, thereby driving up the overall operating cost of the system.
[0023] Secondly, there is confusion at the management level. In the existing architecture, business interfaces A, B, and C each manage their own subscription status independently, lacking a unified coordination mechanism. Furthermore, there is no control node within the client to centrally manage all subscription relationships. When business interface B exits due to program errors or user-forced shutdown, failing to correctly send an unsubscribe request to securities S to the market data access service, the subscription relationship remains on the market data access service side, forming a de facto zombie subscription. This zombie subscription continuously occupies the data push channel of external market data sources but cannot be effectively identified and cleaned up.
[0024] Secondly, there is tight coupling at the architectural level. Business interfaces A, B, and C all interact directly with the market data access service, meaning there is a lack of necessary isolation between the front-end business logic and the underlying data access logic. When the interface protocol of the market data access service changes, or when a different market data provider is needed, all directly connected business interface modules may require corresponding adaptation adjustments. This tight dependency is detrimental to the modular design and subsequent maintenance of the system, and also limits the flexible scalability of the client software in different scenarios.
[0025] To address the aforementioned problems in existing technologies, this application provides a financial market data subscription management mechanism. By introducing a market data caching and management module as an intermediary between all business interfaces and the market data access service, it avoids repeatedly fetching the same data, unifies the management of the subscription lifecycle, and further facilitates the modularity and maintainability of the overall architecture.
[0026] Optionally, the following provides possible implementations of the financial market data subscription management method executed by the market data caching and management module. Specifically, Figure 2 This is a flowchart illustrating a financial market data subscription management method provided in an embodiment of the present invention. (See attached diagram.) Figure 2 The method includes: Step 100: Receive the subscription request from the business interface module, and query the market data cache to see if there is a corresponding cache record based on the target code in the subscription request.
[0027] The market data cache is used to cache all cached objects.
[0028] Optionally, in this application, "subject matter" refers to a financial product or contract that has market data and can be bought and sold on a trading venue. For example, it can refer to securities (spot products, such as stocks), futures, and options (such as gold futures and soybean meal options). Furthermore, the "target subject matter code" is used to uniquely identify the specific subject matter for which market data is to be subscribed. In actual business operations, the target subject matter code typically carries trading venue identification information to distinguish market data from the same code in different markets.
[0029] Step 101: When the target code is subscribed for the first time, create a cache object corresponding to the target code, increment the reference count, and send a subscription request to the market data access service to obtain the market data corresponding to the target code.
[0030] Reference counting is used to indicate the number of times the target code has been subscribed to.
[0031] Step 104: When the target code has been subscribed, increment the reference count and reuse the market data corresponding to the cached target code.
[0032] Step 106: Receive the unsubscribe request from the business interface module and decrement the reference count.
[0033] Step 107: When the decremented reference count equals 0, determine the dynamic grace period based on the jitter history of the target code.
[0034] Optionally, the jitter history is used to characterize how frequently the target code is repeatedly subscribed to and unsubscribed from over a period of time.
[0035] Step 108: If a subscription request for the target code is received again during the dynamic grace period, the dynamic grace period is extended and the current cancellation request is cancelled.
[0036] Step 109: If the dynamic grace period expires and no new subscription request is received, initiate a cancellation request to the market data access service.
[0037] The financial market data subscription management method provided in this invention manages subscription relationships through market data caching and reference counting: Subscription is initiated only to the market data access service for the first subscription; cached market data is reused when already subscribed, and only one subscription channel is maintained for the same asset, eliminating bandwidth waste and market data source pressure caused by duplicate subscriptions. Upon receiving a cancellation request, the reference count is immediately decremented. Once the reference count reaches zero, a dynamic grace period is determined based on historical jitter. If another subscription request is received within the grace period, the grace period is extended and the external cancellation is cancelled, avoiding frequent creation and release of external subscriptions due to fluctuations in subscription demand. A cancellation request is only initiated to the market data access service when the grace period expires and no new subscriptions are received, ensuring resources are released only after the subscription demand truly disappears. The grace period is dynamically adjusted based on historical jitter, balancing the suppression of subscription jitter with resource recovery efficiency.
[0038] Optionally, for the initial subscription scenario in the above example, possible implementations are provided below. Specifically, in Figure 2 On this basis, Figure 3 A flowchart illustrating another financial market data subscription management method provided in this embodiment of the invention is shown below. Figure 3 Step 101 includes: Step 101-1: If no cache record corresponding to the target code is found, determine that the target code is the first subscription.
[0039] Step 101-2: Create a cache object.
[0040] The cached object contains a reference count, the current grace period, the maximum grace period, and the latest market data. The current grace period is used to delay sending a cancellation request to the market data access service after the reference count decreases to 0. The maximum grace period is used to indicate the upper limit of the current grace period.
[0041] Optionally, taking a security as the target asset as an example, suppose business interface module A initiates a subscription request for security SH.600570 for the first time. After receiving the request, the market data caching and management module queries the cache record of security SH.600570 in the market data cache. Since no business interface has subscribed to this security before, no corresponding cache record is found, confirming that this is the first subscription for this security.
[0042] Subsequently, the market data caching and management module creates a cache object corresponding to stock SH.600570 in the market data cache. Specifically, optionally, Figure 4 This is a schematic diagram of a cache object structure provided in an embodiment of the present invention. See also: Figure 4 The market data cache stores market data for multiple securities, with each data point corresponding to a cache object. Continuing with the example of the target stock code SH.600570, this cache object contains the following fields: SH (securities market), 600570 (securities code), market data (including real-time order book data such as buy 1 to buy 5 and sell 1 to sell 5), reference count, current grace period, maximum grace period, and cancellation timestamp.
[0043] The reference count is initially set to 1, the current grace period is initially set to the default grace period of 5 seconds, the maximum grace period is set to the preset upper limit of 60 seconds, and the cancellation timestamp is initially empty. After creation, the cache object is added to the market data cache, and the market data cache and management module then initiates a subscription request to the market data access service for securities SH.600570, establishing a data channel with the external market data source.
[0044] The cancellation timestamp records the most recent time the unsubscribe action was triggered. In practice, when the business interface module sends a unsubscribe request causing the reference count to decrease to 0, the market data caching and management module writes the current system time to this cancellation timestamp. During periodic scanning, the market data caching management thread calculates the time difference between the current system time and this cancellation timestamp to determine if the time difference has exceeded the current grace period, thus deciding whether to initiate a real unsubscribe request to the market data access service. Therefore, the cancellation timestamp is the timing benchmark for the correct execution of the grace period mechanism.
[0045] This example encapsulates reference counts, grace period parameters, and market data into the same cache object, providing a unified data carrier for subscription status management and facilitating subsequent query, update, and detection thread scanning processes.
[0046] Optionally, the following provides a possible implementation method for the processing mechanism after obtaining subscribed market data. Specifically, in Figure 2 On this basis, Figure 5A flowchart illustrating another financial market data subscription management method provided in this embodiment of the invention is shown below. Figure 5 Following step 101, the method further includes: Step 102: After the market data access service receives the market data corresponding to the target code from the external market data source, it updates the market data to the cache object.
[0047] Step 103: Push market data to all business interface modules that have currently subscribed to the target stock code.
[0048] For example, after the market data access service receives the latest market data for securities SH.600570 from an external market data source, it passes the data to the market data caching and management module. The market data caching and management module uses the securities market plus the securities code as the primary key and updates the latest market data in the latest market data field of the cached object corresponding to securities SH.600570 in the market data cache.
[0049] Subsequently, the market data caching and management module can push the updated market data to all business interface modules currently subscribed to securities SH.600570 via an asynchronous callback mechanism. For example, if business interface module A and business interface module B are both currently subscribed to securities SH.600570, both will receive the latest market data via asynchronous callback. The asynchronous mechanism ensures that the push operation does not block the main processing flow of the market data access service.
[0050] In this example, an asynchronous update mechanism is used to handle the reception and distribution of market data, avoiding synchronous blocking and ensuring the system's response speed and stability in high-concurrency subscription scenarios. The market data in the cache can always be kept up-to-date, providing an immediately available data snapshot for newly subscribed business interfaces.
[0051] Optionally, for the processing mechanism after obtaining cached market data, a possible implementation method is provided, specifically, in Figure 2 On this basis, Figure 6 A flowchart illustrating another financial market data subscription management method provided in this embodiment of the invention is shown below. Figure 6 Following step 104, the following steps are also included: Step 105: Push the cached market data to the business interface module that initiated the subscription request.
[0052] Suppose that after business interface module A has already subscribed to security SH.600570, business interface module B also initiates a subscription request for security SH.600570. The market data caching and management module finds that the cache record for this security already exists, confirms that the security has been subscribed, increments the reference count in the cache object from 1 to 2, and does not need to send a subscription request to the outside world.
[0053] Subsequently, the market data caching and management module directly pushes the latest market data already cached in the cache object to the business interface module B that initiated the subscription request. Since the market data already exists in the cache, business interface module B does not need to wait for the market data access service to fetch data from an external source and can immediately obtain the current market data for securities SH.600570.
[0054] This example demonstrates how returning cached market data directly to the business interface module that initiated the resubscription request enables the module to obtain the required data instantly, thereby improving user experience and system response efficiency.
[0055] Optionally, in scenarios where some business interfaces unsubscribe but others continue to use the securities, data service continuity must be maintained to ensure that business interface modules that have not unsubscribed are unaffected. Below is one possible implementation method for continuing to push market data; specifically, in... Figure 2 On this basis, Figure 7 A flowchart illustrating another financial market data subscription management method provided in this embodiment of the invention is shown below. Figure 7 Following step 106, the following is also included: Step 110: When the reference count is greater than 0, continue to push the corresponding market data to the business interface module of the remaining subscription target code.
[0056] It should be noted that this step and the "Grace Period Processing Procedure When the Reference Count Decreases to 0" are two mutually exclusive paths after the reference count decreases: If the decremented reference count is greater than 0, this step is executed, and market data continues to be pushed to the remaining subscribers without entering the grace period processing procedure; if the decremented reference count is equal to 0, the grace period processing procedure is entered, and this step is not executed. Only one of the two can be executed.
[0057] It should also be noted that the immediate decrement of the reference count and the aforementioned grace period debouncing mechanism are not contradictory; they operate on different targets. The reference count decrement is an accounting operation for the subscription status within the client, completed immediately upon receiving a cancel subscription request, ensuring the reference count always equals the current actual number of subscribers. The grace period debouncing operates on external cancel subscriptions initiated to the market data access service, and intervention is only necessary when the reference count decreases to 0 and the external subscription channel is about to be released. When the reference count is greater than 0, the external subscription channel does not need to be changed, and there are no external actions that could cause fluctuations; therefore, there is no need to activate the grace period, and push notifications can continue directly.
[0058] For example, suppose stock SH.600570 is currently subscribed to by both business interface module A and business interface module B, with a reference count of 2. At this time, business interface module B sends an unsubscribe request because the user closes the interface. Upon receiving this request, the market data caching and management module immediately decrements the reference count from 2 to 1. Determining that the decremented reference count is greater than 0, it does not proceed to the grace period processing flow.
[0059] Since the decremented reference count of 1 is greater than 0, it indicates that business interface module A is still using the securities' market data, and the external subscription channel needs to be maintained. The market data caching and management module does not activate the grace period, nor does it perform any external unsubscription operation, and continues to push the market data of securities SH.600570 to business interface module A, while business interface module B stops receiving pushes. The data reception of business interface module A is not affected by the cancellation operation of business interface module B.
[0060] In this example, by immediately checking whether the reference count is greater than 0 after it decreases, the scenario of some subscribers dropping out is diverted to the branch that continues to push data, ensuring that the remaining subscribers continue to receive market data and maintaining the stability and continuity of the data service. At the same time, this branch does not involve changes to the external subscription channel, so there is no need to introduce a grace period for debouncing, avoiding unnecessary processing delays.
[0061] Optionally, when the reference count decreases to 0, a grace period mechanism is used to prevent frequent fluctuations in external resources caused by subscription jitter, and external resources are only truly released after the system stabilizes and has no references. Specifically, in Figure 2 On this basis, Figure 8 A flowchart illustrating another financial market data subscription management method provided in this embodiment of the invention is shown below. Figure 8 In step 106, the following is included: Step 106-1: When receiving an unsubscribe request from the business interface module, decrement the reference count.
[0062] Step 106-2: Determine whether the decremented reference count is equal to 0.
[0063] If yes, then proceed to step 107-1; if no (i.e., greater than 0), then maintain the subscription relationship with the target code, continue to receive and distribute push data of the target code, end this unsubscribe process, and do not perform the unsubscribe operation.
[0064] For example, taking target code A as an example: if its reference count is 3 when the unsubscribe request is received, the reference count is first updated from 3 to 2. Since the reference count after decrementing by 1 is not equal to 0, it indicates that there are still other business interface modules subscribing to target code A. At this time, the subscription relationship with target code A remains unchanged, and its push data continues to be received and distributed. If its reference count is 1 when the unsubscribe request is received, the reference count is first updated from 1 to 0. Since the reference count after decrementing by 1 is equal to 0, it indicates that there are no valid subscribers for target code A. At this time, step 107-1 is executed to enter the grace period unsubscribe process, and the time point when it decreases to 0 is recorded in the jitter history.
[0065] Optionally, if the reference count of the target code is already 0 when the unsubscribe request is received, the unsubscribe request is ignored, and an exception message can be output to avoid repeated unsubscribing causing a reference count error.
[0066] Accordingly, step 107 includes: Step 107-1: Determine the current grace period based on the jitter history of the target code.
[0067] Optionally, the jitter history can be recorded as: the number of times the reference count corresponding to the target code has decreased to 0 within the most recent preset time period (e.g., 10 minutes); or, as a time series consisting of several recent reference count decreases to 0. The more times the reference count decreases to 0, or the more concentrated the time points of decreasing to 0, the more severe the subscription jitter of the target code, and correspondingly, the longer the dynamic grace period is determined for it; conversely, for target codes with stable subscription relationships, a shorter default grace period is adopted.
[0068] It should be noted that, in this embodiment, the current grace period field in the cache object can itself serve as a carrier of jitter history: whenever the reference count decreases to 0 and a subscription occurs again within the current grace period (i.e., a jitter occurs), the current grace period is extended according to the backoff factor. Therefore, the value of the current grace period reflects the cumulative number of jitters that have occurred in the code history of the target. The market data cache and management module determines the dynamic grace period for the next startup based on the current grace period, which is equivalent to determining the dynamic grace period based on the jitter history.
[0069] Step 107-2: When the reference count is equal to 0 and a subscription request for the target code is received again within the current grace period, the current grace period is extended by the backoff factor, and the extended current grace period does not exceed the maximum grace period.
[0070] The backoff factor is used to calculate a new grace period based on the current grace period when a subscription request is received again within the current grace period.
[0071] Accordingly, step 108 includes: Step 108-1: The market data cache management thread periodically scans the market data cache. When the reference count of the target stock's code is equal to 0 and the current grace period has expired, a request to cancel the subscription is sent to the market data access service.
[0072] Alternatively, assume the retreat factor is b and the current grace period is g. current The maximum grace period is g max Then the new grace period g new for: g new =min(g current *b, g max ) Optionally, the following explanation uses an initial grace period of 5 seconds, a backoff factor of 2, and a maximum grace period of 60 seconds as an example. Please refer to Table 1 for details.
[0073] Table 1
[0074] As shown in Table 1, starting from the fourth jitter, the grace period reaches its maximum limit of 60 seconds. Even if jitter continues thereafter, the grace period remains at 60 seconds and is not extended. This indicates that the security is becoming increasingly difficult to cancel its external subscription.
[0075] For example, suppose business interface module A cancels its subscription to securities SH.600570. The market data caching and management module decrements the reference count of this security from 1 to 0, and determines that the decremented reference count equals 0 (step 106-1). The market data caching and management module queries the volatility history of this security: the reference count has decreased to 0 for the first time within the most recent preset time period (e.g., 10 minutes), indicating that its subscription relationship is relatively stable. Therefore, it determines the current grace period to be the default grace period of 5 seconds and starts the timer (step 106-2).
[0076] If, within the 5-second grace period, business interface module C initiates another subscription request for securities SH.600570, a subscription jitter occurs (step 107-1). At this time, the market data caching and management module increments the reference count to 1, and the current subscription cancellation process terminates. Simultaneously, a new grace period is calculated based on the backoff factor 2, i.e., the current grace period of 5 seconds multiplied by the backoff factor 2 equals 10 seconds. Since this value does not exceed the maximum grace period of 60 seconds, the current grace period in the cached object is updated to 10 seconds, and this jitter is recorded in the jitter history accordingly.
[0077] Assume that business interface module C subsequently cancels the subscription again, and the reference count decreases back to 0. The market data caching and management module determines the current grace period based on the jitter history: since the security has already experienced one jitter, and the current grace period has been updated to 10 seconds, the current grace period for this startup is 10 seconds. If there are no new subscriptions within 10 seconds, the market data caching management thread detects during its periodic scan that the reference count of security SH.600570 is 0 and has exceeded the current grace period of 10 seconds, and then initiates a cancellation request to the market data access service to release external resources (step 108-1); if there are new subscription requests within 10 seconds, the current grace period is extended again according to the backoff factor.
[0078] If a security is repeatedly subscribed to and canceled, the current grace period increases progressively with the number of fluctuations: 10 seconds for the second time the subscription drops to 0, 20 seconds for the third, 40 seconds for the fourth, and 60 seconds for the fifth, after which the maximum grace period is reached and no further increases are made. Therefore, the more frequent the fluctuations in a security's history, the longer its grace period and the less likely it is to be genuinely canceled from external subscriptions.
[0079] This example employs a grace period mechanism to prevent immediate cancellation of external subscriptions after the reference count drops to 0, providing a buffer for short-term switching or jitter. It uses jitter history to track subscription zeroing events and extends the grace period incrementally based on the jitter level using a backoff factor, ensuring the grace period matches the actual jitter frequency of the security. This effectively suppresses subscription jitter and reduces connection fluctuations to external market data sources. Furthermore, the market data cache management thread periodically scans to ensure resources are only released after the reference count reaches 0 and has stably exceeded the current grace period, preventing zombie subscriptions and premature resource reclamation.
[0080] Optionally, the following provides a possible implementation of the signaling interaction of this application. Specifically, Figure 9 The signaling interaction diagram for the financial market data subscription management method provided in this embodiment of the invention is shown below. Figure 9 This example uses the business interface module A, the market data caching and management module, the market data access service, and external market data sources as the main interaction components. It fully demonstrates the entire signaling interaction process, from subscription request processing, cache object creation or reuse, external market data acquisition and asynchronous distribution, to unsubscribe request processing and background resource release of the market data cache management thread. See also Figure 9 The process includes: Step 200: Business interface module A obtains the user's subscribed market data (stock code SH.600570). Step 201: Business interface module A sends a subscription request to the market data caching and management module.
[0081] Step 202: The market data caching and management module queries the target code in the subscription request and checks whether a corresponding cache record exists in the market data cache.
[0082] If the condition exists, proceed to step 203; otherwise, proceed to step 204.
[0083] Step 203: The market data caching and management module will increment the reference count by 1 and send a "subscription successful" message to the business interface module A.
[0084] Step 204: The market data caching and management module creates a cache object corresponding to securities SH.600570.
[0085] Step 205: The market data caching and management module initially sets the reference count to 1.
[0086] Optionally, as shown in the example above, the market data caching and management module can also set the current grace period, the maximum grace period, and cancel the timestamp.
[0087] Step 206: The market data caching and management module initiates a subscription request for securities SH.600570 to the market data access service.
[0088] Step 207: The market data access service receives the subscription request.
[0089] Step 208: Establish a data channel with external market data sources for the market data access service.
[0090] Step 209: Obtain the latest market data from external market sources.
[0091] Step 210: The market data access service will return the subscription information containing the latest market data to the market data cache and management module.
[0092] Step 211: The market data caching and management module updates the market data cache based on the latest market data.
[0093] Step 212: The market data caching and management module starts the market data distribution thread and sends the updated market data back to the business interface module A.
[0094] It should be noted that, for the case of step 203, that is, if there is a corresponding cache record in the market data cache, the updated market data is directly fed back to the business interface module A through step 212.
[0095] Step 213: Business interface module A initiates unsubscription (Securities SH.600570).
[0096] Step 214: The market data caching and management module determines whether a corresponding cache record exists in the market data cache.
[0097] If it exists, proceed to step 215; if it does not exist, proceed to step 217.
[0098] Step 215: The market data caching and management module decrements the reference count by 1.
[0099] Step 216: The market data caching and management module determines the relationship between the reference count and 0.
[0100] If the reference count is greater than 0, proceed to step 217; if the reference count is equal to 0, proceed to steps 218 and 220 respectively.
[0101] Step 217: The market data caching and management module returns to the current process, which means the current process is terminated.
[0102] Step 218: The market data caching and management module determines the current grace period based on the jitter history of the target stock's code.
[0103] Step 219: Update the maximum grace period of the market data cache and management module.
[0104] Specifically, when the reference count is 0 and a subscription request for the target code is received again within the current grace period, the current grace period is extended by the backoff factor, and the extended current grace period does not exceed the maximum grace period.
[0105] It should be noted that the market data caching and management module starts a market data cache management thread to continuously check the market data cache. When the reference count is 0 and the grace period is reached, step 220 is executed.
[0106] Step 220: The market data caching and management module initiates an unsubscription to the market data access service.
[0107] Step 221: Process the market data access service to cancel the subscription.
[0108] Optionally, in order to perform the various steps of the above examples to achieve the corresponding technical effects, this application also provides a possible implementation of a financial market data subscription and management device. Specifically, Figure 10 This is a schematic diagram of a financial market data subscription management device provided in an embodiment of the present invention. The device 30 includes: a market data caching and management module 300 and a market data access service 301. As mentioned above, the market data caching and management module 300 is communicatively connected to various business interface modules; the market data access service 301 is communicatively connected to external market data sources.
[0109] The market data caching and management module 300 receives subscription requests from the business interface module and queries the market data cache to see if a corresponding cached record exists based on the target code in the subscription request. The market data cache is used to cache all cached objects. When the target code is subscribed for the first time, a cached object corresponding to the target code is created, the reference count is incremented, and a subscription request is sent to the market data access service 301 to obtain the market data corresponding to the target code. The reference count is used to indicate the number of times the target code has been subscribed. When the target code has already been subscribed, the reference count is incremented, and the cached market data corresponding to the target code is reused. When a cancellation request is received from the business interface module, the reference count is decremented. When the decremented reference count equals 0, a dynamic grace period is determined based on the jitter history of the target code. During the dynamic grace period, if another subscription request for the target code is received, the dynamic grace period is extended, and the current cancellation request is cancelled. If the dynamic grace period expires and no new subscription request is received, a cancellation request is sent to the market data access service.
[0110] Optionally, the market data caching and management module 300 is specifically used to determine that the target code is a first subscription when no cache record corresponding to the target code is found; create a cache object; the cache object includes a reference count, current grace period, maximum grace period, and the latest market data; wherein, the current grace period is used to delay sending a cancellation request to the market data access service 301 after the reference count decreases to 0; the maximum grace period is used to indicate the upper limit of the current grace period.
[0111] Optionally, the market data access service 301 is used to update the market data to the cache object after receiving the market data corresponding to the code of the target from an external market data source; The market data caching and management module 300 is also used to push market data to all business interface modules that have currently subscribed to the target stock code.
[0112] Optionally, the market data caching and management module 300 is also used to push the cached market data to the business interface module that initiates the subscription request.
[0113] Optionally, the market data caching and management module 300 is also used to continue pushing the corresponding market data to the business interface module of the remaining subscription target code when the reference count is greater than 0.
[0114] Optionally, the market data caching and management module 300 is specifically used to decrement the reference count when receiving an unsubscribe request from the business interface module; determine whether the decremented reference count is equal to 0; if so, determine the current grace period based on the jitter history of the target code; when the reference count is equal to 0 and a subscription request for the target code is received again within the current grace period, extend the current grace period according to the backoff factor, and the extended current grace period shall not exceed the maximum grace period; the backoff factor is used to calculate a new grace period based on the current grace period when a subscription request is received again within the current grace period; and periodically scan the market data cache through the market data cache management thread, and when the reference count corresponding to the target code is equal to 0 and exceeds the current grace period, initiate an unsubscribe request to the market data access service.
[0115] Optionally, Figure 11 A schematic structural block diagram of an electronic device provided in an embodiment of the present invention is shown below. Figure 11 The electronic device 40 includes a memory 401, a processor 402, and a communication interface 403. The processor 402 and the memory 401 are electrically connected directly or indirectly to each other to realize data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. The memory 401 can be used to store software programs and modules, such as the program instructions / modules corresponding to the financial market data subscription management device 30 provided in this application embodiment. The processor 402 executes the software programs and modules stored in the memory 401 to perform various functional applications and data processing.
[0116] The memory 401 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0117] Processor 402 can be an integrated circuit chip with signal processing capabilities. Processor 402 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0118] The communication interface 403 is used to enable data transmission and reception between the electronic device 40 and other devices or modules. In this embodiment, the communication interface 403 is specifically used for: receiving subscription requests and unsubscription requests for target codes sent by various business interface modules; pushing corresponding market data to each business interface module that has currently subscribed to the target code; and sending subscription requests or unsubscription requests for target codes to the market data access service, and receiving the market data corresponding to the target code returned by the market data access service.
[0119] Optionally, the communication interface 403 can be a wired communication interface, such as an Ethernet interface, a Universal Serial Bus (USB) interface, etc.; or it can be a wireless communication interface, such as a Wireless Fidelity (Wi-Fi) interface, a Bluetooth interface, a cellular mobile communication interface, etc. The number of communication interfaces 403 can be one or more.
[0120] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0121] In addition, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0122] If a function is implemented as a software module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0123] The above are merely preferred embodiments of this application and are not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
[0124] It will be apparent to those skilled in the art that this application is not limited to the details of the exemplary embodiments described above, and that this application can be implemented in other specific forms without departing from the spirit or essential characteristics of this application. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of this application is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within this application. No reference numerals in the claims should be construed as limiting the scope of the claims.
Claims
1. A method for managing financial market data subscriptions, characterized in that, include: Receive subscription requests from the business interface module, and query the market data cache to see if there is a corresponding cache record based on the target code in the subscription request; The market data cache is used to cache all cached objects; When the target code is subscribed for the first time, a cache object corresponding to the target code is created, the reference count is incremented, and a subscription request is sent to the market data access service to obtain the market data corresponding to the target code; the reference count is used to indicate the number of times the target code has been subscribed. When the target code has been subscribed, the reference count is incremented, and the market data corresponding to the cached target code is reused; Upon receiving the unsubscribe request from the business interface module, decrement the reference count; When the decremented reference count equals 0, a dynamic grace period is determined based on the jitter history of the target code; the jitter history is used to characterize the frequency with which the target code is repeatedly subscribed to and unsubscribed within a certain period of time; If a subscription request for the target code is received again during the dynamic grace period, the dynamic grace period is extended and the current cancellation request is cancelled. If the dynamic grace period expires and no new subscription request is received, a cancellation request will be sent to the market data access service.
2. The method according to claim 1, characterized in that, The step of creating a cache object corresponding to the target code when the target code is subscribed for the first time includes: If no cache record corresponding to the target code is found, it is determined that the target code is a first subscription. Create the cache object; the cache object contains a reference count, a current grace period, a maximum grace period, and the latest market data; wherein, the current grace period is used to delay initiating the unsubscribe request to the market data access service after the reference count decreases to 0; the maximum grace period is used to indicate the upper limit of the current grace period.
3. The method according to claim 1, characterized in that, After the step of initiating a subscription request to the market data access service to obtain the market data corresponding to the target code, the method further includes: When the market data access service receives the market data corresponding to the target code from an external market data source, it updates the market data to the cache object. The market data will be pushed to all business interface modules that have currently subscribed to the target stock code.
4. The method according to claim 1, characterized in that, After the step of reusing the cached market data corresponding to the target code, the method further includes: The cached market data is pushed to the business interface module that initiated the subscription request.
5. The method according to claim 1, characterized in that, Following the step of decrementing the reference count, the method further includes: When the reference count is greater than 0, the corresponding market data continues to be pushed to the business interface modules of the remaining subscribed code of the target.
6. The method according to claim 1, characterized in that, The step of receiving the unsubscribe request from the business interface module and decrementing the reference count includes: When receiving an unsubscribe request from the business interface module, the reference count is decremented; Determine whether the decremented reference count is equal to 0; The step of determining the dynamic grace period based on the jitter history of the target code when the decremented reference count is equal to 0 includes: if the reference count is equal to 0, then determining the current grace period based on the jitter history of the target code; The step of extending the dynamic grace period if a subscription request for the target code is received again during the dynamic grace period includes: When the reference count is equal to 0 and a subscription request for the target code is received again within the current grace period, the current grace period is extended by a backoff factor, and the extended current grace period does not exceed the maximum grace period; the backoff factor is used to calculate a new grace period based on the current grace period when a subscription request is received again within the current grace period. The step of initiating a cancellation request to the market data access service if the dynamic grace period expires and no new subscription request is received includes: The market data cache management thread periodically scans the market data cache. When the reference count of the code corresponding to the target stock is equal to 0 and the current grace period has expired, a request to cancel the subscription is sent to the market data access service.
7. A financial market data subscription and management device, characterized in that, include: The market data caching and management module is used to receive subscription requests from the business interface module and query whether there is a corresponding cache record in the market data cache based on the target code in the subscription request. The market data cache is used to cache all cached objects; When the target code is subscribed for the first time, a cache object corresponding to the target code is created, the reference count is incremented, and a subscription request is sent to the market data access service to obtain the market data corresponding to the target code; the reference count is used to indicate the number of times the target code has been subscribed. When the target code has been subscribed, the reference count is incremented, and the market data corresponding to the cached target code is reused; Upon receiving the unsubscribe request from the business interface module, decrement the reference count; When the decremented reference count equals 0, a dynamic grace period is determined based on the jitter history of the target code; the jitter history is used to characterize the frequency with which the target code is repeatedly subscribed to and unsubscribed within a certain period of time; If a subscription request for the target code is received again during the dynamic grace period, the dynamic grace period is extended and the current cancellation request is cancelled; if the dynamic grace period expires and no new subscription request is received, a cancellation request is initiated to the market data access service.
8. An electronic device, characterized in that, include: Memory, used to store one or more programs; processor; When the one or more programs are executed by the processor, the method as described in any one of claims 1-6 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-6.
10. A program product, characterized in that, When the program product is executed by the processor, it implements the method as described in any one of claims 1-6.
Citation Information
Patent Citations
Financial quotation subscription method and device based on shared memory message queue and medium
CN117608871A
