lazou / mtapi

Fork of MetaTrader API, only for MetaTrader 5 targeting .NET Core
MIT License
16 stars 2 forks source link

MT4 Dotnet Core #18

Open maartenschalekamp opened 1 year ago

maartenschalekamp commented 1 year ago

Good day,

I am trying to replicate what you have done for MT5 but to do it as well for MT4. When using the MtApiServiceNetCore I am able to connect, but somewhere I believe there is some issue with the data contract or something.

I get the following error: System.ServiceModel.CommunicationException: 'Service connection failed! The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:GetQuotesResult. The InnerException message was 'There was an error deserializing the object of type System.Collections.Generic.List 1'[[MTApiService.MtQuote, MtApiServiceNetCore, Version=1.0.32.0, Culture=neutral, PublicKeyToken=null]]. The input source is not correctly formatted.'. Please see InnerException for more details.'

and the inner exception. {"The input source is not correctly formatted."}

Any suggestions on what could be the issue. When using the MtApiService directly does work fine (in dotnet framework).

lazou commented 1 year ago

Hi @maartenschalekamp, this also happens on my side, it is unrelated to mt4 or mt5. It has something to do with wcf versions >= 4.9.0. To better investigate this issue, I created the test server project for checking only the wcf communication. But recently I had no time for further analyzation, but it is on my Todo list. Sorry :(

To solve it on your end, you can just use the 4.8.0 wcf dependencies, with them I Do not face this issue and all is working as expected.

lazou commented 1 year ago

Maybe some additional background. The json payload is for some methods generated directly in mql5, for others not. The GetQuoteResults is called directly after a connection is established.

maartenschalekamp commented 1 year ago

Thank you for confirming. I really though I was doing something wrong. I will try downgrading to 4.8.0. Really appreciated!

Migrating the server part seems to be a big project as well, but there seems to be some limited support for WCF now in core from a community project.

lazou commented 1 year ago

If you downgrade to 4.8.0, you have to re-add some workarounds. Just have a look at this commit for some details (e.g. the CallbackBehaviorAttribute). https://github.com/lazou/mtapi/pull/5/commits/91af1124c41a88b1f761086dc670cbeb584a7270

Migrating the server part seems to be a big project as well, but there seems to be some limited support for WCF now in core from a community project.

Yep, but requires a better understanding of the mtapi implementation. I think that would be a nice goal to achieve in combination 😉

lazou commented 1 year ago

@maartenschalekamp I did some debugging and found the issue for your observed exception. It is not related to the wcf dependencies (which still have another issue on versions greater than 4.8.0), but has something to do with the used .net core version. There is a regression in .net7, it will still work with .net6. Here are two issues I found for this behavior:

maartenschalekamp commented 1 year ago

Thank you Lazou. I want able to work on my project for a while. I initially tried to just downgrade to 4.8.0 and then ran into other random issues. Downgraded to .net6 and it works now!

cshawky commented 1 year ago

Hi maartenschalekamp and lazou This project looks really cool. I have just come across MTAPI and hope to try it out this week on MT5. I much prefer C# programming than C++ and MQL, having spent a lot of effort creating my own EA on MQL4 many of its issues would be easily fixed through C#. I do not programme often enough for C++ to create a standalone app in C++. However, I am quite comfortable in C#.

I like the many changes lazou has done with his fork of vdemydiuk but the latter still has MT4. I note also https://github.com/VeriEasi has a fork focusing on MT4, but has many commits behind lazou.

My use case combines both MT5 and MT4. Unfortunately, Maarten your MT4 development does not appear to be public, so I am not sure what direction to take.

What do you recommend?

Thanks

lazou commented 1 year ago

Hi @cshawky, I decided to remove MT4 since I only use MT5 and could not test MT4 for my own. Additionally it made the project setup easier. That said, I personnally recommend the usege of MT5. But at the end it is up to you :wink:

cshawky commented 1 year ago

@lazou that makes perfect sense. However, I am supporting an EA for multiple clients who use MT4 exclusively and their favorite broker does not support MT5. To solve limitations with that EA, the magic sauce needs to be done outside of MT4. I myself have started using MT5 and do like it. For that use case I only need a private copy service. I might reach out to VeriEasi and see when he/she is at. At least that clone of your repository seems to have maintained the MT4 build. However, has not kept the MT5 updates from you synchronised. This may actually be reasonably easy to merge with a little cooperation, even if portions are declared "untested" or "limited testing". Thanks

cshawky commented 1 year ago

Thanks, I've just started on this, with a fork. What is the current status for .net as I note a few different versions from .NET 5, 6 and framework 4.8 selected for different projects. Is it safe for .Net 7 yet or should one stick to an earlier version?

lazou commented 1 year ago

I think it is totally fine to use NET7, but I have no experience with it until now (still using NET5). So at the end it is up to you.