The main task for a developer is to transfer all the data, obtained in the MetaTrader 5 Gateway API. For application programmers we can compose the following algorithm to work with this API:
-
Initialization. At this stage, developer has to load the library.
-
Obtaining and running server port interface. All interaction with API is done via server port interface. This interface contains methods of data management and sending. When you create a user interface API, developer must specify his own notification handler. Using this handler API will notify the developer about new connections of History Servers and their parameters (quotes symbols, operation mode, additional parameters). This information only notifies a user and its use is optional.
-
Sending data. Server port interface contains all the necessary methods for sending data to connected History Servers.
-
Exiting. At this stage, a developer has to release server port interface and unload the library.
MetaTrader 5 Gateway API is described in a single 'MT5APIGateway.h' file and implemented in the 'MT5APIGateway.dll' and 'MT5APIGateway64.dll' files for win32 and x64 platforms, respectively. For an application that uses API, it is necessary that these files must be available. Simply copy them into the application folder.
The library exports a few simple functions:
-
MTAPIRES MTGatewayVersion(UINT &version) - returns the version of the Gateway API.
-
MTAPIRES MTGatewayCreateLocal(MTGatewayInfo& info,IMTGatewayAPI **gateway,int argc,wchar_t** argv) - creates and returns an instance of the gateway interface taking into account its description and parameters passed in the command line. In the command line from History Server passed are the time zone and the server port number, on which interface must be started as a server accepting incoming connections. Command line is also used to obtain Data Feed description. By passing command line parameters to the library, we've freed developers from parsing line parameters, time zone initialization and Data Feed description formatting. This method is used only by Data Feeds, controlled by History Server.
-
MTAPIRES MTGatewayCreate(MTGatewayInfo& info,IMTGatewayAPI **gateway) - creates and returns an instance of gateway interface.
When creating a gateway interface, we need to pass to it a correctly filled out MTGatewayInfo structure. This structure contains the description of a data feed and its default settings.