Skip to content

Commit

Permalink
Phoenix: Add readme with code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
skynetcap committed Nov 28, 2023
1 parent fdb0305 commit 4530b13
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions phoenix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# SolanaJ-programs - Phoenix
A SolanaJ module for interfacing with the Ellipsis Phoenix DEX.
## Code Examples
(See PhoenixTest.java)

### Get All Markets and Orderbooks
```java
PhoenixManager phoenixManager = new PhoenixManager(client);
MetaplexManager metaplexManager = new MetaplexManager(client);

phoenixManager.getPhoenixMarkets().forEach(market -> {
log.info("Market: {}", market.getMarketId().toBase58());

metaplexManager.getTokenMetadata(market.getPhoenixMarketHeader().getBaseMintKey())
.ifPresent(metadata -> log.info("Base token: {}", metadata.getSymbol()));
metaplexManager.getTokenMetadata(market.getPhoenixMarketHeader().getQuoteMintKey())
.ifPresent(metadata -> log.info("Quote token: {}", metadata.getSymbol()));

market.getBidListNormalized().forEach(phoenixOrder -> {
log.info(String.format("Bid: %.10f x %.4f, Trader: %s", phoenixOrder.getPrice(),
phoenixOrder.getSize(), phoenixOrder.getTrader().toBase58()));
});
market.getAskListNormalized().forEach(phoenixOrder -> {
log.info(String.format("Ask: %.10f x %.4f, Trader: %s", phoenixOrder.getPrice(),
phoenixOrder.getSize(), phoenixOrder.getTrader().toBase58()));
});
});
```

### Order Placement
```java
LimitOrderPacketRecord limitOrderPacketRecord = LimitOrderPacketRecord.builder()
.clientOrderId(new byte[]{})
.matchLimit(0)
.numBaseLots(18L)
.priceInTicks((long) (market.getBestBid().get().getFirst().getPriceInTicks() * .9995))
.selfTradeBehavior((byte) 1)
.side((byte) 0)
.useOnlyDepositedFunds(false)
.build();

tx.addInstruction(
PhoenixProgram.placeLimitOrder(
SOL_USDC_MARKET,
tradingAccount.getPublicKey(),
baseWallet,
quoteWallet,
market.getPhoenixMarketHeader().getBaseVaultKey(),
market.getPhoenixMarketHeader().getQuoteVaultKey(),
limitOrderPacketRecord
)
);

// submit TX
```

0 comments on commit 4530b13

Please sign in to comment.