aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/edu/brown/cs/student/term/Main.java2
-rw-r--r--src/main/java/edu/brown/cs/student/term/ProfitCalculation.java25
2 files changed, 15 insertions, 12 deletions
diff --git a/src/main/java/edu/brown/cs/student/term/Main.java b/src/main/java/edu/brown/cs/student/term/Main.java
index 7838dd3..fd352f7 100644
--- a/src/main/java/edu/brown/cs/student/term/Main.java
+++ b/src/main/java/edu/brown/cs/student/term/Main.java
@@ -48,7 +48,7 @@ public final class Main {
}
- ProfitCalculation person = new ProfitCalculation(null, "Sophie", new Date(1615629591000L), new Date(1615507898000L));
+ ProfitCalculation person = new ProfitCalculation(null, "Vincent", new Date(1515629591000L), new Date(1715507898000L));
try {
person.setConnection("./data/mock_tradeClarks.sqlite3");
} catch(Exception e) {
diff --git a/src/main/java/edu/brown/cs/student/term/ProfitCalculation.java b/src/main/java/edu/brown/cs/student/term/ProfitCalculation.java
index 998ea26..021e48b 100644
--- a/src/main/java/edu/brown/cs/student/term/ProfitCalculation.java
+++ b/src/main/java/edu/brown/cs/student/term/ProfitCalculation.java
@@ -76,9 +76,11 @@ public class ProfitCalculation {
// TODO: add start and end time
prep =
conn.prepareStatement("SELECT * FROM \'trades\' WHERE holder_name= ? "
+ + " AND trade_timestamp BETWEEN ? AND ?"
+ "order by trade_timestamp asc;");
prep.setString(1, this.person);
- //prep.setString(2, "NVDA");
+ prep.setDate(2, startTime);
+ prep.setDate(3, endTime);
ResultSet rs = prep.executeQuery();
while (rs.next()) {
@@ -215,15 +217,17 @@ public class ProfitCalculation {
//convert body to JSONObject
//object.getDouble("price")
- String API_KEY = "NW169NGWKDG9UGXO";
- String url = "https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol="
- + ticker
- + "&apikey="
- + API_KEY;
+ String BASE_URL = "https://data.alpaca.markets/v1";
+ String PRICE_URL = BASE_URL + "/last/stocks/" + ticker;
+
+
+ String API_KEY = "PKT53Z9QW0TMSSC9XNPQ";
+ String SECRET_KEY = "udvetWCvwyVmZgrjgCPfX3W0nprKBrbunh5wNnCv";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
- .uri(URI.create(url))
+ .uri(URI.create(PRICE_URL)).setHeader("APCA-API-KEY-ID", API_KEY)
+ .setHeader("APCA-API-SECRET-KEY", SECRET_KEY)
.build();
HttpResponse<String> response = null;
@@ -236,16 +240,15 @@ public class ProfitCalculation {
e.printStackTrace();
}
- System.out.println(response.body());
+
JSONObject object = new JSONObject(response.body());
- return object.getJSONObject("Global Quote").getDouble("05. price");
+ return object.getJSONObject("last").getDouble("price");
}
public void calculateGains() {
organizeOrders();
getRealizedGains();
getUnrealizedGains();
- double totalGains = 0;
double realizedGains = 0;
double unrealizedGains = 0;
@@ -257,7 +260,7 @@ public class ProfitCalculation {
unrealizedGains += value;
}
- totalGains = unrealizedGains + realizedGains;
+ double totalGains = unrealizedGains + realizedGains;
System.out.println(
"Total: " + totalGains + "| unrealized: " + unrealizedGains + " | realized: " +