Created
December 21, 2018 15:37
-
-
Save landjd19/54e25b58fce544dc1909409b6af6abb6 to your computer and use it in GitHub Desktop.
stockmarket
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char letter; | |
String sym = ""; | |
String words = ""; | |
String lines = ""; | |
float linePlace = -150; | |
ArrayList<String> priceList = new ArrayList<String>(); | |
String placeHolder = ""; | |
int spot = 0; | |
int which = 0; | |
//In draw method | |
void setup(){ | |
size(600,400); | |
} | |
void draw(){ | |
textSize(12); | |
background(155); | |
text("Current key: ", 10, 40); | |
text(words, 85, 40); | |
fill(255,0,0); | |
rect(10,70,100,40); | |
fill(255,255,255); | |
if(minute()%10 == 0 && second() == 0){ | |
for(int i = 0; i < priceList.size(); i++){ | |
sym = priceList.get(i); | |
sym = sym.substring(0,sym.indexOf(":")); | |
read(); | |
} | |
} | |
if(priceList.size() > 0){ | |
textSize(20); | |
text(priceList.get(which), linePlace, 300); | |
linePlace += 2; | |
} | |
if(linePlace > width && priceList.size() > 0){ | |
linePlace = -150; | |
if(which < priceList.size() - 1){ | |
which++; | |
}else{ | |
which = 0; | |
} | |
} | |
/* for(int i = 0; i < priceList.size(); i++){ | |
textSize(20); | |
text(priceList.get(i), 10, 300 + (24 * i)); | |
}*/ | |
} | |
// keyTyped | |
void keyTyped() { | |
if ((key >= 'A' && key <= 'z') || key == ' ') { | |
letter = key; | |
letter = Character.toUpperCase(letter); | |
words = words + letter;//add this to keyTyped | |
} | |
} | |
//button | |
void keyPressed() { | |
if (keyCode == 32) { | |
words = ""; | |
} | |
if(keyCode == 37){ | |
words = words.substring(0,words.length()-1); | |
} | |
if(keyCode == 10){ | |
println("Clicked"); | |
sym = words; | |
sym = trim(sym); | |
read(); | |
words = ""; | |
} | |
} | |
void mousePressed(){ | |
if(mouseX>10 && mouseX<110 && mouseY>70 && mouseY < 170){ | |
println("Clicked"); | |
sym = words; | |
sym = trim(sym); | |
read(); | |
words = ""; | |
priceList.add(placeHolder); | |
} | |
} | |
public void read(){ | |
lines=""; | |
placeHolder = ""; | |
String test = "https://financialmodelingprep.com/api/company/profile/" + sym; | |
println(test); | |
String[] ll = loadStrings("https://financialmodelingprep.com/api/company/profile/" + sym); | |
ll[0] = trim(ll[0].substring(ll[0].indexOf("{"))); | |
for(int i=0; i<ll.length; i++){ | |
lines += ll[i]; | |
} | |
println(lines); | |
JSONObject jarr = JSONObject.parse(lines); | |
JSONObject stock = jarr.getJSONObject(sym); | |
float price = stock.getFloat("Price"); | |
String beta = stock.getString("Beta"); | |
String name = stock.getString("companyName"); | |
println(price + ", " + beta + ", " + name); | |
placeHolder = (words + ": " + price); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment