Class AutoWetter
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Map<Long, BuchmacherOuterClass.Wette> This variable represents a collection of completed bets.private static final doubleAmount to bet on a quoteprivate static org.eclipse.paho.client.mqttv3.MqttClientprivate static final doubleThreshold for making a bet on a quoteprivate static Stringprivate static final intInterval in milliseconds for the tickprivate static Stringprivate static longstatic booleanprivate Map<Long, BuchmacherOuterClass.Wettangebot> Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidChecks and manages subscriptions to topics for receiving game offers.private voidChecks the available wettangebote for potential bets and places the bets if applicable.static Map<Long, BuchmacherOuterClass.Wette> Retrieves a map of completed bets.static longRetrieves the user ID.static voidThe main method of the AutoWetter program.private static voidprepare()voidrun()The run method is called when the thread starts running.static voidsetUserId(long userId) This method is used to set the token for the user.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
messageClient
private static org.eclipse.paho.client.mqttv3.MqttClient messageClient -
serverUri
-
token
-
userId
private static long userId -
VERBOSE
public static boolean VERBOSE -
abgeschlosseneWetten
This variable represents a collection of completed bets.It is a private static field of type Mapinvalid input: '<'Long, BuchmacherOuterClass.Wette>, where: - Long is the key type representing the unique identifier of each bet. - BuchmacherOuterClass.Wette is the value type representing the details of each bet.
The purpose of this variable is to store all the completed bets in a key-value format, where the key is the bet ID and the value is the detailed information of the bet.
-
QUOTE_THRESHOLD
private static final double QUOTE_THRESHOLDThreshold for making a bet on a quote- See Also:
-
BET_AMOUNT
private static final double BET_AMOUNTAmount to bet on a quote- See Also:
-
TICK_INTERVAL_MS
private static final int TICK_INTERVAL_MSInterval in milliseconds for the tick- See Also:
-
subscribedAngeboteTopics
-
wettangebote
-
-
Constructor Details
-
AutoWetter
public AutoWetter()
-
-
Method Details
-
main
The main method of the AutoWetter program.- Parameters:
args- The command line arguments passed to the program.
-
prepare
private static void prepare() -
checkAndManageSubscriptions
private void checkAndManageSubscriptions() throws IOException, org.eclipse.paho.client.mqttv3.MqttExceptionChecks and manages subscriptions to topics for receiving game offers. This method retrieves the list of games from the specified server URI and creates a list of topics based on the game IDs. It then subscribes to each topic that is not already subscribed to and adds the received game offers to the wettangebote map. Additionally, it unsubscribes from topics that are no longer present in the newTopics list.- Throws:
IOException- if an I/O error occurs while retrieving the game listorg.eclipse.paho.client.mqttv3.MqttException- if an error occurs during MQTT subscription/unsubscription
-
checkWettangeboteForWetten
private void checkWettangeboteForWetten()Checks the available wettangebote for potential bets and places the bets if applicable.This method iterates through all the wettangebote in the wettangebote map. It skips the wettangebote that are already present in the abgeschlosseneWetten map.
For each wettangebot, it checks the team with the highest quote that is above the QUOTE_THRESHOLD. If such a team is found, it places a bet on that team by calling the placeBet method of the WebSnippets class. The bet is placed with the BET_AMOUNT and using the provided serverUri, token, and wettangebot details.
If no team is found for a wettangebot, or if the wettangebot is already present in the abgeschlosseneWetten map, it is skipped and the next wettangebot is processed.
This method does not return any value, it directly places the bets using the WebSnippets.placeBet method.
Note: The QUOTE_THRESHOLD should be defined and set appropriately before calling this method.
-
run
public void run()The run method is called when the thread starts running. It contains a continuous loop that performs two main tasks: 1. Calls the checkAndManageSubscriptions() method to check and manage the MQTT subscriptions. 2. Calls the checkWettangeboteForWetten() method to perform some processing on the received MQTT messages.If an IOException or MqttException occurs during the execution of these tasks, it prints an error message to the console and exits the program with an exit status of 1.
After each iteration of the loop, the thread sleeps for a specified interval, TICK_INTERVAL_MS (in milliseconds).
-
setUserId
public static void setUserId(long userId) This method is used to set the token for the user.- Parameters:
userId- The user ID to set.
-
getUserId
public static long getUserId()Retrieves the user ID.- Returns:
- The user ID as a long value.
-
getAbgeschlosseneWetten
Retrieves a map of completed bets.- Returns:
- A map containing the completed bets. The key is of type Long, representing the bet ID, and the value is of type BuchmacherOuterClass.Wette, representing the bet itself .
-