Use queues and provide a reference for queue items as “company id_account id”
If you are only trying to attach few fights from those account then you would have use substring function to fetch required of that account and then concatenate with company id.
If you got the logic, and have issue when robot is breaking down. Would it be possible for you to save the couple somewhere when it has been couple? Then use a tryCatch in the for each (or what you are using), the it will continue if it breaks. In the catch you could log what it failed on.
If it breaks, now you have a list of what went well and can either filter it out or create an if in the loop to quickly skip the current couple.
Use a two-phase queue-based approach to ensure reliable pairing and processing. First, extract and sort Fiduciary and Settlement accounts by CompanyID and Currency to maintain deterministic pairing. Create one pair per queue item and assign a unique reference using: CompanyID_FiduciaryAccount_SettlementAccount. Store full details in JSON.
The processing workflow simply retrieves queue items, executes logic per pair, and marks items as Successful or Business/ System Exception. Built-in retry logic and queue status ensure no duplication and safe restart if the bot stops mid-run. Logging and exception handling ensure traceability, making the design scalable and fault-tolerant.