Worker details mostly done
This commit is contained in:
parent
7631eb2416
commit
6201ddf096
|
|
@ -2,6 +2,12 @@ package com.example.dcav2gui;
|
||||||
|
|
||||||
import static com.example.dcav2gui.MainActivity.globalSettings;
|
import static com.example.dcav2gui.MainActivity.globalSettings;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
|
@ -50,8 +56,7 @@ public class WorkerInterface {
|
||||||
System.err.println("The parsed JSON response contains Error");
|
System.err.println("The parsed JSON response contains Error");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
JsonObject value = jsonObject.getAsJsonObject();
|
||||||
JsonObject value = jsonObject.get(pair).getAsJsonObject();
|
|
||||||
try {
|
try {
|
||||||
boolean isShort = value.has("is_short") && value.get("is_short").isJsonPrimitive() && value.get("is_short").getAsBoolean();
|
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 isBoosted = value.has("is_boosted") && value.get("is_boosted").isJsonPrimitive() && value.get("is_boosted").getAsBoolean();
|
||||||
|
|
@ -654,6 +659,67 @@ public class WorkerInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void fetchWorkerStats(String exchange, String pair, Context context) {
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
InstanceInterface.WorkerStatsData result = WorkerInterface.getWorkerDetails(exchange, pair, true);
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> WorkerInterface.showWorkerDetailsDialog(result, context));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(context, "Failed to fetch exchange config", Toast.LENGTH_SHORT).show());
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showWorkerDetailsDialog(InstanceInterface.WorkerStatsData result, Context context) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle(result.getPair() + " status");
|
||||||
|
String isPausedExtraString = "";
|
||||||
|
if (result.getIsPaused()) {
|
||||||
|
isPausedExtraString = "Pause reason: " + result.getPauseReason() + "\n";
|
||||||
|
}
|
||||||
|
String oldLongExtraString = "";
|
||||||
|
if (result.getIsShort() && result.getOldLongDictionary()!=null) {
|
||||||
|
double oldTarget = result.getOldLongDictionary().getTpAmount() * result.getOldLongDictionary().getTpPrice();
|
||||||
|
double baseLeft = result.getOldLongDictionary().getTpAmount() - result.getBaseBought();
|
||||||
|
double minSwitchPrice = (oldTarget - result.getQuoteSpent()) / baseLeft;
|
||||||
|
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" +
|
||||||
|
"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 order ID: " + result.getTpOrderId() + "\n" +
|
||||||
|
"Safety order ID: " + result.getSoOrderId() + "\n" +
|
||||||
|
"Short: " + result.getIsShort() + "\n" +
|
||||||
|
"Boosted: " + result.getIsBoosted() + "\n" +
|
||||||
|
"Paused: " + result.getIsPaused() + "\n" + isPausedExtraString +
|
||||||
|
"Autoswitch: " + result.getAutoSwitchEnabled() + "\n" +
|
||||||
|
"Last call: " + result.getStopWhenProfit() + "\n" +
|
||||||
|
"Order size: " + result.getOrderSize() + "\n" +
|
||||||
|
"Quote in deal: " + result.getQuoteSpent() + "\n" +
|
||||||
|
"Base in deal: " + result.getBaseBought() + "\n" +
|
||||||
|
"Safety orders sent: " + (result.getSoAmount()-1) + "\n" +
|
||||||
|
"Max safety orders: " + result.getNumberOfSafetyOrders() + "\n" +
|
||||||
|
"Start time: " + result.getStartTime() + "\n" +
|
||||||
|
"Start price: " + result.getStartPrice() + "\n" +
|
||||||
|
"Deal start time: " + result.getDealStartTime() + "\n" +
|
||||||
|
"Deal uptime: " + result.getDealUptime() + "\n" +
|
||||||
|
"Total uptime: " + result.getTotalUptime() + "\n" +
|
||||||
|
"Fees paid in base: " + result.getFeesPaidInBase() + "\n" +
|
||||||
|
"Fees paid in quote: " + result.getFeesPaidInQuote() + "\n" +
|
||||||
|
"Partial profit: " + result.getPartialProfit() + "\n" +
|
||||||
|
oldLongExtraString);
|
||||||
|
builder.setPositiveButton("OK", null);
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,18 @@
|
||||||
// BinanceFragment.java
|
// BinanceFragment.java
|
||||||
package com.example.dcav2gui.ui.exchanges;
|
package com.example.dcav2gui.ui.exchanges;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.PopupMenu;
|
import android.widget.PopupMenu;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
@ -16,9 +21,11 @@ import androidx.lifecycle.ViewModelProvider;
|
||||||
import com.example.dcav2gui.InstanceInterface;
|
import com.example.dcav2gui.InstanceInterface;
|
||||||
import com.example.dcav2gui.MainActivity;
|
import com.example.dcav2gui.MainActivity;
|
||||||
import com.example.dcav2gui.R;
|
import com.example.dcav2gui.R;
|
||||||
|
import com.example.dcav2gui.WorkerInterface;
|
||||||
import com.example.dcav2gui.databinding.FragmentBinanceBinding;
|
import com.example.dcav2gui.databinding.FragmentBinanceBinding;
|
||||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -66,7 +73,7 @@ public class BinanceFragment extends Fragment implements WorkerCardAdapter.OnCar
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.workerMenuDetails) {
|
if (item.getItemId() == R.id.workerMenuDetails) {
|
||||||
System.err.println(pair + " Details... option clicked");
|
WorkerInterface.fetchWorkerStats("binance",pair, getContext());
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.addTrader) {
|
} else if (item.getItemId() == R.id.addTrader) {
|
||||||
System.err.println(pair + " Add trader option clicked");
|
System.err.println(pair + " Add trader option clicked");
|
||||||
|
|
@ -117,4 +124,7 @@ public class BinanceFragment extends Fragment implements WorkerCardAdapter.OnCar
|
||||||
popupMenu.show();
|
popupMenu.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProvider;
|
||||||
import com.example.dcav2gui.InstanceInterface;
|
import com.example.dcav2gui.InstanceInterface;
|
||||||
import com.example.dcav2gui.MainActivity;
|
import com.example.dcav2gui.MainActivity;
|
||||||
import com.example.dcav2gui.R;
|
import com.example.dcav2gui.R;
|
||||||
|
import com.example.dcav2gui.WorkerInterface;
|
||||||
import com.example.dcav2gui.databinding.FragmentGateioBinding;
|
import com.example.dcav2gui.databinding.FragmentGateioBinding;
|
||||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ public class GateioFragment extends Fragment implements WorkerCardAdapter.OnCard
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.workerMenuDetails) {
|
if (item.getItemId() == R.id.workerMenuDetails) {
|
||||||
System.err.println(pair + " Details... option clicked");
|
WorkerInterface.fetchWorkerStats("gateio",pair, getContext());
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.addTrader) {
|
} else if (item.getItemId() == R.id.addTrader) {
|
||||||
System.err.println(pair + " Add trader option clicked");
|
System.err.println(pair + " Add trader option clicked");
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProvider;
|
||||||
import com.example.dcav2gui.InstanceInterface;
|
import com.example.dcav2gui.InstanceInterface;
|
||||||
import com.example.dcav2gui.MainActivity;
|
import com.example.dcav2gui.MainActivity;
|
||||||
import com.example.dcav2gui.R;
|
import com.example.dcav2gui.R;
|
||||||
|
import com.example.dcav2gui.WorkerInterface;
|
||||||
import com.example.dcav2gui.databinding.FragmentKucoinBinding;
|
import com.example.dcav2gui.databinding.FragmentKucoinBinding;
|
||||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ public class KucoinFragment extends Fragment implements WorkerCardAdapter.OnCard
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.workerMenuDetails) {
|
if (item.getItemId() == R.id.workerMenuDetails) {
|
||||||
System.err.println(pair + " Details... option clicked");
|
WorkerInterface.fetchWorkerStats("kucoin",pair, getContext());
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.addTrader) {
|
} else if (item.getItemId() == R.id.addTrader) {
|
||||||
System.err.println(pair + " Add trader option clicked");
|
System.err.println(pair + " Add trader option clicked");
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProvider;
|
||||||
import com.example.dcav2gui.InstanceInterface;
|
import com.example.dcav2gui.InstanceInterface;
|
||||||
import com.example.dcav2gui.MainActivity;
|
import com.example.dcav2gui.MainActivity;
|
||||||
import com.example.dcav2gui.R;
|
import com.example.dcav2gui.R;
|
||||||
|
import com.example.dcav2gui.WorkerInterface;
|
||||||
import com.example.dcav2gui.databinding.FragmentOkxBinding;
|
import com.example.dcav2gui.databinding.FragmentOkxBinding;
|
||||||
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
import com.example.dcav2gui.ui.exchanges.adapters.WorkerCardAdapter;
|
||||||
|
|
||||||
|
|
@ -65,7 +66,7 @@ public class OkxFragment extends Fragment implements WorkerCardAdapter.OnCardLon
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
if (item.getItemId() == R.id.workerMenuDetails) {
|
if (item.getItemId() == R.id.workerMenuDetails) {
|
||||||
System.err.println(pair + " Details... option clicked");
|
WorkerInterface.fetchWorkerStats("okex",pair, getContext());
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getItemId() == R.id.addTrader) {
|
} else if (item.getItemId() == R.id.addTrader) {
|
||||||
System.err.println(pair + " Add trader option clicked");
|
System.err.println(pair + " Add trader option clicked");
|
||||||
|
|
|
||||||
|
|
@ -444,7 +444,7 @@ public class HomeFragment extends Fragment {
|
||||||
new Handler(Looper.getMainLooper()).post(() -> showInstanceDetailsDialog(result));
|
new Handler(Looper.getMainLooper()).post(() -> showInstanceDetailsDialog(result));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show());
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch exchange details", Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
@ -460,7 +460,7 @@ public class HomeFragment extends Fragment {
|
||||||
new Handler(Looper.getMainLooper()).post(() -> showPausedTradersDialog(result));
|
new Handler(Looper.getMainLooper()).post(() -> showPausedTradersDialog(result));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show());
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch paused traders", Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
@ -485,7 +485,7 @@ public class HomeFragment extends Fragment {
|
||||||
new Handler(Looper.getMainLooper()).post(() -> showServerTimeDialog(result));
|
new Handler(Looper.getMainLooper()).post(() -> showServerTimeDialog(result));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch missing pairs", Toast.LENGTH_SHORT).show());
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch server time", Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
@ -497,7 +497,7 @@ public class HomeFragment extends Fragment {
|
||||||
new Handler(Looper.getMainLooper()).post(() -> showTraderTimeDialog(result));
|
new Handler(Looper.getMainLooper()).post(() -> showTraderTimeDialog(result));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch missing pairs", Toast.LENGTH_SHORT).show());
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch trader time", Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
@ -512,7 +512,7 @@ public class HomeFragment extends Fragment {
|
||||||
new Handler(Looper.getMainLooper()).post(() -> showInstanceConfigDialog(result));
|
new Handler(Looper.getMainLooper()).post(() -> showInstanceConfigDialog(result));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show());
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch exchange config", Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
@ -525,7 +525,7 @@ public class HomeFragment extends Fragment {
|
||||||
new Handler(Looper.getMainLooper()).post(() -> showLastTradesDetailsDialog(result));
|
new Handler(Looper.getMainLooper()).post(() -> showLastTradesDetailsDialog(result));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch details", Toast.LENGTH_SHORT).show());
|
new Handler(Looper.getMainLooper()).post(() -> Toast.makeText(getContext(), "Failed to fetch last deals", Toast.LENGTH_SHORT).show());
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue