def webhook(): """Combine all functions in actions.py, and run flask server""" if request.method == 'POST': print('*' * 60) # Parse the string data from tradingview into a python dict data = parse_webhook(request.get_data(as_text=True))[0] tail = parse_webhook(request.get_data(as_text=True))[1] message = tail if (data['type'] != "Skip") and (get_token() == data['key']): # Check that the key is correct print(' [Alert Received] ') print(tail) for account, account_info in config.Accounts.items(): if account_info['Name'] in data['BotName']: exchange = ccxt.ftx({ 'apiKey': account_info['exchangeapi'], 'secret': account_info['exchangesecret'], 'enableRateLimit': True, }) if account_info['Subaccount'] == 'Yes': exchange.headers = { 'FTX-SUBACCOUNT': account_info['SubName'], } send_order(data, tail, exchange, account_info['Name'], account_info['Track']) if account_info['UseTelegram'] == 'Yes': send_to_telegram(tail, data) if account_info['UseTwitter'] == 'Yes': post_tweet(message) else: pass return '', 200 if data['type'] == "Skip": print(' [ALERT ONLY - NO TRADE] ') print(tail) for account, account_info in config.Accounts.items(): if account_info['Name'] in data['BotName']: if account_info['UseTelegram'] == 'Yes': send_to_telegram(tail, data) if account_info['UseTwitter'] == 'Yes': post_tweet(message) print('*' * 60, '/n') return '', 200 else: abort(400)
def webhook(): if request.method == 'POST': # Parse the string data from tradingview into a python dict data_msg = parse_webhook(request.get_data(as_text=True)) print(data_msg) print("===========================================================================") if data_msg: print(' [Alert Received] ') return '', 200 else: abort(403) else: abort(400)
def webhook(): if request.method == 'POST': # Parse the string data from tradingview into a python dict data = parse_webhook(request.get_data(as_text=True)) # Check that the key is correct if get_token() == data['key']: print(' [Alert Received] ') print('POST Received:', data) send_order(data) return '', 200 else: abort(403) else: abort(400)
def webhook(): if request.method == 'POST': # Parse the string data from tradingview into a python dict data = parse_webhook(request.get_data(as_text=True)) # Check that the key is correct if get_token() == data['key']: logger.log("SIGNAL", "{} | Incoming Signal: {}", data['algo'], data['side']) process_alert(data) return '', 200 else: logger.error("Incoming Signal From Unauthorized User.") abort(403) else: abort(400)
def webhook(): if request.method == 'POST': # Parse the string data from tradingview into a python dict datas = parse_webhook(request.get_data(as_text=True)) print(datas) # Check that the key is correct if get_token() == datas['key']: print(' [Alert Received] ') print('POST Received/Updated Data:', datas) send_order(datas) return '', 200 else: logger.error("Incoming Signal From Unauthorized User.") abort(403) else: abort(400)
def webhook(): if request.method == 'POST': # Parse the string data from tradingview into a python dict data = parse_webhook(request.get_data(as_text=True)) # Check that the key is correct if get_token() == data['key']: print(' ---------- TradingView Alert Received!! ---------- ') if data['move'] == 'Long': send_long_order(data) set_trailing(data) else: #send_short_order(data) print("not shorting right now!") return '', 200 else: abort(403) else: abort(400)
def webhook(): if request.method == 'POST': # Parse the string data from tradingview into a python dict data = parse_webhook(request.get_data(as_text=True)) # Check that the key is correct if get_token() == data['token']: print(' [Alert Received] ') print('POST Received:', data) app.logger.info("POST Received:%s", data) if data['action'] == 'long' or data['action'] == 'short close': res = client.place_order('buy', 'XBTUSD', 2) return res[0].__str__(), 200 if data['action'] == 'short' or data['action'] == 'long close': res = client.place_order('sell', 'XBTUSD', 2) return res[0].__str__(), 200 else: abort(403) else: abort(400)
# Example Order # https://github.com/ccxt/ccxt/wiki/Manual#symbols-and-market-ids # symbol = 'BTC/USD' # type = 'limit' # side = 'buy' # amount = 0.01 # price = 7000 def post_test(): ''' <Response[200]> = PASS <Response[405]> = FAIL <Response[500] = FAIL ''' r = requests.post('http://localhost:5000/webhook', data=str({"type": "limit", "side": "buy", "amount": "10", "symbol": "BTC/USD", "price": "7000", "key": "99fb2f48c6af4761f904fc85f95eb56190e5d40b1f44ec3a9c1fa319"})) print(r) x = parse_webhook(str({"type": "limit", "side": "buy", "amount": "10", "symbol": "BTC/USD", "price": "7000", "key": "99fb2f48c6af4761f904fc85f95eb56190e5d40b1f44ec3a9c1fa319"})) print("Sending POST") print(x) if post_test() != "200": print("Tests pass") else: print("Tests fail")