diff options
author | clarkohw <clark_oh-willeke@brown.edu> | 2021-04-19 03:01:48 -0400 |
---|---|---|
committer | clarkohw <clark_oh-willeke@brown.edu> | 2021-04-19 03:01:48 -0400 |
commit | 0508b076ac948a11bde14cfa9f5261796d890ef2 (patch) | |
tree | a22f1803b10093561283f5ce03135dab49e5b538 /src | |
parent | 8e76bf15c53c540a72a273ec560a624dfb7e11df (diff) |
caching of prices profit
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java | 1 | ||||
-rw-r--r-- | src/test/java/edu/brown/cs/student/ProfitCalculationTest.java | 12 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java index fe12612..77c1c3a 100644 --- a/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java +++ b/src/main/java/edu/brown/cs/student/term/profit/ProfitCalculation.java @@ -251,6 +251,7 @@ public class ProfitCalculation { JSONArray object = new JSONObject(response.body()).getJSONArray(ticker); try { double endPrice = object.getJSONObject(object.length() - 1).getDouble("c"); + currentStockPrices.put(ticker, endPrice); return endPrice; } catch (JSONException e) { currentStockPrices.put(ticker, -1.0); diff --git a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java index f435c7c..a4baa53 100644 --- a/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java +++ b/src/test/java/edu/brown/cs/student/ProfitCalculationTest.java @@ -56,13 +56,17 @@ public class ProfitCalculationTest { //price of GME at end time is 154.69 List<StockHolding> trade = profitCalculation.getHoldingsList(); //buy with no sell - assertEquals(trade.get(0).getUnrealizedGain(), 3842.25,.25); + assertEquals(trade.get(0).getUnrealizedGain(), 3842.25, .25); assertEquals(trade.get(0).getRealizedGain(), 0, .01); + } + + public void checkAPICalls() { + ProfitCalculation profitCalculation = + new ProfitCalculation(DatabaseQuerier.getConn(), "Don", new Date(1618234200000l), + new Date(1618814264000l)); - profitCalculation = new ProfitCalculation(DatabaseQuerier.getConn(), "Don", new Date(1618234200000l), - new Date(1618814264000l)); - + //check sp500 calculation. 411.28 to 417.30 assertEquals(profitCalculation.compareToSP500(), .01464, .001); } |