Webhooks
TradersPost allows third party applications like TradingView and TrendSpider to integrate with your connected brokers via webhooks.
Webhooks are automated messages sent from applications when something happens. They have a message that can contain a payload of data and are sent to a unique URL.
In the context of automated trading, the webhook message contains all the information about the trade signal like what ticker to buy and at what price. Here is an example simple webhook.
{
"ticker": "AMD",
"action": "buy"
}
Here is a full reference API documentation for the trading webhoook API end point.
post
https://webhooks.traderspost.io
/trading/webhook/{uuid}/{password}
TradersPost Webhook Request API documentation.
Here are some example webhook JSON payloads to demonstrate the different use cases.
{
"ticker": "SQ",
"action": "buy"
}
{
"ticker": "SQ",
"action": "exit"
}
You can also use the sentiment field to exit a bullish position without entering a bearish position on the other side. When you send sentiment=flat, it will always exit the full quantity of the open position.
{
"ticker": "SQ",
"action": "sell",
"sentiment": "flat"
}
{
"ticker": "SQ",
"action": "sell"
}
{
"ticker": "SQ",
"action": "exit"
}
You can also use the sentiment field to exit a bearish position without entering a bullish position on the other side. When you send sentiment=flat, it will always exit the full quantity of the open position.
{
"ticker": "SQ",
"action": "buy",
"sentiment": "flat"
}
Cancel all the open orders for the given ticker.
{
"ticker": "SQ",
"action": "cancel"
}
You can add to an existing open position by using the add action. This will add to the existing open position regardless of if Allow add to position is checked in your strategy subscription settings.
{
"ticker": "SQ",
"action": "add"
}
The signal quantity will only be used if you check Use signal quantity in the strategy subscription settings in TradersPost.
{
"ticker": "SQ",
"action": "buy",
"quantity": 5
}
The signal price is optional. If you omit a price from the signal, the mid point between the bid and the ask will be used if you have limit orders configured.
{
"ticker": "SQ",
"action": "buy",
"price": 60.30
}
You can optionally send take profit information with your entry signals.
The signal take profit will only be used if you check Use signal take profit in the strategy subscription settings in TradersPost.
The following fields are allowed on the takeProfit object.
- limitPrice - Absolute limit price calculated on the webhook sender side.
- percent: Relative percentage take profit to calculate relative to entry price. The entry price for market orders is estimated based on the mid point between the bid and ask on the most recent quote.
- amount - Relative dollar amount take profit to calculate relative to entry price. The entry price for market orders is estimated based on the mid point between the bid and ask on the most recent quote.
{
"ticker": "SQ",
"action": "buy",
"takeProfit": {
"percent": 10
}
}
{
"ticker": "SQ",
"action": "buy",
"takeProfit": {
"amount": 10
}
}
{
"ticker": "SQ",
"action": "buy",
"takeProfit": {
"limitPrice": 19.99
}
}
You can optionally send stop loss information with your entry signals.
The signal take profit will only be used if you check Use signal stop loss in the strategy subscription settings in TradersPost.
The following fields are allowed on the stopLoss object.
- type - Type of stop loss. If a value is provided, it overrides the stop loss type configured in strategy subscription settings. Allowed values are: stop, stop_limit, trailing_stop.
- percent: Relative percentage stop loss to calculate relative to entry price.
- amount - Relative dollar amount stop loss to calculate relative to entry price.
- stopPrice - Absolute stop price calculated on the webhook sender side.
- limitPrice - Absolute limit price calculated on the webhook sender side. type must be set to stop_limit to use this field.
- trailPrice - A dollar value away from the highest water mark. If you set this to 2.00 for a sell trailing stop, the stop price is always hwm - 2.00. type must be set to trailing_stop to use this field.
- trailPercent - A percent value away from the highest water mark. If you set this to 1.0 for a sell trailing stop, the stop price is always hwm * 0.99. type must be set to trailing_stop to use this field.
Percentage stop loss calculated relative to entry price.
{
"ticker": "SQ",
"action": "buy",
"stopLoss": {
"percent": 5
}
}
{
"ticker": "SQ",
"action": "buy",
"stopLoss": {
"amount": 5
}
}
{
"ticker": "SQ",
"action": "buy",
"stopLoss": {
"stopPrice": 10.71
}
}
{
"ticker": "SQ",
"action": "buy",
"stopLoss": {
"type": "stop_limit",
"stopPrice": 10.71,
"limitPrice": 10.75
}
}
{
"ticker": "SQ",
"action": "buy",
"stopLoss": {
"type": "trailing_stop",
"trailPercent": 1
}
}
{
"ticker": "SQ",
"action": "buy",
"stopLoss": {
"type": "trailing_stop",
"trailPrice": 1
}
}
Because TradersPost works using standard webhooks, this enables users to integrate with third party platforms that support sending alerts as webhooks.
Here are some popular platforms that enable you to build strategies and send alerts as webhooks.
- TradingView - TradingView is a social network of 30 million traders and investors using the world's best charts and tools to spot trading opportunities across global markets.
- TrendSpider - TrendSpider provides technical analysis software for retail traders and investors focused on the US equity and foreign exchange markets.
In addition to sending webhooks from third parties, you can send webhooks to TradersPost from custom code using programming languages like PHP or Python. Here is an example using PHP and the Symfony HTTP Client.
mkdir traderspost
cd traderspost
Now require the
symfony/http-client
package using composer.composer require symfony/http-client
Now you are ready to create a file named
traderspost-test.php
and paste the following code inside of the file.<?php
// traderspost-test.php
require 'vendor/autoload.php';
use Symfony\Component\HttpClient\HttpClient;
$webhookUrl = 'https://traderspost.io/trading/webhook/9d9f8620-d60d-416e-827e-0ec01ef93532/9b5b8c4264421f5515fd4fcb6571af50';
$client = HttpClient::create();
$response = $client->request('POST', $webhookUrl, [
'json' => [
'ticker' => 'AMD',
'action' => 'buy',
'price' => 85.50,
]
]);
echo $response->getContent();
Now you are ready to send the webhook to TradersPost!
php traderspost-test.php
{"success":true,"id":"cd481b19-9bb7-4845-8227-523203971d47","payload":{"ticker":"AMD","action":"buy","price":85.50}}
This is a simple example, but you can combine this with a service like Polygon.io to get live real-time market data and build your own completely custom trading strategies and TradersPost can handle the integrations with your broker.
Last modified 1mo ago