-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy path"Add Binary Bot code
More file actions
85 lines (71 loc) · 2.75 KB
/
"Add Binary Bot code
File metadata and controls
85 lines (71 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Bot Options Binary — تجربة على Quotex (educational only)
# يستخدم مكتبة غير رسمية للتواصل مع المنصة (تحذير: تجريب فقط)
# pip install quotexpy
from quotexpy import Quotex
import time, math
# ----- إعدادات -----
EMAIL = "your_email@example.com"
PASSWORD = "your_password"
SYMBOL = "EURUSD" # الأصل المالي
TIMEFRAME = 60 # مدة الصفقة بالدقائق
RISK_PERCENT = 1.0 # نسبة المخاطرة لكل صفقة %
MAX_TRADES = 2 # أقصى عدد صفقات مفتوحة في نفس الوقت
RSI_PERIOD = 14
SMA_PERIOD = 50
# ----- اتّصال بالمنصة -----
client = Quotex(email=EMAIL, password=PASSWORD)
connected, msg = client.connect()
if not connected:
print("❌ فشل الاتصال:", msg)
exit()
# ----- دوال تحليل -----
def calc_rsi(closes, period=RSI_PERIOD):
gains = []
losses = []
for i in range(1, len(closes)):
diff = closes[i] - closes[i-1]
if diff >= 0:
gains.append(diff)
losses.append(0)
else:
gains.append(0)
losses.append(abs(diff))
avg_gain = sum(gains[-period:]) / period
avg_loss = sum(losses[-period:]) / period
if avg_loss == 0: return 100
rs = avg_gain / avg_loss
return 100 - (100 / (1 + rs))
def calc_sma(closes, period=SMA_PERIOD):
if len(closes) < period:
return sum(closes) / len(closes)
return sum(closes[-period:]) / period
# ----- تنفيذ صفقة -----
def open_trade(direction, amount):
result = client.buy_simple(SYMBOL, amount, direction, TIMEFRAME)
print(f"✅ فتح صفقة {direction} بمبلغ {amount}")
return result
def count_trades_open():
trades = client.get_open_trades()
return len([t for t in trades if t["symbol"] == SYMBOL])
# ----- الحلقة الرئيسية -----
while True:
# تأكّد عدد الصفقات المفتوحة أقل من الحد
if count_trades_open() >= MAX_TRADES:
time.sleep(5)
continue
candles = client.get_candles(symbol=SYMBOL, timeframe=TIMEFRAME, limit=100)
closes = [c["close"] for c in candles]
rsi = calc_rsi(closes)
sma = calc_sma(closes)
last = candles[-1]
direction = None
if last["close"] > last["open"] and last["close"] > sma and rsi < 30:
direction = "call"
elif last["close"] < last["open"] and last["close"] < sma and rsi > 70:
direction = "put"
if direction:
balance = client.get_balance()
amount = balance * (RISK_PERCENT / 100.0)
amount = max(amount, 1.0) # حد أدنى $1
open_trade(direction, amount)
time.sleep(TIMEFRAME * 60) # انتظار حتى انتهاء مدة الصفقة