النتائج 1 إلى 12 من 12
الموضوع: عمل بوتات التليجرام
- 30-08-2025, 11:10 AM #1
عمل بوتات التليجرام
ممكن شرح، هل يمكن لبوت التليجرام تنفيذ الصفقات بشكل مباشر على منصات مثل منصة ميتاتريدر؟ وهل يمكنه مراقبة و تعديل الصفقات واغلاقها؟
- 30-08-2025, 05:27 PM #2
اهلا بك اخى ،
لا أعتقد ذالك فى الحقيقه ،
و لكن لا يوجد مستحيل فى البرمجه ،
فإن أمكن ذالك فسوف يكون بأكثر من برنامج و بأكثر من لغه بحيث الموضوع سوف يكون معقد جدا بتكلفه لا تناسب الجدوى المنتظره ، ناهيك عن الضعف المحتمل و الخربطه فى التنفيذ نتيجه لتداخل عمل البرامج مع بعض على سيرفرات مختلفه ،
- 30-08-2025, 06:26 PM #3
يمكن ذلك عبر استخدام N8n وربطة ب api بالميتاتريدر
او online api مثل تريدينق فيو
- 30-08-2025, 09:46 PM #4
السلام عليكم
ممكن جدا عمل بوت تيليغرام عن طريق Botfather , و بعدين تعمل سكربت بالايثون عشان يكون جسر بين النليغرام بوت و الميتاتريدر
الاوامر اللي مكن تعملها زي هيك:
/sell GOLD 0.2 → بيع ذهب.
/closeall → يسكّر كل الصفقات المفتوحة.
/balance → يجيبلك الرصيد و الإيكويتي.
/status → يعرض كل الصفقات المفتوحة.
مثال :
# ────────────────┠€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€
# Telegram + MT5 Control Bot
# ────────────────┠€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€
import telebot
import MetaTrader5 as mt5
from datetime import datetime
# === إعداداتك الشخصية ===
BOT_TOKEN = "ضع_توكن_البوت_هنا" # من BotFather
ALLOWED_USER_ID = 123456789 # رقم التيلجرام ID تبعك
MT5_LOGIN = 12345678 # رقم الحساب
MT5_PASSWORD = "كلمة_المرور"
MT5_SERVER = "اسم_السيرفر"
# === تشغيل البوت ===
bot = telebot.TeleBot(BOT_TOKEN)
# === الاتصال مع MT5 ===
def mt5_login():
if not mt5.initialize():
return False, mt5.last_error()
if not mt5.login(MT5_LOGIN, password=MT5_PASSWORD, server=MT5_SERVER):
return False, mt5.last_error()
return True, "Connected to MT5"
# === دالة للتحقق من الشخص المرسل ===
def is_authorized(message):
return message.from_user.id == ALLOWED_USER_ID
# === أوامر البوت ===
@bot.message_handler(commands=['start'])
def start(message):
if not is_authorized(message):
return bot.reply_to(message, " غير مسموح")
bot.reply_to(message, "✅ بوت MT5 جاهز، جرب الأوامر: /buy /sell /closeall /balance /status")
@bot.message_handler(commands=['buy'])
def buy(message):
if not is_authorized(message):
return
try:
_, symbol, volume = message.text.split()
volume = float(volume)
request = {
"action": mt5.TRADE_ACTION_DEAL,
"symbol": symbol,
"volume": volume,
"type": mt5.ORDER_TYPE_BUY,
"price": mt5.symbol_info_tick(symbol).ask,
"deviation": 20,
"magic": 123456,
"comment": "TelegramBotBuy",
"type_time": mt5.ORDER_TIME_GTC,
"type_filling": mt5.ORDER_FILLING_FOK,
}
result = mt5.order_send(request)
if result.retcode == mt5.TRADE_RETCODE_DONE:
bot.reply_to(message, f"✅ BUY {symbol} {volume} تم التنفيذ")
else:
bot.reply_to(message, f"⌠خطأ: {result.comment}")
except:
bot.reply_to(message, "âڑ*ï¸ڈ صيغة الأمر: /buy EURUSD 0.1")
@bot.message_handler(commands=['sell'])
def sell(message):
if not is_authorized(message):
return
try:
_, symbol, volume = message.text.split()
volume = float(volume)
request = {
"action": mt5.TRADE_ACTION_DEAL,
"symbol": symbol,
"volume": volume,
"type": mt5.ORDER_TYPE_SELL,
"price": mt5.symbol_info_tick(symbol).bid,
"deviation": 20,
"magic": 123456,
"comment": "TelegramBotSell",
"type_time": mt5.ORDER_TIME_GTC,
"type_filling": mt5.ORDER_FILLING_FOK,
}
result = mt5.order_send(request)
if result.retcode == mt5.TRADE_RETCODE_DONE:
bot.reply_to(message, f"✅ SELL {symbol} {volume} تم التنفيذ")
else:
bot.reply_to(message, f"⌠خطأ: {result.comment}")
except:
bot.reply_to(message, "âڑ*ï¸ڈ صيغة الأمر: /sell GOLD 0.2")
@bot.message_handler(commands=['closeall'])
def closeall(message):
if not is_authorized(message):
return
positions = mt5.positions_get()
if positions:
for pos in positions:
order_type = mt5.ORDER_TYPE_SELL if pos.type == 0 else mt5.ORDER_TYPE_BUY
price = mt5.symbol_info_tick(pos.symbol).bid if pos.type == 0 else mt5.symbol_info_tick(pos.symbol).ask
request = {
"action": mt5.TRADE_ACTION_DEAL,
"symbol": pos.symbol,
"volume": pos.volume,
"type": order_type,
"position": pos.ticket,
"price": price,
"deviation": 20,
"magic": 123456,
"comment": "CloseAll",
"type_time": mt5.ORDER_TIME_GTC,
"type_filling": mt5.ORDER_FILLING_FOK,
}
mt5.order_send(request)
bot.reply_to(message, "✅ تم إغلاق جميع الصفقات")
else:
bot.reply_to(message, "ℹï¸ڈ لا يوجد صفقات مفتوحة")
@bot.message_handler(commands=['balance'])
def balance(message):
if not is_authorized(message):
return
account = mt5.account_info()
if account:
bot.reply_to(message, f" Balance={account.balance}\n Equity={account.equity}\nâڑ–ï¸ڈ Margin={account.margin}")
else:
bot.reply_to(message, "⌠فشل جلب معلومات الحساب")
@bot.message_handler(commands=['status'])
def status(message):
if not is_authorized(message):
return
positions = mt5.positions_get()
if positions:
reply = " الصفقات المفتوحة:\n"
for pos in positions:
reply += f"- {pos.symbol} | {pos.volume} لوت | {'BUY' if pos.type==0 else 'SELL'} | Profit={pos.profit}\n"
bot.reply_to(message, reply)
else:
bot.reply_to(message, "ℹï¸ڈ لا يوجد صفقات مفتوحة")
# === تشغيل البوت ===
ok, msg = mt5_login()
print("MT5:", msg)
bot.polling(none_stop=True)
بالتوفيق
- 30-08-2025, 10:07 PM #5
- 30-08-2025, 10:23 PM #6
- 30-08-2025, 10:24 PM #7
آخر تعديل بواسطة Ahmed_Gameel22 ، 30-08-2025 الساعة 10:27 PM
- 30-08-2025, 10:33 PM #8
- 30-08-2025, 10:37 PM #9
- 30-08-2025, 10:53 PM #10
ممكن جدا ... بس عليك تعمل اكسبيرت expert advisor in mql4
و تضيف https://api.telegram.org
على web request فس الميتاتريدر
بس عمليا البايثون افضل و اسرع
mt4 expert advisor://+------------------------------------------------------------------+
//| Telegram Bot EA for MT4 |
//+------------------------------------------------------------------+
#property strict
// === إعدادات البوت ===
input string BotToken = "PUT-YOUR-BOT-TOKEN-HERE"; // ضع هنا التوكن
input string ChatID = "PUT-YOUR-CHAT-ID-HERE"; // ضع هنا الشات ID
input int PollingIntervalSec = 5; // كل كم ثانية يفحص أوامر تيليجرام
datetime lastCheck = 0;
int lastUpdateID = 0;
//+------------------------------------------------------------------+
//| إرسال رسالة إلى تيليجرام |
//+------------------------------------------------------------------+
void SendTelegram(string msg)
{
string url = "https://api.telegram.org/bot" + BotToken + "/sendMessage";
string headers;
char post[];
string body = "chat_id=" + ChatID + "&text=" + msg;
StringToCharArray(body, post);
string result;
int res = WebRequest("POST", url, headers, 5000, post, result);
if(res == 200)
Print("✅ Telegram message sent: ", msg);
else
Print("⌠Telegram send error: ", GetLastError(), " Result=", result);
}
//+------------------------------------------------------------------+
//| استقبال أوامر من تيليجرام |
//+------------------------------------------------------------------+
void CheckTelegramCommands()
{
if(TimeCurrent() - lastCheck < PollingIntervalSec) return;
lastCheck = TimeCurrent();
string url = "https://api.telegram.org/bot" + BotToken + "/getUpdates?offset=" + IntegerToString(lastUpdateID+1);
string headers;
char post[];
string result;
int res = WebRequest("GET", url, headers, 5000, post, result);
if(res != 200)
{
Print("⌠Telegram getUpdates error: ", GetLastError(), " Result=", result);
return;
}
int startPos = 0;
while(true)
{
int idPos = StringFind(result, ""update_id":", startPos);
if(idPos == -1) break;
string updStr = StringSubstr(result, idPos);
int msgID = StringToInteger(GetJsonValue(updStr, "update_id"));
if(msgID <= lastUpdateID) { startPos = idPos + 1; continue; }
lastUpdateID = msgID;
string text = GetJsonValue(updStr, "text");
if(text=="") { startPos = idPos + 1; continue; }
text = StringTrim(text);
// التعامل مع الأوامر
if(StringFind(text,"/buy",0)==0)
{
OpenOrder(OP_BUY);
SendTelegram(" Buy order opened");
}
else if(StringFind(text,"/sell",0)==0)
{
OpenOrder(OP_SELL);
SendTelegram(" Sell order opened");
}
else if(StringFind(text,"/closeall",0)==0)
{
CloseAllOrders();
SendTelegram(" All orders closed");
}
startPos = idPos + 1;
}
}
//+------------------------------------------------------------------+
//| دالة مساعدة لقراءة قيم من JSON (بسيطة) |
//+------------------------------------------------------------------+
string GetJsonValue(string json, string key)
{
int keyPos = StringFind(json, """ + key + "":");
if(keyPos==-1) return "";
int start = StringFind(json, """, keyPos + StringLen(key) + 3);
int end = StringFind(json, """, start+1);
if(start==-1 || end==-1) return "";
return StringSubstr(json, start+1, end-start-1);
}
//+------------------------------------------------------------------+
//| فتح صفقة |
//+------------------------------------------------------------------+
void OpenOrder(int type)
{
double lot = 0.1;
double sl = 0, tp = 0;
int ticket;
if(type==OP_BUY)
ticket = OrderSend(Symbol(), OP_BUY, lot, Ask, 3, sl, tp, "Telegram Buy", 12345, 0, clrGreen);
else
ticket = OrderSend(Symbol(), OP_SELL, lot, Bid, 3, sl, tp, "Telegram Sell", 12345, 0, clrRed);
if(ticket<0)
Print("⌠OrderSend failed: ", GetLastError());
else
Print("✅ Order opened: ",ticket);
}
//+------------------------------------------------------------------+
//| إغلاق كل الصفقات |
//+------------------------------------------------------------------+
void CloseAllOrders()
{
for(int i=OrdersTotal()-1; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed) ;
else if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,3,clrGree n);
}
}
}
//+------------------------------------------------------------------+
//| OnInit |
//+------------------------------------------------------------------+
int init()
{
SendTelegram(" Telegram Bot EA started on " + Symbol());
return(0);
}
//+------------------------------------------------------------------+
//| OnDeinit |
//+------------------------------------------------------------------+
int deinit()
{
SendTelegram("⌠Telegram Bot EA stopped");
return(0);
}
//+------------------------------------------------------------------+
//| OnTick |
//+------------------------------------------------------------------+
void start()
{
CheckTelegramCommands();
}
- 30-08-2025, 10:55 PM #11
this also for mt5 ..expert advisor://+------------------------------------------------------------------+
//| Telegram Bot EA for MT5 |
//+------------------------------------------------------------------+
#property strict
#include <Trade/Trade.mqh>
CTrade trade;
// === إعدادات البوت ===
input string BotToken = "PUT-YOUR-BOT-TOKEN-HERE"; // ضع هنا التوكن
input string ChatID = "PUT-YOUR-CHAT-ID-HERE"; // ضع هنا الشات ID
input int PollingIntervalSec = 5; // كل كم ثانية يفحص أوامر تيليجرام
datetime lastCheck = 0;
int lastUpdateID = 0;
//+------------------------------------------------------------------+
//| إرسال رسالة إلى تيليجرام |
//+------------------------------------------------------------------+
void SendTelegram(string msg)
{
string url = "https://api.telegram.org/bot" + BotToken + "/sendMessage";
string headers;
char post[];
string body = "chat_id=" + ChatID + "&text=" + msg;
StringToCharArray(body, post);
string result;
ResetLastError();
int res = WebRequest("POST", url, headers, 5000, post, result);
if(res == 200)
Print("✅ Telegram message sent: ", msg);
else
Print("⌠Telegram send error: ", GetLastError(), " Result=", result);
}
//+------------------------------------------------------------------+
//| استقبال أوامر من تيليجرام |
//+------------------------------------------------------------------+
void CheckTelegramCommands()
{
if(TimeCurrent() - lastCheck < PollingIntervalSec) return;
lastCheck = TimeCurrent();
string url = "https://api.telegram.org/bot" + BotToken + "/getUpdates?offset=" + IntegerToString(lastUpdateID+1);
string headers;
char post[];
string result;
ResetLastError();
int res = WebRequest("GET", url, headers, 5000, post, result);
if(res != 200)
{
Print("⌠Telegram getUpdates error: ", GetLastError(), " Result=", result);
return;
}
int startPos = 0;
while(true)
{
int idPos = StringFind(result, ""update_id":", startPos);
if(idPos == -1) break;
string updStr = StringSubstr(result, idPos);
int msgID = StringToInteger(GetJsonValue(updStr, "update_id"));
if(msgID <= lastUpdateID) { startPos = idPos + 1; continue; }
lastUpdateID = msgID;
string text = GetJsonValue(updStr, "text");
if(text=="") { startPos = idPos + 1; continue; }
text = StringTrim(text);
// التعامل مع الأوامر
if(StringFind(text,"/buy",0)==0)
{
OpenOrder(ORDER_TYPE_BUY);
SendTelegram(" Buy order opened");
}
else if(StringFind(text,"/sell",0)==0)
{
OpenOrder(ORDER_TYPE_SELL);
SendTelegram(" Sell order opened");
}
else if(StringFind(text,"/closeall",0)==0)
{
CloseAllOrders();
SendTelegram(" All orders closed");
}
startPos = idPos + 1;
}
}
//+------------------------------------------------------------------+
//| دالة مساعدة لقراءة قيم من JSON (بسيطة) |
//+------------------------------------------------------------------+
string GetJsonValue(string json, string key)
{
int keyPos = StringFind(json, """ + key + "":");
if(keyPos==-1) return "";
int start = StringFind(json, """, keyPos + StringLen(key) + 3);
int end = StringFind(json, """, start+1);
if(start==-1 || end==-1) return "";
return StringSubstr(json, start+1, end-start-1);
}
//+------------------------------------------------------------------+
//| فتح صفقة |
//+------------------------------------------------------------------+
void OpenOrder(ENUM_ORDER_TYPE type)
{
double lot = 0.1;
double sl=0, tp=0;
MqlTradeResult res;
if(type==ORDER_TYPE_BUY)
{
if(!trade.Buy(lot,_Symbol,0,sl,tp,"Telegram Buy"))
Print("⌠Buy failed: ",GetLastError());
}
else if(type==ORDER_TYPE_SELL)
{
if(!trade.Sell(lot,_Symbol,0,sl,tp,"Telegram Sell"))
Print("⌠Sell failed: ",GetLastError());
}
}
//+------------------------------------------------------------------+
//| إغلاق كل الصفقات |
//+------------------------------------------------------------------+
void CloseAllOrders()
{
for(int i=PositionsTotal()-1; i>=0; i--)
{
string sym = PositionGetSymbol(i);
if(PositionSelect(sym))
{
long type; double vol;
PositionGetInteger(POSITION_TYPE,type);
PositionGetDouble(POSITION_VOLUME,vol);
if(type==POSITION_TYPE_BUY)
trade.Sell(vol,sym);
else if(type==POSITION_TYPE_SELL)
trade.Buy(vol,sym);
}
}
}
//+------------------------------------------------------------------+
//| OnInit |
//+------------------------------------------------------------------+
int OnInit()
{
SendTelegram(" Telegram Bot EA started on " + _Symbol);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| OnDeinit |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
SendTelegram("⌠Telegram Bot EA stopped");
}
//+------------------------------------------------------------------+
//| OnTick |
//+------------------------------------------------------------------+
void OnTick()
{
CheckTelegramCommands();
}
- 06-09-2025, 06:27 PM #12
الأكثر زيارة
رد مع اقتباس