Foreign exchange service position contract grouping and circulating delivery method and system
By grouping foreign exchange position contracts by user and currency and using Redis zset and skip list structures, the automation and independence issues of the foreign exchange position contract settlement system were solved, improving settlement speed and success rate.
Patent Information
- Application Number
- CN202411166357.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2025-01-10
AI Technical Summary
The existing foreign exchange position contract settlement system cannot automatically initiate cyclical settlements every night, and the settlement processes for different clients and currencies affect each other and cannot be carried out independently.
Foreign exchange business position contracts are grouped by user and currency to generate several queues, and the data is stored using Redis zset and skip list structure. The settlement logic is executed independently and concurrently by multiple threads, and the settlement is carried out in a loop until all position contracts are successfully settled or cannot be settled.
It enables independent settlement for different clients and currencies, improving settlement speed and success rate, reducing the time complexity of data query and deletion, and avoiding mutual interference of processing logic.
Smart Images

Figure CN119295208A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information management technology, and in particular to a method and system for grouping and cyclic delivery of foreign exchange business position contracts. Background Art
[0002] The daily delivery data of the foreign exchange business position contract needs to automatically initiate a cyclic delivery every night. When creating a foreign exchange contract, the customer will specify the delivery date. On the night of the delivery date, the foreign exchange service needs to deliver the contract whose delivery date is the same day. In the prior art, after the foreign exchange transaction is connected to the fund background, the business personnel generally handle each transaction connected to the fund background. Specifically, the transaction processing process of the business personnel includes: the business personnel determine the clearing exchange route of the transaction and supplement the remarks or notes; then, manually review the authorized clearing exchange route and the remarks or notes information, and after the authorization is passed, the clearing process is executed for the transaction to obtain the delivery cash flow; if the transaction incurs expenses, the business personnel also need to enter the fee delivery request in the fee module, and then review the authorization process; for the net amount netting delivery transaction, such as the primary investment net amount netting delivery transaction, the clearing exchange route needs to be adjusted after delivery, and then the above manual review of the authorized clearing exchange route and subsequent steps are repeated.
[0003] There are also some delivery systems that can perform automatic delivery, but the existing foreign exchange business position contract delivery system cannot automatically initiate delivery and complete all delivery tasks every night when delivering daily data. The delivery processing processes of different customers will affect each other, and different currencies of the same customer will also affect each other. The delivery of different users and different currencies cannot be carried out independently. Summary of the invention
[0004] The purpose of the present invention is to solve the shortcomings of the above-mentioned prior art, and to provide a method and system for grouping and cyclic delivery of foreign exchange business position contracts, so as to realize automatic initiation of cyclic delivery every night, and at the same time, the delivery processing processes of different customers do not affect each other. Each time there is successful delivery data in a queue to be delivered, a round of delivery needs to be initiated again until all positions are delivered or no position can be successfully delivered after one cyclic delivery.
[0005] On the one hand, the method for grouping and cyclic delivery of foreign exchange business position contracts comprises the following steps: S1: fetch the list of positions to be delivered on the day from the database, and group the list of positions to be delivered according to users and currencies to generate several queues; S2: Create an independent of Redis zset collection, the position contract data in each queue is added to the corresponding Redis zset collection according to the queue order score number, and each Redis zset collection is a queue to be delivered; S3: Carry out this round of delivery, obtain each queue to be delivered in turn, start multiple threads, and each thread independently executes the delivery logic of a queue to be delivered until all queues to be delivered complete this round of delivery; S4: If after this round of delivery, the size of all queues to be delivered is smaller than the size of the queues to be delivered before this round of delivery and is not 0, then repeat S3 for a new round of delivery.
[0006] Furthermore, in step S1, a list of position contracts to be delivered on that day is retrieved from the database, and the list of position contracts to be delivered is grouped according to users and currencies to generate a plurality of queues, further comprising: According to the delivery date conditions, the data set of the position contracts to be delivered on the delivery date is retrieved from the relational database; Sort the data set of the pending delivery position contracts in the pending delivery list according to actual business needs; The list to be delivered is grouped according to the user and currency, the contract data to be delivered corresponding to the same currency of the same user is placed in the same group, and each of the groups is independently stored in a delivery queue.
[0007] Further, in step S2, an independent of The redis zset collection, the position contract data in each queue is added to the corresponding redis zset collection according to the queue order score number, further including: According to the order score number of the position contract data in each queue, the data of each queue in the redis zset set is stored in a skip list structure; The mapping data of the order score number of each data in the redis zset collection and the position contract id value is stored as a hash table.
[0008] Preferably, in the delivery logic of step S3, when obtaining the position contract id according to the score sequence number of the queue, the jump table and hash table are queried according to the ZRANGEBYSCORE command to obtain the corresponding position contract id.
[0009] Furthermore, the delivery logic specifically includes: Read the queues according to the score sequence number of the queues to be delivered, and initiate delivery from the first data to be delivered in the queue; If the current data to be delivered is delivered successfully, the current data to be delivered and its record are deleted from the queue to be delivered, and the next data to be delivered is delivered; If the current data to be delivered fails to be delivered, the next data to be delivered in the queue will be delivered directly.
[0010] Further, in step S4, if the size of the queue to be delivered after the current round of delivery is smaller than the size of the queue to be delivered before the current round of delivery and is not 0, then repeating S3 for a new round of delivery further includes: Use the ZCARD command to obtain the size of the queue to be delivered after this round of delivery. If the queue size is empty, the delivery is over and the delivery task of the current queue is completed; If the queue size is not empty and is smaller than the size of the queue to be delivered before the current round of delivery, repeat the delivery logic to perform a new round of delivery on the remaining queues to be delivered; If the queue size is equal to the size of the queue to be delivered before this round of delivery, the default process is triggered and the delivery task of the current queue is completed.
[0011] Preferably, the data to be delivered of the specified index n in the delivery queue is obtained through the "ZRANGE nn" command, n=0 when the delivery logic is initiated, and then the next data to be delivered according to the queue order score is obtained through the "ZRANGE n+1 n+1" command.
[0012] On the other hand, the foreign exchange business position contract grouping and cyclic delivery system includes: The collection and grouping module is used to retrieve the list of positions to be delivered on the day from the database, and group the list of positions to be delivered according to users and currencies to generate several queues; Ordered storage module, used to create independent of Redis zset collection, the position contract data in each queue is added to the corresponding Redis zset collection according to the queue order score number, and each Redis zset is a queue to be delivered; The delivery module is used to perform this round of delivery, loop through each queue to be delivered in turn, start multiple threads, and each thread independently executes the delivery logic of a queue to be delivered until all queues to be delivered complete this round of delivery; if after this round of delivery, the size of all queues to be delivered is less than the size of the queues to be delivered before this round of delivery and is not 0, a new round of delivery is performed according to the delivery logic.
[0013] Compared with the prior art, the present invention has the following beneficial effects: (1) The present invention groups a customer's pending delivery data needs and currencies, and then divides the target pending delivery data into small queues. Each queue runs the delivery logic independently and concurrently, thereby improving the data processing speed. At the same time, the processing logic of each queue is independent of each other and does not affect each other; (2) The present invention sets a circular delivery logic, so that when the buying and selling data to be delivered are interdependent, the dependent position contracts can also be delivered successfully; (3) The data storage bottom layer of the present invention uses a skip table and a hash table data structure, and the time complexity of searching and deleting is O(logN), which improves the data query speed and deletion speed and reduces the number of times the database data is directly read. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings: Figure 1 A core flow diagram of a foreign exchange business position contract grouping cyclic delivery method of the present invention; Figure 2 A schematic diagram of foreign exchange business position contract data grouping according to the present invention; Figure 3 A schematic diagram of a redis zset queue position contract data storage method according to the present invention; Figure 4 The present invention is a schematic diagram of sequential score and ID mapping data storage of a redis zset queue. DETAILED DESCRIPTION
[0015] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0016] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0017] After the end-of-day delivery batch function of foreign exchange position contracts uses the logic of the present invention, the delivery of position contracts of different users will no longer affect each other. The business party expects that the daily data of position contracts to be delivered can be grouped for delivery, which can improve the delivery speed and avoid the mutual influence of the processing logic of different users. After there are deliverable position contracts, another round of delivery can be cycled until all deliveries are completed or all position contracts cannot be delivered.
[0018] The main purpose of the present invention is to provide a solution to the problem of grouped cyclic delivery of foreign exchange business position contracts by realizing grouped cyclic delivery logic. The business party hopes that the daily position contract data to be delivered can be grouped for delivery to improve the delivery speed and avoid the mutual influence of the processing logic of different users. After there are deliverable position contracts, another round of delivery can be cycled until all deliveries are completed or all position contracts cannot be delivered.
[0019] The specific implementation of the present invention is described below with reference to the accompanying drawings and embodiments.
[0020] Example 1 To achieve Figure 1 As shown, this embodiment provides a method for grouping and cyclic delivery of foreign exchange business position contracts. The daily delivery data of the foreign exchange business position contracts needs to automatically initiate cyclic delivery every night. At the same time, the delivery processing processes of different customers cannot affect each other. At the same time, the data to be delivered by a customer needs to be grouped according to the currency type, and the delivery of different users and different currencies is carried out independently. Each time there is successful delivery data in a queue to be delivered, a round of delivery needs to be initiated again until all deliveries are completed or no position can be successfully delivered after a cyclic delivery, including the following steps: S1: fetch the list of positions to be delivered on the day from the database, and group the list of positions to be delivered according to users and currencies to generate several queues; S2: Create an independent of Redis zset collection, the position contract data in each queue is added to the corresponding Redis zset collection according to the queue order score number, and each Redis zset collection is a queue to be delivered; S3: Carry out this round of delivery, obtain each queue to be delivered in turn, start multiple threads, and each thread independently executes the delivery logic of a queue to be delivered until all queues to be delivered complete this round of delivery; S4: If after this round of delivery, the size of all queues to be delivered is smaller than the size of the queues to be delivered before this round of delivery and is not 0, then repeat S3 for a new round of delivery.
[0021] Among them, in the prior art, after the foreign exchange transaction is connected to the funds background, the business personnel generally process each transaction connected to the funds background. In step S1 of the present application, in order to prevent different customers' exchange contracts from affecting each other during the delivery process, and at the same time prevent different currencies in the data to be delivered of the same customer from affecting each other, the data to be delivered are grouped according to customers and currencies, and the delivery of different users and different currencies is carried out independently.
[0022] Specific as Figure 2 As shown, a list of position contracts to be delivered on that day is retrieved from the database, and the list of position contracts to be delivered is grouped according to users and currencies to generate a plurality of queues, further comprising: According to the delivery date conditions, the data set of the position contracts to be delivered on the delivery date is retrieved from the relational database; Sort the data set of the pending delivery position contracts in the pending delivery list according to actual business needs; The list to be delivered is grouped according to the user and currency, the contract data to be delivered corresponding to the same currency of the same user is placed in the same group, and each of the groups is independently stored in a delivery queue.
[0023] After dividing the target data to be delivered into small queues, each queue runs the delivery logic independently and concurrently, which improves the data processing speed. At the same time, the processing logic of each queue is independent of each other and does not affect each other.
[0024] Then in step S2, we need to store the data of these delivery queues in order.
[0025] like Figure 3 and Figure 4 As shown, first, create an independent of Redis zset collection, the position contract data in each queue is added to the corresponding Redis zset collection according to the queue order score number, further including: According to the order score number of each queue, the data of each queue in the redis zset set is stored in a skip list structure, and the time complexity is reduced from O(n) of the traditional linked list to O(logN). Figure 3 As shown, in this embodiment, the following data needs to be stored: p1, p2, p3, p4, p5, p6, p7, p8, p9, and the order in which they need to be stored in the queue is in the order of the ID, so the score sequence number stored in the redis zset set is 1, 2, 3, ..., 9.
[0026] For example: ZADD userId1-USD 1 contract 1 (where "userId1-USD" is the queue name, and "1" is the order of the position contract of "contract 1" in the small queue grouped by user and currency).
[0027] When processing large amounts of data, the skip table achieves fast positioning through multi-layer indexing, without the need to compare each element one by one, while supporting efficient range queries; the time complexity of insertion and deletion operations is also O(LogN), which is better than many dynamic data structures. This is especially important in the field of financial transactions, because the rapid changes in position contracts require the underlying data structure to be able to efficiently reflect these changes, and it is often necessary to query contracts within a specific time period or fractional interval. The range query function of the skip table fully meets this demand.
[0028] Secondly, the mapping data between each queue score number and position contract id value is stored as a hash table. Figure 4 As shown in the figure, the mapping between sequence and contract data is completed through the hash method, which improves the speed of querying value and the time complexity is O(1).
[0029] The underlying data storage uses skip table and hash table data structures to improve data query and deletion speeds and reduce the number of times database data is directly read.
[0030] In the delivery logic of step S3, when obtaining the position contract id according to the score sequence number of the queue, the jump table and hash table are queried according to the ZRANGEBYSCORE command to obtain the corresponding position contract id.
[0031] The delivery logic specifically includes: Read the queues according to the score sequence number of the queues to be delivered, and initiate delivery from the first data to be delivered in the queue; If the current data to be delivered is delivered successfully, the current data to be delivered and its record are deleted from the queue to be delivered, and the next data to be delivered is delivered; If the current data to be delivered fails to be delivered, the next data to be delivered in the queue will be delivered directly.
[0032] Further, in step S4, if the size of the queue to be delivered after the current round of delivery is smaller than the size of the queue to be delivered before the current round of delivery and is not 0, then repeating S3 for a new round of delivery further includes: Use the ZCARD command to obtain the size of the queue to be delivered after this round of delivery. If the queue size is empty, the delivery is over and the delivery task of the current queue is completed; If the queue size is not empty and is smaller than the size of the queue to be delivered before the current round of delivery, the delivery logic is repeated to perform a new round of delivery on the remaining queues to be delivered. In this embodiment, a check logic is added to prevent an infinite loop, and the number of cyclic deliveries is less than 100 times; If the queue size is equal to the size of the queue to be delivered before this round of delivery, the default process is triggered and the delivery task of the current queue is completed.
[0033] After the delivery is completed, the remaining position contracts that cannot be delivered need to be handled as default due to failed delivery.
[0034] Among them, the data to be delivered of the specified index n in the delivery queue is obtained through the "ZRANGE nn" command. When the delivery logic is initiated, n=0, and then the next data to be delivered according to the queue sequence score is obtained through the "ZRANGE n+1 n+1" command. In this embodiment, under a delivery queue, elements are sequentially obtained from the queue according to the score sequence number. If the position contract is delivered successfully, the element is deleted from the queue. For example, if the delivery is currently started, the zset element with score=1 is obtained for delivery. After the delivery of the element with score=1 is completed, the element with score=1 is deleted, and the element with score=2 is obtained for delivery, and so on.
[0035] In this embodiment, at the beginning of a round of delivery, the size of the delivery queue is recorded. When a position contract is delivered, the current data is removed from the queue. After the current round of delivery, if the queue size is reduced and is not empty, a new round of delivery will continue. Until the delivery queue is empty, or no position contract can be delivered in this round. The remaining contracts that cannot be delivered will follow the default logic.
[0036] After the above logic is used in the end-of-day delivery batch function of foreign exchange position contracts, the delivery of position contracts of different users will no longer affect each other. Grouping users and then performing delivery concurrently significantly increases the delivery speed. In theory, the delivery speed of several small queues is several times faster than that of a large queue.
[0037] At the same time, this delivery method has a circular delivery function. When the buying and selling data to be delivered are interdependent, the dependent position contracts can also be delivered successfully.
[0038] The circular delivery function allows users to settle all their position contract data when they are interdependent (for example, Contract 1 sells 100 USD to get EUR, Contract 2 sells CNH to get 100 USD, but the user's account currently has no USD balance, but only sufficient CNH balance. After Contract 2 is settled, Contract 1 can be settled in the next round of settlement).
[0039] Example 2 In this embodiment, a foreign exchange business position contract grouping and cyclic delivery system is disclosed, including: The collection and grouping module is used to retrieve the list of positions to be delivered on the day from the database, and group the list of positions to be delivered according to users and currencies to generate several queues; Ordered storage module, used to create independent of Redis zset collection, the position contract data in each queue is added to the corresponding Redis zset collection according to the queue order score number, and each Redis zset is a queue to be delivered; The delivery module is used to perform the current round of delivery, loop to obtain each queue to be delivered, start multiple threads, and each thread independently executes the delivery logic of a queue to be delivered until all queues to be delivered complete the current round of delivery.
[0040] Obviously, those skilled in the art can make various changes and modifications to the invention without departing from the spirit and scope of the invention. Thus, if these modifications and variations of the invention fall within the scope of the claims of the invention and their equivalents, the invention is also intended to include these modifications and variations.
[0041] Finally, it should be noted that the above are only preferred embodiments of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for grouping and cyclic delivery of foreign exchange business position contracts, characterized in that: The steps include: S1: fetch the list of positions to be delivered on the day from the database, and group the list of positions to be delivered according to users and currencies to generate several queues; S2: Create an independent redis zset set for each queue. The position contract data in each queue is added to the corresponding redis zset set according to the score sequence number of the queue order. Each redis zset set is a queue to be delivered. S3: Carry out this round of delivery, obtain each queue to be delivered in turn, start multiple threads, and each thread independently executes the delivery logic of a queue to be delivered until all queues to be delivered complete this round of delivery; S4: If after this round of delivery, the size of all queues to be delivered is smaller than the size of the queues to be delivered before this round of delivery and is not 0, then repeat S3 for a new round of delivery.
2. The method for grouping and cyclic delivery of foreign exchange business position contracts according to claim 1, characterized in that: In step S1, a list of positions to be delivered on that day is retrieved from a database, and the list of positions to be delivered is grouped according to users and currencies to generate a number of queues, further comprising: According to the delivery date conditions, the data set of the position contracts to be delivered on the delivery date is retrieved from the relational database; Sort the data set of the pending delivery position contracts in the pending delivery list according to actual business needs; The list to be delivered is grouped according to the user and currency, the contract data to be delivered corresponding to the same currency of the same user is placed in the same group, and each of the groups is independently stored in a delivery queue.
3. The method for grouping and cyclical delivery of foreign exchange business position contracts according to claim 1, characterized in that: In step S2, an independent redis zset set is created for each queue, and the position contract data in each queue is added to the corresponding redis zset set according to the queue order score number, further including: According to the order score number of the position contract data in each queue, the data of each queue in the redis zset set is stored in a skip list structure; The mapping data of the order score number of each data in the redis zset collection and the position contract id value is stored as a hash table.
4. The method for grouping and cyclical delivery of foreign exchange business position contracts according to claim 3, characterized in that: In the delivery logic of step S3, when obtaining the position contract id according to the score sequence number of the queue, the jump table and hash table are queried according to the ZRANGEBYSCORE command to obtain the corresponding position contract id.
5. The method for grouping and cyclical delivery of foreign exchange business position contracts according to claim 4, characterized in that: The delivery logic specifically includes: Read the queues according to the score sequence number of the queues to be delivered, and initiate delivery from the first data to be delivered in the queue; If the current data to be delivered is delivered successfully, the current data to be delivered and its record are deleted from the queue to be delivered, and the next data to be delivered is delivered; If the current data to be delivered fails to be delivered, the next data to be delivered in the queue will be delivered directly.
6. The method for grouping and cyclic delivery of foreign exchange business position contracts according to claim 5, characterized in that: In step S4, if the size of the queue to be delivered after the current round of delivery is smaller than the size of the queue to be delivered before the current round of delivery and is not 0, then repeating S3 for a new round of delivery further includes: Use the ZCARD command to obtain the size of the queue to be delivered after this round of delivery. If the queue size is empty, the delivery is over and the delivery task of the current queue is completed; If the queue size is not empty and is smaller than the size of the queue to be delivered before the current round of delivery, repeat the delivery logic to perform a new round of delivery on the remaining queues to be delivered; If the queue size is equal to the size of the queue to be delivered before this round of delivery, the default process is triggered and the delivery task of the current queue is completed.
7. The method for grouping and cyclical delivery of foreign exchange business position contracts according to claim 6, characterized in that: The "ZRANGE nn" command is used to obtain the data to be delivered of the specified index n in the delivery queue. When the delivery logic is initiated, n=0. Then the "ZRANGE n+1n+1" command is used to obtain the next data to be delivered according to the score of the queue sequence.
8. A foreign exchange business position contract grouping and cyclic delivery system, characterized in that: include: The collection and grouping module is used to retrieve the list of positions to be delivered on the day from the database, and group the list of positions to be delivered according to users and currencies to generate several queues; The ordered storage module is used to create an independent redis zset set for each queue. The position contract data in each queue is added to the corresponding redis zset set according to the score sequence number of the queue order. Each redis zset is a queue to be delivered. The delivery module is used to perform this round of delivery, loop through each queue to be delivered in turn, start multiple threads, and each thread independently executes the delivery logic of a queue to be delivered until all queues to be delivered complete this round of delivery; if after this round of delivery, the size of all queues to be delivered is less than the size of the queues to be delivered before this round of delivery and is not 0, a new round of delivery is performed according to the delivery logic.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by the processor, a method for grouping and cyclically settling foreign exchange business position contracts according to any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the foreign exchange business position contract group cyclic delivery method as described in any one of claims 1 to 7.
Citation Information
Cited By
Position contract delivery method, electronic equipment and medium
CN121639211A