MT3 API for VB.net and C#
  #1 (permalink)  
Old 04-24-2005, 02:20 PM
scorpion's Avatar
Forex Guru
 
Join Date: Aug 2004
Location: Behind You
Posts: 2,103
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Default MT3 API for VB.net and C#

Hey,

Just a quick note to trading robot developers and system automators. I successfully wrapped the mtapi.dll (MetaTrader version 3.x API) ages ago for my own use, and now I'm happy to share my hard work for free.

My wrapped MetaTrader v3.xx API for dotNet framework features:

- Object oriented way: much easier to program in .Net.
- Safe multithreading: no more strange error codes returned.
- Pumping Message Mechanism is programmed for you: all you need to do is to handle the messages.
- A method to avoid 'Too frequent requests' error is programmed for you.
- A very basic demo source code in VB.net is included.
- Support Visual Basic .Net, C#, C++ .Net, and more dotNet compatible languages.

You can download from
www.fxfisherman.com/downloads/MT3API_dotNet.zip and feel free to give comment.

Important: I really do suggest you understand how the original api works first; to do so you need to read the C source code provided with the original api.

Requirement: Microsoft .Net Framework version 1.1 or newer.

Disclaimer: The product is provided free of charge, and, therefore, on an "as is" basis, without warranty of any kind, express or implied, including without limitation the warranties that it is free of defects, virus free, able to operate on an uninterrupted basis, merchantable, fit for a particular purpose or non-infringing. In any case, the author will not be responsible or liable for ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, INDIRECT OR ANY OTHER LOSSES caused by using of this software library.


mehreeizad likes this.
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.

Last edited by scorpion; 05-18-2005 at 12:37 PM.
Reply With Quote
  #2 (permalink)  
Old 04-27-2005, 03:30 AM
gazuz's Avatar
Forex Honorary Moderator
 
Join Date: Aug 2004
Location: California
Posts: 752
gazuz is a name known to allgazuz is a name known to allgazuz is a name known to allgazuz is a name known to allgazuz is a name known to allgazuz is a name known to all
Default

move to members' area?
__________________
____________________________\/
___________________________( )
______________________o0o___(_)___o0o__
_________________________________
Reply With Quote
  #3 (permalink)  
Old 04-27-2005, 04:24 AM
scorpion's Avatar
Forex Guru
 
Join Date: Aug 2004
Location: Behind You
Posts: 2,103
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Default

No, I want to present this goodie to the public to make the best use of it.
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #4 (permalink)  
Old 04-27-2005, 09:22 AM
Forex Trader
 
Join Date: Apr 2005
Posts: 50
sccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the rough
Default

Quote:
Originally Posted by scorpion
No, I want to present this goodie to the public to make the best use of it.
First of all, many thanks for providing the the public with this. I've spent too long trying t ofigure out a way to get the mtapi.dll working in .NET!

I've gone through your example and everything works fine until I try managing orders. Looking at the original API and comparing to the methods in your wrapped dll, I am unsure of certain parameters that are required to send orders. For CloseOrder() I'm sure I'm using the correct price (just grabbing the closeprice from the traderecord) but I'm getting a NotEnoughRightsException, same with ModifyOrder(). Also, for SendOrderInfo, I'm unsure as to what the CRC and Req_Code shoudl be. Lastly, do I have to specify a price (current bid/ask) or can I leave that as 0?

Again, many thanks
Reply With Quote
  #5 (permalink)  
Old 04-27-2005, 09:46 AM
scorpion's Avatar
Forex Guru
 
Join Date: Aug 2004
Location: Behind You
Posts: 2,103
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Default

You'll need to use 2 connections logged into the same account concurrently. The first connection is used to listen for pumping messages, and the second connection is used for calling other methods. The NotEnoughRightsException occured because you used the same connection to call restricted methods while in pumping mode.

CRC and Req_code are not used in SendOrderInfo, and also you have to specify Bid price for sell order and Ask price for buy order. Simple, isn't it?
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #6 (permalink)  
Old 05-03-2005, 01:56 PM
Forex Trader
 
Join Date: Apr 2005
Posts: 50
sccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the rough
Default

works a treat! One question though. I'm having a problem with spawning off multiple threads to kick off trades or even modify orders. The first command usually goes through pretty quickyl but the subsequent ones take qutie a few seconds and often result in too frequent requests exceptions.

I'm probably not explainign this very well.

I have written a function that will modify a position by putting the stop to entry. Say I have 5 open positions all onside with no stops. Inside a loop a spwan off 5 threads that place a stop at entry for each one. Why this all doesn't happen in under a second I don't know. However, if I have 5 seperate instances of my application, and modify the stops for each position in a seperate instance of the app, it works fine. Confusing ....
Reply With Quote
  #7 (permalink)  
Old 05-03-2005, 03:47 PM
scorpion's Avatar
Forex Guru
 
Join Date: Aug 2004
Location: Behind You
Posts: 2,103
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Default

It's good that you have it made some trades so soon.

Your problem: It takes long time to modify the 5 trades, because you use the one same connection. It is a mechanism designed by me to avoid 'Too frequent requests' errors raised by the low-level api. MetaQuotes imposed a rule inside their api to limit 1 trade transaction per 5 to 10 seconds.

The only solution now is to spawn two or three more connections the same way you did in multiple instances. But you should aware that MetaQuotes also imposed a rule to limit the number of connections logged into the same account.

I hope API version 4 doesn't have these limiations.
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #8 (permalink)  
Old 05-03-2005, 10:28 PM
Forex Trader
 
Join Date: Apr 2005
Posts: 50
sccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the rough
Default

Quote:
Originally Posted by scorpion
It's good that you have it made some trades so soon.

Your problem: It takes long time to modify the 5 trades, because you use the one same connection. It is a mechanism designed by me to avoid 'Too frequent requests' errors raised by the low-level api. MetaQuotes imposed a rule inside their api to limit 1 trade transaction per 5 to 10 seconds.

The only solution now is to spawn two or three more connections the same way you did in multiple instances. But you should aware that MetaQuotes also imposed a rule to limit the number of connections logged into the same account.

I hope API version 4 doesn't have these limiations.
Thanks for the confirmation. I thought it might be something I was doing wrong in the code. I've had to resort to spawnging off console apps to do the dirty work for now. Do you have any idea as to when the next version of the api is to be released?
Reply With Quote
  #9 (permalink)  
Old 05-04-2005, 12:21 AM
scorpion's Avatar
Forex Guru
 
Join Date: Aug 2004
Location: Behind You
Posts: 2,103
scorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to beholdscorpion is a splendid one to behold
Default

MetaQuotes says the API4 will be realeased when MetaTrader 4 is in stable version.
__________________
Make easy pips with the Advanced Economic Calendar for Forex Trading.
Reply With Quote
  #10 (permalink)  
Old 05-18-2005, 11:39 AM
Forex Trader
 
Join Date: Apr 2005
Posts: 50
sccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the roughsccz97 is a jewel in the rough
Default

Quote:
Originally Posted by scorpion
MetaQuotes says the API4 will be realeased when MetaTrader 4 is in stable version.
That's good news! Have another question. The GetCurrentRate method does not seem to work with standard accounts, only minis (interbankfx) is this a known issue?
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket problems with MT3 API fxtrader625 MetaTrader and ZeroCode 2 12-29-2005 01:26 PM


All times are GMT. The time now is 08:56 PM.

Registered members gain free access to online FOREX currency trading tools, foreign exchange software, Metatrader MT4/MT5 expert advisors, MT4 indicators and EAs. Register now