vdemydiuk / mtapi

MetaTrader API (terminal bridge)
http://mtapi4.net/
MIT License
524 stars 283 forks source link

Problem with OrderSendAsync() in MtApi5 #251

Closed ackem closed 3 years ago

ackem commented 3 years ago

Hi Vyacheslav.

Please help me.

In this simple code:

                MtApi5Client _mt = new MtApi5Client();
        MqlTradeRequest request = new MqlTradeRequest();
                MqlTradeResult result = null;
                request.Action = ENUM_TRADE_REQUEST_ACTIONS.TRADE_ACTION_PENDING;
                request.Symbol = symbol;
                request.Volume = volume;
                request.Price = price;
                request.Type = ENUM_ORDER_TYPE.ORDER_TYPE_BUY_LIMIT;
                request.Type_filling = ENUM_ORDER_TYPE_FILLING.ORDER_FILLING_RETURN;
                request.Type_time = ENUM_ORDER_TYPE_TIME.ORDER_TIME_DAY;
                bool boolResult = _mt.OrderSendAsync(request, out result);

Method OrderSendAsync() throws exception:

MtApi5.ExecutionException: Unknown request type
   at MtApi5.MtApi5Client.SendRequest[T](RequestBase request)
   at MtApi5.MtApi5Client.OrderSendAsync(MqlTradeRequest request, MqlTradeResult& result)
   at testing_MtApi5.Program.Main(String[] args) in C:\CSharpProjects5\testing_MtApi5\testing_MtApi5\Program.cs:line 65

But the same code with OrderSend() works ok.

ghhv commented 3 years ago

Hi Ackem, What is _mt?
This should work... MtApi5Client _mt = new MtApi5Client(); bool boolResult = _mt.OrderSendAsync(request, out result);

ackem commented 3 years ago

This should work... MtApi5Client _mt = new MtApi5Client(); bool boolResult = _mt.OrderSendAsync(request, out result);

Yes, I do so. Doesn't work, Bro.

ghhv commented 3 years ago

did you add references to that project? and mt5api?

ackem commented 3 years ago

But the same code with OrderSend() works ok. !!!

ghhv commented 3 years ago

yes, but you should be awaiting an async.. I don't have MT5 to test, but in the MT4 API, you'd do it like this: await Execute(() => _mtapi.GetOrder(blah, blah));

vdemydiuk commented 3 years ago

@ackem In my opinion you haven't update MtApi5.ex5 in your Terminal's data folder for Expert Advisors (../MQL5/Experts). Please check it.

ackem commented 3 years ago

@vdemydiuk Works! You're magician!) Thank you, Bro)