OrderBook Blueprint
The OrderBook Blueprint is an extended standard template built on top of the Basic Blueprint. It is designed to help developers create custom Agents with order book functionality. In addition to inheriting all features of the Basic Blueprint, the OrderBook Blueprint introduces several core functionalities to support the creation, management, and settlement of orders.
OrderBook Blueprint Analysis
New Core Features
Make Order: Allows the Agent to create Notes (orders).
Execute Settlement: The core operation during the matching and settlement phases, enabling the actual transfer of assets.
Cancel Order: Cancels published Notes that have not yet been settled.
Detailed Code Explanation
1. Make Order
This feature enables the Agent to publish trading intentions using Notes, which specify trading conditions (e.g., asset type and quantity), supporting the creation of orders in the order book.
Feature Description:
Allows the Agent owner to create new Notes by calling this interface.
Key Code Logic:
Validate the legality of input parameters (e.g., asset type, quantity, expiration time).
Call the FFP protocol’s CreateNote interface to generate a Note and store it in the Agent’s internal data table.
2. Execute Settlement
Feature Description:
When Notes issued by the Agent enter the settlement phase, the FFP settlement center triggers the Agent to execute asset transfer operations.
Supports the Agent in handling asset delivery for Notes it created during settlement.
Key Code Logic:
Validate the Note’s legitimacy (e.g., ensure it exists, was issued by the Agent, and has an Open status).
Update the Note’s status to Executed.
Transfer the corresponding assets to the FFP settlement center.
3. Cancel Orders
Feature Description:
Allows the Agent owner to cancel Notes that have not yet been settled.
Only Notes in the Open status can be canceled; other statuses (e.g., Executed or Settled) cannot be canceled.
Key Code Logic:
Verify that the Note belongs to the current Agent and ensure its status is Open.
Call the FFP protocol’s Cancel interface to cancel the Note.
Update the local Note status to Canceled.
Complete Code
Before development, copy orderbook.lua and utils.lua into your development environment.
Summary
The OrderBook Blueprint is an upgraded version of the Basic Blueprint, designed for developers requiring advanced transaction and order management logic. It provides standardized foundational features for building custom order book Agents, enabling developers to quickly get started and focus on optimizing and implementing their business logic.
Last updated
Was this helpful?