SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Dec 16, 2019 6:47 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Oct 17, 2019 9:34 am 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
harsh wrote:
Do we need to call both, Subscribe from SubscriptionManager and Add from EventManager.BarFactory? or these are two ways for subscribing the live data?

If both statements are needed then do we still need to pass providerId in BarFactory.Add(..) call as you suggested earlier?

Thanks,

Yes, both are necessary to subscribe to market data and create bars from the input data.


Top
 Profile  
 
PostPosted: Thu Oct 17, 2019 11:25 am 
Offline

Joined: Mon Sep 02, 2019 10:31 am
Posts: 27
I am calling both, Subscribe from SubscriptionManager and Add from EventManager.BarFactory. But still, Bar event is neer triggered. Can you please look once?

Code:
public partial class IQFeedLiveDataDemo : Form
{
  Framework framework;
  IDataProvider dataProider;
  long totalBarCount = 0;
  int barFactoryBarSize = 1;

  List<Instrument> subscribedInstruments = new List<Instrument>();

  public IQFeedLiveDataDemo()
  {
    InitializeComponent();
     
    framework = Framework.Current;

    dataProider = framework.ProviderManager.GetDataProvider("IQFeed");
    dataProider.Connect();

    while (!dataProider.IsConnected) { }

    framework.EventManager.Dispatcher.Bar += Dispatcher_Bar;
    framework.EventManager.Dispatcher.Trade += Dispatcher_Trade;
    framework.EventManager.Dispatcher.Ask += Dispatcher_Ask;
    framework.EventManager.Dispatcher.BarOpen += Dispatcher_BarOpen;
    framework.EventManager.Dispatcher.Bid += Dispatcher_Bid;
     
  }

  private void Dispatcher_Bar(object sender, Bar bar)
  {
    dataGridViewResult.BeginInvoke(new Action(() => dataGridViewResult.Rows.Insert(0, framework.InstrumentManager.GetById(bar.InstrumentId).Symbol, bar.OpenDateTime, bar.CloseDateTime, bar.Open, bar.High, bar.Low, bar.Close, bar.Volume)));
    totalBarCount++;
    labelTotalCount.BeginInvoke(new Action(() => labelTotalCount.Text = string.Format($"Total: {totalBarCount,8}")));
  }

  private void buttonOk_Click(object sender, EventArgs e)
  {
    UnsubscribeAll();

    dataGridViewResult.Rows.Clear();
    totalBarCount = 0;

    var symbols = textBoxSymbol.Text.Split(',').Select(s => s.Trim());

    foreach (var symbol in symbols)
    {
      Instrument instrument = framework.InstrumentManager[symbol];

      if (instrument != null)
      {
        framework.SubscriptionManager.Subscribe(dataProider, instrument);
        framework.EventManager.BarFactory.Add(instrument, BarType.Tick, barFactoryBarSize);
        subscribedInstruments.Add(instrument);
      }
      else
      {
        MessageBox.Show($"Instrument with symbol {symbol} doesn't exist. Skipping!");
      }
    }
  }

  private void UnsubscribeAll()
  {
    foreach (var instrument in subscribedInstruments)
    {
      framework.SubscriptionManager.Unsubscribe(dataProider, instrument);
      framework.EventManager.BarFactory.Remove(instrument, BarType.Tick, barFactoryBarSize);
    }

    subscribedInstruments.Clear();
  }

  private void IQFeedLiveDataDemo_FormClosing(object sender, FormClosingEventArgs e)
  {
    UnsubscribeAll();
    framework.Dispose();
  }
}


Top
 Profile  
 
PostPosted: Thu Oct 17, 2019 12:47 pm 
Offline

Joined: Wed May 05, 2010 9:49 pm
Posts: 562
Tested and it works fine. Testing code:
Code:
class Program
    {
        static Framework framework;
        static IDataProvider dataProider;
        static long totalBarCount = 0;
        static int barFactoryBarSize = 10;

        static List<Instrument> subscribedInstruments = new List<Instrument>();
        static List<string> symbols = new List<string>() { "@NQ#" };

        static void Main(string[] args)
        {
            framework = Framework.Current;
            framework.Mode = FrameworkMode.Realtime;

            dataProider = framework.ProviderManager.GetDataProvider(ProviderId.IQFeed);
            dataProider.Connect();

            while (!dataProider.IsConnected) { }

            framework.EventManager.Dispatcher.Bar += Dispatcher_Bar;
            framework.EventManager.Dispatcher.Trade += Dispatcher_Trade;

            Subscribe();

            Console.ReadLine();
        }

        private static void Subscribe()
        {
            foreach (var symbol in symbols)
            {
                Instrument instrument = framework.InstrumentManager[symbol];

                if (instrument != null)
                {
                    framework.SubscriptionManager.Subscribe(dataProider, instrument);
                    framework.EventManager.BarFactory.Add(instrument, BarType.Tick, barFactoryBarSize);
                    subscribedInstruments.Add(instrument);
                }
                else
                {
                    Console.WriteLine($"Instrument with symbol {symbol} doesn't exist. Skipping!");
                }
            }
        }

        private static void Dispatcher_Trade(object sender, Trade trade)
        {
            Console.WriteLine(trade);
        }

        private static void Dispatcher_Bar(object sender, Bar bar)
        {
            Console.WriteLine(bar);
        }
    }


You can see in log two types of bar: 10 tick and 5 seconds, second type is coming from IQFeed streaming bars.
Log:
Code:
17.10.2019 12:39:21 Event manager thread started: Framework =  Clock = Simulation
17.10.2019 12:39:21 Data manager thread started: Framework =  Clock = Simulation
Can not create provider type SmartQuant.CX.Currenex, SmartQuant.CX
Can not create provider type SmartQuant.DW.FIX.DriveWealth, SmartQuant.DW
Can not create provider type SmartQuant.DW.REST.DriveWealth, SmartQuant.DW
Can not create provider type SmartQuant.HS.Hotspot, SmartQuant.HS
Can not create provider type SmartQuant.IB.IBTWS, SmartQuant.IB
Can not create provider type SmartQuant.ID.Integral, SmartQuant.ID
Can not create provider type SmartQuant.KB.Kibot, SmartQuant.KB
Can not create provider type SmartQuant.MX.MoexFAST, SmartQuant.MX
Can not create provider type SmartQuant.NN.Nordnet, SmartQuant.NN
Can not create provider type SmartQuant.OEC.OpenECry, SmartQuant.OEC
Can not create provider type SmartQuant.QB.QuantBase, SmartQuant.QB
Can not create provider type SmartQuant.QB2014.QuantBase2014, SmartQuant.QB2014
Can not create provider type SmartQuant.QR.QuantRouter, SmartQuant.QR
Can not create provider type SmartQuant.QR2014.QuantRouter2014, SmartQuant.QR2014
Can not create provider type SmartQuant.QR2014.QuantRouter2014Multi, SmartQuant.QR2014
Can not create provider type SmartQuant.Quandl.QuandlAPI, SmartQuant.Quandl
Can not create provider type SmartQuant.TT.TTAPI, SmartQuant.TT
Can not create provider type SmartQuant.TT.TTFIX, SmartQuant.TT
[IQFeed] Status: Disconnected -> Connecting
[IQFeed] Status: Connecting -> Connected
SubscriptionManager::Subscribe provider id = 54 IQFeed (IQFeed provider) http://www.iqfeed.net @NQ#
Trade 17.10.2019 12:39:27 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:28 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:28 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:28 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:28 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:28 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:29 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:31 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:31 54 11 7961,75 1 -1
Bar [17.10.2019 5:29:25 - 17.10.2019 5:29:30] Instrument=11 Type=Time Size=5 Open=7961,75 High=7961,75 Low=7961,5 Close=7961,5 Volume=12
Bar [17.10.2019 12:39:27 - 17.10.2019 12:39:31] Instrument=11 Type=Tick Size=10 Open=7961,75 High=7962 Low=7961,5 Close=7962 Volume=10
Trade 17.10.2019 12:39:31 54 11 7962 1 -1
Trade 17.10.2019 12:39:31 54 11 7962 1 -1
Trade 17.10.2019 12:39:31 54 11 7962 1 -1
Trade 17.10.2019 12:39:31 54 11 7962,25 1 -1
Trade 17.10.2019 12:39:31 54 11 7962,25 1 -1
Trade 17.10.2019 12:39:31 54 11 7962,25 11 -1
Trade 17.10.2019 12:39:31 54 11 7962 1 -1
Trade 17.10.2019 12:39:31 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:31 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:31 54 11 7961,75 1 -1
Bar [17.10.2019 12:39:31 - 17.10.2019 12:39:32] Instrument=11 Type=Tick Size=10 Open=7962 High=7962,25 Low=7961,75 Close=7961,75 Volume=20
Trade 17.10.2019 12:39:32 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:32 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:32 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:32 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:32 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:32 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:32 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:32 54 11 7961,5 1 -1
Trade 17.10.2019 12:39:33 54 11 7961,75 1 -1
Trade 17.10.2019 12:39:33 54 11 7961,5 1 -1
Bar [17.10.2019 12:39:32 - 17.10.2019 12:39:34] Instrument=11 Type=Tick Size=10 Open=7961,5 High=7962,25 Low=7961,5 Close=7962,25 Volume=10
Trade 17.10.2019 12:39:34 54 11 7962,25 1 -1
Trade 17.10.2019 12:39:34 54 11 7962,25 1 -1
Trade 17.10.2019 12:39:34 54 11 7962,25 1 -1
Trade 17.10.2019 12:39:34 54 11 7962,25 1 -1
Trade 17.10.2019 12:39:34 54 11 7962,25 1 -1
Trade 17.10.2019 12:39:40 54 11 7962,5 1 -1
Bar [17.10.2019 5:29:30 - 17.10.2019 5:29:35] Instrument=11 Type=Time Size=5 Open=7961,75 High=7962,25 Low=7961,5 Close=7962,25 Volume=37
Trade 17.10.2019 12:39:40 54 11 7962,5 1 -1
Trade 17.10.2019 12:39:41 54 11 7962,5 1 -1
Trade 17.10.2019 12:39:41 54 11 7962,5 1 -1
Trade 17.10.2019 12:39:42 54 11 7962,5 1 -1
Bar [17.10.2019 12:39:34 - 17.10.2019 12:39:45] Instrument=11 Type=Tick Size=10 Open=7962,25 High=7962,75 Low=7962,25 Close=7962,75 Volume=10
Trade 17.10.2019 12:39:45 54 11 7962,75 1 -1
Trade 17.10.2019 12:39:45 54 11 7962,5 1 -1
Trade 17.10.2019 12:39:45 54 11 7962,75 1 -1
Trade 17.10.2019 12:39:45 54 11 7962,75 1 -1
Trade 17.10.2019 12:39:45 54 11 7962,75 1 -1
Trade 17.10.2019 12:39:45 54 11 7963 1 -1
Trade 17.10.2019 12:39:45 54 11 7963 1 -1
Trade 17.10.2019 12:39:45 54 11 7963 1 -1
Trade 17.10.2019 12:39:45 54 11 7962,75 1 -1
Trade 17.10.2019 12:39:45 54 11 7962,75 1 -1
Bar [17.10.2019 12:39:45 - 17.10.2019 12:39:45] Instrument=11 Type=Tick Size=10 Open=7962,5 High=7963 Low=7962,5 Close=7962,75 Volume=10
Trade 17.10.2019 12:39:45 54 11 7962,75 1 -1
Trade 17.10.2019 12:39:46 54 11 7963 1 -1
Bar [17.10.2019 5:29:40 - 17.10.2019 5:29:45] Instrument=11 Type=Time Size=5 Open=7962,5 High=7963 Low=7962,5 Close=7962,75 Volume=16


Top
 Profile  
 
PostPosted: Mon Oct 21, 2019 4:52 pm 
Offline

Joined: Mon Sep 02, 2019 10:31 am
Posts: 27
Thanks!

It works now. I think I was missing setting framework's mode to realtime. :oops:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page Previous  1, 2

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group