Back

Post Request With Header

Hello,

So I am trying to use the Webhook tool to send notifications about the orders I make. The server which I am sending the notifications to requires that I provide authorization in a header that goes along with any post requests that I make. So, I would like to do a webhook notification with a header.The webhook notification has the following form: self.Notify.Web("myServer.com", data). It has only two parameters, the website, and the data. So unfortunately there does not seem to be a way of adding in the header that I need for authentication. Is there some other way to do this? When I tried just using the post function from the requests library in python, I got an error. Thanks in advance for any help!

Update Backtest







0

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.


Notifications don't have this feature (but they should, I'll try to keep it in mind). But we do have the self.Download() endpoint which you could use for this sort of behavior:

Download(string address, IEnumerable<KeyValuePair<string, string>> headers, string userName, string password)

# Used like this:
self.Download("mywebsite.com", optional-dict-headers, "optional user", "optional password")
https://github.com/QuantConnect/Lean/blob/master/Algorithm/QCAlgorithm.cs#L2135

 

0

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.


Hi Jared,

 

Thank you for the reply. I keep getting a 403 forbidden and a 443 port error when trying to do post requests like this:

numShares = int(self.CalculateOrderQuantity("TQQQ",1.00))
headers = {
'Content-Type': 'application/json',
'Authorization': 'xx',
}

data = '[{"instrumentId": xx", "shares": %s}]\n'%(numShares)
response = requests.post('https://xxxx', headers=headers, data=data)

This is the error. I do not know it is on my end or yours.

 

Runtime Error: In Scheduled Event 'EveryDay: 9.52', ProxyError : HTTPSConnectionPool(host=xxx', port=443): Max retries exceeded with url: xxx (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',)))
at Rebalance in main.py:line 88
ProxyError : HTTPSConnectionPool(host='xxx', port=443): Max retries exceeded with url: xxx (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',))) (Open Stacktrace)

Thanks,

Ken

1

Hi Ken Hampel ,

For security reasons, algorithms cannot make post requests.
We will look into adding a parameter for the authentication header in Notify,Web method.

1

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.


Update Backtest





0

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.


Loading...

This discussion is closed