Skip to content

Commit

Permalink
OBv2: Add docs
Browse files Browse the repository at this point in the history
OBv2: Update orderbook test
  • Loading branch information
skynetcap committed Dec 21, 2023
1 parent d9eaa5a commit aa520ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
40 changes: 29 additions & 11 deletions openbook/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
# Serum in SolanaJ
A SolanaJ module for interfacing with the Serum DEX.
# solanaj-programs - OpenBook v2
A SolanaJ module for interfacing with the OpenBook v2 DEX.
## Code Examples

### Get Orderbook
### Get SOL/USDC Orderbook
```java
final PublicKey solUsdcPublicKey = new PublicKey("7xMDbYTCqQEcK2aM9LbetGtNFJpzKdfXzLL5juaLh4GJ");
final Market solUsdcMarket = new MarketBuilder()
.setClient(new RpcClient())
.setPublicKey(solUsdcPublicKey)
.setRetrieveOrderBooks(true)
.build();

final OrderBook bids = solUsdcMarket.getBidOrderBook();
// SOL/USDC
RpcClient client = new RpcClient("YOUR_RPC_HOST");
OpenBookManager openBookManager = new OpenBookManager(client);

OpenBookMarket solUsdc = openBookManager.getMarket(
PublicKey.valueOf("C3YPL3kYCSYKsmHcHrPWx1632GUXGqi2yMXJbfeCc57q"),
false,
true
).get();

log.info("Bids: {}", solUsdc.getBidOrders());
log.info("Asks: {}", solUsdc.getAskOrders());

assertFalse(solUsdc.getBidOrders().isEmpty());
```
```text
[main] INFO OpenBookTest - Bids: [OpenBookOrder(price=67.6, size=0.007, trader=FsQhJepwFkqsghZ3fiCRNCP7qEQk3BVcwPiCJCza3MsB), OpenBookOrder(price=69.0, size=0.002, trader=9SMAjQPumpCPJNRakX1ofdgJ736Fz7TN6ywsurj789ZX), OpenBookOrder(price=65.0, size=0.046, trader=9SMAjQPumpCPJNRakX1ofdgJ736Fz7TN6ywsurj789ZX), OpenBookOrder(price=50.0, size=0.1, trader=9SMAjQPumpCPJNRakX1ofdgJ736Fz7TN6ywsurj789ZX), OpenBookOrder(price=2.0, size=0.181, trader=9SMAjQPumpCPJNRakX1ofdgJ736Fz7TN6ywsurj789ZX)]
[main] INFO OpenBookTest - Asks: [OpenBookOrder(price=80.0, size=0.1, trader=9SMAjQPumpCPJNRakX1ofdgJ736Fz7TN6ywsurj789ZX), OpenBookOrder(price=200.0, size=1.0, trader=4gpeoTcx9awU7cHWWZugRe1scHot5wZdCwyc5xLYQn5T), OpenBookOrder(price=86.0, size=0.02, trader=9SMAjQPumpCPJNRakX1ofdgJ736Fz7TN6ywsurj789ZX), OpenBookOrder(price=85.0, size=0.01, trader=9SMAjQPumpCPJNRakX1ofdgJ736Fz7TN6ywsurj789ZX)]
```

### Get All Markets
```java
RpcClient client = new RpcClient("YOUR_RPC_HOST");

OpenBookManager openBookManager = new OpenBookManager(client);
log.info("Market cache: {}", openBookManager.getOpenBookMarkets());
```
3 changes: 2 additions & 1 deletion openbook/src/test/java/OpenBookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public void getOBv2MarketWithBooksTest() {
true
).get();

log.info("Manager: {}", solUsdc);
log.info("Bids: {}", solUsdc.getBidOrders());
log.info("Asks: {}", solUsdc.getAskOrders());

assertFalse(solUsdc.getBidOrders().isEmpty());
}
Expand Down

0 comments on commit aa520ca

Please sign in to comment.