Guide
Send alerts from your Python script to your broker
Any program that can make an HTTPS request can send alerts to a Nyria strategy, and a Python script with the requests library is the shortest version of one. This guide shows where the webhook URL comes from, the fields the webhook reference documents, a minimal sender that posts one stock market buy, how to read the response and the strategy's Logs tab, and how to check a message in the alert tester before the first real post. Paper first, then live.
The webhook URL
- 1
Copy the webhook URL
Create a strategy with Custom webhook as the alert source, open its Integration tab and copy the webhook URL. It has the form https://trades.nyria.io/webhooks/{your_strategy_token}: the token at the end is a 64-character lowercase hexadecimal string with no prefix, and each strategy has its own.
- 2
Keep the token private
The token in the path is the endpoint's only authentication. There is no Authorization header, no signature header and no IP allowlist, so treat the URL like an API key. If it leaks, select Rotate token on the Integration tab: the old URL stops working at once, so update every sender that used it.
- 3
Check the format, then activate
On the Integration tab, give one example alert per trade type and select Check format. The strategy goes Active once its alert format passes, and a strategy that is a draft, paused or archived answers every post with rejected.
The fields the webhook documents
Apart from the ticker and the action, every field is optional. Send one only to state what the strategy cannot work out, or to override its settings for one alert.
- ticker, instrument or symbol
- The ticker, such as SPY or BTCUSD. All three keys mean the same thing.
- action
- OPEN or CLOSE for entries and exits, or MODIFY or CANCEL for order management. Nyria also accepts and maps buy, sell, entry and exit.
- direction
- LONG or SHORT. Send it with OPEN and CLOSE.
- price
- A limit price as a decimal, used when order_type is limit or the strategy's limit target is Alert price.
- order_type
- market or limit. Overrides the strategy's order type for this one alert, on an alert that names action and direction. Leave it out to use the strategy's order type.
- marketPosition, prevMarketPosition
- TradingView's position fields, long, short or flat. Send both and Nyria works out the action and direction from the change.
- metadata.message_id
- A value Nyria compares to spot duplicates instead of hashing the whole body.
- legs
- On an options strategy set to Provided in alert, one entry per leg: symbol, side, action, strike, expiration, price and live_price. Leave it out on a From my rules strategy.
An alert cannot set the entry size. Size always comes from the bot's settings, and Nyria ignores a quantity or notional key on an entry alert. How long an order stays open comes from the strategy's Duration setting; the alert has no field for it. Nyria places market and limit orders only, on every broker.
A minimal sender
One documented message, a stock market buy, posted with the requests library. On a long-only stock strategy with AAPL in its ticker list, this opens a long at market.
send_alert.py
import requests
WEBHOOK_URL = "https://trades.nyria.io/webhooks/REPLACE_WITH_YOUR_TOKEN"
payload = {
"ticker": "AAPL",
"action": "OPEN",
"direction": "LONG",
"order_type": "market",
}
r = requests.post(WEBHOOK_URL, json=payload, timeout=10)
r.raise_for_status()
body = r.json()
if body.get("status") == "processed":
print("Nyria read the alert and handed it to the bots")
else:
print("Nyria did not act on it:", body)The body names its action and direction, so Nyria reads order_type on it and sends a market order whatever order type the strategy is set to. raise_for_status() turns a 4xx or 5xx into an exception your retry logic can see. It does not catch a rejection or a duplicate, which answer 200, so check status too. Always set a timeout: Nyria answers quickly, but a hung socket can stall your sender. To close the position later, post the same ticker with action CLOSE and direction LONG; Nyria closes the whole open position, and there is no partial-close field.
To rest a limit order instead, send order_type as limit with a price. At a broker the order rests at your price until it fills or is canceled; Nyria Paper fills it immediately or refuses it. MODIFY re-prices the working order on that side, on Tradier and Alpaca only, and CANCEL pulls a resting entry before it fills. Neither one opens a trade, and a market order that filled is a position, so close it with CLOSE.
Reading the response and the Logs tab
Nyria answers with an HTTP status code and a JSON body. A structured error carries class, code and userMessage. Have your sender log or alert on anything that is not processed.
- 200, status processed
- Nyria read the alert and handed it to your bots. Check the bot's Logs tab for the fill.
- 200, rejected true
- The strategy is not Active: a draft, paused or archived.
- 200, status rejected
- The ticker is not in the strategy's list, that direction is turned off, or there is no open position to close. The reason is in the body.
- 200, status duplicate
- The body repeats an earlier one. Change the body if you meant to repeat it.
- 400 or 404
- The token in the URL is malformed, or no strategy has it. Copy the URL again.
- 413
- The payload is larger than 256 KB.
- 422
- Nyria could not use the alert: a missing field, unreadable text, an unknown symbol, no matching strike or DTE range, or more than 4 option legs. userMessage names the cause.
- 429
- Over the limit of 10 alerts at once, then 1 a second. Nyria dropped it; wait as long as Retry-After says, then resend.
- 503
- Reading the alert or fetching market data failed temporarily. Sending the same alert again can succeed.
- 500
- Any other failure, such as a missing price when the strategy takes its limit price from the alert. The Logs tab has the reason.
A 200 means Nyria read the alert and passed it to your bots. It does not mean the broker filled anything. The strategy's Logs tab has a row per alert, and a rejected or failed one carries its reason; the bot's Logs tab shows what the broker did. If there is no row at all, the request never reached Nyria: check the URL, and that the sender uses https.
If your script retries after a network failure, Nyria catches the repeat: an identical body again within 30 seconds is a duplicate. So is one within 5 minutes with nothing else in between. Only the first places an order. To scale into the same position on purpose, make the body differ, or set a unique metadata.message_id per intended order.
Check the message first
Before the script posts anything, paste the body into the alert tester, choose Webhook as the source and the asset type, and read the order Nyria would send: open or close, long or short, the order type, and for options each leg's strike, side and expiry. When Nyria would not trade the alert, it shows the refusal word for word, the most common being a message with no trade in it. Nothing is traded and no account is needed. Then give the same body on the strategy's Integration tab as the example for that trade type and select Check format.
The webhook reads a line of text too, such as SPY long entry sent as text/plain, and the tester reads it the same way. JSON is the better format when you control the sender: it carries order_type, price and option legs, and it answers with codes your retry logic can act on.
Paper first, then live
Deploy the first bot on Nyria Paper, the free simulated broker built into Nyria: one click, no credentials, and the free plan runs up to 10 paper bots with no time limit. Run the script against it, then open the bot in Nyria and check the order is there: with the payload above you see an AAPL market buy at the bot's size. Nyria Paper fills or refuses each order at once. When the paper run reads right, deploy a bot on the broker account, Charles Schwab, Tradier, tastytrade or Alpaca, or edit the paper bot to use it. The same payload works for every connectable broker: Nyria converts it into that broker's order format.
Every field, with curl examples for each broker, is in the webhook payload reference, and the setup walk-through is Send alerts from your own bot in the docs. The short version is on the custom webhook alert source page.
Questions
- Can the alert set how many shares to buy?
- No. Size always comes from the bot's settings, and Nyria ignores a quantity or notional key on an entry alert. The one exception is MODIFY, which can re-size an order that is already working, on Tradier and Alpaca.
- Does the script need a signature or an API key?
- No. The token in the webhook URL is the only authentication, so keep the URL private and rotate it from the Integration tab if it leaks.
- What does it cost?
- Paper is free. Live trading from $15 a month.
Guides
Automate trading alerts into broker orders
What an alert is, three ways to automate it, and what to check before you trust it.
TradingView webhook not working: a checklist
Six checks, most common first: script type, the URL box, expiry, the message, the bot, and where the reason is logged.
TrendSpider alerts to your broker, automatically
How an Alert or Strategy Bot webhook reaches Nyria, what the message must say, which brokers and asset types, paper first.
Point the script at a paper bot first
Paper is free. Live trading from $15 a month.