I am trying to develop new data plugin to be imported during my algo execution. Before deploying my service I want to test it locally. Is it possible to access localhost from docker container.
internal class EarningsDateDataType : BaseDataCollection
{
public DateTime EarningsReleaseDateTime { get; set; }
public override SubscriptionDataSource GetSource(
SubscriptionDataConfig config,
DateTime date,
bool isLive)
{
return new SubscriptionDataSource($"https://localhost:7165/EarningsDate?ticker={config.Symbol}", SubscriptionTransportMedium.RemoteFile, FileFormat.Csv);
}
public override BaseData Reader(SubscriptionDataConfig config, string line, DateTime date, bool isLiveMode)
{
var l = line.Replace(Environment.NewLine, string.Empty);
var s = DateTime.Parse(l);
return new EarningsDateDataType()
{
EarningsReleaseDateTime = s,
Symbol = config.Symbol
};
}
public override Resolution DefaultResolution()
{
return Resolution.Daily;
}
}
Mia Alissi
Yes, it is possible to access localhost from a Docker container. However, because algorithms run in a Docker container,
localhost
does not point to your computer'slocalhost
. You should substitutelocalhost
withhost.docker.internal
if your algorithm needs to connect to other services running on your computer. In other words, instead of connecting tohttp://localhost:<port>/
, connect tohttp://host.docker.internal:<port>/
.So, in your case, you should change the URL in the
GetSource
method fromhttps://localhost:7165/EarningsDate?ticker={config.Symbol}
tohttps://host.docker.internal:7165/EarningsDate?ticker={config.Symbol}
.Here is the updated code:
This information is based on the QuantConnect Documentation.
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.
Nikolay Zdravkov
Hi,
I am sorry, got COVID and was completely out of computer for several days. I've been asking this question from Mia assistance, but changing it to host.docker.internal doesn't help. Has anyone else tried this?
Mia Alissi
I'm sorry to hear that you're not feeling well, Nikolay. I hope you recover soon.
Regarding your issue, it's important to note that
host.docker.internal
is currently only guaranteed to work on Windows and Mac systems. If you're running Docker on a Linux system, this hostname may not be recognized, which could be the cause of the error you're seeing.If you're running Docker on a Mac or Windows system and still seeing this error, it could be due to a misconfiguration or issue with your Docker installation. In this case, you may want to try reinstalling Docker or checking your Docker settings to ensure that
host.docker.internal
is correctly mapped to your host's IP address.If you're still unable to solve your issues, you are welcome to contact the QuantConnect engineers by opening an issue in the QuantConnect/lean-cli repository on GitHub. Before doing so, please run the command that's giving issues with the
--verbose
flag and copy and paste the output into the issue. The--verbose
flag enables debug messages to be printed, which makes it easier for the engineers to help you. This information is mentioned in the Troubleshooting section of the documentation.I hope this helps and wish you a speedy recovery.
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.
Nikolay Zdravkov
Default behaviour of HttpClient in .NET is to verify validity of SSL certificate. When running server locally certificate is self-signed and usually issued only for localhost. To overcome this there is need to generate certificate for host.docker.internal domain. I've found answer on stackoverflow about this.
Mia Alissi
I'm glad you found a solution, Nikolay. Indeed, when running a server locally with a self-signed certificate, you may need to generate a certificate for the
host.docker.internal
domain to overcome SSL certificate validation issues. This is because the default behavior of HttpClient in .NET is to verify the validity of the SSL certificate.The StackOverflow answer you found seems to provide a good solution for this issue. For others who might encounter the same problem, here is the link to the StackOverflow answer Nikolay mentioned.
Remember, it's important to ensure the security of your connections, especially when dealing with financial data. Always use secure connections and validate SSL certificates when connecting to remote servers.
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.
Nikolay Zdravkov
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!