Disclosure of Invention
Based on the problems, the invention provides a transaction entrusted account book and span map display system and a method; the interactive fluency can be improved, the server side resources can be saved, and the system efficiency can be improved.
In a first aspect, the application shows a transaction ledger and span-chart display system comprising:
the system comprises a feedback module, a rendering module, an analysis module and an aggregation service;
the feedback module includes: the system comprises a span diagram component, a transaction entrusted ledger component, a feedback module DOM structure and a UI display component; the span map component and the transaction entrusted ledger component are used for data interaction with the user side; the DOM structure is used for receiving DOM updates; the UI display component is used for displaying view data; the feedback module executes the task queue by adopting a javascript asynchronous process; the feedback module is used for drawing and calculating the overall layout of the page;
the rendering module includes: a React frame; the React frame is used for receiving a layout loading request of the feedback module and updating the DOM to the feedback module; receiving the unidirectional data stream synchronized by the analysis module; the rendering module is used for drawing a transaction entrusted ledger book and a span map;
the parsing module includes: redox state machine and Redox/Redox-saga framework; the frame is accessed with Web Worker asynchronous calculation; the Redox state machine is used for receiving the view visible region parameters and the data parameters transmitted by the feedback module; subscribing full Level2 data to the aggregation service and receiving pushed data of the aggregation service in real time, wherein the Redox/Redox-saga framework performs throttling cache on the data pushed by the aggregation service and performs calculation through a Web Worker, the Web Worker performs aggregation calculation on quantity and cumulant according to the aggregation precision of a transaction entrusted account book selected by a user, and updates the calculation result to a Redox state machine;
the aggregated service comprises: io service end; the socket.io server is used for communicating with the analysis module; full/incremental calibration and price screening of full Level2 data was performed.
In a second aspect, the present application shows a transaction ledger sheet and a span map display method, which are used for a whole process from a browser side to a transaction side, and the method includes:
s101: a user enters a transaction target terminal from a browser end and requests to view a transaction entrusted account book and span map data; the transaction target terminal includes: the system comprises a feedback module, a rendering module, an analysis module and an aggregation service;
s102: the feedback module receives a client viewing request, acquires target information, merging precision and view information, transmits the target information, the merging precision and the view information to the analysis module for processing, and simultaneously transmits the user viewing request to the analysis module;
s103: the analysis module receives a user viewing request and subscribes full Level2 order data to the aggregation service; the transaction entrusted ledger and the span map data are constructed based on full Level2 order data;
s104: the aggregation service subscribes full Level2 order data to the exchange-side application programming interface;
s105: the exchange end receives the subscription information of the aggregation service, pushes full Level2 order data to the aggregation service in real time through an application programming interface of the exchange end, performs calibration/aggregation processing in the aggregation service and puts the data into a memory;
s106: when calibration/aggregation processing is carried out in the aggregation service and the memory is put into the aggregation service, the aggregation service pushes real-time full Level2 order data to an analysis module; the analysis module receives the full Level2 order data and processes the order data to obtain a transaction entrusted ledger and span map data; the processing and treating process comprises the following steps: calling Web Worker asynchronous calculation precision combination and span accumulation according to the full Level2 order data;
s107: after processing, the analysis module updates the single data stream to the rendering module through the Redox framework;
s108: the rendering module synchronously updates the visible transaction entrusted ledger book and the span map data to the feedback module;
s109: and the feedback module displays the real-time transaction entrusted account book and the span map data to the user side through the UI component interface.
In a third aspect, the present application shows a transaction entrusted ledger and a span map display method, which are used for a browser side, and the method includes:
s201: the user enters a transaction target terminal from a browser end and views a transaction entrusted ledger and span map data, and the transaction target terminal comprises: the system comprises a feedback module, a rendering module, an analysis module and an aggregation module;
s202: the feedback module receives a client viewing request and sends a layout loading request to the rendering module;
s203: the rendering module performs a DOM update to the feedback module,
s204: after the updating, the feedback module obtains the view visible region parameters and the data parameters, and synchronizes the view visible region parameters and the data parameters to the analysis module, wherein the analysis module comprises: the system comprises a Redox state machine and a Redox-saga frame, wherein Web Worker asynchronous calculation is accessed into the frame;
s205: a Redox state machine of the analysis module synchronizes the visible region parameters and the data parameters of the view; the analysis module subscribes full Level2 data to the aggregation service and receives push data of the aggregation service in real time;
s206: when the analysis module receives the pushed data of the aggregation service in real time, the analysis module performs throttling cache on the data pushed by the aggregation service, and the data is calculated through a Web Worker, and the Web Worker performs quantity and cumulant aggregation calculation according to the aggregation precision of the transaction entrusted account book selected by the user; updating the calculation result to a Redox state machine of the analysis module;
s207: when the transaction entrusted ledger data and the span map data are updated to the Redox state machine, the analysis module updates the transaction entrusted ledger data and the span map data in a one-way data flow direction rendering module;
s208: after the rendering module is updated, the rendering module updates DOM to the feedback module;
s209: after the data is updated to the feedback module, the feedback module interacts with a user; and displaying the real-time transaction entrusted account book and the span map data to the user side through the UI component interface.
The beneficial effect of this application does:
splitting a full-scale span diagram of a trading exchange and Level2 data calculation, saving browser page resources, and providing real-time market data for users with higher interactive fluency; the aggregation service efficiently schedules and processes matching engine application program interface data and user subscription data tasks as required, so that server resources are saved; the feedback module monitors the state of the user behavior, and adjusts system parameters in real time, so that system resources only serve the data concerned by the user, and the system efficiency is improved; the transaction entrusted account book and the span map are packaged, so that multi-project and multi-project multiplexing can be realized, and the development cost is saved; the virtual list and price window mechanism ensures that the interaction effect displayed to the user is still a whole data list, and the actual user browser only processes the part to be browsed and performs data calculation as required. Optimizing an area graph random edge sampling algorithm, eliminating redundant data points and accelerating span graph drawing; and the calculation of the Web Worker in parallel to the main flow is utilized, the calculation capability of the front end is expanded, and the page performance overhead is greatly saved integrally.
Detailed Description
To facilitate understanding by those skilled in the art, a part of technical terms related to the technical solutions shown in the present application will be explained first.
DOM (Document Object Model), a standard programming interface that handles extensible markup language. It is a platform and language independent application program interface that can dynamically access programs and scripts, update their content, structure, the document can be further processed, and the results of the processing can be added to the current page.
A UI component (User Interface Module) for User Interface interaction.
javascript is a lightweight, interpreted or just-in-time programming language with function precedence.
The React framework is a Web development framework and is mainly used for constructing a UI (user interface), and various types of parameters such as declaration codes can be transmitted in the React framework to help render the UI; or static HTML DOM elements; dynamic variables, even interactive application components, can also be passed.
Redux, an application data flow framework, is used for application state management.
Web Worker is a multi-threaded solution that can run some computationally expensive code without freezing the user interface.
Referring to fig. 1, fig. 1 shows a transaction commitment ledger and span map display system, the system comprising:
the system comprises a feedback module, a rendering module, an analysis module and an aggregation service;
the feedback module includes: the system comprises a span diagram component, a transaction entrusted ledger component, a feedback module DOM structure and a UI display component; the span map component and the transaction entrusted ledger component are used for data interaction with the user side; the DOM structure is used for receiving DOM updates; the UI display component is used for displaying view data; the feedback module executes the task queue by adopting a javascript asynchronous process; the feedback module is used for drawing and calculating the overall layout of the page;
the rendering module includes: a React frame; the React frame is used for receiving a layout loading request of the feedback module and updating the DOM to the feedback module; receiving the unidirectional data stream synchronized by the analysis module; the rendering module is used for drawing a transaction entrusted ledger book and a span map;
the parsing module includes: redox state machine and Redox/Redox-saga framework; the frame is accessed with Web Worker asynchronous calculation; the Redox state machine is used for receiving the view visible region parameters and the data parameters transmitted by the feedback module; subscribing full Level2 data to the aggregation service and receiving pushed data of the aggregation service in real time, wherein the Redox/Redox-saga framework performs throttling cache on the data pushed by the aggregation service and performs calculation through a Web Worker, the Web Worker performs aggregation calculation on quantity and cumulant according to the aggregation precision of a transaction entrusted account book selected by a user, and updates the calculation result to a Redox state machine;
the aggregated service comprises: io service end; the socket.io server is used for communicating with the analysis module; full/incremental calibration and price screening of full Level2 data was performed.
Referring to fig. 2, fig. 2 shows a transaction ledger and span map display method for a whole process from a browser end to an exchange end, the method includes:
s101: a user enters a transaction target terminal from a browser end and requests to view a transaction entrusted account book and span map data; the transaction target terminal includes: the system comprises a feedback module, a rendering module, an analysis module and an aggregation service;
s102: the feedback module receives a client viewing request, acquires target information, merging precision and view information, transmits the target information, the merging precision and the view information to the analysis module for processing, and simultaneously transmits the user viewing request to the analysis module;
s103: the analysis module receives a user viewing request and subscribes full Level2 order data to the aggregation service; the transaction entrusted ledger and the span map data are constructed based on full Level2 order data;
s104: the aggregation service subscribes full Level2 order data to the exchange-side application programming interface; in a possible embodiment: the method for the aggregation service to subscribe the full Level2 order data to the exchange end application programming interface comprises the following steps: the aggregated service comprises: a sub-service; the sub-service is used as a subscription service; the analysis module subscribes a price window data parameter from the sub-service; the sub-service subscribes full Level2 order data to the exchange application programming interface according to the subscribed parameter range and the corresponding price window; when full-Level 2 order data are obtained, the sub-service pushes the full-Level 2 order data to an analysis module; the aggregated service further comprises: subscribing task management algorithm, wherein the subscribing task management algorithm adopts a modified LRU algorithm;
s105: the exchange end receives the subscription information of the aggregation service, pushes full Level2 order data to the aggregation service in real time through an application programming interface of the exchange end, performs calibration/aggregation processing in the aggregation service and puts the data into a memory;
s106: when calibration/aggregation processing is carried out in the aggregation service and the memory is put into the aggregation service, the aggregation service pushes real-time full Level2 order data to an analysis module; the analysis module receives the full Level2 order data and processes the order data to obtain a transaction entrusted ledger and span map data; the processing and treating process comprises the following steps: calling Web Worker asynchronous calculation precision combination and span accumulation according to the full Level2 order data;
s107: after processing, the analysis module updates the single data stream to the rendering module through the Redox framework;
s108: the rendering module synchronously updates the visible transaction entrusted ledger book and the span map data to the feedback module;
s109: and the feedback module displays the real-time transaction entrusted account book and the span map data to the user side through the UI component interface.
Referring to fig. 3, fig. 3 illustrates a transaction ledger sheet and span map display method for a browser side, the method comprising:
s201: the user enters a transaction target terminal from a browser end and views a transaction entrusted ledger and span map data, and the transaction target terminal comprises: the system comprises a feedback module, a rendering module, an analysis module and an aggregation module;
s202: the feedback module receives a client viewing request and sends a layout loading request to the rendering module;
s203: the rendering module performs a DOM update to the feedback module,
s204: after the updating, the feedback module obtains the view visible region parameters and the data parameters, and synchronizes the view visible region parameters and the data parameters to the analysis module, wherein the analysis module comprises: the system comprises a Redox state machine and a Redox-saga frame, wherein Web Worker asynchronous calculation is accessed into the frame;
s205: a Redox state machine of the analysis module synchronizes the visible region parameters and the data parameters of the view; the analysis module subscribes full Level2 data to the aggregation service and receives push data of the aggregation service in real time;
s206: when the analysis module receives the pushed data of the aggregation service in real time, the analysis module performs throttling cache on the data pushed by the aggregation service, and the data is calculated through a Web Worker, and the Web Worker performs quantity and cumulant aggregation calculation according to the aggregation precision of the transaction entrusted account book selected by the user; updating the calculation result to a Redox state machine of the analysis module;
s207: when the transaction entrusted ledger data and the span map data are updated to the Redox state machine, the analysis module updates the transaction entrusted ledger data and the span map data in a one-way data flow direction rendering module;
s208: after the rendering module is updated, the rendering module updates DOM to the feedback module;
s209: after the data is updated to the feedback module, the feedback module interacts with a user; and displaying the real-time transaction entrusted account book and the span map data to the user side through the UI component interface.
In a feasible embodiment, the transaction entrusted ledger and span map display method is used for a browser end; the method further comprises the following steps:
s301: when the feedback module interacts with a user, the user rolls to cause the visible area to change, at the moment, the feedback module checks whether data filling meets the DOM layout, and if so, the current DOM layout is displayed; if not, executing batch completion;
the batch supplementing method comprises the following steps: the feedback module acquires the view visible region parameters and the data parameters and synchronizes the view visible region parameters and the data parameters to the analysis module; the parsing module includes: the system comprises a Redox state machine and a Redox-saga frame, wherein Web Worker asynchronous calculation is accessed into the frame;
s302: a Redox state machine of the analysis module synchronizes the visible region parameters and the data parameters of the view; the analysis module supplements full Level2 data to the aggregation service according to conditions and receives push data of the aggregation service in real time;
s303: the analysis module performs throttling cache on data pushed by the aggregation service, calculates through a Web Worker, performs quantity and cumulant aggregation calculation according to the aggregation precision of a transaction entrusted account book selected by a user, and updates a calculation result to a Redox state machine;
in a possible embodiment, the view refresh is 60fps (frames/second), the reasonable throttling time is 16ms (milliseconds); the throttling algorithm is as follows: the data frame received in the throttling time is replaced by the last data frame in the throttling time
The analysis module throttling caching method comprises the following steps:
replacing the data frame received in the throttling time of 16ms with the last data in the throttling time;
carrying out asynchronous calculation on the replaced data by adopting a Web worker;
the Web worker carries out aggregation calculation of quantity and cumulant according to the data aggregation precision;
and updating the result after the aggregation calculation to a Redox state machine.
S304: when the transaction entrusted ledger data and the span map data are updated to the Redox state machine, the analysis module updates the transaction entrusted ledger data and the span map data in a one-way data flow direction rendering module;
s305: after the rendering module is updated, the rendering module updates DOM to the feedback module;
s306: after the data is updated to the feedback module, the feedback module interacts with a user; and displaying the real-time transaction entrusted account book and the span map data to the user side through the UI component interface. Each time the UI layout changes, the feedback module is triggered to recalculate.
Referring to fig. 4, fig. 4 is a flow chart illustrating the feedback module acquiring the view visible region parameter and the data parameter;
the method for acquiring the parameters of the visible region of the view and the data parameters by the feedback module comprises the following steps:
monitoring DOM changes of the drawing area by the constructor;
filling the target drawing area by the drawing area DOM, wherein the drawing area DOM is changed, and the user view display area is changed;
local updating is realized according to the change of the user view display area; the local update content includes: a lowest buying price interval and a highest selling price interval.
The feedback module calculates the parameters of the obtained visual visible region and the data parameters by adopting a price window mechanism; the maximum data range required to be prepared; the calculation is used for screening out the data set stored in the browser end from the aggregation service.
The method for realizing local updating according to the change of the user view display area comprises the following steps:
obtaining (scrollTop, scrollHeight), wherein the scrollTop refers to the height of the content in the element beyond the upper boundary part of the element and is used for setting the vertical offset of the scroll bar in the element; the scrollHeight refers to the complete height of the return element and is the total height of the element content; changing the DOM of the drawing area to enable a getBoundingClientRect function to obtain showHeight (height of a display area), and obtaining an expanded data set through a self-increasing and adjusting price window of n; wherein, the initial n is 2, and the n is a multiple which changes with the user interaction/scrolling the view visible area; meanwhile, the DOM of the drawing area changes to change the DOM of the order, and the DOM of the order sets the height of each element through rowHeight;
the feedback module calculates the change of the display area according to the acquired content to realize local updating;
updating a data area distributed near a visible area according to a part of order purchase orders displayed in the visible area of a browser end user; local update content is obtained. The local update content maintains a transaction commitment ledger at the browser end.
In a feasible embodiment, the analysis module usage scenario comprises a scenario of precision aggregation and merging orders with the same price; when the analysis module is in the scene, the feedback module cannot fill and complete all target drawing areas according to a price interval corresponding to a certain layout; when the feedback module updates the parameters of the visual visible region and the data parameters, the internal drawing inspection of the feedback module is triggered;
if the unfilled region does not exist, updating through checking;
if the unfilled region exists, the feedback module calculates the filling range, expands the height parameter of the display region, and obtains an expanded data set through the self-increasing adjusting price window of n; where initial n is 2, the n is a multiple of the change in the visible area as the view is interacted/scrolled by the user.
In the process that the analysis module updates transaction entrusted book data and span map data by a unidirectional data flow to the rendering module, the specific position updated to the rendering module by the analysis module is a read component of the rendering module, and the read component is used for calculating DOM update; and synchronizing the DOM update to the feedback module;
when the analysis module updates the transaction entrusted ledger data and the span map data by a one-way data flow rendering module; the method for updating DOM to the feedback module by the rendering module comprises the following steps:
the rendering module is used for drawing a transaction entrusted ledger book and a span map; and the rendering module adopts a virtual list algorithm to draw a transaction entrusted ledger book and adopts a DOM Canvas to draw a span diagram.
The virtual list algorithm is a dynamically rendered DOM structure created substantially by an algorithm, which differs from a common standard DOM list by the control of the number of elements, the list virtual algorithm calculates a data set corresponding to the visible area of the current list relative to the full list data by pre-estimating the full data, the visible range of the current list, the user interaction state of a feedback module, according to the user scroll height and the external height of the list; meanwhile, high-frequency data stream updating is solved by combining DOM frames, frame output is carried out by utilizing the refresh frequency of a display, a small part of views are quickly rendered, and a good fps index is achieved.
The virtual list algorithm principle is as follows:
the lower-layer tables are estimated by constructing a FilterMask mask area, so that one FilterMask manages N lower-layer tables,
applying the virtual list algorithm principle to the scene shown in the application;
the method for drawing the transaction entrusted ledger comprises the following steps:
the rendering module is used for drawing the order forms of the buy order and the order form at the same time to obtain only a display item and a cache item;
meanwhile, the height of the hidden area data is only calculated and reset to the height of the list, so that the height of the scroll bar is opened, and the position of the scroll bar is positioned; the actual display effect is consistent with the rendering of all data;
the method for drawing the span map comprises the following steps:
the rendering module is used for drawing a transaction entrusted ledger book and a span map;
the method for drawing the transaction entrusted ledger comprises the following steps:
the rendering module is used for drawing the order forms of the buy order and the order form at the same time to obtain only a display item and a cache item; meanwhile, the height of the hidden area data is only calculated and reset to the height of the list, so that the height of the scroll bar is opened, and the position of the scroll bar is positioned; the actual display effect is consistent with the rendering of all data.
The principle of the span map drawing optimization algorithm is as follows:
the span map is a two-dimensional area map with price as an X axis and quantity as a Y axis; when the data volume is too dense, each pixel point in the two-dimensional area map has a large number of data points which have no meaning to users, so that the data points are combined; the merging adopts a simplified edge sampling algorithm to merge and extract data points, so that the number of drawn data points is reduced, and the Canvas drawing efficiency is improved.
Since the span map is an area map, it is necessary to process a matrix of data points as [ [ [ x1, y1], [ x2, y2], … ], which is a two-dimensional array.
The method for drawing the span map comprises the following steps:
drawing the pixel length N of the region according to the data point array length M and the X axis of the area map; if M is larger than N, randomly taking 3N data and disordering the data to form an array K; if M < ═ N; the subsequent steps are omitted;
adding K to the area map starting point [ x1, 0] and the ending point [ xn, 0 ];
traversing each data element of K and calculating the distance Dis between the point and all other points, recording the distance and the index0, index1 of the two points to a new array R, wherein the elements of the new array R are [ Dis, index0 and index1 ];
sequencing the new array R in the positive sequence according to Dis, and if two indexes have points which are not deleted, recording the points into a deleted array RM; the above process is circulated until len (rm) 2N is found, and the deletion can be finished;
and traversing K, deleting points of the index in the RM, and sequencing according to the price to obtain simplified area map data.
Referring to fig. 5, fig. 5 is a flowchart of the aggregated service work;
in a feasible embodiment, the aggregated service is deployed separately; the method for the aggregation service to subscribe the full Level2 order data to the exchange end application programming interface comprises the following steps:
the aggregated service comprises: a sub-service; the sub-service is used as a subscription service; the analysis module subscribes a price window data parameter from the sub-service; the sub-service subscribes full Level2 order data to the exchange application programming interface according to the subscribed parameter range and the corresponding price window;
when full Level2 order data is obtained, the sub-service pushes the full Level2 order data to the analysis module.
Referring to fig. 6, fig. 6 is a schematic diagram of an aggregated service subscription task management algorithm.
The aggregated service further comprises: and subscribing a task management algorithm, wherein the subscribing task management algorithm adopts a modified LRU algorithm.
The LRU algorithm is used for task management and realizes real-time on-demand scheduling on-demand calculation.
The present application has been described in detail with reference to specific embodiments and illustrative examples, but the description is not intended to limit the application. Those skilled in the art will appreciate that various equivalent substitutions, modifications or improvements may be made to the embodiments and implementations of the disclosure without departing from the spirit and scope of the disclosure, which is within the scope of the disclosure as defined by the appended claims.