QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.83k stars 3.26k forks source link

Add Security with real exchange (not the general one which is Market.USA) not working #4437

Closed aytacasan closed 4 years ago

aytacasan commented 4 years ago

Expected Behavior

After add security to srategy with initialize method, expecting to receive it's data (tick and/or bar) with OnData method.

Actual Behavior

Never calling OnData method.

Potential Solution

I'm not sure and don't understand why i have to use Market.USA when add seurity to algorithm. Maybe the problem is IQFeedDataQueueUniverseProvider.cs code files's LoadSymbols method adding all equities with Market.USA.

Reproducing the Problem

  1. Create new algorithm.
  2. Inside algorith class define private field. private int _code = 100;
  3. Inside algorith class write private method. private void AddMarketIfNotExist(string market) { var code = Market.Encode(market.ToLower()); if (code == null) { Market.Add(market, _code++); } }
  4. Override Initialize method and add nasdaq market. AddMarketIfNotExist("NASDAQ");
  5. Beucase you'll receive an error message when call AddSecurity method. First define market hours for the new market which is NASDAQ. var entry = MarketHoursDatabase.GetEntry(Market.USA, string.Empty, SecurityType.Equity); MarketHoursDatabase.SetEntry("nasdaq", string.Empty, SecurityType.Equity, entry.ExchangeHours, entry.DataTimeZone);
  6. Then you can add a security to algorithm. AddSecurity(SecurityType.Equity, "AAPL", Resolution.Minute, "nasdaq", false, 0, true);
  7. Override OnData and put breakpoint to start of the method. Run the solution and wait the first data(tick or bar, in this case tradebar).

System Information

Windows 10 IQFeed Client Visual Studio 2019

Checklist

adam-may commented 4 years ago

@aytacasan - most US equities are listed on multiple exchanges. To help with this, there's a "logical exchange" (for want of a better word) - Market.USA, which is the one equities currently support. I believe at this point in time, only futures support the market in the way you're trying to use them

jaredbroad commented 4 years ago

The market segmentation is based on whether the asset is fungible. e.g. Can you buy on IEX and sell on NASDAQ? Yes; so they're all under Market.USA

Perhaps @aytacasan you could zoom out a little and share what you're trying to achieve with IQFeed? You do not need to edit the markets to use Equities+IQFeed.