Skip to content

Commit

Permalink
Added 'Crank A Market' section to README.md
Browse files Browse the repository at this point in the history
The 'Crank A Market' section, including the corresponding code, has been added to the README.md file in the openbook directory. This provides a comprehensive example of how to crank a market in the OpenBook system.
  • Loading branch information
skynetcap committed Dec 25, 2023
1 parent f189362 commit ed428de
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions openbook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,43 @@ Optional<OpenBookEventHeap> eventHeap = openBookManager.getEventHeap(PublicKey.v
eventHeap.get().getOutEvents().forEach(openBookOutEvent -> {
log.info("Out Event: {}", openBookOutEvent.toString());
});
```

### Crank A Market
```java
Account tradingAccount = Account.fromJson(
Resources.toString(Resources.getResource(PRIVATE_KEY_FILE), Charset.defaultCharset())
);
OpenBookMarket solUsdc = openBookManager.getMarket(
PublicKey.valueOf("5hYMkB5nAz9aJA33GizyPVH3VkqfkG7V4S2B5ykHxsiM"),
true,
false
).get();

OpenBookEventHeap eventHeap = openBookManager.getEventHeap(
solUsdc.getEventHeap()
).get();

List<PublicKey> peopleToCrank = new ArrayList<>();
eventHeap.getFillEvents()
.forEach(openBookFillEvent -> {
peopleToCrank.add(openBookFillEvent.getMaker());
});

Transaction tx = new Transaction();
tx.addInstruction(
OpenbookProgram.consumeEvents(
tradingAccount,
solUsdc.getMarketId(),
solUsdc.getEventHeap(),
peopleToCrank,
8
)
);

String consumeEventsTx = new RpcClient(Cluster.MAINNET).getApi().sendTransaction(
tx,
List.of(tradingAccount),
null
);
```

0 comments on commit ed428de

Please sign in to comment.