Spaces:
No application file
No application file
Abhishek
commited on
Commit
·
757031e
1
Parent(s):
77d52bd
for deploying in the hugging face
Browse files- README.md +110 -11
- binance_dashboard.py +171 -0
- requirements.txt +5 -0
README.md
CHANGED
|
@@ -1,14 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 📊 Binance Crypto Market Dashboard
|
| 2 |
+
|
| 3 |
+
This project is a real-time cryptocurrency market tracker built using **Streamlit**, powered by **Binance's public API**. It displays the **top 10 traded coins** based on 24-hour volume and includes smart insights like **investment suggestions**, **market movement predictions**, and **trend charts** that update every 10 seconds.
|
| 4 |
+
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
## 🚀 Live Demo
|
| 8 |
+
|
| 9 |
+
⚠️ **IMPORTANT**: Due to **Binance's legal restrictions and regional API blocks**, this app may **not work correctly on Streamlit Cloud** (you may see a `451` error).
|
| 10 |
+
✅ It works perfectly when run **locally** on your own machine. See instructions below.
|
| 11 |
+
|
| 12 |
---
|
| 13 |
+
|
| 14 |
+
## 🧠 Features
|
| 15 |
+
|
| 16 |
+
- ✅ **Top 10 Coins by 24h Volume**
|
| 17 |
+
- 🔄 **Auto-refresh every 10 seconds**
|
| 18 |
+
- 🔺 **Price Change with Emoji Indicators**
|
| 19 |
+
- 💡 **Market Suggestions** (Trending Up / Avoid / Neutral)
|
| 20 |
+
- 🔮 **Prediction Labels** (Likely ↑ / ↓ / Uncertain)
|
| 21 |
+
- 📈 **Trendline Charts** (Last 5 minutes of activity)
|
| 22 |
+
- 💵 **Currency Conversion Support**
|
| 23 |
+
- Supports USD, INR, EUR, GBP, JPY
|
| 24 |
+
- Uses live exchange rates via `exchangerate.host`
|
| 25 |
+
- Falls back to manual rates if the API fails
|
| 26 |
+
- 🧭 **Sidebar Controls**:
|
| 27 |
+
- Toggle Market Tips
|
| 28 |
+
- Toggle Drop Alerts
|
| 29 |
+
- Select preferred currency
|
| 30 |
+
- 🧠 Optimized with `@st.cache_data` for smooth refresh
|
| 31 |
+
- 🌐 Fully interactive via Streamlit UI
|
| 32 |
+
|
| 33 |
---
|
| 34 |
|
| 35 |
+
## 📦 Tech Stack
|
| 36 |
+
|
| 37 |
+
| Tool | Purpose |
|
| 38 |
+
|--------------------|------------------------------------|
|
| 39 |
+
| `Streamlit` | Web UI + real-time interactivity |
|
| 40 |
+
| `Binance API` | Live crypto market data |
|
| 41 |
+
| `exchangerate.host`| Live USD-to-currency conversion |
|
| 42 |
+
| `Pandas` | Data processing and transformation |
|
| 43 |
+
| `Matplotlib` | Price trend visualization |
|
| 44 |
+
| `Requests` | REST API access |
|
| 45 |
+
|
| 46 |
+
---
|
| 47 |
+
|
| 48 |
+
## ⚙️ How to Run Locally
|
| 49 |
+
|
| 50 |
+
If the online version fails (due to Binance API block), run the app locally:
|
| 51 |
+
|
| 52 |
+
1. **Clone the repository**
|
| 53 |
+
```bash
|
| 54 |
+
git clone https://github.com/abhishekmohank/binance_dashboard.git
|
| 55 |
+
cd binance_dashboard
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
2. **Install the required packages**
|
| 59 |
+
```bash
|
| 60 |
+
pip install -r requirements.txt
|
| 61 |
+
```
|
| 62 |
+
|
| 63 |
+
3. **Start the app**
|
| 64 |
+
```bash
|
| 65 |
+
streamlit run app.py
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## 🛑 Known Issues
|
| 71 |
+
|
| 72 |
+
> Binance may **block Streamlit Cloud or other hosts** in certain regions, resulting in:
|
| 73 |
+
> ```
|
| 74 |
+
> 451 Client Error: Unavailable For Legal Reasons
|
| 75 |
+
> ```
|
| 76 |
+
> ✅ This app works fine on:
|
| 77 |
+
> - Your **local machine**
|
| 78 |
+
> - Platforms like **Render**, **Replit**, or **a personal VPS**
|
| 79 |
+
|
| 80 |
+
---
|
| 81 |
+
|
| 82 |
+
## ✅ Updates & Enhancements
|
| 83 |
+
|
| 84 |
+
- ✅ Market tip system showing top trending coins
|
| 85 |
+
- ✅ Drop alert system warning against falling assets
|
| 86 |
+
- ✅ Live currency conversion with USD, INR, EUR, GBP, JPY
|
| 87 |
+
- ✅ Fallback to manual conversion if API fails
|
| 88 |
+
- ✅ Smart emoji-based prediction and suggestions
|
| 89 |
+
- ✅ Live trend charting using Matplotlib
|
| 90 |
+
- ✅ Sidebar toggles and currency selector
|
| 91 |
+
|
| 92 |
+
---
|
| 93 |
+
|
| 94 |
+
## 🧪 Future Enhancements (Optional Ideas)
|
| 95 |
+
|
| 96 |
+
- 📤 Export table to CSV or JSON
|
| 97 |
+
- 📱 Make layout responsive on mobile
|
| 98 |
+
- 🔔 Add custom alerts (e.g., if price > X)
|
| 99 |
+
- 🧠 Basic ML for short-term trend prediction
|
| 100 |
+
|
| 101 |
+
---
|
| 102 |
+
|
| 103 |
+
## 🙋♂️ About the Author
|
| 104 |
+
|
| 105 |
+
Made with ❤️ by **Abhishek Mohan**
|
| 106 |
+
🔗 [GitHub](https://github.com/abhishekmohank)
|
| 107 |
+
🌐 [Portfolio](https://abhishek-amk.vercel.app)
|
| 108 |
+
|
| 109 |
+
---
|
| 110 |
+
|
| 111 |
+
## 📜 License
|
| 112 |
+
|
| 113 |
+
MIT License — free to use, modify, and share.
|
binance_dashboard.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_autorefresh import st_autorefresh
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import requests
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
|
| 7 |
+
# Page setup
|
| 8 |
+
st.set_page_config(page_title="Binance Crypto Tracker", layout="wide")
|
| 9 |
+
st.title("📊 Binance Crypto Market Dashboard")
|
| 10 |
+
|
| 11 |
+
# 🔁 Auto-refresh every 10 seconds
|
| 12 |
+
st_autorefresh(interval=10 * 1000, limit=None, key="auto_refresh")
|
| 13 |
+
|
| 14 |
+
st.caption("Updates every 10 seconds. Shows live top 10 coins by 24h volume.")
|
| 15 |
+
|
| 16 |
+
# Currency symbols
|
| 17 |
+
currency_symbols = {
|
| 18 |
+
"USD": "$",
|
| 19 |
+
"INR": "₹",
|
| 20 |
+
"EUR": "€",
|
| 21 |
+
"GBP": "£",
|
| 22 |
+
"JPY": "¥"
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# Hybrid exchange rate: live + fallback
|
| 26 |
+
def get_exchange_rate(to_currency):
|
| 27 |
+
manual_rates = {
|
| 28 |
+
"USD": 1,
|
| 29 |
+
"INR": 83.2,
|
| 30 |
+
"EUR": 0.92,
|
| 31 |
+
"GBP": 0.78,
|
| 32 |
+
"JPY": 157.6
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
if to_currency == "USD":
|
| 36 |
+
return 1
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
url = f"https://api.exchangerate.host/latest?base=USD&symbols={to_currency}"
|
| 40 |
+
response = requests.get(url, timeout=5)
|
| 41 |
+
response.raise_for_status()
|
| 42 |
+
data = response.json()
|
| 43 |
+
|
| 44 |
+
if not data.get("success") or to_currency not in data.get("rates", {}):
|
| 45 |
+
raise ValueError("Invalid exchange rate response.")
|
| 46 |
+
|
| 47 |
+
return data["rates"][to_currency]
|
| 48 |
+
except Exception as e:
|
| 49 |
+
st.warning(f"⚠️ Could not fetch live rate for {to_currency}. Using fallback.\n\nError: {e}")
|
| 50 |
+
return manual_rates.get(to_currency, 1)
|
| 51 |
+
|
| 52 |
+
# Fetch Binance market data
|
| 53 |
+
@st.cache_data(ttl=10)
|
| 54 |
+
def fetch_market_data():
|
| 55 |
+
url = "https://api.binance.com/api/v3/ticker/24hr"
|
| 56 |
+
try:
|
| 57 |
+
response = requests.get(url, timeout=10)
|
| 58 |
+
response.raise_for_status()
|
| 59 |
+
data = response.json()
|
| 60 |
+
if not isinstance(data, list):
|
| 61 |
+
st.error("⚠️ Binance API returned unexpected format.")
|
| 62 |
+
return pd.DataFrame()
|
| 63 |
+
df = pd.DataFrame(data)
|
| 64 |
+
df = df[["symbol", "lastPrice", "priceChangePercent", "quoteVolume"]]
|
| 65 |
+
df["quoteVolume"] = df["quoteVolume"].astype(float)
|
| 66 |
+
df["priceChangePercent"] = df["priceChangePercent"].astype(float)
|
| 67 |
+
df["lastPrice"] = df["lastPrice"].astype(float)
|
| 68 |
+
return df.sort_values("quoteVolume", ascending=False).head(10)
|
| 69 |
+
except Exception as e:
|
| 70 |
+
st.error(f"❌ Error fetching Binance data: {e}")
|
| 71 |
+
return pd.DataFrame()
|
| 72 |
+
|
| 73 |
+
# Helpers
|
| 74 |
+
def format_change(pct):
|
| 75 |
+
return f"🔺 {pct:.2f}%" if pct > 0 else f"🔻 {pct:.2f}%"
|
| 76 |
+
|
| 77 |
+
def suggest_investment(row):
|
| 78 |
+
if row["priceChangePercent"] > 2 and row["quoteVolume"] > 100_000_000:
|
| 79 |
+
return "✅ Suggest: Trending Up"
|
| 80 |
+
elif row["priceChangePercent"] < -3:
|
| 81 |
+
return "⚠️ Avoid: Falling"
|
| 82 |
+
else:
|
| 83 |
+
return "➖ Neutral"
|
| 84 |
+
|
| 85 |
+
def predict_movement(row):
|
| 86 |
+
if row["priceChangePercent"] > 3:
|
| 87 |
+
return "📈 Likely ↑"
|
| 88 |
+
elif row["priceChangePercent"] < -3:
|
| 89 |
+
return "📉 Likely ↓"
|
| 90 |
+
else:
|
| 91 |
+
return "❓ Uncertain"
|
| 92 |
+
|
| 93 |
+
# Sidebar
|
| 94 |
+
st.sidebar.header("🔧 Options")
|
| 95 |
+
show_market_tip = st.sidebar.checkbox("💡 Show Market Tip", True)
|
| 96 |
+
show_drop_alert = st.sidebar.checkbox("📉 Show Drop Alert", True)
|
| 97 |
+
st.sidebar.markdown("💱 **Currency Conversion**")
|
| 98 |
+
currency = st.sidebar.selectbox("Convert to:", ["USD", "INR", "EUR", "GBP", "JPY"], index=0)
|
| 99 |
+
exchange_rate = get_exchange_rate(currency)
|
| 100 |
+
currency_symbol = currency_symbols.get(currency, "$")
|
| 101 |
+
st.sidebar.caption("🔁 Uses live rates with fallback to manual.")
|
| 102 |
+
|
| 103 |
+
# Track chart history
|
| 104 |
+
if "history" not in st.session_state:
|
| 105 |
+
st.session_state.history = {}
|
| 106 |
+
|
| 107 |
+
# Fetch data
|
| 108 |
+
df = fetch_market_data()
|
| 109 |
+
|
| 110 |
+
if not df.empty:
|
| 111 |
+
df["Change (24h)"] = df["priceChangePercent"].apply(format_change)
|
| 112 |
+
df["Suggestion"] = df.apply(suggest_investment, axis=1)
|
| 113 |
+
df["Prediction"] = df.apply(predict_movement, axis=1)
|
| 114 |
+
|
| 115 |
+
# Convert price/volume
|
| 116 |
+
df["converted_price"] = df["lastPrice"] * exchange_rate
|
| 117 |
+
df["converted_volume"] = df["quoteVolume"] * exchange_rate
|
| 118 |
+
df["Last Price"] = df["converted_price"].apply(lambda x: f"{currency_symbol}{x:,.2f}")
|
| 119 |
+
df["24h Volume"] = df["converted_volume"].apply(lambda x: f"{currency_symbol}{x:,.0f}")
|
| 120 |
+
|
| 121 |
+
# Market tip
|
| 122 |
+
if show_market_tip:
|
| 123 |
+
rising = df[df["Prediction"] == "📈 Likely ↑"]
|
| 124 |
+
if not rising.empty:
|
| 125 |
+
coins = ", ".join(rising["symbol"].tolist())
|
| 126 |
+
st.success(f"💡 **Market Tip**: Watch or buy: **{coins}** — trending up.")
|
| 127 |
+
else:
|
| 128 |
+
st.info("🔎 No strong upward trends right now.")
|
| 129 |
+
|
| 130 |
+
# Drop alert
|
| 131 |
+
if show_drop_alert:
|
| 132 |
+
falling = df[df["Prediction"] == "📉 Likely ↓"]
|
| 133 |
+
if not falling.empty:
|
| 134 |
+
coins = ", ".join(falling["symbol"].tolist())
|
| 135 |
+
st.warning(f"⚠️ **Drop Alert**: Falling coins: **{coins}**. Watch out.")
|
| 136 |
+
else:
|
| 137 |
+
st.info("✅ No sharp drops detected.")
|
| 138 |
+
|
| 139 |
+
# Update chart history
|
| 140 |
+
for _, row in df.iterrows():
|
| 141 |
+
sym = row["symbol"]
|
| 142 |
+
price = row["converted_price"]
|
| 143 |
+
if sym not in st.session_state.history:
|
| 144 |
+
st.session_state.history[sym] = []
|
| 145 |
+
st.session_state.history[sym].append(price)
|
| 146 |
+
st.session_state.history[sym] = st.session_state.history[sym][-30:]
|
| 147 |
+
|
| 148 |
+
# Display table
|
| 149 |
+
st.subheader(f"📋 Top 10 Coins by Volume ({currency})")
|
| 150 |
+
st.dataframe(
|
| 151 |
+
df[["symbol", "Last Price", "Change (24h)", "Suggestion", "Prediction", "24h Volume"]]
|
| 152 |
+
.rename(columns={"symbol": "Symbol"}),
|
| 153 |
+
use_container_width=True,
|
| 154 |
+
hide_index=True
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
# Display charts
|
| 158 |
+
st.subheader("📈 Price Trend Charts (Last 5 minutes, 10s intervals)")
|
| 159 |
+
cols = st.columns(2)
|
| 160 |
+
for i, (symbol, prices) in enumerate(list(st.session_state.history.items())[:6]):
|
| 161 |
+
with cols[i % 2]:
|
| 162 |
+
st.markdown(f"**{symbol}**")
|
| 163 |
+
fig, ax = plt.subplots()
|
| 164 |
+
ax.plot(prices, marker='o')
|
| 165 |
+
ax.set_title(f"{symbol} Price Trend ({currency})")
|
| 166 |
+
ax.set_xlabel("Ticks (10s)")
|
| 167 |
+
ax.set_ylabel(f"Price ({currency_symbol})")
|
| 168 |
+
ax.grid(True)
|
| 169 |
+
st.pyplot(fig)
|
| 170 |
+
else:
|
| 171 |
+
st.warning("🔄 Waiting for valid data from Binance API...")
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
requests
|
| 4 |
+
matplotlib
|
| 5 |
+
streamlit-autorefresh
|