5

I'm trying to have alerts sent via webhook (TradingView's new feature) to a python program, and use them to make trades with Alpaca.

I tried using ngrok plus this script I found on Github:

https://github.com/Robswc/tradingview-webhooks-bot

After changing the port to 80 (no other port seems to work, I think this is on TradingView's end) I finally got something to come through:

127.0.0.1 - - [25/Dec/2019 21:26:45] code 400, message Bad request version ('À\x14À')
127.0.0.1 - - [25/Dec/2019 21:26:45] " Ì  ÈÁÄJÂ$/g{$¹¦HºÏE(·úå[:Ü´J÷ D+µ6ÑfYxºûáÙØkc`¸Ø­°ÜAzÜ  À/À0À+À,̨̩ÀÀ   ÀÀ" HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [25/Dec/2019 21:26:51] code 400, message Bad request version ('À\x14À')
127.0.0.1 - - [25/Dec/2019 21:26:51] " Ì  ÈÃE¿¾GЪ6áe>ÃÝnI6MÚ3YÖ·¦7Ñ ïþG{äÉýCVÙA$ºÕ0ÒBô2õ+px¶  À/À0À+À,̨̩ÀÀ   ÀÀ[0m" HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [25/Dec/2019 21:27:47] code 400, message Bad request version ('À\x14À')
4s"H  À/À0À+À,̨̩ÀÀ    ÀÀ" HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [25/Dec/2019 21:27:52] code 400, message Bad HTTP/0.9 request type ('\x16\x03\x01\x00Ì\x01\x00\x00È\x03\x03\x92¯;H\x9c\x91ÁD7³\x04ʵù¶Óf\x9bzúÊä')
127.0.0.1 - - [25/Dec/2019 21:27:52] " Ì  ȯ;HÁD7³Êµù¶ÓfzúÊä Åïn@g" HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [25/Dec/2019 21:27:58] code 400, message Bad request version ('À\x14À')
127.0.0.1 - - [25/Dec/2019 21:27:58] " Ì  ÈèÊh>Rd-«RN?Æ©Àh¯`á-õ¿  űE`²ÈìþW\y¼DÅî¿=9ÒüX  À/À0À+À,̨̩ÀÀ ÀÀ" HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [25/Dec/2019 21:28:03] code 400, message Bad request version ('À\x14À')
127.0.0.1 - - [25/Dec/2019 21:28:03] " Ì  ȸêó^é:÷gPç©àóÛq}/p¬<ÉN ö3Ð<½w,øÒpa0&`¬[tý( »ÎV   À/À0À+À,̨̩ÀÀ  ÀÀ" HTTPStatus.BAD_REQUEST -

Anyone have any idea how to get this working? I'm just trying to send some json to the webhook on my local machine, then I can use Alpaca functions to make trades with it. Thanks in advance for any advice you can provide, and please let me know any information that can help further solve this, and I will gladly add it.

Wayne Filkins
  • 317
  • 1
  • 5
  • 14
  • Where do you store your auth token? Have you submitted an issue on GitHub? 400 error is obviously a bad request, so it might be an auth issue. What about using the alpaca-api library? https://github.com/alpacahq/alpaca-trade-api-python/ – Mark Moretto Dec 26 '19 at 02:59
  • 1
    Is timing essential on this? Looking at some of this code, why would you want to print something out before executing the order? https://github.com/Robswc/tradingview-webhooks-bot/blob/master/tradingview-webhooks-bot/actions.py – Mark Moretto Dec 26 '19 at 03:01
  • I believe the issue is between TradingView and the client machine, not between client and the exchange. I'm not going to use ccxt, that's just what it comes with. Once I get the message to go through via webhook, then i'm going to replace ccxt with Alpaca. First I need to get the alert message through the webhook to the client. – Wayne Filkins Dec 26 '19 at 03:17
  • My first issue was no auth token. I then added it to the folder with ngrok.exe in it. I was getting some other error until I created the auth file. Now the only thing I can get through is that jibberish that I pasted above. I may be using the wrong ngrok command as i'm new to ngrok, but everything else I try gives the other error (I think it's 405, not authorized) – Wayne Filkins Dec 26 '19 at 03:20
  • If anyone wants to try to replicate, you can install the github repo, and run the script and run ngrok and if you give me the ngrok url I can enter it into my alert box and see what you get. I can also send Tradingview's info on using webhook alerts. It says something about only using port 80 or 443 so I think that's why 80 is working for me. Also i'm on Windows 10...this is where I assumed the issue started. I may try on my Ubuntu VPS next. – Wayne Filkins Dec 26 '19 at 03:23
  • Solved it. I had to put /webhook after the ngrok url. – Wayne Filkins Dec 27 '19 at 20:33
  • Great! Wow, that's weird, but I'm glad you found the answer. – Mark Moretto Dec 27 '19 at 20:51

1 Answers1

5

The NGROK url needed /webhook after it. This got me past the 405 error. The other error was caused by running it on port 80 and using http instead of https. I don't know why this is, but I basically switched it to port 5000 (default port in the Github repo) and added /webhook after the NGROK address and now it's working as it should.

Wayne Filkins
  • 317
  • 1
  • 5
  • 14
  • Sidebar, but you can easily and programmatically manage `ngrok` from Python application using `pyngrok`. [Here are the](https://pyngrok.readthedocs.io/en/latest) docs, if you're interested. – alexdlaird Apr 26 '20 at 23:30
  • I don't think this is an efficient way, as it has to go through a couple of networking layer. I hope TV could provide a better solution – DennisLi Aug 08 '21 at 10:49