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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| package jopencomponents.symbol;
import org.joda.time.DateTime;
/**
* Encapsulates the price bar information.
*/
public class PriceBar {
private long date;
private double open, high, low, close;
private long volume;
/**
* This constructor is used to create a new historical bar
*/
public PriceBar(long date, double open, double high, double low, double close, long volume) {
this.date = date;
this.open = open;
this.high = high;
this.low = low;
this.close = close;
this.volume = volume;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(" date: ").append(getShortDate());
sb.append(" open: ").append(open);
sb.append(" high: ").append(high);
sb.append(" low: ").append(low);
sb.append(" close: ").append(close);
sb.append(" volume: ").append(volume);
return sb.toString();
}
public String getShortDate() {
DateTime dateTime = new DateTime(date);
return dateTime.toString("dd MMMMM yyyy");
}
public double getOpen() {
return open;
}
public double getHigh() {
return high;
}
public double getLow() {
return low;
}
public double getClose() {
return close;
}
public double getMidpoint() {
return (low + high) / 2;
}
public void setOpen(double open) {
this.open = open;
}
public void setHigh(double high) {
this.high = high;
}
public void setLow(double low) {
this.low = low;
}
public void setClose(double close) {
this.close = close;
}
public void setDate(long date) {
this.date = date;
}
public void setVolume(long volume) {
this.volume = volume;
}
public long getVolume() {
return volume;
}
public DateTime getDateTime() {
DateTime dateTime = new DateTime(date);
return dateTime;
}
public long getDate() {
return date;
}
} |
Partager