如何使用MetaTrader4.Manager.Wrapper监听TradeAdded / TradeClosed / TradeDeleted的事件

时间:2016-10-27 08:38:39

标签: metatrader4

我想听看TradeAdded / TradeClosed / TradeDeleted的事件,这是我的代码:

public partial class Demo : Form
{

    public static ConnectionParameters conParam = new ConnectionParameters();

    public static ClrWrapper mt;


    private void Hedera_Load(object sender, EventArgs e)
    {
        Login();
    }

    public void Login()
    {
            conParam = new ConnectionParameters
            {
                Login = serverConfig.ManageAccount,
                Password = serverConfig.ManagePassword,
                Server = serverConfig.ManageServer
            };
            mt = new ClrWrapper(conParam); 
            List<UserRecord> users = mt.UsersRequest().ToList();

            mt.TradeClosed +=new TradeRecordUpdated(this.MyTradeClosed);
            mt.TradeDeleted += new TradeRecordUpdated(this.MyTradeDeleted);
            mt.TradeAdded += new TradeRecordUpdated(this.MyTradeAdded);
    } 

    public void MyTradeAdded(ClrWrapper mt, TradeRecord tradeRecord)
    {
        MessageBox.Show("MyTradeAdded");
    }
    public void MyTradeClosed(ClrWrapper mt, TradeRecord tradeRecord)
    {
        MessageBox.Show("MyTradeClosed");
    }
    public void MyTradeDeleted(ClrWrapper mt, TradeRecord tradeRecord)
    {
        MessageBox.Show("MyTradeDeleted");
    }
}

当我在MetaTrader4客户端进行交易时,我想在我的C#程序中获取通知。

“UsersRequest”现在没问题,但事件没有运行。

我的代码出错了吗?

你能为我写一个例子吗?

1 个答案:

答案 0 :(得分:0)

这些事件仅在扩展抽水模式下触发。所以你必须切换:

public void Login()
{
        conParam = new ConnectionParameters
        {
            Login = serverConfig.ManageAccount,
            Password = serverConfig.ManagePassword,
            Server = serverConfig.ManageServer
        };
        mt = new ClrWrapper(conParam); 
        List<UserRecord> users = mt.UsersRequest().ToList();

        mt.TradeClosed +=new TradeRecordUpdated(this.MyTradeClosed);
        mt.TradeDeleted += new TradeRecordUpdated(this.MyTradeDeleted);
        mt.TradeAdded += new TradeRecordUpdated(this.MyTradeAdded);
        metatrader.PumpingSwitchEx();
} 

然而,在切换到泵送模式后,您将无法使用非泵送方法