How do alerts work?

The basics

Huskly alerts are predefined sets of rules that trigger specific events based on some specific activity that matches its rules. Currently, Huskly only supports alerts that are sent whenever a new order is filled on your account. However, in the future, we will have more alert triggers, for example, for stock price movements, trading signals, etc.

An example

Consider that you just opened ThinkOrSwim and decided to buy 10 shares of AAPL for $100 (hypothetically speaking) and you have an alert configured to be sent to https://example.com/alerts on new orders in your account. As soon as your AAPL shares are bought, your alert will be triggered because buying or selling stock involves sending a new order to your broker (TD Ameritrade) which was then "filled". A "filled" order means it was matched with a counterparty in an exchange (a buy order was matched with a seller or a sell order matched with a buyer).
Currently, Huskly alerts are delivered via webhooks. Put simply, a webhook is a HTTP POST request sent to a predefined URL (configured in your alert settings, in this example, https://example.com/alerts).

Alert triggering

As soon as Huskly picks up your new order, a POST request will be issued to https://example.com containing the message payload as configured. Your alert message may contain placeholder data variables specific to your order. The currently suppported variables are: side, amount, symbol, price and timestamp. Variables need to be enclosed with ${variable}, eg.: ${symbol}. For the AAPL example above, your message would look somewhat like the one below:
"Buy 10 AAPL for $100 at 12-31-2022 01:42:54 PM UTC"

Delivery timing

We cannot guarantee how quickly alerts will be triggered because that depends primarily on how quickly TDA will have your order details available through their API after your order is filled. However, In general, you can expect alerts to be delivered within 1-2 minutes after your order is filled. Again, this may fluctuate and there are no guarantees here. If you notice any missing alert deliveries or extraordinarily slow ones, please contact our support for further investigation.

Conclusion

Alerts are a powerful way to consume trading events and integrate with other services. You can for example have alerts be delivered to a Telegram group, Discord, Slack, Twitter, etc.