X: Do not return old closed positions
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.r35157.libs.jupiter.perps;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -26,7 +29,7 @@ public interface JupiterPerpsService {
|
||||
* @throws InterruptedException if the calling thread is interrupted while fetching
|
||||
* the position account
|
||||
*/
|
||||
JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount)
|
||||
@Nullable JupiterPerpsPosition getPosition(@NotNull ΩJupiterPerpsPositionAccountΩ positionAccount)
|
||||
throws IOException, InterruptedException;
|
||||
|
||||
/**
|
||||
@@ -40,6 +43,6 @@ public interface JupiterPerpsService {
|
||||
* @throws IOException if the position accounts could not be fetched or decoded
|
||||
* @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;
|
||||
}
|
||||
+6
-8
@@ -4,15 +4,19 @@ import com.r35157.libs.codec.Base58Codec;
|
||||
import com.r35157.libs.codec.impl.ref.Base58CodecImpl;
|
||||
import com.r35157.libs.jupiter.perps.JupiterPerpsPositionDirection;
|
||||
import com.r35157.libs.solana.SolanaAccountInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.Base64;
|
||||
|
||||
import static java.math.BigDecimal.ZERO;
|
||||
|
||||
class AnchorIdlJupiterPerpsPositionDecoder {
|
||||
|
||||
JupiterPerpsPositionInfo decode(SolanaAccountInfo accountInfo) {
|
||||
@Nullable JupiterPerpsPositionInfo decode(@NotNull SolanaAccountInfo accountInfo) {
|
||||
byte[] data = Base64.getDecoder().decode(accountInfo.dataBase64());
|
||||
|
||||
if (data.length < PRICE_OFFSET + U64_LENGTH) {
|
||||
@@ -51,13 +55,7 @@ class AnchorIdlJupiterPerpsPositionDecoder {
|
||||
.valueOf(rawSizeUsd)
|
||||
.movePointLeft(6);
|
||||
|
||||
|
||||
JupiterPerpsPositionInfo posInfo = new JupiterPerpsPositionInfo(
|
||||
entryPrice,
|
||||
direction,
|
||||
sizeUsd,
|
||||
collateralUsd
|
||||
);
|
||||
JupiterPerpsPositionInfo posInfo = new JupiterPerpsPositionInfo(entryPrice, direction, sizeUsd, collateralUsd);
|
||||
|
||||
return posInfo;
|
||||
}
|
||||
|
||||
+15
-5
@@ -7,6 +7,8 @@ import com.r35157.libs.solana.SolanaBlockChain;
|
||||
import com.r35157.libs.solana.SolanaProgramAccountMemcmpFilter;
|
||||
import com.r35157.libs.solana.valuetypes.WellKnownCurrencyTypes;
|
||||
import com.r35157.libs.valuetypes.basic.MoneyAmount;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
@@ -26,7 +28,7 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JupiterPerpsPosition getPosition(ΩJupiterPerpsPositionAccountΩ positionAccount)
|
||||
public @Nullable JupiterPerpsPosition getPosition(@NotNull ΩJupiterPerpsPositionAccountΩ positionAccount)
|
||||
throws IOException, InterruptedException {
|
||||
SolanaAccountInfo accountInfo = solanaBlockChain.getAccountInfo(positionAccount);
|
||||
|
||||
@@ -44,6 +46,10 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
|
||||
|
||||
JupiterPerpsPositionInfo info = positionDecoder.decode(accountInfo);
|
||||
|
||||
JupiterPerpsPosition pos;
|
||||
if(info == null) {
|
||||
pos = null;
|
||||
} else {
|
||||
ΩUSDCAmountΩ value = ZERO; // TODO - Dummy
|
||||
ΩUSDCAmountΩ pnl = ZERO; // TODO - Dummy
|
||||
BigDecimal pnlPercent = ZERO; // TODO - Dummy
|
||||
@@ -54,7 +60,7 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
|
||||
ΩUSDCAmountΩ closeFeePending = ZERO; // TODO - Dummy
|
||||
ΩSolanaAmountΩ accountRent = new MoneyAmount(ZERO, WellKnownCurrencyTypes.SOLANA.getCurrencyType()); // TODO - Dummy
|
||||
|
||||
JupiterPerpsPosition pos = new JupiterPerpsPosition(
|
||||
pos = new JupiterPerpsPosition(
|
||||
positionAccount,
|
||||
tradedTokenMint,
|
||||
info.direction(),
|
||||
@@ -71,12 +77,13 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
|
||||
closeFeePending,
|
||||
accountRent
|
||||
);
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<JupiterPerpsPosition> getOpenPositions(ΩSolanaWalletIdΩ owner)
|
||||
public @NotNull Set<JupiterPerpsPosition> getOpenPositions(@NotNull ΩSolanaWalletIdΩ owner)
|
||||
throws IOException, InterruptedException {
|
||||
Set<SolanaAccountInfo> accountInfos = solanaBlockChain.getProgramAccounts(
|
||||
JUPITER_PERPS_PROGRAM_ID,
|
||||
@@ -98,9 +105,12 @@ public class AnchorIdlJupiterPerpsServiceImpl implements JupiterPerpsService {
|
||||
throw new IllegalArgumentException(errorMsg);
|
||||
}
|
||||
|
||||
ΩSPLMintAddressΩ tradedTokenMint = getTradedTokenMint(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Ω pnl = ZERO; // TODO - Dummy
|
||||
|
||||
Reference in New Issue
Block a user