Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
📖 OpenBook
🐧 Linux (Recommended) |
🪟 Windows |
---|---|
Download Executable File | Download .exe File |
cargo install openbook --all-features |
cargo install openbook --all-features |
📖1️⃣2️⃣ A CLI, TUI and SDK to interact with OpenBook V1 and V2 markets on the Solana blockchain.
Table of Contents
🚀 Installation
To install openbook
cli, use the following Cargo command:
✨ Functionalities
The following features are available on both OpenBook V1 and V2 markets:
- Fetch market info in the OpenBook market.
- Place a limit bid in the OpenBook market.
- Cancel an existing order in the OpenBook market.
- Settle balances in the OpenBook market.
- Cancel settle place order in the OpenBook market.
- Cancel settle place bid order in the OpenBook market.
- Cancel settle place ask order in the OpenBook market.
- Consume events instructions in the OpenBook market.
- Consume events permissioned instructions in the OpenBook market.
- Load orders for a specific owner in the OpenBook market.
- Find open orders accounts for a specific owner in the OpenBook market.
Usage
Before using the openbook
crate or CLI, make sure to set the following environment variables:
⌨ Usage as TUI
📖 OpenBook 2️⃣
# same as `openbook v2`, the default is openbook v2
[!NOTE] To trade on the openbook v2 market, you will need an indexer and open order account. This current release of this crate generates one for your wallet, but it's empty. You'll have to add funds to it. In the future, you can add funds through the TUI. But, if you already have funds in your open order account, set up this variable before starting the TUI:
📖 OpenBook 1️⃣
[!NOTE] To trade on the openbook v1 market, you will need an open order account. This current release of this crate generates one for your wallet, but it's empty. You'll have to add funds to it. In the future, you can add funds through the TUI. But, if you already have funds in your open order account, set up this variable before starting the TUI:
⌨ Usage as CLI
📖 OpenBook 1️⃣
Fetch Market Info:
Place a limit bid order:
)
)
)
)
)
)
)
)
)
)
)
)
)
)
Place a limit ask order:
Cancel all limit orders:
Settle balances:
Cancel Settle Place Order:
Cancel Settle Place Bid Order:
Cancel Settle Place Ask Order:
Fetch all orders for current owner (bids + asks):
Match orders transaction:
Consume events instruction:
Consume events permissioned instruction:
[!TIP] Use
v1 --market-id
argument to overwrite the market id in the cli.
📖 OpenBook 2️⃣
Fetch Market Info:
[!TIP] Use your own rpcpool or Helius for example to fetch the account openorder key, otherwise, you will get the following error: Error: HTTP status client error (410 Gone) for url (https://api.mainnet-beta.solana.com/)
[!TIP] Use
v2 --market-id
argument to overwrite the market id in the cli.
Place a limit bid order:
[*] Transaction successful, signature: 247o59Zq6whJQEKiRRU4gWKv4AUaX77WwciTeiCkhnaXth1k4gKmoLpgXgojGqPKjoxhRsShrqQEfNLge1hVceYG
2024-06-09T22:38:35.398259Z INFO
EncodedConfirmedTransactionWithStatusMeta { slot: 270899054, transaction: EncodedTransactionWithStatusMeta { transaction: Binary("ATS0gb/FEoRtWQfCfjNFaWbyUpSNLxHnuVUYL+o6H4e3F0lIqLlYS7nxnRXn/5qHmdP9qcra6VC+J8HiS/FjvQEBAAIKohRG/SHSqd4bNgk96sjOYpPd6KNxSlux7kYBS+FkB588LeWtpGPfntkqrLmTW/MQLVW9Nw1GwM8ucxVYKsxFSnP98LGDhJ/ybrUq8uWKvzWc3Qpkvvh8E4f2QpW0Nd1EjveagppmyVh9NXIGTw0Bu7mAX2BvMYmYkrlA15HQ9PSWgHlgvAz3Z3x8KWarha2BMyZsqEbzAmtDepM8+Mm5KacjXI27/y9eRSqBJTejbSZKPNm3H93t4JR5DNkAIT+qw3jg0kqnkNPjNhW2cX9TsNhBiL70MalsYDHszXbtA8DRxb79bp/33peN90XvJVUtvNyE0YS9gCLrvZLGUYMh9Qbd9uHXZaGT2cvhRs7reawctIXtX1s3kTqM9YV+/wCpC/6/vfur+tC0ZXG/lYweuCR4e7CZS7GEayl4Bx4Xmb6yEk0J06j3rHHL8r+QC2b6Vbzd29CWDuMlpNeRAkcMyQEJDAAECQIFAwEHBgkJCDQzwpuvbYJgagABAAAAAAAAAEBUiQAAAAAAKEYPAAAAAAAUvkfXL+UJSQI4gGdmAAAAAAIM", Base64), meta: Some(UiTransactionStatusMeta { err: None, status: Ok(()), fee: 5000, pre_balances: [380632810, 633916800, 2039280, 633916800, 9688320, 6792960, 2039280, 636255360, 934087680, 1141440], post_balances: [380627810, 633916800, 2039280, 633916800, 9688320, 6792960, 2039280, 636255360, 934087680, 1141440], inner_instructions: Some([]), log_messages: Some(["Program opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb invoke [1]", "Program log: Instruction: PlaceOrder", "Program opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb consumed 27535 of 200000 compute units", "Program return: opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb AZt1rP3/////AQAAAAAAAAA=", "Program opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb success"]), pre_token_balances: Some([UiTransactionTokenBalance { account_index: 2, mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", ui_token_amount: UiTokenAmount { ui_amount: Some(12.91488), decimals: 6, amount: "12914880", ui_amount_string: "12.91488" }, owner: Some("Bugys1jBEBcFegRSjFvbpvNzJjo7qtdgSV7ytEYsWJ7Q"), program_id: Some("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") }, UiTransactionTokenBalance { account_index: 6, mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", ui_token_amount: UiTokenAmount { ui_amount: Some(111009.20637), decimals: 6, amount: "111009206370", ui_amount_string: "111009.20637" }, owner: Some("B44ts4KVwst9dYSYqGB5vY4Wee2KB3AK3e92yEdJzwrw"), program_id: Some("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") }]), post_token_balances: Some([UiTransactionTokenBalance { account_index: 2, mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", ui_token_amount: UiTokenAmount { ui_amount: Some(12.91488), decimals: 6, amount: "12914880", ui_amount_string: "12.91488" }, owner: Some("Bugys1jBEBcFegRSjFvbpvNzJjo7qtdgSV7ytEYsWJ7Q"), program_id: Some("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") }, UiTransactionTokenBalance { account_index: 6, mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", ui_token_amount: UiTokenAmount { ui_amount: Some(111009.20637), decimals: 6, amount: "111009206370", ui_amount_string: "111009.20637" }, owner: Some("B44ts4KVwst9dYSYqGB5vY4Wee2KB3AK3e92yEdJzwrw"), program_id: Some("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA") }]), rewards: Some([]), loaded_addresses: Some(UiLoadedAddresses { writable: [], readonly: [] }), return_data: Some(UiTransactionReturnData { program_id: "opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb", data: ("AZt1rP3/////AQAAAAAAAAA=", Base64) }), compute_units_consumed: Some(27535) }), version: Some(Legacy(Legacy)) }, block_time: Some(1717972675) }
Version: legacy
Recent Blockhash: Cz7kpy1Rt8Ub1sedTGnsBYXVmaa6fcYFPxkFhPX59TFv
Signature 0: 247o59Zq6whJQEKiRRU4gWKv4AUaX77WwciTeiCkhnaXth1k4gKmoLpgXgojGqPKjoxhRsShrqQEfNLge1hVceYG
Account 0: srw- Bugys1jBEBcFegRSjFvbpvNzJjo7qtdgSV7ytEYsWJ7Q (fee payer)
Account 1: -rw- 53v47CBoaKwoM8tSEDN4oNyCc2ZJenDeuhMJTEw7fL2M
Account 2: -rw- 8onULHc8pHT7N7XnVfbkkLeU8mqEHnQbGwiBnTdVESio
Account 3: -rw- Ad5skEiFoaeA27G3UhbpuwnFBCvmuuGEyoiijZhcd5xX
Account 4: -rw- B8Vn7eYX1xMB1a3NanJfqhyEgWRfR5ptzscXnjv3qhN8
Account 5: -rw- CFSMrBssNG8Ud1edW59jNLnq2cwrQ9uY5cM3wXmqRJj3
Account 6: -rw- EA3Qa1WUxuY2BZo6b2Dy3ZxGiK3qS5hkeSwbCzUNomBm
Account 7: -rw- F7s6bScqRXB2gsU6s8QHSXJTmpS5t6SfVBs4V2k3HNKn
Account 8: -r-- TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
Account 9: -r-x opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb
Instruction 0
Program: opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb (9)
Account 0: Bugys1jBEBcFegRSjFvbpvNzJjo7qtdgSV7ytEYsWJ7Q (0)
Account 1: B8Vn7eYX1xMB1a3NanJfqhyEgWRfR5ptzscXnjv3qhN8 (4)
Account 2: opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb (9)
Account 3: 8onULHc8pHT7N7XnVfbkkLeU8mqEHnQbGwiBnTdVESio (2)
Account 4: CFSMrBssNG8Ud1edW59jNLnq2cwrQ9uY5cM3wXmqRJj3 (5)
Account 5: Ad5skEiFoaeA27G3UhbpuwnFBCvmuuGEyoiijZhcd5xX (3)
Account 6: 53v47CBoaKwoM8tSEDN4oNyCc2ZJenDeuhMJTEw7fL2M (1)
Account 7: F7s6bScqRXB2gsU6s8QHSXJTmpS5t6SfVBs4V2k3HNKn (7)
Account 8: EA3Qa1WUxuY2BZo6b2Dy3ZxGiK3qS5hkeSwbCzUNomBm (6)
Account 9: opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb (9)
Account 10: opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb (9)
Account 11: TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA (8)
Data: [51, 194, 155, 175, 109, 130, 96, 106, 0, 1, 0, 0, 0, 0, 0, 0, 0, 64, 84, 137, 0, 0, 0, 0, 0, 40, 70, 15, 0, 0, 0, 0, 0, 20, 190, 71, 215, 47, 229, 9, 73, 2, 56, 128, 103, 102, 0, 0, 0, 0, 2, 12]
Status: Ok
Fee: ◎0.000005
Account 0 balance: ◎0.38063281 -> ◎0.38062781
Account 1 balance: ◎0.6339168
Account 2 balance: ◎0.00203928
Account 3 balance: ◎0.6339168
Account 4 balance: ◎0.00968832
Account 5 balance: ◎0.00679296
Account 6 balance: ◎0.00203928
Account 7 balance: ◎0.63625536
Account 8 balance: ◎0.93408768
Account 9 balance: ◎0.00114144
Compute Units Consumed: 27535
Log Messages:
Program opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb invoke [1]
Program log: Instruction: PlaceOrder
Program opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb consumed 27535 of 200000 compute units
Program return: opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb AZt1rP3/////AQAAAAAAAAA=
Program opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb success
Return Data from Program opnb2LAfJYbRMAHHvqjCwQxanZn7ReEHp1k81EohpZb:
Length: 17 (0x11) bytes
0000: 01 9b 75 ac fd ff ff ff ff 01 00 00 00 00 00 00 ..u.............
0010: 00
💻 Usage as Dependency
OpenBook V1
[]
= { = "0.1.0" , = ["v1"] }
use OrderReturnType;
use OBClient;
use Side;
use CommitmentConfig;
async
OpenBook V2
[]
= { = "0.1.0" , = ["v2"] }
use OBClient;
use Side;
use CommitmentConfig;
async
🎨 Top Level Command
Commands | Description |
---|---|
v1 |
- |
v2 |
- |
V1 SubCommands
SubCommands | Default Value | Description |
---|---|---|
place -t <TARGET_AMOUNT_QUOTE> -s <SIDE> -b <BEST_OFFSET_USDC> -e -p <PRICE_TARGET> |
- | Place a limit order with the specified parameters. |
cancel -e |
- | Cancel all existing order for the current owner. |
settle -e |
- | Settle balances in the OpenBook market. |
cancel-settle-place -u <USDC_ASK_TARGET> -b <TARGET_USDC_BID> -p <PRICE_JLP_USDC_BID> -a <ASK_PRICE_JLP_USDC> |
- | Cancel all limit orders, settle balances, and place new bid and ask orders. |
cancel-settle-place-bid -b <TARGET_SIZE_USDC_BID> -p <BID_PRICE_JLP_USDC> |
- | Cancel all limit orders, settle balances, and place a bid order. |
cancel-settle-place-ask -a <TARGET_SIZE_USDC_ASK> -p <ASK_PRICE_JLP_USDC> |
- | Cancel all limit orders, settle balances, and place an ask order. |
match --limit <LIMIT> |
- | Match orders transaction with the specified limit. |
consume --limit <LIMIT> |
- | Consume events instruction with the specified limit. |
consume-permissioned --limit <LIMIT> |
- | Consume events permissioned instruction with the specified limit. |
load |
- | Load orders for the current owner, bids + asks. |
info |
- | Fetch OpenBook V1 market info. |
V2 SubCommands
SubCommands | Default Value | Description |
---|---|---|
info |
- | Fetch OpenBook V2 market info. |
🤝 Contributing
Contributions and feedback are welcome! If you'd like to contribute, report an issue, or suggest an enhancement, please engage with the project on GitHub. Your contributions help improve this CLI and library for the community.
📄 License
This project is licensed under the MIT License.