X: Do not return old closed positions

This commit is contained in:
2026-07-05 01:06:52 +02:00
parent dac76a2686
commit f8387f6034
3 changed files with 51 additions and 40 deletions
@@ -1,5 +1,8 @@
package com.r35157.libs.jupiter.perps; package com.r35157.libs.jupiter.perps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException; import java.io.IOException;
import java.util.Set; import java.util.Set;
@@ -26,7 +29,7 @@ public interface JupiterPerpsService {
* @throws InterruptedException if the calling thread is interrupted while fetching * @throws InterruptedException if the calling thread is interrupted while fetching
* the position account * the position account
*/ */
JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount) @Nullable JupiterPerpsPosition getPosition(@NotNull ΩJupiterPerpsPositionAccountΩ positionAccount)
throws IOException, InterruptedException; throws IOException, InterruptedException;
/** /**
@@ -40,6 +43,6 @@ public interface JupiterPerpsService {
* @throws IOException if the position accounts could not be fetched or decoded * @throws IOException if the position accounts could not be fetched or decoded
* @throws InterruptedException if the calling thread is interrupted while fetching positions * @throws InterruptedException if the calling thread is interrupted while fetching positions
*/ */
Set<JupiterPerpsPosition> getOpenPositions(ΩSolanaWalletIdΩ owner) @NotNull Set<JupiterPerpsPosition> getOpenPositions(@NotNull ΩSolanaWalletIdΩ owner)
throws IOException, InterruptedException; throws IOException, InterruptedException;
} }
@@ -4,15 +4,19 @@ import com.r35157.libs.codec.Base58Codec;
import com.r35157.libs.codec.impl.ref.Base58CodecImpl; import com.r35157.libs.codec.impl.ref.Base58CodecImpl;
import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection; import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection;
import com.r35157.libs.solana.SolanaAccountInfo; import com.r35157.libs.solana.SolanaAccountInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.util.Base64; import java.util.Base64;
import static java.math.BigDecimal.ZERO;
class AnchorIdlJupiterPerpsPositionDecoder { class AnchorIdlJupiterPerpsPositionDecoder {
JupiterPerpsPositionInfo decode(SolanaAccountInfo accountInfo) { @Nullable JupiterPerpsPositionInfo decode(@NotNull SolanaAccountInfo accountInfo) {
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64()); byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
if (data.length < PRICE_OFFSET + U64_LENGTH) { if (data.length < PRICE_OFFSET + U64_LENGTH) {
@@ -51,13 +55,7 @@ class AnchorIdlJupiterPerpsPositionDecoder {
.valueOf(rawSizeUsd) .valueOf(rawSizeUsd)
.movePointLeft(6); .movePointLeft(6);
JupiterPerpsPositionInfo posInfo = new JupiterPerpsPositionInfo(entryPrice, direction, sizeUsd, collateralUsd);
JupiterPerpsPositionInfo posInfo = new JupiterPerpsPositionInfo(
entryPrice,
direction,
sizeUsd,
collateralUsd
);
return posInfo; return posInfo;
} }
@@ -7,6 +7,8 @@ import com.r35157.libs.solana.SolanaBlockChain;
import com.r35157.libs.solana.SolanaProgramAccountMemcmpFilter; import com.r35157.libs.solana.SolanaProgramAccountMemcmpFilter;
import com.r35157.libs.solana.valuetypes.WellKnownCurrencyTypes; import com.r35157.libs.solana.valuetypes.WellKnownCurrencyTypes;
import com.r35157.libs.valuetypes.basic.MoneyAmount; import com.r35157.libs.valuetypes.basic.MoneyAmount;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
@@ -26,7 +28,7 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
} }
@Override @Override
public JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount) public @Nullable JupiterPerpsPosition getPosition(@NotNull ΩJupiterPerpsPositionAccountΩ positionAccount)
throws IOException, InterruptedException { throws IOException, InterruptedException {
SolanaAccountInfo accountInfo = solanaBlockChain.getAccountInfo(positionAccount); SolanaAccountInfo accountInfo = solanaBlockChain.getAccountInfo(positionAccount);
@@ -44,39 +46,44 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
JupiterPerpsPositionInfo info = positionDecoder.decode(accountInfo); JupiterPerpsPositionInfo info = positionDecoder.decode(accountInfo);
ΩUSDCAmountΩ value = ZERO; // TODO - Dummy JupiterPerpsPosition pos;
ΩUSDCAmountΩ pnl = ZERO; // TODO - Dummy if(info == null) {
BigDecimal pnlPercent = ZERO; // TODO - Dummy pos = null;
BigDecimal leverage = ZERO; // TODO - Dummy } else {
ΩUSDCPriceΩ marketPrice = ZERO; // TODO - Dummy ΩUSDCAmountΩ value = ZERO; // TODO - Dummy
ΩUSDCAmountΩ totalFees = ZERO; // TODO - Dummy ΩUSDCAmountΩ pnl = ZERO; // TODO - Dummy
ΩUSDCAmountΩ borrowFeesDue = ZERO; // TODO - Dummy BigDecimal pnlPercent = ZERO; // TODO - Dummy
ΩUSDCAmountΩ closeFeePending = ZERO; // TODO - Dummy BigDecimal leverage = ZERO; // TODO - Dummy
ΩSolanaAmountΩ accountRent = new MoneyAmount(ZERO, WellKnownCurrencyTypes.SOLANA.getCurrencyType()); // TODO - Dummy ΩUSDCPriceΩ marketPrice = ZERO; // TODO - Dummy
ΩUSDCAmountΩ totalFees = ZERO; // TODO - Dummy
ΩUSDCAmountΩ borrowFeesDue = ZERO; // TODO - Dummy
ΩUSDCAmountΩ closeFeePending = ZERO; // TODO - Dummy
ΩSolanaAmountΩ accountRent = new MoneyAmount(ZERO, WellKnownCurrencyTypes.SOLANA.getCurrencyType()); // TODO - Dummy
JupiterPerpsPosition pos = new JupiterPerpsPosition( pos = new JupiterPerpsPosition(
positionAccount, positionAccount,
tradedTokenMint, tradedTokenMint,
info.direction(), info.direction(),
value, value,
info.sizeUsd(), info.sizeUsd(),
pnl, pnl,
pnlPercent, pnlPercent,
leverage, leverage,
info.entryPrice(), info.entryPrice(),
marketPrice, marketPrice,
info.collateralUsd(), info.collateralUsd(),
totalFees, totalFees,
borrowFeesDue, borrowFeesDue,
closeFeePending, closeFeePending,
accountRent accountRent
); );
}
return pos; return pos;
} }
@Override @Override
public Set<JupiterPerpsPosition> getOpenPositions(ΩSolanaWalletIdΩ owner) public @NotNull Set<JupiterPerpsPosition> getOpenPositions(@NotNull ΩSolanaWalletIdΩ owner)
throws IOException, InterruptedException { throws IOException, InterruptedException {
Set<SolanaAccountInfo> accountInfos = solanaBlockChain.getProgramAccounts( Set<SolanaAccountInfo> accountInfos = solanaBlockChain.getProgramAccounts(
JUPITER_PERPS_PROGRAM_ID, JUPITER_PERPS_PROGRAM_ID,
@@ -98,9 +105,12 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
throw new IllegalArgumentException(errorMsg); throw new IllegalArgumentException(errorMsg);
} }
ΩSPLMintAddressΩ tradedTokenMint = getTradedTokenMint(accountInfo);
JupiterPerpsPositionInfo info = positionDecoder.decode(accountInfo); JupiterPerpsPositionInfo info = positionDecoder.decode(accountInfo);
if(info == null || info.sizeUsd().compareTo(ZERO) == 0) {
continue;
}
ΩSPLMintAddressΩ tradedTokenMint = getTradedTokenMint(accountInfo);
ΩUSDCAmountΩ value = ZERO; // TODO - Dummy ΩUSDCAmountΩ value = ZERO; // TODO - Dummy
ΩUSDCAmountΩ pnl = ZERO; // TODO - Dummy ΩUSDCAmountΩ pnl = ZERO; // TODO - Dummy