SmartQuant Discussion
http://www.smartquant.com/forums/

How to develop a custom market data or execution provider
http://www.smartquant.com/forums/viewtopic.php?f=64&t=6561
Page 1 of 1

Author:  Dr. Anton Fokin [ Mon Mar 24, 2008 3:16 pm ]
Post subject:  How to develop a custom market data or execution provider

You can find examples of custom market data and execution providers in OpenQuant installation folder (windows Start menu SmartQuant Ltd -> OpenQuant -> Samples -> Sample Providers). These examples include full source code for MBT, OEC and TT FIX providers that can be compiled under MSVS 2005. You can use this code as a pattern to develop interfaces to brokers and market data providers not supported out of the box.

Once you develop a new provider and compile it as dll in MSVS, you can add this new provider to OpenQuant via main menu -> Tools -> Options -> Configuration -> Providers -> User -> Add.

Author:  flotschie [ Mon Aug 04, 2008 1:40 pm ]
Post subject: 

I want to create a very simple "MarketData" provider to treat the performance of the system as an instrument.

If I had the performance as an OpenQuant Instrument, I could add it to the instruments list of my system, visualize the chart and than use f.e. indicators to manage equity trading. I dont want to send orders etc., I just want to recieve the new "price" of the performance if a position of my base system is closed.

To be honest, I looked at the sample code of the different user providers and do not understand everything. For example: In the connection void, a new client object is generated, and some events are added to the object.


Code:
client = new OECClient();

            client.OnLoginComplete += new OnLoginCompleteEvent(client_OnLoginComplete);
            client.OnLoginFailed   += new OnLoginFailedEvent(client_OnLoginFailed);
            client.OnDisconnected  += new OnDisconnectedEvent(client_OnDisconnected);
            client.OnError         += new OnErrorEvent(client_OnError);
            client.OnPriceTick     += new OnPriceChangedEvent(client_OnPriceTick);



This client object is of type OECClient (which inherits from the Component Object of MS I assume). There, I don't find the code where exactly this object is getting the actual price (and therefore triggers the OnPriceChangedEvent).

In my case, I think it would work like this: My base system closes a position. The actual performance of the system is send to another application (I have to write I assume). This application provides the new price to the userprovider in OpenQuant and so I can display the new price on the chart f.e.

Is there an easy way to get this done?

Author:  Dr. Anton Fokin [ Mon Aug 04, 2008 8:03 pm ]
Post subject: 

flotschie wrote:
This client object is of type OECClient (which inherits from the Component Object of MS I assume). There, I don't find the code where exactly this object is getting the actual price (and therefore triggers the OnPriceChangedEvent).


OECClient is OEC API object, so I guess OEC API gets prices from OEC servers and then OECClient fires these event...

Regards,
Anton

Author:  flotschie [ Mon Aug 04, 2008 8:12 pm ]
Post subject: 

Thank you anton. I think now I have to write my own API Client which gets prices and then fires the events.

Does anyone from the community know how I can create this kind of client?

Author:  Dr. Anton Fokin [ Mon Aug 04, 2008 8:40 pm ]
Post subject: 

You don't really need to write a separate API client, you can get prices right in OQ provider. The rest depends on how you get prices (performance) from your trading application...

Regards,
Anton

Author:  flotschie [ Tue Aug 05, 2008 12:07 am ]
Post subject: 

Ok thx. I made this User Provider:

Code:
using System;
using System.ComponentModel;
using System.Collections.Generic;
using OpenQuant.API;
using System.Threading;
using System.Windows.Forms;
namespace EProv.dll
{
    class EProv : OpenQuant.API.Plugins.UserProvider
    {
        public EProv()
        {
            base.name = "EPROV";
            base.description = "testing";
            base.id = 100;
            base.url = "http://www.hello.com";
        }
        protected override void Subscribe(Instrument instrument)
        {           
            base.Subscribe(instrument);
        }
        protected override void Connect()
        {
            base.isConnected = true;
            Instrument i = new Instrument(InstrumentType.Stock, "EC");
            Subscribe(i);
            double p = 0;
            while (true)
            {
                Thread.Sleep(1000);
                MessageBox.Show("Bing!");
                recieveprice(i, p);
                p++;
            }
        }
        public void recieveprice(Instrument i, double p)
        {
            base.EmitNewTrade(i, Clock.Now, p, 1);
        }
        protected override void Disconnect()
        {

            base.isConnected = false;
        }
        protected override bool IsConnected
        {
            get
            {
                return base.IsConnected;
            }
        }

    }
}



to test it. But everytime I connect, I get a NullReferenceException:

System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
bei SmartQuant.Instruments.DataManager.UKF3Ns8gP(Object , TradeEventArgs )
bei SmartQuant.Providers.ProviderManager.TrSc6nZMi(Object , TradeEventArgs )
bei OpenQuant.API.Plugins.SQProvider.EmitTrade(Instrument instrument, DateTime time, Double price, Int32 size)

Its in the line

Code:
base.EmitNewTrade(i, Clock.Now, p, 1);


I think it has something to do with the instrument. I have this instrument in the list of instruments in my strategy.

By the way: Is it possible to have more than one market data provider for a strategy? Because I had to set the Live trading Market Date Provider to my User Provider. I wonder then where my base system is getting the IB Market Data.

Author:  flotschie [ Tue Aug 05, 2008 12:37 am ]
Post subject: 

I solved this by getting the instrument via the OpenQuant.API.Instrument list, don't know if this is elegant...

Code:
 Instrument i; //= new Instrument(InstrumentType.Stock, "EC");
            i = OpenQuant.API.InstrumentManager.Instruments["EC"];


But I still have this last question above.

Author:  RickTrader99 [ Sun Nov 07, 2010 8:53 pm ]
Post subject:  Re: How to develop a custom market data or execution provide

Hi Dr. Anton Fokin,

I am unable to locate the sample as mentioned in this post, can you give me some light where i can download the sample.

Thanks

Dr. Anton Fokin wrote:
You can find examples of custom market data and execution providers in OpenQuant installation folder (windows Start menu SmartQuant Ltd -> OpenQuant -> Samples -> Sample Providers). These examples include full source code for MBT, OEC and TT FIX providers that can be compiled under MSVS 2005. You can use this code as a pattern to develop interfaces to brokers and market data providers not supported out of the box.

Once you develop a new provider and compile it as dll in MSVS, you can add this new provider to OpenQuant via main menu -> Tools -> Options -> Configuration -> Providers -> User -> Add.

Author:  Dr. Anton Fokin [ Sun Nov 07, 2010 9:09 pm ]
Post subject:  Re: How to develop a custom market data or execution provide

Hi,

exactly as discussed in the original post:

Windows Start menu SmartQuant Ltd -> OpenQuant -> Samples -> Sample Providers

These folder contains two shortcuts to MS Visual Studio projects, so that you need to have Visual Studio installed to click and load them. Just in case... Windows Start menu is the main Windows menu (-> All Programs under Vista or Win 7), it's not OpenQuant menu.

Regards,
Anton

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/