Path: blob/main/docs/versioned_docs/version-v0.26/02-guide/07-interchange/07-creating-buy-orders.md
1007 views
---
---
Creating Buy Orders
In this chapter, you implement the creation of buy orders. The logic is very similar to the sell order logic you implemented in the previous chapter.
Modify the Proto Definition
Add the buyer to the proto file definition:
Now, use Ignite CLI to build the proto files for the send-buy-order
command. You used this command in previous chapters.
IBC Message Handling in SendBuyOrder
Check if the pair exists on the order book
If the token is an IBC token, burn the tokens
If the token is a native token, lock the tokens
Save the voucher received on the target chain to later resolve a denom
On Receiving a Buy Order
Update the buy order book
Distribute sold token to the buyer
Send the sell order to chain A after the fill attempt
Implement a FillBuyOrder Function
The FillBuyOrder
function tries to fill the sell order with the order book and returns all the side effects:
Implement a LiquidateFromBuyOrder Function
The LiquidateFromBuyOrder
function liquidates the first buy order of the book from the sell order. If no match is found, return false for match:
Receiving a Buy Order Acknowledgment
After a buy order acknowledgement is received, chain Mars
:
Stores the remaining sell order in the sell order book.
Distributes sold
marscoin
to the buyers.Distributes to the seller the price of the amount sold.
On error, mints back the burned tokens.
AppendOrder
appends an order in the buy order book. Add the following function to the x/dex/types/buy_order_book.go
file in the types
directory.
OnTimeout of a Buy Order Packet
If a timeout occurs, mint back the native token:
Summary
Congratulations, you implemented the buy order logic.
Again, it's a good time to save your current state to your local GitHub repository: