improved price formatting

This commit is contained in:
Nicolás Sánchez 2024-12-24 20:09:23 -03:00
parent 22b2ce40a9
commit 108c4a0a10
6 changed files with 20 additions and 20 deletions

View File

@ -9,6 +9,7 @@ import android.os.Looper;
import android.widget.Toast;
import java.io.IOException;
import java.util.Locale;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@ -673,6 +674,9 @@ public class WorkerInterface {
public static void showWorkerDetailsDialog(InstanceInterface.WorkerStatsData result, Context context) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
int priceDecimals = countDecimalPlaces(result.getPrice());
String numberFormat = "%." + priceDecimals + "f";
builder.setTitle(result.getPair() + " status");
String isPausedExtraString = "";
if (result.getIsPaused()) {
@ -686,15 +690,15 @@ public class WorkerInterface {
oldLongExtraString = "\nOLD LONG:\n" +
"Switch date: " + result.getOldLongDictionary().getDatetime() + "\n" +
"Amount of base in the deal: " + result.getOldLongDictionary().getTpAmount() + "\n" +
"Take profit price: " + result.getOldLongDictionary().getTpPrice() + "\n" +
"Switch price: " + minSwitchPrice + "\n" +
"Take profit price: " + String.format(Locale.ROOT, numberFormat,result.getOldLongDictionary().getTpPrice()) + "\n" +
"Switch price: " + String.format(Locale.ROOT, numberFormat, minSwitchPrice) + "\n" +
"Quote spent: " + result.getOldLongDictionary().getQuoteSpent() + "\n" +
"Fees paid in quote: " + result.getOldLongDictionary().getFeesPaidInQuote();
}
builder.setMessage("Price: " + result.getPrice() + "\n" +
"Take profit price: " + result.getTakeProfitPrice() + "\n" +
"Next safety order price: " + result.getTakeProfitPrice() + "\n" +
"Take profit price: " + String.format(Locale.ROOT, numberFormat,result.getTakeProfitPrice()) + "\n" +
"Next safety order price: " + String.format(Locale.ROOT, numberFormat,result.getNextSoPrice()) + "\n" +
"Take profit order ID: " + result.getTpOrderId() + "\n" +
"Safety order ID: " + result.getSoOrderId() + "\n" +
"Short: " + result.getIsShort() + "\n" +
@ -708,7 +712,7 @@ public class WorkerInterface {
"Safety orders sent: " + (result.getSoAmount()-1) + "\n" +
"Max safety orders: " + result.getNumberOfSafetyOrders() + "\n" +
"Start time: " + result.getStartTime() + "\n" +
"Start price: " + result.getStartPrice() + "\n" +
"Start price: " + String.format(Locale.ROOT, numberFormat,result.getStartPrice()) + "\n" +
"Deal start time: " + result.getDealStartTime() + "\n" +
"Deal uptime: " + result.getDealUptime() + "\n" +
"Total uptime: " + result.getTotalUptime() + "\n" +
@ -720,6 +724,17 @@ public class WorkerInterface {
builder.show();
}
public static int countDecimalPlaces(double number) {
String numberStr = String.valueOf(number);
int decimalIndex = numberStr.indexOf('.');
// If there are no decimals, return 0
if (decimalIndex == -1) {
return 0;
}
return numberStr.length() - decimalIndex - 1;
}
}

View File

@ -114,9 +114,6 @@ public class BinanceFragment extends Fragment implements WorkerCardAdapter.OnCar
} else if (item.getItemId() == R.id.addQuote) {
System.err.println(pair + " Add quote option clicked");
return true;
} else if (item.getItemId() == R.id.workerMenuLastCall) {
System.err.println(pair + " Worker menu last call option clicked");
return true;
}
return false;
}

View File

@ -107,9 +107,6 @@ public class GateioFragment extends Fragment implements WorkerCardAdapter.OnCard
} else if (item.getItemId() == R.id.addQuote) {
System.err.println(pair + " Add quote option clicked");
return true;
} else if (item.getItemId() == R.id.workerMenuLastCall) {
System.err.println(pair + " Worker menu last call option clicked");
return true;
}
return false;
}

View File

@ -107,9 +107,6 @@ public class KucoinFragment extends Fragment implements WorkerCardAdapter.OnCard
} else if (item.getItemId() == R.id.addQuote) {
System.err.println(pair + " Add quote option clicked");
return true;
} else if (item.getItemId() == R.id.workerMenuLastCall) {
System.err.println(pair + " Worker menu last call option clicked");
return true;
}
return false;
}

View File

@ -107,9 +107,6 @@ public class OkxFragment extends Fragment implements WorkerCardAdapter.OnCardLon
} else if (item.getItemId() == R.id.addQuote) {
System.err.println(pair + " Add quote option clicked");
return true;
} else if (item.getItemId() == R.id.workerMenuLastCall) {
System.err.println(pair + " Worker menu last call option clicked");
return true;
}
return false;
}

View File

@ -26,7 +26,6 @@
android:title="Toggle cleanup"/>
<item android:id="@+id/toggleLastCall"
android:title="Toggle last call"/>
</menu>
</item>
<item android:id="@+id/workerMenuSwitch"
@ -49,6 +48,4 @@
android:title="Add quote"/>
</menu>
</item>
<item android:id="@+id/workerMenuLastCall"
android:title="Last call" />
</menu>