-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/BitStats/CryptoDashboard
- Loading branch information
Showing
8 changed files
with
699 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package mx.itam.Backend; | ||
|
||
import java.text.NumberFormat; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Clase que maneja el precio de una moneda dada en el presente | ||
* @author BitStats | ||
*/ | ||
public class ActualPrice { | ||
private Symbol symbol; | ||
private double price; | ||
private final static Logger logger = | ||
Logger.getLogger(ActualPrice.class.getName()); | ||
|
||
/** | ||
* Método constructor de la clase | ||
* @param symbol Define la moneda con que se está trabajando | ||
* @param price Precio actual de la moneda dada | ||
*/ | ||
public ActualPrice(Symbol symbol, double price) { | ||
|
||
this.symbol = symbol; | ||
this.price = price; | ||
logger.log(Level.INFO,"Guardando precio actual"); | ||
} | ||
|
||
/** | ||
* | ||
* @return El símbolo de la moneda que se está considerando | ||
*/ | ||
public Symbol getSymbol() { | ||
return symbol; | ||
} | ||
|
||
/** | ||
* | ||
* @return El precio de la moneda que se está considerando | ||
*/ | ||
public double getPrice() { | ||
return price; | ||
} | ||
|
||
/** | ||
* | ||
* @return El precio de la moneda en el formato de moneda $xxxx.xx | ||
*/ | ||
public String currencyFormat(){ | ||
NumberFormat formatter = NumberFormat.getCurrencyInstance(); | ||
formatter.setMinimumFractionDigits(10); //Especifica 10 como la cantidad mínima de dígitos fraccionarios | ||
return formatter.format(price); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
package mx.itam.Backend; | ||
|
||
import java.text.NumberFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* Clase para manejar los precios de una moneda durante un intervalo | ||
* @author BitStats | ||
*/ | ||
public class DataHistorica { | ||
private long openTime; | ||
private double openPrice; | ||
private double maxPrice; | ||
private double minPrice; | ||
private double closePrice; | ||
private Interval interval; | ||
private final static Logger logger = | ||
Logger.getLogger(DataHistorica.class.getName()); | ||
|
||
/** | ||
* Método constructor de la clase | ||
* @param openTime Primer momento en el intervalo | ||
* @param openPrice Precio que se tuvo en el openTime | ||
* @param maxPrice Precio máximo que tuvo la moneda en el intervalo | ||
* @param minPrice Precio mínimo que tuvo la moneda en el intervalo | ||
* @param closePrice Precio que se tuvo en el final del intervalo | ||
* @param interval Intervalo que se está midiendo | ||
*/ | ||
public DataHistorica(long openTime, double openPrice, double maxPrice, double minPrice, double closePrice, Interval interval) { | ||
this.openTime = openTime; | ||
this.openPrice = openPrice; | ||
this.maxPrice = maxPrice; | ||
this.minPrice = minPrice; | ||
this.closePrice = closePrice; | ||
this.interval = interval; | ||
logger.log(Level.INFO,"Guardando data de la fecha: "+beautyDate()); | ||
|
||
} | ||
|
||
/** | ||
* | ||
* @param time Un momento en fecha UNIX | ||
* @return La fecha UNIX convertida a formato dd/MM/yyyy | ||
*/ | ||
public static String getDateFromEpoch(long time){ | ||
return new SimpleDateFormat("dd/MM/yyyy").format(new Date(time)); | ||
} | ||
|
||
/** | ||
* Método para regresar una fecha dada en un formato consistente | ||
* @return La fecha de los datos historicos en formato | ||
*/ | ||
public String beautyDate(){ | ||
if(interval.getTimeCode().contains("m")){ | ||
return new SimpleDateFormat("HH:mm:ss").format(new Date(openTime)); | ||
} | ||
if(interval.getTimeCode().contains("h")){ | ||
return new SimpleDateFormat("dd-HH:mm").format(new Date(openTime)); | ||
} | ||
if(interval.getTimeCode().contains("d") || interval.getTimeCode().contains("w")){ | ||
return new SimpleDateFormat("dd-MMM").format(new Date(openTime)); | ||
} | ||
if(interval.getTimeCode().contains("M")){ | ||
return new SimpleDateFormat("dd/MMM/yyyy").format(new Date(openTime)); | ||
} | ||
return ""; | ||
} | ||
|
||
/** | ||
* | ||
* @return Momento en que comienza el intervalo | ||
*/ | ||
public long getOpenTime() { | ||
return openTime; | ||
} | ||
|
||
/** | ||
* | ||
* @return Fecha formateada | ||
*/ | ||
public String getDate(){ | ||
return getDateFromEpoch(openTime); | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio al comienzo del intervalo | ||
*/ | ||
public double getOpenPrice() { | ||
return openPrice; | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio máximo durante el intervalo | ||
*/ | ||
public double getMaxPrice() { | ||
return maxPrice; | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio mínimo durante el intervalo | ||
*/ | ||
public double getMinPrice() { | ||
return minPrice; | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio al cierre del intervalo | ||
*/ | ||
public double getClosePrice() { | ||
return closePrice; | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio al principio del intervalo en formato de moneda | ||
*/ | ||
public String getOpenPriceBeauty(){ | ||
NumberFormat formatter = NumberFormat.getCurrencyInstance(); | ||
formatter.setMinimumFractionDigits(10); | ||
return formatter.format(openPrice); | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio al cierre del intervalo en formato de moneda | ||
*/ | ||
public String getClosePriceBeauty(){ | ||
NumberFormat formatter = NumberFormat.getCurrencyInstance(); | ||
formatter.setMinimumFractionDigits(10); | ||
return formatter.format(closePrice); | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio máximo durante el intervalo en formato de moneda | ||
*/ | ||
public String getMaxPriceBeauty(){ | ||
NumberFormat formatter = NumberFormat.getCurrencyInstance(); | ||
formatter.setMinimumFractionDigits(10); | ||
return formatter.format(maxPrice); | ||
} | ||
|
||
/** | ||
* | ||
* @return Precio mínimo durante el intervalo en formato de moneda | ||
*/ | ||
public String getMinPriceBeauty(){ | ||
NumberFormat formatter = NumberFormat.getCurrencyInstance(); | ||
formatter.setMinimumFractionDigits(10); | ||
return formatter.format(minPrice); | ||
} | ||
|
||
/** | ||
* | ||
* @return String conteniendo los datos históricos de la moneda en el intervalo | ||
*/ | ||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Open Time: ").append(getDateFromEpoch(openTime)).append("\tOpen Price: ").append(openPrice); | ||
sb.append("\tMax Price: ").append(maxPrice).append("\tMin Price: ").append(minPrice); | ||
sb.append("\tClose Price: ").append(closePrice); | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.