2

I'm trying to trigger a python module (market order for Oanda) using web hooks(from trading view).

Similar to this

1) https://www.youtube.com/watch?v=88kRDKvAWMY&feature=youtu.be and this 2)https://github.com/Robswc/tradingview-webhooks-bot

But my broker is Oanda so I'm using python to place the trade. This link has more information. https://github.com/hootnot/oanda-api-v20

The method is web hook->ngrok->python. When a web hook is sent, the ngrok (while script is also running) shows a 500 internal service error and that the server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

This is what my script says when its running (see picture);

First says some stuff related the market order then; running script picture One thing I noticed is that after Debug it doesn't say Running on... (so maybe my flask is not active?

Here is the python script;

from flask import Flask
import market_orders
# Create Flask object called app.
app = Flask(__name__)
# Create root to easily let us know its on/working.
@app.route('/')
def root():
    return 'online'
@app.route('/webhook', methods=['POST'])
def webhook():
    if request.method == 'POST':
        # Parse the string data from tradingview into a python dict
        print(market_orders.myfucn())
    else:
        print('do nothing')
if __name__ == '__main__':
    app.run()

Let me know if there is any other information that would be helpful.

Thanks for your help.

Michael
  • 37
  • 1
  • 5

1 Answers1

1

I fixed it!!!! Google FTW

The first thing I learned was how to make my module a FLASK server. I followed these websites to figure this out;

This link helped me set up the flask file in a virtual environment. I also moved my Oanda modules to this new folder. And opened the ngrok app while in this folder via the command window. I also ran the module from within the command window using flask run. https://topherpedersen.blog/2019/12/28/how-to-setup-a-new-flask-app-on-a-mac/

This link showed me how to set the FLASK_APP and the FLASK_ENV Flask not displaying http address when I run it

Then I fixed the internal service error by adding return 'okay' after print(do nothing) in my script. This I learned from;

Flask Value error view function did not return a response

Michael
  • 37
  • 1
  • 5