Skip to content

docs: Add OpenBook integration guide and remove Serum references #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions code/openbook/adding-liquidity/adding-liquidity.en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Example TypeScript code for adding liquidity on OpenBook
const liquidity = await OpenBook.addLiquidity({
pool: "BTC/USDC",
amountA: 10,
amountB: 10000,
});
console.log("Liquidity added:", liquidity);
5 changes: 5 additions & 0 deletions code/openbook/adding-liquidity/adding-liquidity.preview.en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const liquidity = await OpenBook.addLiquidity({
pool: "BTC/USDC",
amountA: 10,
amountB: 10000,
});
4 changes: 4 additions & 0 deletions code/openbook/connecting-solana/connecting-solana.en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Connection } from "@solana/web3.js";

const connection = new Connection("https://api.mainnet-beta.solana.com");
console.log("Connected to Solana");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const connection = new Connection("https://api.mainnet-beta.solana.com");
5 changes: 5 additions & 0 deletions code/openbook/executing-trades/executing-trades.en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { OpenBook } from "openbook-library"; // Replace with the correct import

// Example TypeScript code for executing a trade on OpenBook
const trade = await OpenBook.executeTrade(order);
console.log("Trade executed:", trade);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const trade = await OpenBook.executeTrade(order);
10 changes: 10 additions & 0 deletions code/openbook/placing-order/placing-order.en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { OpenBook } from "openbook-library"; // Replace with the correct import

// Example TypeScript code for placing an order on OpenBook
const order = await OpenBook.placeOrder({
market: "BTC/USDC",
side: "buy",
price: 45000,
quantity: 0.1,
});
console.log("Order placed:", order);
6 changes: 6 additions & 0 deletions code/openbook/placing-order/placing-order.preview.en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const order = await OpenBook.placeOrder({
market: "BTC/USDC",
side: "buy",
price: 45000,
quantity: 0.1,
});
3 changes: 2 additions & 1 deletion docs/.vuepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export default defineUserConfig<DefaultThemeOptions>({
text: "Integrations",
children: [
"/integrations",
"/integrations/serum.md",
//"/integrations/serum.md",
"/integrations/openbook.md",
"/integrations/pyth.md",
"/integrations/switchboard.md",
"/integrations/mango.md",
Expand Down
168 changes: 168 additions & 0 deletions docs/integrations/openbook.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
---
title: OpenBook
head:
- - meta
- name: title
content: Solana Cookbook | Building on OpenBook
- - meta
- name: og:title
content: Solana Cookbook | Building on OpenBook
- - meta
- name: description
content: OpenBook is an innovative DEX on Solana. Learn how to use and build on top of OpenBook.
- - meta
- name: og:description
content: OpenBook is an innovative DEX on Solana. Learn how to use and build on top of OpenBook.
- - meta
- name: og:image
content: https://solanacookbook.com/cookbook-sharing-card.png
- - meta
- name: og:image:alt
content: Solana splash card
- - meta
- name: twitter:card
content: summary
- - meta
- name: twitter:site
content: "@solanacookbook"
- - meta
- name: twitter:image
content: "https://solanacookbook.com/cookbook-sharing-card.png"
- - meta
- name: robots
content: index,follow,noodp
- - meta
- name: googlebot
content: index,follow
---

# OpenBook

OpenBook is a decentralized exchange (DEX) built on Solana. You can use OpenBook to trade various tokens, provide liquidity, and access decentralized finance (DeFi) services on the Solana blockchain.

## Prerequisites

Before diving into OpenBook integration, ensure you have the following:

- A Solana wallet.
- SOL tokens for transaction fees.
- OpenBook tokens for trading.

## Getting Started

### Connecting to Solana

To begin, you need to connect your Solana wallet to the Solana blockchain. Ensure your wallet is properly configured.

<SolanaCodeGroup>
<SolanaCodeGroupItem title="TS" active>

<template v-slot:default>

@[code](@/code/openbook/connecting-solana/connecting-solana.en.ts)

</template>

<template v-slot:preview>

@[code](@/code/openbook/connecting-solana/connecting-solana.preview.en.ts)

</template>

</SolanaCodeGroupItem>

</SolanaCodeGroup>

### Depositing Funds

Deposit the tokens you intend to trade into your Solana wallet.

## Trading on OpenBook

### Selecting a Market

Choose the market and trading pair you want to trade. OpenBook offers a variety of markets; make sure to select the one that suits your trading needs.

### Placing an Order
Place a buy or sell order with the desired price and quantity. Below is an example in TypeScript:

<SolanaCodeGroup>
<SolanaCodeGroupItem title="TS" active>

<template v-slot:default>

@[code](@/code/openbook/placing-order/placing-order.en.ts)

</template>

<template v-slot:preview>

@[code](@/code/openbook/placing-order/placing-order.preview.en.ts)

</template>

</SolanaCodeGroupItem>

</SolanaCodeGroup>

### Executing Trades

Confirm and execute the trade using the following TypeScript code:

<SolanaCodeGroup>
<SolanaCodeGroupItem title="TS" active>

<template v-slot:default>

@[code](@/code/openbook/executing-trades/executing-tradesr.en.ts)

</template>

<template v-slot:preview>

@[code](@/code/openbook/executing-trades/executing-trades.preview.en.ts)

</template>

</SolanaCodeGroupItem>

</SolanaCodeGroup>

## Providing Liquidity

If you wish to provide liquidity to OpenBook's liquidity pools, follow these steps:

### Selecting a Liquidity Pool

Choose a liquidity pool that you want to contribute assets to.

### Adding Liquidity

Deposit equal amounts of two tokens into the selected pool. Here's an example in TypeScript:

<SolanaCodeGroup>
<SolanaCodeGroupItem title="TS" active>

<template v-slot:default>

@[code](@/code/openbook/adding-liquidity/adding-liquidity.en.ts)

</template>

<template v-slot:preview>

@[code](@/code/openbook/adding-liquidity/adding-liquidity.preview.en.ts)

</template>

</SolanaCodeGroupItem>

</SolanaCodeGroup>

## Building on OpenBook

Developers can extend the functionality of OpenBook by accessing the OpenBook API and documentation on the [OpenBook Developer Portal](https://openbook.dev/).

## Conclusion

OpenBook offers a decentralized and efficient way to trade and participate in DeFi on the Solana blockchain. Explore the platform, try out trading, or contribute to its ecosystem as a developer.