-
Notifications
You must be signed in to change notification settings - Fork 1
/
Intraday.java
158 lines (108 loc) · 3.99 KB
/
Intraday.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PriceAction101;
import org.json.JSONObject;
import org.json.JSONArray;
import java.util.ArrayList;
import static javafx.application.Platform.exit;
import org.json.JSONException;
/**
* Class to store Intraday Data and Interval based Data.
* @author Man Eesh
*/
public class Intraday {
public ArrayList<OHLCV> mins = new ArrayList<>();
long min;
int recent = 0;
long max;
int totalVolume=0;
private String symbol ;
public Intraday(String symbol)throws Exception{
this.symbol = symbol;
this.getIntraday();
}
/**
* Makes OHLCV Array of 1min Intraday data from YFinance.
* @param series
* @param max
* @param range
*/
public void makeIntraday(JSONArray series , long max , long min){
OHLCV minute;
int i=this.recent; // enables implicit updation w/o new OHLCV object
long t= 0;
//CHECK MAX i FROM TIME RANGE
this.max = max;
this.min = min;
try{
while(t <= max-80) {
t = series.getJSONObject(i).getLong("Timestamp");
minute = new OHLCV( series.getJSONObject(i).getDouble("open"),
series.getJSONObject(i).getDouble("high"),
series.getJSONObject(i).getDouble("low"),
series.getJSONObject(i).getDouble("close"),
series.getJSONObject(i).getInt("volume"),
t
);
this.mins.add(minute);
i++;
}
}catch(JSONException e){
//System.out.println(e);
//System.out.println(e);
}
finally{
int j;
for(j=this.recent ; j <= i-1 ; j++)
this.totalVolume += this.mins.get(j).getVolume();
this.recent = i-1;
// System.out.println( i-1);
}
}
public void getIntraday() throws Exception{
JSONObject json = GetMaster.getJSON(this.symbol,1);
JSONArray series = json.getJSONArray("series");
long max = json.getJSONObject("Timestamp").getLong("max");
long min = json.getJSONObject("Timestamp").getLong("min");
// System.out.println("masdf: ");
this.makeIntraday(series,max,min);
// }catch(Exception e){System.out.println("getIntraday() : "+symbol + e);}
// System.out.println(newday.getMins().toString());
}
/**
* Returns ArrayList of OHLCV.
* @return ArrayList
*/
public ArrayList<OHLCV> getMins() {
return mins;
}
public int getAV(int mins){
int av = this.totalVolume/(this.recent+1);
return av*mins;
}
public int getAV(){
int av = this.totalVolume/(this.recent+1);
return av;
}
/**
* Returns most recent quotes 1min volume.
* @return int
*/
public int getRecentVolume(){
//string interval param
int rv;
try{rv = this.getMins().get(this.recent-1).getVolume();
}catch(Exception e){rv = 0;}
return rv;
}
public int getRecentVolume(int mins){
//string interval param
int rv;
try{rv = this.getMins().get(this.recent-1-mins).getVolume();
}catch(Exception e){rv = 0;}
return rv;
}
}