Hello,
I need to be able to trade in the after hours of the market, and I've read that IB and Quantconnect support it. However, I cannot find a solid exmple on how to request trading hours.
This is what is in the documentation:
AddEquity(string ticker,
Resolution resolution = Resolution.Minute,
string market = Market.USA,
bool fillDataForward = true,
decimal leverage = 0m,
bool extendedMarketHours = false)
Obviously this cannot be run as is. In Python, should the true and false arguments be strings or the native True and False functions of Python? Also, when I run the code, I get an AttributeError : USA.
I'm not doing something right, and I need to know how fix it. Any advice on what and what not to do when trading after hours would be much appriciated as well.
Thanks,
Malachi
Quant Trader
Hi,
Do you have a piece of (simpel) code you with an security you want to trade after market hours? I guess you get more data returned from the subscriptionmanager if I read the source code right:
// Add the symbol to Data Manager -- generate unified data streams for algorithm events var configList = new SubscriptionDataConfigList(symbol); configList.AddRange(from subscriptionDataType in subscriptionDataTypes let dataType = subscriptionDataType.Item1 let tickType = subscriptionDataType.Item2 select subscriptionManager.Add(dataType, tickType, symbol, resolution, dataTimeZone, exchangeHours.TimeZone, isCustomData, fillDataForward, extendedMarketHours, isInternalFeed, isFilteredSubscription));
Malachi Bazar
Hello,
I was under the impression that I need to change some default paramater when I add an exquity.
Here is an example of the equity that I want to trade during after hours. I just need to know how to fill this out:
self.xiv = self.AddEquity("XIV", Resolution.Hour, Market.USA, "true", "0m", "true").Symbol
When I run as is, I get:
Python.Runtime.PythonException: AttributeError : USA
I'm guessing that I'm not doing something right when I call Market.USA.
Thanks,
Malachi
Jared Broad
self.AddEquity("SPY", Resolution.Minute, Market.USA, True, 1, True)
The above snippet works fine. Boolean parameters are either True or False; leverage should be at least 1. Unless required for some reason I'd just put things on 1 line instead of spacing them over multiple lines. The documentation spaced them out for clarity.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Malachi Bazar
Thanks Jared,
I implimented your example as follows:
self.xiv = self.AddEquity("XIV", Resolution.Hour, Market.USA, True, 1, True).Symbol
When I run this, I get:
Python.Runtime.PythonException: AttributeError : USA
Am I not importing a libary correctly? Here's the rest of my initialize definition:
from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Data import * import numpy as np from datetime import timedelta import math class BasicTemplateAlgorithm(QCAlgorithm): def Initialize(self): # Set the cash we'd like to use for our backtest # This is ignored in live trading self.SetCash(37000) # Set benchmark self.SetBenchmark("XIV") # Start and end dates for the backtest. # These are ignored in live trading. self.SetStartDate(2013,06,8) self.SetEndDate(2018,1,23) #Assets predetermined self.vxx = self.AddEquity("UVXY", Resolution.Hour).Symbol self.xiv = self.AddEquity("XIV", Resolution.Hour, Market.USA, True, 1, True).Symbol self.spy = self.AddEquity("SPY", Resolution.Hour).Symbol
Thanks,
Malachi
Jared Broad
Strange one but turned out just needed another import at the top of the main.py. The import must've been in the basic template but wasn't in your headers.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Malachi Bazar
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!