I am writing a bot for trading. I need to get the price difference in time intervals. Let's say at 00:00:00:0000 GMT the price of a pair is 100.0000, and at 00:00:00:0005 GMT the price is 101.0000, I want to get this difference.
I am using Spring boot scheduler, when I run the app it always returns that the price isn't much. I want it to continually check nutil the price difference gets to the price.
This is to check every 5 minutes
@Scheduled(fixedRate = (10*60*1000))
private double getInitialPrice(){
try {
initialPrice = Double.parseDouble(String.valueOf(api.pricesMap().get("BTCUSDT")));
} catch (BinanceApiException e) {
e.printStackTrace();
}
return initialPrice;
}
This is to check every 5 milliseconds
@Scheduled(fixedRate = (5))
private double getInstancePrice(){
try {
instancePrice = Double.parseDouble(String.valueOf(api.pricesMap().get("BTCUSDT")));
} catch (BinanceApiException e) {
e.printStackTrace();
}
return instancePrice;
}
I'm now checking with the hope that the getInstancePrice() method will always check until it's true. It failed the test as it always returns that the price is not higher, whereas when manually checked it's higher. How do I make it continually check until it gives the time difference?
if( getInstancePrice() > getInitialPrice() ){
//do this
}