Colored switch price on worker card

This commit is contained in:
Nicolás Sánchez 2024-12-25 20:59:56 -03:00
parent 7931bbed12
commit 6bd530672c
3 changed files with 25 additions and 4 deletions

View File

@ -24,7 +24,6 @@ public class WorkerData {
boolean isBoosted, boolean isAuto, boolean isPaused, boolean stopWhenProfit, boolean isBoosted, boolean isAuto, boolean isPaused, boolean stopWhenProfit,
InstanceInterface.OldLongDictionary oldLongDictionary) { InstanceInterface.OldLongDictionary oldLongDictionary) {
// TODO: Add total_amount_of_quote and total_amount_of_base
this.pair = pair; this.pair = pair;
this.amountOfSafetyOrders = amountOfSafetyOrders; this.amountOfSafetyOrders = amountOfSafetyOrders;
this.maxSafetyOrders = maxSafetyOrders; this.maxSafetyOrders = maxSafetyOrders;
@ -57,4 +56,15 @@ public class WorkerData {
public boolean isPaused() { return isPaused; } public boolean isPaused() { return isPaused; }
public boolean getStopWhenProfit() { return stopWhenProfit; } public boolean getStopWhenProfit() { return stopWhenProfit; }
public InstanceInterface.OldLongDictionary getOldLongDictionary() { return oldLongDictionary; } public InstanceInterface.OldLongDictionary getOldLongDictionary() { return oldLongDictionary; }
public double getMinSwitchPrice() {
if (oldLongDictionary==null) return 0;
double oldTarget = oldLongDictionary.getTpAmount() * oldLongDictionary.getTpPrice();
double baseLeft = oldLongDictionary.getTpAmount() - totalAmountOfBase;
if (baseLeft <= 0) return 0;
return (oldTarget - totalAmountOfQuote) / baseLeft;
}
} }

View File

@ -79,8 +79,19 @@ public class WorkerCardAdapter{
//Cyan //Cyan
pair.setTextColor(Color.parseColor("#008B8B")); pair.setTextColor(Color.parseColor("#008B8B"));
} }
price.setText(String.format(Locale.ROOT, "%.8f", worker.getPrice())); price.setText(String.format(Locale.ROOT, "%.8f", worker.getPrice()));
//TODO: If short and old_long and next_so_price<switch_price, set color to green
nextSoPrice.setText(String.format(Locale.ROOT, "%.8f", worker.getNextSoPrice())); nextSoPrice.setText(String.format(Locale.ROOT, "%.8f", worker.getNextSoPrice()));
if (worker.isShort() &&
worker.getOldLongDictionary()!=null &&
worker.getOldLongDictionary().getTpAmount() * worker.getOldLongDictionary().getTpPrice() - worker.getTotalAmountOfQuote()>0 &&
worker.getOldLongDictionary().getTpAmount() - worker.getTotalAmountOfBase() > 0 &&
worker.getNextSoPrice()>worker.getMinSwitchPrice()) {
//Green
nextSoPrice.setTextColor(Color.parseColor("#00FF00"));
}
takeProfitPrice.setText(String.format(Locale.ROOT, "%.8f", worker.getTakeProfitPrice())); takeProfitPrice.setText(String.format(Locale.ROOT, "%.8f", worker.getTakeProfitPrice()));
double percentageToProfit = abs(worker.getTakeProfitPrice()- worker.getPrice())/worker.getPrice()*100; double percentageToProfit = abs(worker.getTakeProfitPrice()- worker.getPrice())/worker.getPrice()*100;
@ -88,7 +99,7 @@ public class WorkerCardAdapter{
percentage.setText(percentageToDisplay); percentage.setText(percentageToDisplay);
if (percentageToProfit<1) { if (percentageToProfit<1) {
//Green //Green
percentage.setTextColor(Color.parseColor("#006A00")); percentage.setTextColor(Color.parseColor("#00FF00"));
} else if (percentageToProfit>20) { } else if (percentageToProfit>20) {
//Red //Red
percentage.setTextColor(Color.parseColor("#FFFF0000")); percentage.setTextColor(Color.parseColor("#FFFF0000"));
@ -96,7 +107,7 @@ public class WorkerCardAdapter{
//Yellow //Yellow
percentage.setTextColor(Color.parseColor("#FFA500")); percentage.setTextColor(Color.parseColor("#FFA500"));
} else { } else {
percentage.setTextColor(Color.parseColor("#FF424242")); percentage.setTextColor(Color.parseColor("#CACACA"));
} }
String safetyOrdersToDisplay = worker.getAmountOfSafetyOrders()-1 + "/" + worker.getMaxSafetyOrders(); String safetyOrdersToDisplay = worker.getAmountOfSafetyOrders()-1 + "/" + worker.getMaxSafetyOrders();

View File

@ -423,7 +423,7 @@ public class HomeFragment extends Fragment {
} }
private void setPercentageColor(TextView textView, double percentage) { private void setPercentageColor(TextView textView, double percentage) {
int upColor = ContextCompat.getColor(requireContext(), R.color.dark_green); int upColor = ContextCompat.getColor(requireContext(), R.color.bright_green);
String formattedPercentage = formatPercentage(percentage); String formattedPercentage = formatPercentage(percentage);
textView.setText(formattedPercentage); textView.setText(formattedPercentage);