Trading-bot / main.py
growthex's picture
Update main.py
581f709 verified
Raw History Blame Contribute Delete
6.42 kB
import ccxt
import pandas as pd
import time
from datetime import datetime
import sys
import numpy as np
# --- কনফিগারেশন ---
COINS = [
'BTC/USDT', 'ETH/USDT', 'BNB/USDT', 'SOL/USDT', 'XRP/USDT', 'ADA/USDT',
'AVAX/USDT', 'TRX/USDT', 'DOT/USDT', 'LINK/USDT', 'MATIC/USDT', 'LTC/USDT',
'ATOM/USDT', 'NEAR/USDT', 'APT/USDT', 'SUI/USDT', 'ARB/USDT', 'OP/USDT',
'DOGE/USDT', 'SHIB/USDT', 'PEPE/USDT', 'WIF/USDT', 'BONK/USDT', 'FET/USDT'
]
TIMEFRAME = '15m'
LOOKBACK_PERIOD = 500 # সাপোর্ট বের করার জন্য ডাটা
RSI_PERIOD = 14
MACD_FAST = 12
MACD_SLOW = 26
MACD_SIGNAL = 9
exchange = ccxt.mexc({
'enableRateLimit': True,
'options': {'defaultType': 'swap'}
})
def fetch_data(symbol):
try:
# ১০০০ ক্যান্ডেল ডাটা আনা
ohlcv = exchange.fetch_ohlcv(symbol, TIMEFRAME, limit=1000)
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
# অর্ডার বুক ডাটা
order_book = exchange.fetch_order_book(symbol, limit=50)
return df, order_book
except:
return None, None
def calculate_indicators(df):
# 1. RSI
delta = df['close'].diff()
gain = (delta.where(delta > 0, 0)).rolling(window=RSI_PERIOD).mean()
loss = (-delta.where(delta < 0, 0)).rolling(window=RSI_PERIOD).mean()
rs = gain / loss
df['rsi'] = 100 - (100 / (1 + rs))
# 2. MACD
exp12 = df['close'].ewm(span=MACD_FAST, adjust=False).mean()
exp26 = df['close'].ewm(span=MACD_SLOW, adjust=False).mean()
df['macd'] = exp12 - exp26
df['signal_line'] = df['macd'].ewm(span=MACD_SIGNAL, adjust=False).mean()
df['histogram'] = df['macd'] - df['signal_line']
# 3. Support & Resistance (Major Levels)
df['strong_support'] = df['low'].rolling(window=LOOKBACK_PERIOD).min()
df['strong_resistance'] = df['high'].rolling(window=LOOKBACK_PERIOD).max()
# 4. Volatility Forecasting (GARCH Proxy using ATR)
df['tr'] = df[['high', 'low', 'close']].max(axis=1) - df[['high', 'low', 'close']].min(axis=1)
df['atr'] = df['tr'].rolling(window=14).mean()
return df
def analyze_market(symbol):
df, order_book = fetch_data(symbol)
if df is None: return
# ইন্ডিকেটর ক্যালকুলেশন
df = calculate_indicators(df)
current = df.iloc[-1]
# --- Ostad's Imbalance ($It$) ---
bids = order_book['bids']
asks = order_book['asks']
bid_vol = sum([b[1] for b in bids])
ask_vol = sum([a[1] for a in asks])
imbalance = (bid_vol - ask_vol) / (bid_vol + ask_vol)
current_price = order_book['bids'][0][0]
# --- FORECASTING LOGIC (Min/Max Range) ---
# GARCH মডেলের কনসেপ্ট: বর্তমান ভোলাটিলিটি দিয়ে আগামী রেঞ্জ প্রেডিক্ট করা
# আমরা ATR কে 1.5 দিয়ে গুণ করে রেঞ্জ বের করছি
expected_volatility = current['atr']
forecast_high = current_price + (expected_volatility * 1.5) # সর্বোচ্চ এতটুকু উঠতে পারে
forecast_low = current_price - (expected_volatility * 1.5) # সর্বনিম্ন এতটুকু নামতে পারে
# --- SIGNAL LOGIC ---
# [BUY SETUP: Support + Oversold RSI + Bullish Imbalance + MACD Histo Turning Up]
# দাম কি সাপোর্টের কাছে?
at_support = current_price <= (current['strong_support'] * 1.015)
if at_support:
# ফিল্টার ১: RSI < 35 (Oversold)
# ফিল্টার ২: Imbalance > -0.1 (Buyer Entering)
# ফিল্টার ৩: MACD Histogram বাড়ছে (Momentum Shift)
if current['rsi'] < 35 and imbalance > -0.15:
# Entry: Wick Catching (Support এবং বর্তমানের মাঝে)
limit_buy = (current_price + current['strong_support']) / 2
# SL & TP based on Volatility Forecast
# স্টপ লস হবে ফোরকাস্টেড লো এর একটু নিচে
stop_loss = forecast_low
# টেক প্রফিট হবে ফোরকাস্টেড হাই এর দিকে
take_profit = current_price + expected_volatility
print(f"✅ {symbol} | 🔥 SNIPER BUY SIGNAL")
print(f" 📊 Indicators: RSI({current['rsi']:.1f}) | Imbalance({imbalance:.2f})")
print(f" 🧱 Support: {current['strong_support']}")
print(f" 🔮 Forecasted Range (15m): Low {forecast_low:.4f} - High {forecast_high:.4f}")
print(f" 👉 LIMIT BUY ORDER: {limit_buy:.4f}")
print(f" 🛑 SL: {stop_loss:.4f} | 💰 TP: {take_profit:.4f}")
print("-" * 55)
sys.stdout.flush()
# [SELL SETUP: Resistance + Overbought RSI + Bearish Imbalance]
at_resistance = current_price >= (current['strong_resistance'] * 0.985)
if at_resistance:
if current['rsi'] > 65 and imbalance < 0.15:
limit_sell = (current_price + current['strong_resistance']) / 2
stop_loss = forecast_high
take_profit = current_price - expected_volatility
print(f"🔻 {symbol} | ❄️ SNIPER SELL SIGNAL")
print(f" 📊 Indicators: RSI({current['rsi']:.1f}) | Imbalance({imbalance:.2f})")
print(f" 🧱 Resistance: {current['strong_resistance']}")
print(f" 🔮 Forecasted Range (15m): Low {forecast_low:.4f} - High {forecast_high:.4f}")
print(f" 👉 LIMIT SELL ORDER: {limit_sell:.4f}")
print(f" 🛑 SL: {stop_loss:.4f} | 💰 TP: {take_profit:.4f}")
print("-" * 55)
sys.stdout.flush()
def main():
print(f"--- 🧠 GODZILLA AI (RSI+MACD+GARCH) STARTED [{datetime.now().strftime('%H:%M:%S')}] ---")
while True:
for coin in COINS:
analyze_market(coin)
time.sleep(0.3)
print("... Scanning Next Cycle ...")
time.sleep(30)
if __name__ == "__main__":
main()