avatarSzymon Kolber

Summary

The webpage provides a comprehensive guide on understanding and utilizing NFT order books, with a focus on Rarible's API for accessing order book data.

Abstract

The article titled "Master NFT order books in 10 minutes" aims to demystify the concept of order books within the context of NFTs. It explains the roles of makers (sellers) and takers (buyers) in the market, and differentiates between traditional and NFT order books, emphasizing the absence of fees for NFT order book transactions. The piece also delves into the management of order books in the web3 space, clarifying that they are centrally managed for efficiency and cost savings. The author highlights Rarible's API as a tool for interacting with order books, showcasing how to fetch and interpret data such as sell orders, bids, and the "bestBidOffer" for collections like the BoredApeYachtClub. The article concludes by encouraging hands-on practice with the API and invites readers to engage with the Rarible community for further assistance.

Opinions

  • The author suggests that understanding order books is straightforward, involving makers who create the market by setting sell orders and takers who fulfill these orders.
  • It is implied that the centralized management of order books is a necessary compromise for achieving efficiency and cost savings in the web3 ecosystem.
  • The author conveys that Rarible's API simplifies the process of interacting with NFT order books, making it accessible for developers to retrieve and use order book data.
  • By providing real-world examples and highlighting the "bestBidOffer" feature, the author indicates the practical utility of the Rarible API in accessing valuable market information.
  • The article encourages a proactive approach to learning, emphasizing the importance of practical experience over exhaustive documentation when working with the Rarible API.
  • The invitation to join the Rarible community on Discord reflects the author's view that community support and direct communication are important resources for developers.

Master NFT order books in 10 minutes

Understand the core concepts and learn how to use them.

What are order books?

Let’s start with the official definition:

“The term order book refers to an electronic list of buy and sell orders for a specific security or financial instrument organized by price level.”

Order books are pretty simple to understand. You have a maker, aka a person who wants to sell an asset for a specific price, and you have a taker, aka a person who wants to buy it at some price. Makers are the people who are creating a market. It means that they put an order such as “I want to sell a Bitcoin for $10k”, and wait — somebody can buy it or not. Simple. Takers are people who go to the market and buy it. In most scenarios takers also pay some fee.

NFT order books vs regular order books

Since regular order books are most often a part of brokerage software, takers pay some fee. That’s not the case with NFT order books. With NFT order books, you have an NFT, the owner of this NFT, and other people that can possibly be interested in buying this NFT. In this scenario the NFT is an asset, the owner can be a maker, and the buyer can be a taker. I’m using “can be” to emphasize that even though the owner doesn’t want to sell an NFT, he/she can still receive an offer for it. Even when nobody in the whole market wants to buy a given NFT, the owner can still create an offer, informing that he wants to sell it for X. That’s an order book. It stores orders for different assets and aims to connect interested parties to one another.

Relationship between two participating parties

Where does the order book work in a web3 world?

You may have thought that the order book existed in some smart contract and was kept on-chain. It is not true. Order books are managed in a centralized manner, as a way of maintaining efficiency, and speed to save costs.

Every service has its own order book. When you want to place an order, this is what happens:

  1. You pick an NFT you want to create an offer for,
  2. You approve a message in your Metamask,
  3. You sign it, also in your Metamask

If it’s your first time approving a message from a given account, you’ll have to pay a fee, because you’re approving it to do a trade on your behalf, if the other party agrees. Signing it is free, though. After doing that, the service will store your signed offer and execute it when the other party accepts it, i.e. it will be included in the blockchain and the offer will go through.

Order books management with Rarible API

At Rarible, we have our order book that is distributed as a public API. We also store orders from several different marketplaces like OpenSea, ImmutableX, Crypto Punks, and Rarible of course. You can literally get all of the information you need from it! In this part, we’ll explore how you can do just that, in a clever way. 😉 It’s not necessary to go through every endpoint, since the only difference between them is the parameter by which we’re searching. The best way to learn how to use it is to first understand the response parameters, as well as the terms by which we’re searching.

Search Terms

As you can see on the API docs, you can search by three items:

  • Orders,
  • Sell Orders
  • Order Bids

Orders

These are the orders in general, with no distinction between sell or bid orders.

Sell Orders

These are the orders created by the owner of an NFT, that’s why it’s called a sell order — he/she wants to sell it. You can expect to get info about the price set by the owner if you’re searching by itemid, for example.

Sell orders tab on Rarible

Order Bids

These are the orders created by the people who want to buy the NFT. So if you’re searching by this parameter, expect to find bids created by people interested in buying.

Bids tab on Rarible

Response Parameters

For the response example, let’s use some real-world data. We’ll fetch BAYC collection information that contains the “bestbidoffer” parameter.

You can fetch collection by id, using the collection controller like this:

https://api.rarible.org/v0.1/collections/ETHEREUM%3A0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D

What you’ll get in return will look like this:

{
   "id":"ETHEREUM:0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
   "blockchain":"ETHEREUM",
   "type":"ERC721",
   "name":"BoredApeYachtClub",
   "…"[
      "otherProperties"
   ]
"bestBidOrder":{      "id":"ETHEREUM:0xb02d6c21ff92d89d8414c8c01ade9c5d8491d18a49f92ee798cfbb5d2698af12",
      "fill":"0",
      "platform":"RARIBLE",
      "status":"ACTIVE",
      "makeStock":"165",
      "cancelled":false,
      "createdAt":"2022-05-01T01:14:41.489Z",
      "lastUpdatedAt":"2022-05-01T01:14:41.489Z",
      "dbUpdatedAt":"2022-05-01T01:14:41.535Z",
      "takePrice":"165",
      "takePriceUsd":"165.9315375366573705",
      "maker":"ETHEREUM:0xbec065ced3c494eed2ebfa0158ac665e854e6f12",
      "make":{
         "type":{
            "@type":"ERC20",
            "contract":"ETHEREUM:0x6b175474e89094c44da98b954eedeac495271d0f"
         },
         "value":"165"
      },
      "take":{
         "type":{
            "@type":"COLLECTION",
            "contract":"ETHEREUM:0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d"
         },
         "value":"1"
      },
      "salt":"0x0668fa8b7c6a393e4cce69986e3582889f07a27285676f4fa8c10db7848d59b2",
      "signature":"0x6db846a5de805d14aaf172f3f630447a07c4db3206726fa72194902f7a9e8f2a06bea476542fcf7b8f1a6e30f39c94d3807c786f7b83a46b899f4ff0cf993ced1b",
      "pending":[
         
      ],
      "data":{
         "@type":"ETH_RARIBLE_V2",
         "payouts":[
            
         ],
         "originFees":[
            {
               "account":"ETHEREUM:0x1cf0df2a5a20cd61d68d4489eebbf85b8d39e18a",
               "value":250
            }
         ]
      }
   }
}

The “bestBidOffer’’ parameter shows the most attractive offer in the whole collection, i.e. to any NFT from a given collection. It looks exactly the same as the one fetched from the getOrderById endpoint.

Below, you can see a brief description of available properties:

Properties of order

Let’s go through the properties of the received offer. Some of them like id, platform, and status are self-explanatory. Let’s go over the ones which are not.

Fill: it’s the final number for which the order was filled. Here the order is still active so the fill is 0,

MakeStock: the number of offered assets in this example is 1, because the owner wants to sell 1 NFT,

MakePrice: the price for which the owner wants to sell an asset,

Maker: address of the creator of the order,

Make: details about the offered asset,

Take: details about what the maker wants in return,

Salt & Signature: info about the signed transaction

Data: here you can see different parameters set, like makerRelayerFee — which is royalty. Since it’s showing 250, you divide it by 10000 notice that it means 2.5% of every sale will go to the maker of the NFT

And here is the image from our documentation:

Properties of order part 2

Summary

As you can see, using Rarible API for order books is super simple. Remember, the best way to gather knowledge is through practice. That’s why it was so important for me to show you how to think about data in this article, and not go through every endpoint. In case you have any questions, you can always join our discord, or message me directly.

Happy coding 🎉

Rarible
Programming
Order Book
Blockchain
Nft
Recommended from ReadMedium