Binance price tracker class

This commit is contained in:
Nicolás Sánchez 2024-12-12 08:13:29 -03:00
parent e05a47cce0
commit 948430aaad
3 changed files with 13 additions and 10 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application <application
android:allowBackup="true" android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"

View File

@ -1,7 +1,5 @@
package com.example.dcav2gui; package com.example.dcav2gui;
import android.annotation.SuppressLint;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
@ -13,7 +11,7 @@ import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
public class BinancePriceTracker { public class TickerTracker {
private static final String BINANCE_API_BASE_URL = "https://api.binance.com/api/v3/ticker/24hr"; private static final String BINANCE_API_BASE_URL = "https://api.binance.com/api/v3/ticker/24hr";
private static final OkHttpClient httpClient = new OkHttpClient(); private static final OkHttpClient httpClient = new OkHttpClient();
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
@ -115,17 +113,17 @@ public class BinancePriceTracker {
this.priceChangePercent30d = priceChangePercent30d; this.priceChangePercent30d = priceChangePercent30d;
} }
// Getters // Getters (Just in case)
public String getSymbol() { return symbol; } public String getSymbol() { return symbol; }
public double getCurrentPrice() { return currentPrice; } public double getCurrentPrice() { return currentPrice; }
public double getPriceChangePercent24h() { return priceChangePercent24h; } public double getPriceChangePercent24h() { return priceChangePercent24h; }
public double getPriceChangePercent7d() { return priceChangePercent7d; } public double getPriceChangePercent7d() { return priceChangePercent7d; }
public double getPriceChangePercent30d() { return priceChangePercent30d; } public double getPriceChangePercent30d() { return priceChangePercent30d; }
@Override // @Override
public String toString() { // public String toString() {
return String.format("Symbol: %s\nPrice: %.2f%%\n24h Change: %.2f%%\n7d Change: %.2f%%\n30d Change: %.2f%%", // return String.format("Symbol: %s\nPrice: %.2f%%\n24h Change: %.2f%%\n7d Change: %.2f%%\n30d Change: %.2f%%",
symbol, currentPrice, priceChangePercent24h, priceChangePercent7d, priceChangePercent30d); // symbol, currentPrice, priceChangePercent24h, priceChangePercent7d, priceChangePercent30d);
} // }
} }
} }

View File

@ -7,6 +7,11 @@
<color name="teal_700">#FF018786</color> <color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color> <color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color> <color name="white">#FFFFFFFF</color>
<color name="green">#FF008000</color>
<color name="red">#FFFF0000</color>
<color name="blue">#FF0000FF</color>
<color name="yellow">#FFFFFF00</color>
<color name="grey">#FF424242</color>
<color name="secondary_text_color">#FF424242</color> <color name="secondary_text_color">#FF424242</color>
<color name="card_background_color">#FFF6F6F6</color> <color name="card_background_color">#FFF6F6F6</color>