Ethereum: How to get price difference using Spring boot scheduler

Here’s an article on how to get a price difference using the spring boot planner:

Price differences in real -time with spring boot planner

In this article, we will study how to calculate and show price differences between two time intervals using the spring boot planner.

Requirements

  • Spring boot 2.3.0 or higher

  • Java 11 or higher

Step 1: Define Time Intervals

Let’s say we have a simple Ethereumpracepair 'object with the" Timestamp "field, which depicts the time stamp on GMT (Greenwich's average time). We will use this object as a play input for our calculations.

Java

Public class Ethereumpracepair {

Private prolonged time stamp; // in seconds since 00: 0000 GMT

Public Ethereumpracepair (Long Time Stamp) {

This.tiMestamp = Timestamp;

}

// Getters and Seters

}

`

Step 2: Create Spring Boot Planner

We will use the@planned annotation to define our planner. We will assume we want to run every minute.

`Java

Import org.springframework.beans.Factory.Annotation.autowired;

Import org.Springframework.Boot.Autoconfigure.SpringBootApplication;

Import org.springframework.scheduling.Annotation.schedulled;

Import org.springframework.sterotipe@springbootApplication;

@SpringBootApplication

Public class EthereumpricepairschedulerApplication {

@Autowired

Private Ethereumpracepair Priscepair;

Public Static VOID MAID (SOCE [] ARGS) {

Springapplication.run (ethereumpracepairschedulerapplication.Class, ARGS);

}

@SchedULED (Fixeddelay = 60000) // Run every minute

Public VOID Calculation Pricing () {

Long Now = System.Currenttimemillis ();

Long Diff = (Now – PreakAir.GetttiMestamp ()) / 1000; // Convert milliseconds for seconds

Ethereumpracepair couple = new Ethereumpracepair (now);

System.out.println (“Price difference:” + Math.abs (pair.getttimestamp () – prinkair.getttimestamp ()) / 1E6 + “GMTS”);

}

}

`

Step 3: Show the price difference

Ethereum: How to get price difference using Spring boot scheduler

We will assume that we have a simple EtherePredisplay class to show price differences. We will create this class and use it to print the price difference.

`Java

Public class Ethereumpididisplay {

Public VOID DISPLAYPEIDIFFERENCE (Ethereumpricepair Pair) {

System.out.println (pair.getttimestamp () + “GMTS:” + Math.Abs ​​(pair.getttimestamp () – priscepair.getttestamp ()) / 1e6 + “GMTS”);

}

}

`

Putting it all

Here is a complete code with a ‘main’ method to run our robot software:

`Java

Import org.springframework.beans.Factory.Annotation.autowired;

Import org.Springframework.Boot.Autoconfigure.SpringBootApplication;

Import org.springframework.scheduling.Annotation.schedulled;

Import org.springframework.sterotipe@springbootApplication;

@SpringBootApplication

Public class EthereumpricepairschedulerApplication {

@Autowired

Private Ethereumpracepair Priscepair;

Public Static VOID MAID (SOCE [] ARGS) {

Springapplication.run (ethereumpracepairschedulerapplication.Class, ARGS);

}

@SchedULED (Fixeddelay = 60000) // Run every minute

Public VOID Calculation Pricing () {

Long Now = System.Currenttimemillis ();

Long Diff = (Now – PreakAir.GetttiMestamp ()) / 1000; // Convert milliseconds for seconds

Ethereumpracepair couple = new Ethereumpracepair (now);

Ethereumpidisplay Display = New EtherePiredisplay ();

Display.Displaypricediference (pair);

}

}

`

Example of output

The bot will run every minute and print the following output:

`

00: 00: 0000 GMTS: 1.02 GMTS

00: 00: 0015 GMTS: 2.04 GMTS

… …

`

In this example, we calculate the price difference between two time intervals for 1 second and 15 seconds. The bot will print out every minute.

Related Posts