187 lines
17 KiB
MQL5
187 lines
17 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| report.mqh |
|
|
//| Rafael Morgado Silva |
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
#property strict
|
|
#include "Telegram\Telegram.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| CMyBot |
|
|
//+------------------------------------------------------------------+
|
|
class CMyBot: public CCustomBot
|
|
{
|
|
public:
|
|
void SendResult(void)
|
|
{
|
|
long ids[1]={6610010541};//,329475658,6425802004,5970645071};
|
|
for(int i=0; i<ArraySize(ids); i++)
|
|
{
|
|
//Print("Sending results to: ",ids[i]);
|
|
double profit=0;
|
|
double f_profit=0;
|
|
for (int i=0;i<ArraySize(Assets.data);i++)
|
|
{
|
|
string ticker=Assets.data[i].ticker;
|
|
profit+=calc_profit(ticker,DEAL_TYPE_SELL)+calc_profit(ticker,DEAL_TYPE_BUY);//resultado realizado
|
|
f_profit+=float_profit(ticker,POSITION_TYPE_BUY)+float_profit(ticker,POSITION_TYPE_SELL);//lucro flutuante
|
|
}
|
|
SendMessage(ids[i],TimeToString(TimeLocal(),TIME_DATE|TIME_SECONDS)+"\n"+
|
|
"Lucro realizado: "+DoubleToString(profit,2)+" "+DoubleToString(100.0*profit/Money.Balance(),2)+"%\n"
|
|
"Lucro flutuante: "+DoubleToString(f_profit,2)+" "+DoubleToString(100.0*f_profit/Money.Balance(),2)+"%\n");
|
|
string photo_id;
|
|
SendDocument(photo_id,ids[i],EAName+".pdf","Resultado "+EAName);
|
|
}
|
|
}
|
|
void ProcessMessages(void)
|
|
{
|
|
for(int i=0; i<m_chats.Total(); i++)
|
|
{
|
|
CCustomChat *chat=m_chats.GetNodeAtIndex(i);
|
|
//--- se a mensagem não foi processada
|
|
if((!chat.m_new_one.done)&&(
|
|
(chat.m_new_one.from_username=="rafaelmorgadosilva")//||
|
|
//(chat.m_new_one.from_username=="marciuslima13")||
|
|
//(chat.m_new_one.from_id==6425802004)||//Guilherme
|
|
//(chat.m_new_one.from_id==5970645071)//Victor
|
|
))
|
|
{
|
|
chat.m_new_one.done=true;
|
|
string text=chat.m_new_one.message_text;
|
|
if(text=="/start")//--- início
|
|
{
|
|
SendMessage(chat.m_id,"Hello "+chat.m_new_one.from_first_name+"!");
|
|
//SendMessage(chat.m_id,"Chat id: "+IntegerToString(chat.m_id));
|
|
//SendMessage(chat.m_id,chat.);
|
|
//SendMessage(chat.m_id,chat.m_new_one.from_first_name);
|
|
//SendMessage(chat.m_id,chat.m_new_one.from_last_name);
|
|
//SendMessage(chat.m_id,chat.m_new_one.from_id);
|
|
//SendMessage(chat.m_id,chat.m_new_one.chat_username);
|
|
//SendMessage(chat.m_id,chat.m_new_one.chat_first_name);
|
|
//SendMessage(chat.m_id,chat.m_new_one.chat_last_name);
|
|
//SendMessage(chat.m_id,chat.m_new_one.chat_id);
|
|
}
|
|
if(text=="/help")//--- ajuda
|
|
SendMessage(chat.m_id,"My commands list: \n"+
|
|
"/start - start chatting with me \n"+
|
|
"/help - get help\n"+
|
|
"/profit - realized profit and float profit\n"//+
|
|
//"/makeplot - make the equity plot\n"+
|
|
//"/sendplot - send the plot\n"//+
|
|
//"/logson - start sending the logs\n"+
|
|
//"/logsoff - stop sending the logs\n"
|
|
);
|
|
if(text=="/profit")//--- resultado do momento
|
|
{
|
|
double profit=0;
|
|
double f_profit=0;
|
|
for (int i=0;i<ArraySize(Assets.data);i++)
|
|
{
|
|
string ticker=Assets.data[i].ticker;
|
|
profit+=calc_profit(ticker,DEAL_TYPE_SELL)+calc_profit(ticker,DEAL_TYPE_BUY);//resultado realizado
|
|
f_profit+=float_profit(ticker,POSITION_TYPE_BUY)+float_profit(ticker,POSITION_TYPE_SELL);//lucro flutuante
|
|
}
|
|
SendMessage(chat.m_id,TimeToString(TimeLocal(),TIME_DATE|TIME_SECONDS)+"\n"+
|
|
"Lucro realizado: "+DoubleToString(profit,2)+" "+DoubleToString(100.0*profit/Money.Balance(),2)+"%\n"
|
|
"Lucro flutuante: "+DoubleToString(f_profit,2)+" "+DoubleToString(100.0*f_profit/Money.Balance(),2)+"%\n");
|
|
}
|
|
/*if(text=="/makeplot")//--- gera o gráfico
|
|
{
|
|
Metadata.FileToFile(MyName);//lê MyName+DataFname, salva MyName+"-dailyreport.csv"
|
|
ShellOpenFile(MyName+"-dailyreport.bat");//chama gnuplot MyName+"-daylyreport.gp"
|
|
SendMessage(chat.m_id,"Ok. Wait 10 seconds before sending plot");
|
|
}
|
|
if(text=="/sendplot")//--- envia o gráfico
|
|
{
|
|
string photo_id;
|
|
SendDocument(photo_id,chat.m_id,EAName+".pdf","Resultado "+EAName);
|
|
}*/
|
|
/*if(text=="/logson")//--- envia os logs de forma contínua
|
|
{
|
|
int size=ArraySize(TelegramLogsIds);//TelegramLogsIds deveria ser uma lista
|
|
ArrayResize(TelegramLogsIds,size+1);
|
|
TelegramLogsIds[size]=chat.m_id;
|
|
SendMessage(chat.m_id,"Logs enabled!");
|
|
}
|
|
if(text=="/logsoff")//--- pare de mandar os logs de forma contínua
|
|
{
|
|
int size=ArraySize(TelegramLogsIds);
|
|
bool del=false;
|
|
for (int i=0;i<size;i++)
|
|
{
|
|
if (chat.m_id==TelegramLogsIds[i])
|
|
{
|
|
del=true;
|
|
TelegramLogsIds[i]=INT_MIN;
|
|
}
|
|
}
|
|
if (del)
|
|
{
|
|
long tmpids[];
|
|
ArrayResize(tmpids,size-1);
|
|
int j=0;
|
|
for (int i=0;i<size;i++)
|
|
{
|
|
if ((TelegramLogsIds[i]!=INT_MIN)&&(j<(size-1)))
|
|
{
|
|
tmpids[j]=TelegramLogsIds[i];
|
|
j++;
|
|
}
|
|
}
|
|
ArrayResize(TelegramLogsIds,size-1);
|
|
ArrayCopy(TelegramLogsIds,tmpids);
|
|
}
|
|
SendMessage(chat.m_id,"Ok");
|
|
}*/
|
|
}
|
|
}
|
|
}
|
|
void SendLogs(void)
|
|
{
|
|
if (TelegramBuffer!="")
|
|
{
|
|
//long ids[3]={6610010541,329475658,6425802004};
|
|
long ids[1]={6610010541};
|
|
for (int i=0;i<ArraySize(ids);i++)
|
|
//if (TelegramLogsIds[i]!=INT_MIN)
|
|
SendMessage(ids[i],TelegramBuffer);
|
|
//SendMessage(TelegramLogsIds[i],TelegramBuffer);
|
|
TelegramBuffer="";
|
|
}
|
|
}
|
|
};
|
|
//criar o bot no telegram
|
|
//rotinas em oninit e ontimer
|
|
//colocar no feynman
|
|
//usar
|
|
class BotTelegram
|
|
{
|
|
public:
|
|
string InpToken;//="177791741:AAH0yB3YV7ywm80af_-AGqb7hzTR_Ud9DhQ";//Token
|
|
CMyBot bot;
|
|
BotTelegram(void) {InpToken="";}
|
|
void Init(string token)
|
|
{
|
|
InpToken=token;
|
|
bot.Token(InpToken);
|
|
int getme_result=bot.GetMe();//--- checagem token
|
|
if(getme_result!=0)
|
|
{
|
|
Print("Error: ",GetErrorDescription(getme_result));//--- mostrar mensagem de erro
|
|
return;//(INIT_FAILED);
|
|
}
|
|
Update();
|
|
}
|
|
void Update(void)
|
|
{
|
|
//Comment("Bot name: ",bot.Name());//--- mostrar Nome do bot
|
|
bot.GetUpdates();//--- lê as mensagens - aqui é onde tem o filtro de usuários
|
|
bot.ProcessMessages();//--- processando mensagem
|
|
bot.SendLogs();
|
|
}
|
|
void SendResult(void)
|
|
{
|
|
Print("Sending results");
|
|
bot.SendResult();
|
|
}
|
|
};
|