Discussion of article "How to create bots for Telegram in MQL5" - page 12

To add comments, please log in or register
thegosutrader
13
thegosutrader  
Keith Watford:

Please attach the code here instead of linking to an external website.

The bot is sending the same message multiple times, the log says :"Too many requests: retry after 10","parameters":{"retry_after":10}

Here is my mq4 file:

#include <Telegram.mqh>


input string InpChannelName="@xxx";//Channel Name
input string InpToken="1049045330:AxxxxxxbFxxx0-IxwKXyxxxxxxxx";//Bot Token


CCustomBot bot;

datetime time_signal=0;
//int SendMessage(const string channel_name,
                //const string text);




//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   time_signal=0;

//--- set token
   bot.Token(InpToken);


//--- done
   return(INIT_SUCCEEDED);
  }
 
  datetime _opened_last_time = TimeCurrent() ;
  datetime _closed_last_time = TimeCurrent()  ;
  
 

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)

{

}
     
  
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  

   string message = "";
   int total=OrdersTotal();
  
        
   for(int pos=0;pos<total;pos++){  // Current orders -----------------------
     if(OrderSelect(pos,SELECT_BY_POS)==false) continue;
     if(OrderOpenTime() <= _opened_last_time) continue;
     
     message += StringFormat("Order opened!\r\nType: %s\r\nSymbol: %s\r\nPrice: %s\r\nSL: %s\r\nTP: %s\r\nTime: %s\r\nTicket:.%s ",
     order_type(),
     OrderSymbol(),
     DoubleToStr(OrderOpenPrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     DoubleToStr(OrderStopLoss(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     DoubleToStr(OrderTakeProfit(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     TimeToStr(OrderOpenTime(),TIME_MINUTES),
     IntegerToString(OrderTicket())
          
      );
      
     int res=bot.SendMessage(InpChannelName,message);
     if(res!=0)
         Print("Error: ",GetErrorDescription(res));
     
     }
     
      bool is_closed = false;

  
  total = OrdersHistoryTotal();
      
   for(int pos=0;pos<total;pos++){  // History orders-----------------------
      if(OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)==false) continue;
      if(OrderCloseTime() <= _closed_last_time) continue;
     printf(OrderCloseTime());
     is_closed = true;
     
     message += StringFormat("Order closed!\r\nTicket: %s\r\nSymbol: %s\r\nClosing Price: %s\r\nTime: %s",
     IntegerToString(OrderTicket()),
     OrderSymbol(),
     DoubleToStr(OrderClosePrice(),MarketInfo(OrderSymbol(),MODE_DIGITS)),
     TimeToStr(OrderCloseTime(),TIME_MINUTES),
     DoubleToStr(order_pips(),1)
     
     
     );
      
      int res=bot.SendMessage(InpChannelName,message);
     if(res!=0)
         Print("Error: ",GetErrorDescription(res));
      
     }
 
   }
   
   
double order_pips() {
   double pips;
   
   if(OrderType() == OP_BUY) {
      pips =  (OrderClosePrice()-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);
   } else {
      pips =  (OrderOpenPrice()-OrderClosePrice())/MarketInfo(OrderSymbol(),MODE_POINT);
   }
   return pips/10;
}

string order_type_to_str(int type)
{
   return StringSubstr(EnumToString((ENUM_ORDER_TYPE)type), 11);
}
string order_type () {
   return order_type_to_str(OrderType());
   
   if(OrderType() == OP_BUY)        return "BUY";
   if(OrderType() == OP_SELL)       return "SELL";
   if(OrderType() == OP_BUYLIMIT)   return "BUY LIMIT";
   if(OrderType() == OP_SELLLIMIT)  return "SELL LIMIT";
   if(OrderType() == OP_BUYSTOP)    return "BUYSTOP";
   if(OrderType() == OP_SELLSTOP)   return "SELLSTOP";
   
   return "{err}";
}
   

   
//---

Thank you

thegosutrader
13
thegosutrader  
Antonio Vargas:

Hello!, I managed to do since they also work on private channels, everything is on the Telegram.mqh, there is a part in the file where the "@" are located, what I did was replaced by "-", and at the time of placing the name of the channel with the variable InpChannelName there place the following "-10014749xxxxx", the token of the channel with the bot

Hello,

For those who want to send to a private channel,

1) replace the "@" by "-" in the Telegram.mqh at line 1009 and line 1010 (see attached image),

2) in the mq4 file, you put your channel token starting by -1000xxxx like this: InpChannelName="-10000xxxx";//Channel Name

and you should get the messages after setting your channel to private.

Good luck.

Files:
thegosutrader
13
thegosutrader  

Hello,


For the multiple messages sent, this is the error message I am getting in MT4 journal :


{"ok":false,"error_code":429,"description":"Too Many Requests: retry after 11","parameters":{"retry_after":11}}


and 


Error: Unknown error 66965


Thank you for your help.

Agus Wahyu Pratomo
360
Agus Wahyu Pratomo  
thegosutrader:

Hello,

For those who want to send to a private channel,

1) replace the "@" by "-" in the Telegram.mqh at line 1009 and line 1010 (see attached image),

2) in the mq4 file, you put your channel token starting by -1000xxxx like this: InpChannelName="-10000xxxx";//Channel Name

and you should get the messages after setting your channel to private.

Good luck.

So if i have allready set to private channel by change "@" to "-" when i like to send to public channel i should change it back again?


Thanks

thegosutrader
13
thegosutrader  
Agus Wahyu Pratomo:

So if i have allready set to private channel by change "@" to "-" when i like to send to public channel i should change it back again?


Thanks

Yes I guess but I'm not a coder so I believe there is a way to send to public and private at the same time...
kayodemizan
255
kayodemizan  

Hi Andrey,  please am getting HTTP request failed


Please help


Thanks

MichaelBui
8
MichaelBui  
kayodemizan:

Hi Andrey,  please am getting HTTP request failed


Please help


Thanks


Hi @Andrey Voytenko

I'm getting same problem. It have been happening for months. Please help!

Thank you so much!

kayodemizan
255
kayodemizan  

Hello Andrey, 

Can I say the file is corrupted. HTTP request failed Error persisted. 

 Can I get the file Telegram Bot EA again.

Jefferson Metha
3201
Jefferson Metha  
kayodemizan:

Hello Andrey, 

Can I say the file is corrupted. HTTP request failed Error persisted. 

 Can I get the file Telegram Bot EA again.

Please Read through the 11 Pages. 

Your issue was long ago solved

To add comments, please log in or register