MT4 Manager API => .Net ClrWrapper

2019-09-18 12:13发布

问题:

I am using mtmanapi.dll with a .Net CLR wrapper

I am getting correct Ask and Bid values for symbols without any special characters in the Symbol name - ( e.g. EURUSD, GBPUSD and so on ), but if symbols have some special character in it ( e.g. EURUSD', GBPUSD0 and so on ), then it's not fetching Ask and Bid value using a SymbolInfoGet() method.

回答1:

It should work and below code returns quotes for US100, OIL.WTI, 225JPY from my server. I am using SymbolInfoUpdated() however it's similar to SymbolInfoGet(). But there are few notes:

1) you might need to call mt.SymbolsRefresh(); and mt.SymbolAdd(symbol.Name); before switching to pumping

2) SymbolInfoGet() will return you last received quote in pumping. So if you connect on Saturday and call it, it won't return anything until Monday

using (var mt = new ClrWrapper(new ConnectionParameters {Login = 0, Password = "", Server = "" }))
{
    var symbols = mt.CfgRequestSymbol();
    mt.SymbolsRefresh();
    foreach (var symbol in symbols)
    {
        mt.SymbolAdd(symbol.Name);
    }
    mt.PumpingSwitchEx(PumpingMode.Default);

    mt.BidAskUpdated += (sender, args) =>
    {
        var total = 0;
        do
        {
            var symbolsInfos = mt.SymbolInfoUpdated();
            foreach (var symbolInfo in symbolsInfos)
            {                            
                if (!symbolInfo.Symbol.All(char.IsLetter))
                {
                    Console.WriteLine("{0} {1} {2}", DateTime.Now, symbolInfo.Symbol, symbolInfo.Bid);
                }
            }
            total = symbolsInfos.Count;
        } while (total > 0);
    };

    Console.ReadKey();
}