ohls work

This commit is contained in:
7u83 2017-01-06 00:37:21 +01:00
parent af6acdbab1
commit b2680fa71d
2 changed files with 46 additions and 15 deletions

View File

@ -105,9 +105,12 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
} }
protected AbstractXYDataset getDataSet(String stockSymbol) { protected AbstractXYDataset getDataSet(String stockSymbol) {
//This is the dataset we are going to create //This is the dataset we are going to create
DefaultOHLCDataset result = null; DefaultOHLCDataset result;
//This is the data needed for the dataset //This is the data needed for the dataset
OHLCDataItem[] data; OHLCDataItem[] data;
@ -174,12 +177,18 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
List<OHLCDataItem> data = new ArrayList<>(); List<OHLCDataItem> data = new ArrayList<>();
long ct; long ct;
ct = Exchange.getCurrentTimeSeconds(10); ct = Exchange.getCurrentTimeSeconds();
int step=5;
long start = (ct - 60)/step*step;
SortedSet<Quote> h = MainWin.se.getQuoteHistory(start);
for (long i = start * 1000; i < ct * 1000; i += step * 1000) {
OHLCDataItem d = getOhlcData(i, i + step * 1000, h);
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 60);
for (long i = (ct - 60) * 1000; i < (ct + 10) * 1000; i += 10 * 1000) {
OHLCDataItem d = getOhlcData(i, i + 10 * 1000, h);
data.add(d); data.add(d);
} }
@ -258,13 +267,34 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
// q.print(); // q.print();
long ct; long ct;
ct = Exchange.getCurrentTimeSeconds(5); ct = Exchange.getCurrentTimeSeconds();
SortedSet<Quote> h = MainWin.se.getQuoteHistory(ct - 15);
System.out.print("Number of quotes" + ct + "\n");
OHLCDataItem[] data = this.getData();
OHLCDataItem di=data[data.length-1];
System.out.print(
String.format(
"O:%.2f H:%.2f L:%.2f C:%.2f (%d)\n",
di.getOpen(),
di.getHigh(),
di.getLow(),
di.getClose(),
data.length
)
);
long start = (ct - 60)/5*5;
SortedSet<Quote> h = MainWin.se.getQuoteHistory(start);
System.out.print("Number of quotes" + start + ":" + ct + "\n");
System.out.print("Number of quotes:" + h.size() + "\n"); System.out.print("Number of quotes:" + h.size() + "\n");
/* SortedSet h = MainWin.se.getQuoteHistory(60); /* SortedSet h = MainWin.se.getQuoteHistory(60);
System.out.print( System.out.print(
"SortedSet size:" "SortedSet size:"

View File

@ -27,14 +27,15 @@ public class Exchange extends Thread {
} }
public static long getCurrentTimeSeconds(long div) { /**
long ct = System.currentTimeMillis() / (1000 * div) * div; *
return ct * div; * @return
*/
public static long getCurrentTimeSeconds() {
long ct = System.currentTimeMillis();
return ct/1000 ;
} }
public static long getCurrentTimeSeconds() {
return getCurrentTimeSeconds(1);
}
public SortedSet<Quote> getQuoteHistory(long start) { public SortedSet<Quote> getQuoteHistory(long start) {