0
votes

I'm looking for a way to send an identification of a user in the message of a webhook. The user should be able to input their ID and it should be sent in the message when the webhook alert is triggered. So far I have not been able to use custom variables in the message and it seems this is not supported.

myID = input(title="myID", type=input.string, defval="1000")

//===============================
// Alert to trigger Buy
//===============================
alertcondition([YourAlertCondition], title = "Buy", message = "{\"side\": \"Buy\", \"symbol\": \"ASSETNAME\", \"type\": \"Market\", \"amount\": \"20\", \"takeProfit\": \"1\", \"stopLoss\": \"1\", \"trailingStop\": \"None\", \"new_trailing_active\": \"None\", \"Leverage\": \"1\", \"TelegramID\":"+{{myID}}}+"")

Expected Output:

{"side": "Sell", "symbol": "ASSETNAME", "type": "Market", "amount": "20", "takeProfit": "1", "stopLoss": "1", "trailingStop": "None", "new_trailing_active": "None", "Leverage": "1", "myID": "1000" }

The method above is what I have tried with some variations. If it's not possible to use a variable, is there a way to output the user's TradingView username in the message? If that's possible the TradingView username can be used as the ID on the receiving server.

1

1 Answers

0
votes

You could use the alert function instead of alertcondition, in your case you could use:

msg = '{' + str.format('\"side\": \"Buy\", \"symbol\": \"ASSETNAME\", \"type\": \"Market\", \"amount\": \"20\", \"takeProfit\": \"1\", \"stopLoss\": \"1\", \"trailingStop\": \"None\", \"new_trailing_active\": \"None\", \"Leverage\": \"1\", \"TelegramID\":"{0}"',myID) + '}'

if YourAlertCondition
    alert(msg,alert.freq_once_per_bar_close)

see the refman on alert.