একটি প্রোটোটাইপ ক্রিপ্টো ট্রেডিং বট যা Python (Flask) + HTML/CSS/JS দিয়ে তৈরি। এটি রিয়েল টাইম BTC/USDT মার্কেট দেখায়, ছোট ML-based প্রেডিকশন দেয় এবং Buy/Sell/Hold অ্যাডভাইস প্রদান করে।
- রিয়েল টাইম BTC/USDT মার্কেট গ্রাফ দেখাবে
- লাস্ট ৩০ মিনিট / ২৪ ঘন্টা / ৩০ দিনের মার্কেট ট্রেন্ড দেখাবে
- ৫ মিনিটের প্রেডিকশন দিবে (ML-based)
- Buy / Sell / Hold অ্যাডভাইস দেখাবে
ML প্রেডিকশন একটি simple LSTM প্রেডিক্টর (simulation mode) ব্যবহার করে প্রোটোটাইপ তৈরি করা হয়েছে।
crypto_bot/ │ ├── backend/ │ ├── app.py # Flask server │ ├── ml_model.py # ML prediction (LSTM simulation) │ └── utils.py # Binance API + data processing │ ├── frontend/ │ ├── index.html │ ├── main.js │ └── style.css │ └── requirements.txt # Flask, pandas, numpy, tensorflow, websocket-client, requests, etc.
requirements.txt:
Flask==2.3.2 requests==2.31.0 pandas==2.1.0 numpy==1.26.0 tensorflow==2.15.0 websocket-client==1.6.3
Binance থেকে historical এবং live data আনার জন্য:
import requests
import pandas as pd
BASE_URL = "https://api.binance.com/api/v3"
def get_historical_klines(symbol="BTCUSDT", interval="1m", limit=1000):
url = f"{BASE_URL}/klines?symbol={symbol}&interval={interval}&limit={limit}"
data = requests.get(url).json()
df = pd.DataFrame(data, columns=[
"Open time", "Open", "High", "Low", "Close", "Volume",
"Close time", "Quote asset volume", "Number of trades",
"Taker buy base", "Taker buy quote", "Ignore"
])
df["Close"] = df["Close"].astype(float)
df["Open"] = df["Open"].astype(float)
df["High"] = df["High"].astype(float)
df["Low"] = df["Low"].astype(float)
df["Volume"] = df["Volume"].astype(float)
return df
def get_latest_price(symbol="BTCUSDT"):
url = f"{BASE_URL}/ticker/price?symbol={symbol}"
data = requests.get(url).json()
return float(data['price'])
---
ml_model.py
Simple LSTM simulation (prototype):
import numpy as np
import random
def predict_next_price(last_prices):
"""Simple simulation: next price = current price + random small change"""
current = last_prices[-1]
change = current * random.uniform(-0.001, 0.001) # ±0.1% variation
next_price = current + change
return next_price
def decision_advice(current_price, predicted_price):
if predicted_price > current_price * 1.0005:
return "BUY"
elif predicted_price < current_price * 0.9995:
return "SELL"
else:
return "HOLD"
---
app.py
Flask API:
from flask import Flask, jsonify, render_template
from utils import get_historical_klines
from ml_model import predict_next_price, decision_advice
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/api/market')
def market_data():
df = get_historical_klines(limit=100)
last_prices = df['Close'].tolist()
current_price = last_prices[-1]
predicted_price = predict_next_price(last_prices)
advice = decision_advice(current_price, predicted_price)
response = {
"current_price": current_price,
"predicted_price": predicted_price,
"advice": advice,
"last_30m": {
"min": min(last_prices[-30:]),
"max": max(last_prices[-30:]),
"trend": last_prices[-1] - last_prices[-30]
},
"last_24h": {
"min": min(last_prices[-1440:]),
"max": max(last_prices[-1440:]),
"trend": last_prices[-1] - last_prices[-1440]
}
}
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True)
---
Frontend
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Crypto Bot Prototype</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<h1>Crypto Bot Dashboard</h1>
<div>
<p>Current BTC Price: <span id="current_price"></span> USD</p>
<p>Predicted Next Price: <span id="predicted_price"></span> USD</p>
<p>Advice: <span id="advice"></span></p>
</div>
<canvas id="priceChart" width="800" height="400"></canvas>
<script src="main.js"></script>
</body>
</html>
---
main.js
async function fetchMarketData() {
const response = await fetch('/api/market');
const data = await response.json();
document.getElementById('current_price').innerText = data.current_price.toFixed(2);
document.getElementById('predicted_price').innerText = data.predicted_price.toFixed(2);
document.getElementById('advice').innerText = data.advice;
// Update chart
const prices = Array.from({length: 100}, (_, i) => data.last_30m.trend + i);
const ctx = document.getElementById('priceChart').getContext('2d');
if(window.priceChart){
window.priceChart.data.datasets[0].data = prices;
window.priceChart.update();
} else {
window.priceChart = new Chart(ctx, {
type: 'line',
data: {
labels: prices.map((_, i) => i),
datasets: [{
label: 'BTC Price (USD)',
data: prices,
borderColor: 'green',
tension: 0.3
}]
}
});
}
}
setInterval(fetchMarketData, 5000); // 5 seconds update
fetchMarketData();
---
style.css
body {
font-family: Arial, sans-serif;
background-color: #1b1b1b;
color: white;
text-align: center;
}
canvas {
margin-top: 20px;
background-color: #2c2c2c;
}
---
✅ এই প্রোটোটাইপ রিয়েল টাইম মার্কেট দেখাবে, প্রেডিকশন দিবে, এবং Buy/Sell/Hold অ্যাডভাইস দেখাবে।