cleanup
This commit is contained in:
parent
b15fdcd951
commit
1803b09126
|
|
@ -4,7 +4,7 @@
|
|||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2024-12-19T11:30:32.480908965Z">
|
||||
<DropdownSelection timestamp="2024-12-19T12:29:08.104137914Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="LocalEmulator" identifier="path=/home/nicolas/.android/avd/Pixel_6_Pro_API_34.avd" />
|
||||
|
|
|
|||
|
|
@ -441,7 +441,6 @@ public class InstanceInterface {
|
|||
OldLongDictionary oldLongDictionary = null;
|
||||
if (value.has("old_long")) {
|
||||
oldLong = value.get("old_long").getAsJsonObject();
|
||||
//translate from json to OldLongDictionary
|
||||
oldLongDictionary = new OldLongDictionary(
|
||||
oldLong.get("datetime").getAsString(),
|
||||
oldLong.get("fees_paid_in_quote").getAsDouble(),
|
||||
|
|
|
|||
|
|
@ -2,19 +2,13 @@ package com.example.dcav2gui;
|
|||
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;//
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.dcav2gui.ui.exchanges.BinanceFragment;
|
||||
import com.example.dcav2gui.ui.exchanges.OkxFragment;
|
||||
import com.example.dcav2gui.ui.home.HomeFragment;
|
||||
import com.example.dcav2gui.ui.settings.SettingsData;
|
||||
import com.example.dcav2gui.ui.settings.SettingsViewModel;
|
||||
|
|
@ -28,9 +22,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
|||
import com.example.dcav2gui.databinding.ActivityMainBinding;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ package com.example.dcav2gui;
|
|||
import static com.example.dcav2gui.MainActivity.globalSettings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
|
@ -10,6 +13,8 @@ import com.google.gson.JsonParser;
|
|||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class WorkerInterface {
|
||||
private static final String API_BASE_URL = globalSettings.apiUrl;
|
||||
|
|
@ -17,9 +22,121 @@ public class WorkerInterface {
|
|||
private static final OkHttpClient httpClient = new OkHttpClient();
|
||||
|
||||
|
||||
public static WorkerDetails getWorkerDetails(String pair) throws IOException {
|
||||
public static InstanceInterface.WorkerStatsData getWorkerDetails(String exchange, String pair, boolean retry) throws IOException {
|
||||
InstanceInterface.WorkerStatsData valueToReturn = null;
|
||||
|
||||
String[] pairBaseAndQuote = pair.split("/");
|
||||
String base = pairBaseAndQuote[0];
|
||||
String quote = pairBaseAndQuote[1];
|
||||
|
||||
Request workerStatsRequest = new Request.Builder()
|
||||
.url(API_BASE_URL + "/" + exchange + "/worker_status?base="+base+""e="+quote)
|
||||
.header("X-API-KEY", API_KEY)
|
||||
.build();
|
||||
|
||||
try (Response workerStatsResponse = httpClient.newCall(workerStatsRequest).execute()) {
|
||||
if (!workerStatsResponse.isSuccessful()) {
|
||||
if (workerStatsResponse.code() == 503 && retry) {
|
||||
return getWorkerDetails(exchange, pair,false);
|
||||
}
|
||||
throw new IOException("Unexpected code " + workerStatsResponse);
|
||||
}
|
||||
String workersStatsResponseBody = workerStatsResponse.body().string();
|
||||
JsonElement jsonElement = JsonParser.parseString(workersStatsResponseBody);
|
||||
if (!jsonElement.isJsonObject()) {
|
||||
System.err.println("The parsed JSON response is not a JsonObject.");
|
||||
return null;
|
||||
}
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
if (jsonObject.has("Error")) {
|
||||
System.err.println("The parsed JSON response contains Error");
|
||||
return null;
|
||||
}
|
||||
|
||||
JsonObject value = jsonObject.get(pair).getAsJsonObject();
|
||||
try {
|
||||
boolean isShort = value.has("is_short") && value.get("is_short").isJsonPrimitive() && value.get("is_short").getAsBoolean();
|
||||
boolean isBoosted = value.has("is_boosted") && value.get("is_boosted").isJsonPrimitive() && value.get("is_boosted").getAsBoolean();
|
||||
boolean isAutoSwitchEnabled = value.has("is_auto_switch_enabled") && value.get("is_auto_switch_enabled").isJsonPrimitive() && value.get("is_auto_switch_enabled").getAsBoolean();
|
||||
boolean stopWhenProfit = value.has("stop_when_profit") && value.get("stop_when_profit").isJsonPrimitive() && value.get("stop_when_profit").getAsBoolean();
|
||||
double orderSize = value.has("order_size") && value.get("order_size").isJsonPrimitive() ? value.get("order_size").getAsDouble() : 0.0;
|
||||
double quoteSpent = value.has("quote_spent") && value.get("quote_spent").isJsonPrimitive() ? value.get("quote_spent").getAsDouble() : 0.0;
|
||||
double baseBought = value.has("base_bought") && value.get("base_bought").isJsonPrimitive() ? value.get("base_bought").getAsDouble() : 0.0;
|
||||
int soAmount = value.has("so_amount") && value.get("so_amount").isJsonPrimitive() ? value.get("so_amount").getAsInt() : 0;
|
||||
int numberOfSafetyOrders = value.has("no_of_safety_orders") && value.get("no_of_safety_orders").isJsonPrimitive() ? value.get("no_of_safety_orders").getAsInt() : 0;
|
||||
int tpMode = value.has("tp_mode") && value.get("tp_mode").isJsonPrimitive() ? value.get("tp_mode").getAsInt() : 0;
|
||||
String profitTable = value.has("profit_table") && value.get("profit_table").isJsonPrimitive() ? value.get("profit_table").getAsString() : null;
|
||||
double startTime = value.has("start_time") && value.get("start_time").isJsonPrimitive() ? value.get("start_time").getAsDouble() : 0.0;
|
||||
double startPrice = value.has("start_price") && value.get("start_price").isJsonPrimitive() ? value.get("start_price").getAsDouble() : 0.0;
|
||||
double dealStartTime = value.has("deal_start_time") && value.get("deal_start_time").isJsonPrimitive() ? value.get("deal_start_time").getAsDouble() : 0.0;
|
||||
double dealUptime = value.has("deal_uptime") && value.get("deal_uptime").isJsonPrimitive() ? value.get("deal_uptime").getAsDouble() : 0.0;
|
||||
double totalUptime = value.has("total_uptime") && value.get("total_uptime").isJsonPrimitive() ? value.get("total_uptime").getAsDouble() : 0.0;
|
||||
double price = value.has("price") && value.get("price").isJsonPrimitive() ? value.get("price").getAsDouble() : 0.0;
|
||||
double takeProfitPrice = value.has("take_profit_price") && value.get("take_profit_price").isJsonPrimitive() ? value.get("take_profit_price").getAsDouble() : 0.0;
|
||||
double nextSoPrice = value.has("next_so_price") && value.get("next_so_price").isJsonPrimitive() ? value.get("next_so_price").getAsDouble() : 0.0;
|
||||
String tpOrderId = value.has("tp_order_id") && value.get("tp_order_id").isJsonPrimitive() ? value.get("tp_order_id").getAsString() : null;
|
||||
JsonObject takeProfitOrder = value.get("take_profit_order").getAsJsonObject();
|
||||
String safetyOrderId = value.has("safety_order_id") && value.get("safety_order_id").isJsonPrimitive() ? value.get("safety_order_id").getAsString() : null;
|
||||
JsonObject safetyOrder = value.get("safety_order").getAsJsonObject();
|
||||
double feesPaidInBase = value.has("fees_paid_in_base") && value.get("fees_paid_in_base").isJsonPrimitive() ? value.get("fees_paid_in_base").getAsDouble() : 0.0;
|
||||
double feesPaidInQuote = value.has("fees_paid_in_quote") && value.get("fees_paid_in_quote").isJsonPrimitive() ? value.get("fees_paid_in_quote").getAsDouble() : 0.0;
|
||||
double partialProfit = value.has("partial_profit") && value.get("partial_profit").isJsonPrimitive() ? value.get("partial_profit").getAsDouble() : 0.0;
|
||||
String safetyPriceTable = value.has("safety_price_table") && value.get("safety_price_table").isJsonPrimitive() ? value.get("safety_price_table").getAsString() : null;
|
||||
String dealOrderHistory = value.has("deal_order_history") && value.get("deal_order_history").isJsonPrimitive() ? value.get("deal_order_history").getAsString() : null;
|
||||
String pauseReason = value.has("pause_reason") && value.get("pause_reason").isJsonPrimitive() ? value.get("pause_reason").getAsString() : null;
|
||||
String statusString = value.has("status_string") && value.get("status_string").isJsonPrimitive() ? value.get("status_string").getAsString() : null;
|
||||
JsonObject oldLong;
|
||||
InstanceInterface.OldLongDictionary oldLongDictionary = null;
|
||||
if (value.has("old_long")) {
|
||||
oldLong = value.get("old_long").getAsJsonObject();
|
||||
oldLongDictionary = new InstanceInterface.OldLongDictionary(
|
||||
oldLong.get("datetime").getAsString(),
|
||||
oldLong.get("fees_paid_in_quote").getAsDouble(),
|
||||
oldLong.get("quote_spent").getAsDouble(),
|
||||
oldLong.get("tp_amount").getAsDouble(),
|
||||
oldLong.get("tp_price").getAsDouble()
|
||||
);
|
||||
}
|
||||
|
||||
valueToReturn = new InstanceInterface.WorkerStatsData(
|
||||
pair,
|
||||
isShort,
|
||||
isBoosted,
|
||||
isAutoSwitchEnabled,
|
||||
stopWhenProfit,
|
||||
orderSize,
|
||||
quoteSpent,
|
||||
baseBought,
|
||||
soAmount,
|
||||
numberOfSafetyOrders,
|
||||
tpMode,
|
||||
profitTable,
|
||||
startTime,
|
||||
startPrice,
|
||||
dealStartTime,
|
||||
dealUptime,
|
||||
totalUptime,
|
||||
price,
|
||||
takeProfitPrice,
|
||||
nextSoPrice,
|
||||
tpOrderId,
|
||||
takeProfitOrder,
|
||||
safetyOrderId,
|
||||
safetyOrder,
|
||||
feesPaidInBase,
|
||||
feesPaidInQuote,
|
||||
partialProfit,
|
||||
safetyPriceTable,
|
||||
dealOrderHistory,
|
||||
pauseReason,
|
||||
oldLongDictionary,
|
||||
statusString);
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error processing JSON for key '" + pair + "': " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return valueToReturn;
|
||||
}
|
||||
|
||||
public static JsonObject addTrader(String exchange, String pair) throws IOException {
|
||||
return null;
|
||||
|
|
@ -73,11 +190,6 @@ public class WorkerInterface {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static class WorkerDetails {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,16 @@
|
|||
// BinanceFragment.java
|
||||
package com.example.dcav2gui.ui.exchanges;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.PopupMenu;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.example.dcav2gui.InstanceInterface;
|
||||
|
|
@ -22,11 +18,8 @@ import com.example.dcav2gui.MainActivity;
|
|||
import com.example.dcav2gui.R;
|
||||
import com.example.dcav2gui.databinding.FragmentBinanceBinding;
|
||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||
import com.example.dcav2gui.ui.exchanges.WorkerData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
public class BinanceFragment extends Fragment implements WorkerCardAdapter.OnCardLongClickListener {
|
||||
|
|
|
|||
|
|
@ -5,13 +5,10 @@ import static java.lang.Math.abs;
|
|||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -151,70 +148,6 @@ public class WorkerCardAdapter{
|
|||
});
|
||||
}
|
||||
|
||||
// Add long click listener to show the popup menu
|
||||
// cardLayout.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
// @Override
|
||||
// public boolean onLongClick(View v) {
|
||||
// PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
|
||||
// MenuInflater inflater = new MenuInflater(v.getContext());
|
||||
// inflater.inflate(R.menu.worker_popup_menu,popupMenu.getMenu());
|
||||
// popupMenu.setOnMenuItemClickListener(new android.widget.PopupMenu.OnMenuItemClickListener() {
|
||||
// @Override
|
||||
// public boolean onMenuItemClick(MenuItem item) {
|
||||
// if (item.getItemId() == R.id.workerMenuDetails) {
|
||||
// System.err.println("Details... option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.addTrader) {
|
||||
// System.err.println("Add trader option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.removeTrader) {
|
||||
// System.err.println("Remove trader option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.restartTrader) {
|
||||
// System.err.println("Restart option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.importTrader) {
|
||||
// System.err.println("Import option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.togglePause) {
|
||||
// System.err.println("Toggle pause option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.toggleAutoswitch) {
|
||||
// System.err.println("Toggle autoswitch option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.toggleCleanup) {
|
||||
// System.err.println("Toggle cleanup option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.toggleLastCall) {
|
||||
// System.err.println("Toggle last call option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.switchToLong) {
|
||||
// System.err.println("Switch to long option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.switchToShort) {
|
||||
// System.err.println("Switch to short option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.switchQuoteCurrency) {
|
||||
// System.err.println("Switch quote currency option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.addSafetyOrders) {
|
||||
// System.err.println("Add safety orders option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.addQuote) {
|
||||
// System.err.println("Add quote option clicked");
|
||||
// return true;
|
||||
// } else if (item.getItemId() == R.id.workerMenuLastCall) {
|
||||
// System.err.println("Worker menu last call option clicked");
|
||||
// return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
// popupMenu.show();
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
public static String formatSeconds(double seconds) {
|
||||
long days = TimeUnit.SECONDS.toDays((long) seconds);
|
||||
|
|
@ -233,16 +166,7 @@ public class WorkerCardAdapter{
|
|||
int shortWorkers = exchangeData.getShortWorkers();
|
||||
int safetyOrdersSent = exchangeData.getSafetyOrdersSent();
|
||||
int maxSafetyOrders = exchangeData.getMaxSafetyOrders();
|
||||
// int safetyOrdersSent = 0;
|
||||
// int maxSafetyOrders = 0;
|
||||
|
||||
//Iterate workerDataList and extract the total amount of safety orders
|
||||
// for (WorkerData worker : InstanceInterface.translateToWorkerData(exchangeData.getWorkers())) {
|
||||
// if (!worker.isShort()) {
|
||||
// safetyOrdersSent+=worker.getAmountOfSafetyOrders()-1;
|
||||
// maxSafetyOrders+=worker.getMaxSafetyOrders();
|
||||
// }
|
||||
// }
|
||||
String percentage = String.format(Locale.ROOT, "%.2f", (double) safetyOrdersSent/maxSafetyOrders*100);
|
||||
String statusBarText = amountOfWorkers + " traders online (" + longWorkers + "/" + shortWorkers + ") - Occupancy " + percentage + "%";
|
||||
statusBar.setText(statusBarText);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,6 @@ import java.io.IOException;
|
|||
|
||||
public class HomeFragment extends Fragment {
|
||||
private HomeViewModel homeViewModel;
|
||||
private FragmentHomeBinding binding;
|
||||
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
private Handler handler = new Handler();
|
||||
|
|
@ -56,7 +55,6 @@ public class HomeFragment extends Fragment {
|
|||
private TextView progressBarText;
|
||||
private ScrollView mainHomeScrollView;
|
||||
|
||||
|
||||
//Tickers
|
||||
private TextView pricePair1;
|
||||
private TextView pricePair124hPercentage ;
|
||||
|
|
@ -79,11 +77,6 @@ public class HomeFragment extends Fragment {
|
|||
private ImageView exchange3Status;
|
||||
private ImageView exchange4Status;
|
||||
|
||||
// private TextView exchange1Name;
|
||||
// private TextView exchange2Name;
|
||||
// private TextView exchange3Name;
|
||||
// private TextView exchange4Name;
|
||||
|
||||
private TextView exchange1Funds;
|
||||
private TextView exchange2Funds;
|
||||
private TextView exchange3Funds;
|
||||
|
|
@ -114,10 +107,6 @@ public class HomeFragment extends Fragment {
|
|||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
// binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||
// View root = binding.getRoot();
|
||||
|
||||
|
||||
// For the cache
|
||||
MainActivity mainActivity = (MainActivity) requireActivity();
|
||||
HomeFragment.HomeCache homeViewCache = mainActivity.getHomeViewCache();
|
||||
|
|
@ -166,11 +155,6 @@ public class HomeFragment extends Fragment {
|
|||
exchange3Status = root.findViewById(R.id.exchangeStats3Icon);
|
||||
exchange4Status = root.findViewById(R.id.exchangeStats4Icon);
|
||||
|
||||
// exchange1Name = root.findViewById(R.id.exchangeStats1Label);
|
||||
// exchange2Name = root.findViewById(R.id.exchangeStats2Label);
|
||||
// exchange3Name = root.findViewById(R.id.exchangeStats3Label);
|
||||
// exchange4Name = root.findViewById(R.id.exchangeStats4Label);
|
||||
|
||||
exchange1Funds = root.findViewById(R.id.exchangeStats1Funds);
|
||||
exchange2Funds = root.findViewById(R.id.exchangeStats2Funds);
|
||||
exchange3Funds = root.findViewById(R.id.exchangeStats3Funds);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ public class SettingsFragment extends Fragment {
|
|||
Button buttonSaveSettings = root.findViewById(R.id.buttonSaveSettings);
|
||||
|
||||
//Load settings if settings.json exists
|
||||
//SettingsData settingsData = settingsViewModel.loadSettings(getContext());
|
||||
SettingsData settingsData = MainActivity.getGlobalSettings();
|
||||
|
||||
if (settingsData != null) {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,6 @@ import android.content.Context;
|
|||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
|
|
|
|||
Loading…
Reference in New Issue