2 Commits

Author SHA256 Message Date
minimons 25c8a440f8 5: JupiterPerpsAlarm should be able to alarm on price 0 2026-06-19 13:00:40 +02:00
minimons e85474a97d 4: Use severity in request to PushOver 2026-06-19 13:00:40 +02:00
4 changed files with 25 additions and 10 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
# Asset Direction Target TRIGGER SEVERITY NOTE
#############################################################
SOL BELOW 170.0 ONETIME CRITICAL "EMERGENCY: Risiko for Perps Solana long LIKVIDERING!"
SOL BELOW 170.0 ONETIME INFO "EMERGENCY: Risiko for Perps Solana long LIKVIDERING!"
#SOL BELOW 71.4 ONETIME CRITICAL "CRITICAL: Risiko for Solana Raydium LÅN LIKVIDERING!"
@@ -1,9 +1,10 @@
package com.r35157.jupiterperpsalarm;
public enum AlarmSeverity {
EMERGENCY, // Repeated wake-up alarm
CRITICAL, // One-shot wake-up alarm
WARN, // Audible warning respecting quiet hours
INFO, // Low-priority visible notification
SILENT // No user interruption
EMERGENCY, // Repeated wake-up alarm - sound always
CRITICAL, // One-shot wake-up alarm - sound always
WARN, // Audible warning - respecting quiet hours though
INFO, // Normal notification with visual and audible feedback
SILENT, // Low-priority notification - visual feedback without sound/vibration
GHOST // No visual/audible notification - only visible inside the Pushover app
}
@@ -20,6 +20,7 @@ public record PriceAlarmDefinition(
Objects.requireNonNull(trigger, "trigger");
Objects.requireNonNull(note, "note");
// TODO: https://git.r35157.com/r35157/com_r35157_nenjim-hubd-impl_ref/issues/5
if (target.signum() <= 0) {
throw new IllegalArgumentException("Target price must be positive");
}
@@ -1,5 +1,7 @@
package com.r35157.jupiterperpsalarm.impl.ref;
import com.r35157.jupiterperpsalarm.AlarmSeverity;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
@@ -28,13 +30,13 @@ public final class PushoverAlarmAction implements AlarmAction {
price.slot()
);
// Severity and note are intentionally parsed and retained in the model,
// but are not used by Pushover yet.
// TODO: Note is intentionally parsed and retained in the model, but are not used by Pushover yet.
// https://git.r35157.com/r35157/com_r35157_nenjim-hubd-impl_ref/issues/7
String body = form("token", applicationToken) + "&" +
form("user", userKey) + "&" +
form("title", title) + "&" +
form("message", message) + "&" +
"priority=2&retry=30&expire=10800&sound=persistent";
createPushoverSeverityParameters(alarm.severity());;
HttpRequest request = HttpRequest.newBuilder(PUSHOVER_URI)
.timeout(Duration.ofSeconds(15))
@@ -56,7 +58,7 @@ public final class PushoverAlarmAction implements AlarmAction {
response.body()
);
} else {
System.out.println("Pushover emergency alarm sent.");
System.out.println("Pushover alarm sent: " + alarm.severity());
}
});
}
@@ -66,6 +68,17 @@ public final class PushoverAlarmAction implements AlarmAction {
URLEncoder.encode(value, StandardCharsets.UTF_8);
}
private static String createPushoverSeverityParameters(AlarmSeverity severity) {
return switch (severity) {
case EMERGENCY -> "priority=2&retry=30&expire=10800&sound=persistent";
case CRITICAL -> "priority=1&sound=spacealarm";
case WARN -> "priority=0&sound=siren";
case INFO -> "priority=0";
case SILENT -> "priority=-1";
case GHOST -> "priority=-2";
};
}
private final HttpClient httpClient = HttpClient.newHttpClient();
private final String applicationToken;
private final String userKey;