Forexconnect api vb6 0
5 stars based on
This article describes how to start using ForexConnect. Here you can find the API basics explained and step-by-step instructions on creating a working sample of a simple trading application. Microsoft Visual Studio, NET library usage with the Microsoft Silverlight application framework is not supported. NET library running using Mono is not supported. You must distribute your program with all binary libraries and supporting files from "C: ForexConnect libraries and supporting files must be located in the folder where your application is installed.
All APIs used by ForexConnect are asynchronous, so you will have to implement an event-driven architecture in your code. An event-driven architecture is a software architecture pattern that manages the behavior of production, detection and consumption of events as well as the responses they evoke. In this context, an event should be treated as some value or message that can be identified within an ongoing stream of monitored inputs, such as specific conditions or signals or something else.
Event-driven architectures usually consist of event producers and event consumers. Event consumers subscribe to some event manager, and event producers publish to this manager. When the manager receives an event from a producer, it forwards this event to all registered consumers or stores the event for later forwarding. An event handler is a callback routine that operates asynchronously and handles inputs forexconnect api vb60 into a program events. In this context, an event is some meaningful element of application information from an underlying development framework, usually from a graphical user interface GUI toolkit or some kind of input routine.
On the GUI side, for example, events include key strokes, mouse activity, action selections, or timer expirations. On the input side, events include opening or closing files and data streams, reading data and so on. Event handling is the receipt of an event at some event handler forexconnect api vb60 an event producer and subsequent processes. The benefit of event-driven architectures is that they enable arbitrarily large collections of consumers and producers, along with some number of managers, to exchange ongoing status and response information.
They are also usually fairly responsive to events as they occur, and work well in unpredictable and asynchronous communication environments. So you can use appropriate. However you can implement them and use them to receive notifications from the session object after subscription if this is more suitable for forexconnect api vb60. Note that all event handlers that you have implemented for O2GSession events are called in a separate thread.
So you must keep in mind the following:. You do not need any additional resource management for objects obtained using ForexConnect. However it forexconnect api vb60 recommended to call the Dispose method for all obtained objects which implement it.
These calls allow you to free unused system resources more effectively. Forexconnect api vb60 can use the using statement for this purpose:. This sample is a simple console application which uses ForexConnect.
This application has the following features:. To simplify the sample, the whole application logic is implemented forexconnect api vb60 one class MyApp. You can download the whole source code of the sample: The main object of ForexConnect. This object represents a session of user's connection and can be created using a static method of the O2GTransport class:. The O2GSession object notifies subscribers of all changes of the connection state through the following events:.
The data receiving notifications can be handled using the following O2GSession events:. For this, we use a special synchronization signal.
WaitOne in the run method. To receive notifications of request responses or server objects state changes, forexconnect api vb60 must implement and subscribe event handlers to the appropriate events of the O2G2Session instance. Depending on settings of the trade server, the current prices of all instruments either can be automatically received during the login process, or you can explicitly request this data from the trade server.
So, to get the current prices you should do the following actions:. To forexconnect api vb60 the current prices, add the following source code to the run method of our sample after login processing:. In the sample, we wait for receiving the request response using a synchronization signal. Of course, we should set this signal when forexconnect api vb60 data is received. In our sample a "trick" is used to avoid code duplication. As you will see further, response processing is the same when offers data is received from the O2GLoginRules object and when we explicitly retrieve offers data.
So to process the response object received forexconnect api vb60 O2GLoginRulesyou can directly call the implemented event handler of the RequestCompleted event of the session object. As a call of sendRequest is asynchronous, to receive a response with price data, you need to implement the event handler for RequestCompleted event of session object. As this event handler is used to receive notifications of responses of all requests, you should do the following:.
See the source code below for a sample of how to handle receiving of a response. A synchronization signal is set when receiving of offers data is completed.
This "trick" allows waiting for receiving the current prices in the main thread after sending the request. Note that the notification is received in a separate thread, therefore you must use thread-safe reading and updating of the variables that store the received data. We have implemented thread-safe methods to access these variables. As we need an Account ID for our sample, let's retrieve the Accounts table at first.
Retrieving data of the Accounts table is similar to retrieving data of the Offers table. To simplify the sample, get the first account from the user account list and store it in a class-level variable for further usage. The best practice is encapsulation of the order creation logic into a separate method of the MyApp class.
Also you should handle the response to forexconnect api vb60 order creation request in the onRequestCompleted event handler to make sure that the order is created. Note that there are some useful helper classes in the fxcore2. Constants namespace for filling the valueMap object with order parameters:. So you need to do the following:. To simplify our sample, we take the stored account ID and use it in forexconnect api vb60 example of the Orders table retrieving.
Note that if you store orders data, you must provide thread-safe access to this data and correct management of reference counters for the stored objects. In our sample, orders data is not stored, so synchronization is not implemented. As you can see, the stop method of our MyApp class frees all used system resources and unsubscribes all event handlers from session events to stop receiving notifications.
You should call logout before termination of your application. When an error occurs during asynchronous execution of a request, the event handler of the RequestFailed event is invoked. In forexconnect api vb60 sample, we handle the error by putting the error description in the console output and forexconnect api vb60 stopping the application:.
To launch the sample on this stage, we need to implement usage of our MyApp forexconnect api vb60. For this, do the following:. The run method of the sample prepares the application for trading. After the preparation is made, it returns true if all is good. As you can see, this method calls all API functions asynchronously but waits for their responses using special synchronization forexconnect api vb60.
Note that this is not an effective method of using ForexConnectAPI, but it is easy for understanding. Now you can build and run the sample. If forexconnect api vb60 have any problem with building the sample, please compare it with the forexconnect api vb60 source code of the sample: How to Start Using ForexConnect.
Generic ; using System. Text ; using System. Read ; if app. Retrieved from " http: Views Page Discussion View source History. Personal tools Log in.