-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOrderBookUnitInfo.java
More file actions
30 lines (25 loc) · 1.08 KB
/
OrderBookUnitInfo.java
File metadata and controls
30 lines (25 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.cleanengine.coin.orderbook.dto;
import com.cleanengine.coin.orderbook.domain.OrderBookUnit;
public record OrderBookUnitInfo(
Double price,
Double size,
Double priceChangePercent
){
public OrderBookUnitInfo{
if(price == null || size == null || priceChangePercent == null){
throw new IllegalArgumentException("price, size, priceChangePercent cannot be null.");
}
}
public OrderBookUnitInfo(OrderBookUnit orderBookUnit, Double yesterdayClosingPrice) {
this(orderBookUnit.getPrice(),
orderBookUnit.getSize(),
calculateChangePercent(orderBookUnit.getPrice(), yesterdayClosingPrice));
}
private static Double calculateChangePercent(Double price, Double yesterdayClosingPrice) {
if(price == null || yesterdayClosingPrice == null){
throw new IllegalArgumentException("price, yesterdayClosingPrice cannot be null.");
}
return (yesterdayClosingPrice <= 0) ?
0.0 : (price - yesterdayClosingPrice) / yesterdayClosingPrice * 100;
}
}