# Finalizing Orders

Once a trade has been matched, the finalise button will become visible on the UX for both the counterparties to the trade, like so:<br>

<figure><img src="https://2294933522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FewLyC4ny0ztkYYXokV4j%2Fuploads%2FUSF2tjiRSfTZiq9NcS0I%2FScreenshot%202023-04-07%20at%204.07.41%20pm.png?alt=media&#x26;token=55ea4490-4524-4af5-bb6b-0c3c2ce5f30c" alt=""><figcaption><p>Finalising orders using the GUI</p></figcaption></figure>

Similarly, users of the SDK will find that the "EventQListener" will detect when an order has been filled, and provide template transactions for "*FinaliseBid*" and "*FinaliseAsk*".\
\
Either user may then proceed to finalize the order. Upon clicking Finalize, the program logic checks that both the counterparties to the trade have enough tokens in their openorders accounts. If not, it attempts to transfer the appropriate amount of funds from the party to the program owned "vault". Once th\
If so, it proceeds with modifying the balances according to the trade terms, and then marks the trade as finalized (to prevent double spends). After finalization is completed, the user can instantly see their updated balances from their OpenOrdersPDA:<br>

<figure><img src="https://2294933522-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FewLyC4ny0ztkYYXokV4j%2Fuploads%2FT4ImR0eUiQFg1GmoJz92%2FScreenshot%202023-04-07%20at%204.10.42%20pm.png?alt=media&#x26;token=08cae3c1-5cd8-41bc-a1f6-441f6d4b9829" alt=""><figcaption><p>Updated Balances visible on GUI</p></figcaption></figure>

These funds will then available for withdrawal at any time. For a deeper dive into the logic executed at the `finalizeOrders` step, please see [just-in-time-liquidity](https://fermi-dex.gitbook.io/fermi-dex-docs/technical-overview/architecture/just-in-time-liquidity "mention").\
\
Example Finalise Transaction: <https://solscan.io/tx/2bSohxq73L9gouc4dmuQnkkd1uctNxMuNw2xmJms1RntvUNb5cdWt7NqMmpujhjPTGLZFMZxzFqVEJcyAzLGx1uH?cluster=devnet>
