Compare commits

..

No commits in common. "1492315a53d4643f4a3e6a3ea45c23a338dd6631" and "319725f6c5d70be9a584e9fa2e091571ad0cc3a2" have entirely different histories.

11 changed files with 17 additions and 123 deletions

View File

@ -16,7 +16,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -27,7 +26,6 @@ import okhttp3.Response;
public class InstanceInterface { public class InstanceInterface {
private static final String API_BASE_URL = globalSettings.apiUrl; private static final String API_BASE_URL = globalSettings.apiUrl;
private static final String API_KEY = globalSettings.apiKey; private static final String API_KEY = globalSettings.apiKey;
private static final String EARN_API_KEY = globalSettings.earnApiKey;
private static final OkHttpClient httpClient = new OkHttpClient(); private static final OkHttpClient httpClient = new OkHttpClient();
public static ProfitStatsData getProfitStatsData(boolean retry) throws IOException { public static ProfitStatsData getProfitStatsData(boolean retry) throws IOException {
@ -445,11 +443,7 @@ public class InstanceInterface {
}); });
CompletableFuture<Double> fundsAvailableFuture = CompletableFuture.supplyAsync(() -> { CompletableFuture<Double> fundsAvailableFuture = CompletableFuture.supplyAsync(() -> {
try { try {
if (globalSettings.useEarn) {
return getFundsAvailableWithEarn(exchange,"USDT", true);
} else {
return getFundsAvailable(exchange,"USDT", true); return getFundsAvailable(exchange,"USDT", true);
}
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -497,40 +491,6 @@ public class InstanceInterface {
} }
private static double getFundsAvailableWithEarn(String exchange, String coin, boolean retry) throws IOException {
String parsedBroker = exchange;
if (Objects.equals(parsedBroker, "okex")) {
parsedBroker = "okx";
}
Request fundsRequest = new Request.Builder()
.url(API_BASE_URL + "/earn/get_total_balance?broker=" + parsedBroker)
.header("X-API-KEY", EARN_API_KEY)
.build();
try (Response fundsResponse = httpClient.newCall(fundsRequest).execute()) {
if (!fundsResponse.isSuccessful()) {
if (fundsResponse.code() == 503 && retry) {
return getFundsAvailableWithEarn(exchange, coin, false);
}
throw new IOException("Unexpected code " + fundsResponse);
}
String fundsResponseBody = fundsResponse.body().string();
JsonElement jsonElement = JsonParser.parseString(fundsResponseBody);
if (!jsonElement.isJsonObject()) {
System.err.println("The parsed JSON response is not a JsonObject.");
return 0.0;
}
JsonObject jsonObject = jsonElement.getAsJsonObject();
if (!jsonObject.has("trading_balance")) {
System.err.println("The parsed JSON response does not contain the balances requested.");
return 0.0;
}
return jsonObject.get("trading_balance").getAsDouble() + jsonObject.get("earning_balance").getAsDouble();
}
}
private static double getFundsAvailable(String exchange, String coin, boolean retry) throws IOException { private static double getFundsAvailable(String exchange, String coin, boolean retry) throws IOException {
Request fundsRequest = new Request.Builder() Request fundsRequest = new Request.Builder()
.url(API_BASE_URL + "/" + exchange + "/get_balance?coin=" + coin) .url(API_BASE_URL + "/" + exchange + "/get_balance?coin=" + coin)

View File

@ -70,10 +70,10 @@ public class GateioFragment extends Fragment implements WorkerCardAdapter.OnCard
WorkerInterface.sendAddTraderCall("gateio",getContext()); WorkerInterface.sendAddTraderCall("gateio",getContext());
return true; return true;
} else if (item.getItemId() == R.id.removeTrader) { } else if (item.getItemId() == R.id.removeTrader) {
WorkerInterface.sendRemoveTraderCall("gateio",pair, getContext()); System.err.println(pair + " Remove trader option clicked");
return true; return true;
} else if (item.getItemId() == R.id.restartTrader) { } else if (item.getItemId() == R.id.restartTrader) {
WorkerInterface.sendRestartTraderCall("gateio",pair, getContext()); System.err.println(pair + " Restart option clicked");
return true; return true;
} else if (item.getItemId() == R.id.importTrader) { } else if (item.getItemId() == R.id.importTrader) {
WorkerInterface.sendImportTraderCall("gateio",getContext()); WorkerInterface.sendImportTraderCall("gateio",getContext());

View File

@ -70,10 +70,10 @@ public class KucoinFragment extends Fragment implements WorkerCardAdapter.OnCard
WorkerInterface.sendAddTraderCall("kucoin",getContext()); WorkerInterface.sendAddTraderCall("kucoin",getContext());
return true; return true;
} else if (item.getItemId() == R.id.removeTrader) { } else if (item.getItemId() == R.id.removeTrader) {
WorkerInterface.sendRemoveTraderCall("kucoin",pair,getContext()); System.err.println(pair + " Remove trader option clicked");
return true; return true;
} else if (item.getItemId() == R.id.restartTrader) { } else if (item.getItemId() == R.id.restartTrader) {
WorkerInterface.sendRestartTraderCall("kucoin",pair,getContext()); System.err.println(pair + " Restart option clicked");
return true; return true;
} else if (item.getItemId() == R.id.importTrader) { } else if (item.getItemId() == R.id.importTrader) {
WorkerInterface.sendImportTraderCall("kucoin",getContext()); WorkerInterface.sendImportTraderCall("kucoin",getContext());

View File

@ -70,10 +70,10 @@ public class OkxFragment extends Fragment implements WorkerCardAdapter.OnCardLon
WorkerInterface.sendAddTraderCall("okex",getContext()); WorkerInterface.sendAddTraderCall("okex",getContext());
return true; return true;
} else if (item.getItemId() == R.id.removeTrader) { } else if (item.getItemId() == R.id.removeTrader) {
WorkerInterface.sendRemoveTraderCall("okex",pair,getContext()); System.err.println(pair + " Remove trader option clicked");
return true; return true;
} else if (item.getItemId() == R.id.restartTrader) { } else if (item.getItemId() == R.id.restartTrader) {
WorkerInterface.sendRestartTraderCall("okex", pair, getContext()); System.err.println(pair + " Restart option clicked");
return true; return true;
} else if (item.getItemId() == R.id.importTrader) { } else if (item.getItemId() == R.id.importTrader) {
WorkerInterface.sendImportTraderCall("okex",getContext()); WorkerInterface.sendImportTraderCall("okex",getContext());

View File

@ -81,13 +81,8 @@ public class WorkerCardAdapter{
} }
price.setText(String.format(Locale.ROOT, "%.8f", worker.getPrice())); price.setText(String.format(Locale.ROOT, "%.8f", worker.getPrice()));
if (worker.isShort()
&& worker.getOldLongDictionary()!=null
&& worker.getPrice()>worker.getOldLongDictionary().getTpPrice()) {
price.setTextColor(Color.parseColor("#00FF00"));
}
//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() && if (worker.isShort() &&
worker.getOldLongDictionary()!=null && worker.getOldLongDictionary()!=null &&
@ -100,7 +95,7 @@ public class WorkerCardAdapter{
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;
String percentageToDisplay = String.format(Locale.ROOT, "%.2f", percentageToProfit)+"%"; String percentageToDisplay = String.format(Locale.ROOT, "%.2f",percentageToProfit)+"%";
percentage.setText(percentageToDisplay); percentage.setText(percentageToDisplay);
if (percentageToProfit<1) { if (percentageToProfit<1) {
//Green //Green
@ -150,14 +145,7 @@ public class WorkerCardAdapter{
cardLayout.setBackgroundColor(Color.parseColor("#C5C281")); cardLayout.setBackgroundColor(Color.parseColor("#C5C281"));
workerStatusString.setVisibility(View.INVISIBLE); workerStatusString.setVisibility(View.INVISIBLE);
} else if (worker.isAuto()) { } else if (worker.isAuto()) {
String stringToDisplay = "AUTO"; workerStatusString.setText(R.string.autoswitch_notice);
if (worker.getPrice()!=0) {
int multiplier = (int) (worker.getOldLongDictionary().getTpPrice() / worker.getPrice());
if (multiplier>1) {
stringToDisplay = stringToDisplay + " x" + multiplier;
}
}
workerStatusString.setText(stringToDisplay);
workerStatusString.setVisibility(View.VISIBLE); workerStatusString.setVisibility(View.VISIBLE);
} else { } else {
workerStatusString.setText(""); workerStatusString.setText("");

View File

@ -1021,11 +1021,7 @@ public class HomeFragment extends Fragment {
if (binanceData.getFundsNeeded() != 0) { if (binanceData.getFundsNeeded() != 0) {
binanceFundsPercentage = 100 - (binanceData.getFundsNeeded() - binanceData.getFundsAvailable()) / binanceData.getFundsNeeded() * 100; binanceFundsPercentage = 100 - (binanceData.getFundsNeeded() - binanceData.getFundsAvailable()) / binanceData.getFundsNeeded() * 100;
} }
String percentageFormat = "%.2f"; String binanceFundsPercentageString = String.format(Locale.ROOT, "%.2f", binanceFundsPercentage) + "%";
if (binanceFundsPercentage>=100) {
percentageFormat = "%.1f";
}
String binanceFundsPercentageString = String.format(Locale.ROOT, percentageFormat, binanceFundsPercentage) + "%";
exchange1Funds.setText(binanceFunds); exchange1Funds.setText(binanceFunds);
exchange1FundsPercentage.setText(binanceFundsPercentageString); exchange1FundsPercentage.setText(binanceFundsPercentageString);
} }
@ -1038,11 +1034,7 @@ public class HomeFragment extends Fragment {
if (gateioData.getFundsNeeded() != 0) { if (gateioData.getFundsNeeded() != 0) {
gateioFundsPercentage = 100 - (gateioData.getFundsNeeded() - gateioData.getFundsAvailable()) / gateioData.getFundsNeeded() * 100; gateioFundsPercentage = 100 - (gateioData.getFundsNeeded() - gateioData.getFundsAvailable()) / gateioData.getFundsNeeded() * 100;
} }
String percentageFormat = "%.2f"; String gateioFundsPercentageString = String.format(Locale.ROOT, "%.2f", gateioFundsPercentage) + "%";
if (gateioFundsPercentage>=100) {
percentageFormat = "%.1f";
}
String gateioFundsPercentageString = String.format(Locale.ROOT, percentageFormat, gateioFundsPercentage) + "%";
exchange2Funds.setText(gateioFunds); exchange2Funds.setText(gateioFunds);
exchange2FundsPercentage.setText(gateioFundsPercentageString); exchange2FundsPercentage.setText(gateioFundsPercentageString);
} }
@ -1055,11 +1047,7 @@ public class HomeFragment extends Fragment {
if (kucoinData.getFundsNeeded() != 0) { if (kucoinData.getFundsNeeded() != 0) {
kucoinFundsPercentage = 100 - (kucoinData.getFundsNeeded() - kucoinData.getFundsAvailable()) / kucoinData.getFundsNeeded() * 100; kucoinFundsPercentage = 100 - (kucoinData.getFundsNeeded() - kucoinData.getFundsAvailable()) / kucoinData.getFundsNeeded() * 100;
} }
String percentageFormat = "%.2f"; String kucoinFundsPercentageString = String.format(Locale.ROOT, "%.2f", kucoinFundsPercentage) + "%";
if (kucoinFundsPercentage>=100) {
percentageFormat = "%.1f";
}
String kucoinFundsPercentageString = String.format(Locale.ROOT, percentageFormat, kucoinFundsPercentage) + "%";
exchange3Funds.setText(kucoinFunds); exchange3Funds.setText(kucoinFunds);
exchange3FundsPercentage.setText(kucoinFundsPercentageString); exchange3FundsPercentage.setText(kucoinFundsPercentageString);
} }
@ -1072,11 +1060,7 @@ public class HomeFragment extends Fragment {
if (okexData.getFundsNeeded() != 0) { if (okexData.getFundsNeeded() != 0) {
okexFundsPercentage = 100 - (okexData.getFundsNeeded() - okexData.getFundsAvailable()) / okexData.getFundsNeeded() * 100; okexFundsPercentage = 100 - (okexData.getFundsNeeded() - okexData.getFundsAvailable()) / okexData.getFundsNeeded() * 100;
} }
String percentageFormat = "%.2f"; String okexFundsPercentageString = String.format(Locale.ROOT, "%.2f", okexFundsPercentage) + "%";
if (okexFundsPercentage>=100) {
percentageFormat = "%.1f";
}
String okexFundsPercentageString = String.format(Locale.ROOT, percentageFormat, okexFundsPercentage) + "%";
exchange4Funds.setText(okexFunds); exchange4Funds.setText(okexFunds);
exchange4FundsPercentage.setText(okexFundsPercentageString); exchange4FundsPercentage.setText(okexFundsPercentageString);
} }

View File

@ -5,8 +5,6 @@ public class SettingsData {
public String profileName; public String profileName;
public String apiUrl; public String apiUrl;
public String apiKey; public String apiKey;
public boolean useEarn;
public String earnApiKey;
public boolean useTelegram; public boolean useTelegram;
public String botToken; public String botToken;
public String chatId; public String chatId;
@ -18,8 +16,6 @@ public class SettingsData {
String profileName, String profileName,
String apiUrl, String apiUrl,
String apiKey, String apiKey,
boolean useEarn,
String earnApiKey,
boolean useTelegram, boolean useTelegram,
String botToken, String botToken,
String chatId, String chatId,
@ -30,8 +26,6 @@ public class SettingsData {
this.profileName = profileName; this.profileName = profileName;
this.apiUrl = apiUrl; this.apiUrl = apiUrl;
this.apiKey = apiKey; this.apiKey = apiKey;
this.useEarn = useEarn;
this.earnApiKey = earnApiKey;
this.useTelegram = useTelegram; this.useTelegram = useTelegram;
this.botToken = botToken; this.botToken = botToken;
this.chatId = chatId; this.chatId = chatId;

View File

@ -30,8 +30,6 @@ public class SettingsFragment extends Fragment {
EditText editProfileName = root.findViewById(R.id.editProfileName); EditText editProfileName = root.findViewById(R.id.editProfileName);
EditText editApiUrl = root.findViewById(R.id.editApiUrl); EditText editApiUrl = root.findViewById(R.id.editApiUrl);
EditText editApiKey = root.findViewById(R.id.editApiKey); EditText editApiKey = root.findViewById(R.id.editApiKey);
CheckBox checkUseEarn = root.findViewById(R.id.useEarn);
EditText editEarnApiKey = root.findViewById(R.id.earnApiKey);
CheckBox checkBox = root.findViewById(R.id.useTelegram); CheckBox checkBox = root.findViewById(R.id.useTelegram);
EditText editBotToken = root.findViewById(R.id.editBotToken); EditText editBotToken = root.findViewById(R.id.editBotToken);
EditText editChatId = root.findViewById(R.id.editChatId); EditText editChatId = root.findViewById(R.id.editChatId);
@ -39,7 +37,6 @@ public class SettingsFragment extends Fragment {
EditText editAmountOfLogLines = root.findViewById(R.id.editAmountOfLogLines); EditText editAmountOfLogLines = root.findViewById(R.id.editAmountOfLogLines);
EditText editAmountOfLastTrades = root.findViewById(R.id.editAmountOfLastTrades); EditText editAmountOfLastTrades = root.findViewById(R.id.editAmountOfLastTrades);
Button buttonSaveSettings = root.findViewById(R.id.buttonSaveSettings); Button buttonSaveSettings = root.findViewById(R.id.buttonSaveSettings);
//Load settings if settings.json exists //Load settings if settings.json exists
@ -49,8 +46,6 @@ public class SettingsFragment extends Fragment {
editProfileName.setText(settingsData.profileName); editProfileName.setText(settingsData.profileName);
editApiUrl.setText(settingsData.apiUrl); editApiUrl.setText(settingsData.apiUrl);
editApiKey.setText(settingsData.apiKey); editApiKey.setText(settingsData.apiKey);
checkUseEarn.setChecked(settingsData.useEarn);
editEarnApiKey.setText(settingsData.earnApiKey);
checkBox.setChecked(settingsData.useTelegram); checkBox.setChecked(settingsData.useTelegram);
editBotToken.setText(settingsData.botToken); editBotToken.setText(settingsData.botToken);
editChatId.setText(settingsData.chatId); editChatId.setText(settingsData.chatId);
@ -77,8 +72,6 @@ public class SettingsFragment extends Fragment {
String profileName = editProfileName.getText().toString(); String profileName = editProfileName.getText().toString();
String apiUrl = editApiUrl.getText().toString(); String apiUrl = editApiUrl.getText().toString();
String apiKey = editApiKey.getText().toString(); String apiKey = editApiKey.getText().toString();
boolean useEarn = checkUseEarn.isChecked();
String earnApiKey = editEarnApiKey.getText().toString();
boolean useTelegram = checkBox.isChecked(); boolean useTelegram = checkBox.isChecked();
String botToken = editBotToken.getText().toString(); String botToken = editBotToken.getText().toString();
String chatId = editChatId.getText().toString(); String chatId = editChatId.getText().toString();
@ -126,8 +119,6 @@ public class SettingsFragment extends Fragment {
profileName, profileName,
apiUrl, apiUrl,
apiKey, apiKey,
useEarn,
earnApiKey,
useTelegram, useTelegram,
botToken, botToken,
chatId, chatId,

View File

@ -17,8 +17,6 @@ public class SettingsViewModel extends ViewModel {
public String profileName; public String profileName;
public String apiUrl; public String apiUrl;
public String apiKey; public String apiKey;
public boolean useEarn;
public String earnApiKey;
public boolean useTelegram; public boolean useTelegram;
public String botToken; public String botToken;
public String chatId; public String chatId;
@ -31,8 +29,6 @@ public class SettingsViewModel extends ViewModel {
String profileName, String profileName,
String apiUrl, String apiUrl,
String apiKey, String apiKey,
boolean useEarn,
String earnApiKey,
boolean useTelegram, boolean useTelegram,
String botToken, String botToken,
String chatId, String chatId,
@ -45,8 +41,6 @@ public class SettingsViewModel extends ViewModel {
this.profileName = profileName; this.profileName = profileName;
this.apiUrl = apiUrl; this.apiUrl = apiUrl;
this.apiKey = apiKey; this.apiKey = apiKey;
this.useEarn = useEarn;
this.earnApiKey = earnApiKey;
this.useTelegram = useTelegram; this.useTelegram = useTelegram;
this.botToken = botToken; this.botToken = botToken;
this.chatId = chatId; this.chatId = chatId;
@ -60,8 +54,6 @@ public class SettingsViewModel extends ViewModel {
profileName, profileName,
apiUrl, apiUrl,
apiKey, apiKey,
useEarn,
earnApiKey,
useTelegram, useTelegram,
botToken, botToken,
chatId, chatId,

View File

@ -69,20 +69,6 @@
android:inputType="text" android:inputType="text"
android:textSize="16sp"/> android:textSize="16sp"/>
<CheckBox
android:id="@+id/useEarn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Earn" />
<EditText
android:id="@+id/earnApiKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/earn_key_hint"
android:textStyle="italic"
android:inputType="text"
android:textSize="16sp"/>
<CheckBox <CheckBox
android:id="@+id/useTelegram" android:id="@+id/useTelegram"

View File

@ -1,9 +1,9 @@
<resources> <resources>
<string name="app_name" translatable="false">DCAv2GUI</string> <string name="app_name" translatable="false">DCAv2GUI</string>
<string name="nav_header_title" translatable="false">DCAv2</string>
<string name="nav_header_subtitle">Version 2025.01.08</string>
<string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string>
<string name="nav_header_title" translatable="false">DCAv2</string>
<string name="nav_header_subtitle">nicolassanchez@tutanota.com</string>
<string name="nav_header_desc">Navigation header</string> <string name="nav_header_desc">Navigation header</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
@ -15,8 +15,7 @@
<string name="profile_name_hint">Enter the profile name</string> <string name="profile_name_hint">Enter the profile name</string>
<string name="api_url_hint">Enter the API URL</string> <string name="api_url_hint">Enter the API URL</string>
<string name="api_key_hint">Enter the API key</string> <string name="api_key_hint">Enter the API Key</string>
<string name="earn_key_hint">Enter the Earn API key</string>
<string name="use_telegram">Use Telegram</string> <string name="use_telegram">Use Telegram</string>
<string name="bot_token_hint">Enter the bot token</string> <string name="bot_token_hint">Enter the bot token</string>
<string name="chat_id_hint">Enter the chat ID</string> <string name="chat_id_hint">Enter the chat ID</string>