Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added date to CryptoUnit #13

Merged
merged 2 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import com.crazzyghost.alphavantage.parser.DefaultParser;
import com.crazzyghost.alphavantage.parser.Parser;
Expand Down Expand Up @@ -78,8 +79,10 @@ public CryptoResponse parse(Map<String, String> metaDataMap, Map<String, Map<Str

List<CryptoUnit> cryptoUnits = new ArrayList<>();

for (Map<String,String> m: units.values()) {
for (Entry<String,Map<String,String>> entry : units.entrySet()){
Map<String,String> m = entry.getValue();
CryptoUnit.Builder cryptoUnit = new CryptoUnit.Builder();
cryptoUnit.date(entry.getKey());
cryptoUnit.open(Double.parseDouble(m.get("1a. open (" + market + ")" )));
cryptoUnit.high(Double.parseDouble(m.get("2a. high (" + market + ")" )));
cryptoUnit.low(Double.parseDouble(m.get("3a. low (" + market + ")" )));
Expand All @@ -92,6 +95,7 @@ public CryptoResponse parse(Map<String, String> metaDataMap, Map<String, Map<Str
cryptoUnit.marketCap(Double.parseDouble(m.get("6. market cap (USD)")));
cryptoUnits.add(cryptoUnit.build());
}

return new CryptoResponse(metaData, cryptoUnits);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.crazzyghost.alphavantage.cryptocurrency.response;

// TODO add date
public class CryptoUnit {

private double open;
Expand All @@ -13,6 +12,7 @@ public class CryptoUnit {
private double lowUSD;
private double volume;
private double marketCap;
private String date;

public CryptoUnit(Builder builder) {
this.open = builder.open;
Expand All @@ -25,6 +25,7 @@ public CryptoUnit(Builder builder) {
this.lowUSD = builder.lowUSD;
this.volume = builder.volume;
this.marketCap = builder.marketCap;
this.date = builder.date;
}


Expand All @@ -40,6 +41,7 @@ public static class Builder{
double lowUSD;
double volume;
double marketCap;
String date;

public Builder open(double open){
this.open = open;
Expand Down Expand Up @@ -89,10 +91,17 @@ public Builder volume(double volume){
return this;
}

public Builder date(String date){
this.date = date;
return this;
}

public CryptoUnit build(){
return new CryptoUnit(this);
}



}

public double getOpen() {
Expand Down Expand Up @@ -135,10 +144,15 @@ public double getMarketCap() {
return marketCap;
}

public String getDate(){
return date;
}

@Override
public String toString() {
return "\n" + "CryptoUnit {" +
"close=" + close +
"date=" + date +
", close=" + close +
", closeUSD=" + closeUSD +
", high=" + high +
", highUSD=" + highUSD +
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/crypto/CryptoUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class CryptoUnitTest {
public void testCryptoUnit(){

CryptoUnit unit = new CryptoUnit.Builder()
.date("2020-04-12")
.close(40.0)
.closeUSD(45.0)
.high(56.76)
Expand All @@ -25,6 +26,7 @@ public void testCryptoUnit(){
.volume(100.0)
.build();

assertEquals("Crypto unit date not set correctly", "2020-04-12", unit.getDate());
assertEquals(unit.getClose(), 40.0, 0);
assertEquals(unit.getCloseUSD(), 45.0, 0);
assertEquals(unit.getHigh(), 56.76, 0);
Expand Down