πŸ“—Get Market Info - Openbook

Summary

This section serves as a basic guideline to help new user to get started. The very first step is getting market information.

Find Openbook market (trading pair)

Project Openbook has various markets (think of them as trading pairs in traditional exchanges).

The easiest way to find the market you want to trade in and its name is using the GET markets endpoint which will return all markets preloaded in Openbook API.

$ curl 'http://uk.solana.dex.blxrbdn.com/api/v2/openbook/markets' -H "Authorization: <YOUR-AUTHORIZATION-HEADER>" 
{
   "markets":{
      "AAVE/USDC":{
         "market":"AAVE/USDC",
         "status":"MS_ONLINE",
         "address":"8WZrmdpLckptiVKd2fPHPjewRVYQGQkjxi9vzRYG1sfs"
      },
      "AAVE/USDT":{
         "market":"AAVE/USDT",
         "status":"MS_ONLINE",
         "address":"LghsMERQWQFK3zWMTrUkoyAJARQw2wSmcYZjexeN3zy"
      },
      // ...
}

In the response you'll see the names of the markets and their marketAddress, which represents their program address. You can use either value in most Serum API endpoints.

One quick note on market names: avoid the / format in HTTP endpoints. For example, instead of SOL/USDC use SOLUSDC or SOL:USDC. You can freely use SOL/USDC in WebSockets and GRPC.

For the rest of this tutorial, we will be using the SOL/USDC market.

Get Orderbook

Openbook DEX is orderbook based. In order to get the most out of this decentralized trading platform, we recommend using the streaming API to get notifications on the orderbook changes. You can use the GET orderbooks endpoint for the development processes and/or parallel to the streaming. We provide WebSocket & gRPC based streaming service for this endpoint.

$ curl 'https://uk.solana.dex.blxrbdn.com/api/v2/openbook/orderbooks/SOLUSDC?limit=3' -H "Authorization: <YOUR-AUTHORIZATION-HEADER>" 
{
   "market":"SOL/USDC",
   "marketAddress":"9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT",
   "bids":[
      {
         "price":34.602,
         "size":1257.5
      },
      {
         "price":34.643,
         "size":628
      },
      {
         "price":34.664,
         "size":313.8
      }
   ],
   "asks":[
      {
         "price":34.718,
         "size":180
      },
      {
         "price":34.863,
         "size":156.8
      },
      {
         "price":34.874,
         "size":313.6
      }
   ]
}

In this example response, you can see the best three bids and asks in the SOL/USDC market. The best bid wants to buy 10 SOL at the price of 34.664 SOL per USDC. To contrast, the best ask wants to sell 180 SOL at the price of 34.718 SOL per USDC.

$ wscat -c wss://uk.solana.dex.blxrbdn.com/ws --wait 1000 --execute '{"jsonrpc": "2.0", "id": 1, "method": "GetOrderbooksStream", "params": {"market": "SOL/USDC", "limit": 3}}'

{"id":1,"result":{"blockHeight":"138584086","orderbook":{"market":"SOL/USDC","marketAddress":"9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT","bids":[{"price":34.583,"size":228.4},{"price":34.59,"size":314.1},{"price":34.6,"size":157}],"asks":[{"price":34.713,"size":180},{"price":34.788,"size":157},{"price":34.799,"size":314}]}},"jsonrpc":"2.0"}

{"id":1,"result":{"blockHeight":"138584086","orderbook":{"market":"SOL/USDC","marketAddress":"9wFFyRfZBsuAha4YcuxcXLKwMxJR43S7fPfQLusDBzvT","bids":[{"price":34.583,"size":228.4},{"price":34.59,"size":314.1},{"price":34.6,"size":157}],"asks":[{"price":34.723,"size":180},{"price":34.788,"size":157},{"price":34.799,"size":314}]}},"jsonrpc":"2.0"}

Note here that the two responses from the stream may be identical depending on your limit parameter and we don't aggregate orders with the same price. Typically, duplicate responses from the stream indicate that some other activity has happened in the orderbook, though your specific filtering criteria masks the changes (as of v0.1).

Refer to API Stream - Orderbooks for more information.

Last updated