From 3510bc992f9e3404b7356fe07a549b9ee25d830b Mon Sep 17 00:00:00 2001 From: skynetcap <100323448+skynetcap@users.noreply.github.com> Date: Tue, 28 Nov 2023 11:46:10 -0800 Subject: [PATCH] Phoenix test: Add placeSingleOrderTest --- phoenix/src/test/java/PhoenixTest.java | 88 ++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/phoenix/src/test/java/PhoenixTest.java b/phoenix/src/test/java/PhoenixTest.java index 1ae1743..07cf452 100644 --- a/phoenix/src/test/java/PhoenixTest.java +++ b/phoenix/src/test/java/PhoenixTest.java @@ -100,6 +100,94 @@ public void orderLotsConversionTest() { assertEquals(58310, priceInTicks); } + @Test + public void placeSingleOrderTest() throws IOException, RpcException { + PhoenixManager phoenixManager = new PhoenixManager(client); + Account tradingAccount = Account.fromJson( + Resources.toString( + Resources.getResource( + "mikefsWLEcNYHgsiwSRr6PVd7yVcoKeaURQqeDE1tXN.json"), + Charset.defaultCharset() + ) + ); + + Optional marketOptional = phoenixManager.getMarket( + new PublicKey("4DoNfFBfF7UokCC2FQzriy7yHK6DY6NVdYpuekQ5pRgg") + ); + + if (marketOptional.isEmpty()) { + log.error("Unable to get market for test."); + return; + } + + PhoenixMarket market = marketOptional.get(); + log.info("Market: {}", market); + + double price = 13.37; + double size = 0.042; + + LimitOrderPacketRecord limitOrderPacketRecord = LimitOrderPacketRecord.builder() + .clientOrderId(new byte[]{}) + .matchLimit(0) + .numBaseLots(market.convertSizeToNumBaseLots(size)) + .priceInTicks(market.convertPriceToPriceInTicks(price)) + .selfTradeBehavior((byte) 1) + .side((byte) 0) + .useOnlyDepositedFunds(false) + .build(); + + Transaction limitOrderTx = new Transaction(); + limitOrderTx.addInstruction( + ComputeBudgetProgram.setComputeUnitPrice( + 123 + ) + ); + + limitOrderTx.addInstruction( + ComputeBudgetProgram.setComputeUnitLimit( + 130_000 + ) + ); + limitOrderTx.addInstruction( + PhoenixSeatManagerProgram.claimSeat( + SOL_USDC_MARKET, + SOL_USDC_SEAT_MANAGER, + tradingAccount.getPublicKey(), + tradingAccount.getPublicKey() + ) + ); + + limitOrderTx.addInstruction( + PhoenixProgram.cancelAllOrders( + SOL_USDC_MARKET, + tradingAccount.getPublicKey(), + new PublicKey("Avs5RSYyecvLnt9iFYNQX5EMUun3egh3UNPw8P6ULbNS"), + new PublicKey("A6Jcj1XV6QqDpdimmL7jm1gQtSP62j8BWbyqkdhe4eLe"), + market.getPhoenixMarketHeader().getBaseVaultKey(), + market.getPhoenixMarketHeader().getQuoteVaultKey() + ) + ); + + limitOrderTx.addInstruction( + PhoenixProgram.placeLimitOrder( + SOL_USDC_MARKET, + tradingAccount.getPublicKey(), + new PublicKey("Avs5RSYyecvLnt9iFYNQX5EMUun3egh3UNPw8P6ULbNS"), + new PublicKey("A6Jcj1XV6QqDpdimmL7jm1gQtSP62j8BWbyqkdhe4eLe"), + market.getPhoenixMarketHeader().getBaseVaultKey(), + market.getPhoenixMarketHeader().getQuoteVaultKey(), + limitOrderPacketRecord + ) + ); + + String placeLimitOrderTx = client.getApi().sendTransaction( + limitOrderTx, + List.of(tradingAccount), + client.getApi().getRecentBlockhash(Commitment.PROCESSED) + ); + log.info("Single order in transaction: {}, {}", limitOrderPacketRecord, placeLimitOrderTx); + } + @Test public void orderNormalizedTest() { PhoenixManager phoenixManager = new PhoenixManager(client);