Webhook Signals: Open, Close, Increase or Reverse a Position (Draft)
The Webhook Signals described in this section are related to positions on a Signal Bot.
A position can be opened, closed, increased or reversed using a webhook signal.
Summary of types:
Open: Open a new position, either short or long
Increase: increase the size of an existing position
Reverse: (Futures Only). Close the current position and create a new one with the opposite side.
Close: Close current position/s
API key: The API key from your Signal Bot
Secret: The Secret from your Signal Bot
Exchange: and Symbol" See: Webhooks: Valid values for Exchange and Symbol
The Open signal is used to open a new position on the exchange for the chosen market.
For the signal to be received and opened, the following criteria must be met:
The API key and Secret must match those in the Bot Settings.
The
All filter criteria must be met. etc.
Example of an open signal, including only the minimum required settings:
Details about the first four settings are shown above.
For side: valid options are "long" or "short".
Use long for a position that opens with a Buy entry and closes with Sell exit/s.
Use short for a position that opens with a Sell entry and closes with Buy exit/s.
Short positions are available on Spot exchanges if the coins are already owned and available to be sold.
Example of an Open signal including all required and optional settings:
Including TPs, DCAs or SL in the signal
DCAs, TP/s and SL for your signals can either be:
included in your webhook entry signal (see above)
specified in the Signal Bot Settings, or
added manually to your positions once they have opened.
If the DCAs, TPs, and SL will not vary with each signal, then it is simplest to specify them in the Signal Bot settings.
To specify different DCAs, TPs or SL depending on the signal, or the market, then the JSON code can include these, and use the Signal option in the Signal bot.
The Close signal is used to close existing position/s for the specified market, that were opened by the Signal Bot.
The following criteria must be met:
The API key and Secret must match those in the Bot Settings.
Exchange and Symbol must be specified.
Example Close signal, including only the minimum required settings:
Details about the last four settings are shown above. [LINK]
For side: use the side that was used to open the positions that are to be closed.
Example of a Close signal including all required and optional settings:
Optional Settings for the Close Signal
side. If omitted, side will default to "long". This is the side of the original position when it was opeend. Either long positions or short positions can be closed with one signal, not both.
signal_ID (this is the signal_ID of the signal that opened the specific position)
When the signal_ID is omitted, all positions for the specified market and side, and that were opened by the Signal Bot, will be closed. If your bot has a Setting of "Max per market" = 1 , then only one positoin will ever be opened at the same time. In that case, the Close signal will close that single position.
Where there might be more than one position open for the same Symbol and Side, signal_ID is used to specify a specific position. Since it must be recalled from the original signal, this is not possible with standard Trading View indicators. It might be possible to code using PineScript etc.
If a Signal_ID was not specified with the original Signal, Altrady will have created a unique signal_ID for the signal.### Reverse Signal
order_type can be limit or market.
If omitted, a limit order with a price 10% below the current price (for a Long position) or 10% below the current price (for a short position) will be used.
Limit will place a Limit order at the price specified by order_price.
order_price
Must be included if the order_type is limit.
The price at which to place the Limit order.
Must be a numeric value.
The Increase signal is used to increase the position size of one or more open positions,
It will increase the size of existing position/s for the specified market and side, that were opened by the Signal Bot.
The following criteria must be met:
The API key and Secret must match those in the Bot Settings.
Exchange and Symbol must be specified.
Example of an Increase signal including all required and optional settings:
Optional Settings for the Increase signal
side is the only optional setting. If omitted, the side will default to long.
The increase_order block must be included.
Its settings are:
"quantity_percentage" will be multiplied by the initial order size and a new order placed for that amount at the specified price.
"price" is the limit order price for the increase position order. If the price is omittted...
Only valid for Futures exchanges and positions.
The Reverse signal combines the Close and Open signal actions.
Close: If there is one or more open positions (for the relevant side and market), those positions will be closed.
Once the position/s are closed, a new position is opened for the side specified in the signal.
The settings in the signal are then used to open a new position in the opposite direction.
For a new position to be opened, the filter criteria in the Bot Settings mut be met.
The Settings in the Signal will be used to open the new position.
Other than the "action": "reverse", all settings for the reverse signal are identical to those required and available for the Open signal.
Example of a reverse signal, including only the minimum required settings:
Details about the first four settings are shown above.
For side: valid options are "long" or "short". This will be the side of the new position created. If omitted, it will defailt to "long".
Use long for a position that opens with a Buy entry and closes with Sell exit/s.
Use short for a position that opens with a Sell entry and closes with Buy exit/s.
Example of a Reverse signal including all required and optional settings:
Details about the optional settings are included in the Open Signal section.
A position can be opened, closed, increased or reversed using a webhook signal.
Types of Position Signals:
Summary of types:
Open: Open a new position, either short or long
Increase: increase the size of an existing position
Reverse: (Futures Only). Close the current position and create a new one with the opposite side.
Close: Close current position/s
Required Settings for all Signal Types
API key: The API key from your Signal Bot
Secret: The Secret from your Signal Bot
Exchange: and Symbol" See: Webhooks: Valid values for Exchange and Symbol
Open Signal
The Open signal is used to open a new position on the exchange for the chosen market.
For the signal to be received and opened, the following criteria must be met:
The API key and Secret must match those in the Bot Settings.
The
All filter criteria must be met. etc.
Example of an open signal, including only the minimum required settings:
{
"api_key": "YOUR_ALTRADY_API_KEY",
"api_secret": "YOUR_ALTRADY_API_SECRET",
"exchange": "EXCHANGE CODE",
"symbol": "MARKET CODE",
"side": "long"
}
Details about the first four settings are shown above.
For side: valid options are "long" or "short".
Use long for a position that opens with a Buy entry and closes with Sell exit/s.
Use short for a position that opens with a Sell entry and closes with Buy exit/s.
Short positions are available on Spot exchanges if the coins are already owned and available to be sold.
Example of an Open signal including all required and optional settings:
{
"api_key": "YOUR_ALTRADY_API_KEY",
"api_secret": "YOUR_ALTRADY_API_SECRET",
"exchange": "EXCHANGE CODE",
"symbol": "MARKET CODE",
"side": "long",
"test": true,
"action": "open",
"quote_amount": 0,
"signal_id": "string",
"leverage": 0,
"signal_price": 0,
"dca_orders": [
{
"price_percentage": 0,
"quantity_percentage": 0
}
],
"take_profit": [
{
"price_percentage": 0,
"position_percentage": 0
}
],
"stop_loss": {
"stop_percentage": 0,
"cool_down_amount": 0,
"cool_down_time_frame": "minute"
},
}
Optional Settings for the Open Signal
Setting | Values | Notes |
---|---|---|
test | true or false | Defaults to false. When test is true, the Position will open Pending orders instead of Live orders. Use this for testing signals |
action | open | Defaults to open |
quote_amount OR base_amount | numeric value, optional | This is a fixed amount, not percentage of the account. If both settings (quote and base) are included in the signal, an error will occur |
signal_id | If included, must be a unique character string for each signal | Generally only used with Pinescript. Can be included in the Open signal if it will be need for updating the position later. If omitted, Altrady will generate a unique signal_ID. |
signal_price | numeric value | The special Trading View variable "{{close}}" can be used to substitute the Close price from the candle. If signal_price is omitted, Altrady will substitute the current price. Note that Entry orders are always limit orders. To simulate a Market order, use a positive Entry Price Deviation in the Signal Bot Settings. |
leverage | numeric value | If included, the leverage value will overwrite leverage included in the Signal Bot Settings |
dca_orders | To use the DCA values from the webhook Signal, select the DCA from Signal option in the Signal Bot Settings. Multiple DCAs can be included by repeating the block (see example below). | |
price_percentage | numeric value | The percentage below the average entry price for the order to be placed. |
quantity_percentage | numeric value | The percentage of the initial entry order for this DCA (e.g. 200 represents 200% or 2x the entry order size. |
take_profit | To use the TP values from the webhook Signal, select the DCA from Signal option in the Signal Bot Settings. Multiple Take Profit orders can be included by repeating the block (see example below) | |
price_percentage | numeric value | The percentage above the average entry price for the order to be placed. |
position_percentage | numeric value | The percentage of the position size for this order. |
stop_loss | Include this block to set a Stop Loss value in the Signal. To use the SL values from the webhook Signal, select the SL from Signal option in the Signal Bot Settings. | |
stop_percentage | numeric value | The percentage below the signal price for the SL to be placed. NB. Stop Price is fixed, and does not vary with average entry price. More details. |
cool_down_amount | for minutes: 1 to 60; for hours: 1 to 24; for days: 1 to 30 | More details about the SL cooldown |
cool_down_time_frame | "minutes" "hours" or "days" |
Including TPs, DCAs or SL in the signal
DCAs, TP/s and SL for your signals can either be:
included in your webhook entry signal (see above)
specified in the Signal Bot Settings, or
added manually to your positions once they have opened.
If the DCAs, TPs, and SL will not vary with each signal, then it is simplest to specify them in the Signal Bot settings.
To specify different DCAs, TPs or SL depending on the signal, or the market, then the JSON code can include these, and use the Signal option in the Signal bot.
Close Signal
The Close signal is used to close existing position/s for the specified market, that were opened by the Signal Bot.
The following criteria must be met:
The API key and Secret must match those in the Bot Settings.
Exchange and Symbol must be specified.
Example Close signal, including only the minimum required settings:
{
"action": "close",
"api_key": "YOUR_ALTRADY_API_KEY",
"api_secret": "YOUR_ALTRADY_API_SECRET",
"exchange": "EXCHANGE CODE",
"symbol": "MARKET CODE"
}
Details about the last four settings are shown above. [LINK]
For side: use the side that was used to open the positions that are to be closed.
Example of a Close signal including all required and optional settings:
{
"action": "close",
"api_key": "YOUR_ALTRADY_API_KEY",
"api_secret": "YOUR_ALTRADY_API_SECRET",
"exchange": "EXCHANGE CODE",
"symbol": "MARKET CODE",
"side": "ORIGINAL SIDE",
"signal_ID": "ORIGINAL SIGNAL ID",
"order_type": "limit",
"order_price": 99
}
Optional Settings for the Close Signal
side. If omitted, side will default to "long". This is the side of the original position when it was opeend. Either long positions or short positions can be closed with one signal, not both.
signal_ID (this is the signal_ID of the signal that opened the specific position)
When the signal_ID is omitted, all positions for the specified market and side, and that were opened by the Signal Bot, will be closed. If your bot has a Setting of "Max per market" = 1 , then only one positoin will ever be opened at the same time. In that case, the Close signal will close that single position.
Where there might be more than one position open for the same Symbol and Side, signal_ID is used to specify a specific position. Since it must be recalled from the original signal, this is not possible with standard Trading View indicators. It might be possible to code using PineScript etc.
If a Signal_ID was not specified with the original Signal, Altrady will have created a unique signal_ID for the signal.### Reverse Signal
order_type can be limit or market.
If omitted, a limit order with a price 10% below the current price (for a Long position) or 10% below the current price (for a short position) will be used.
Limit will place a Limit order at the price specified by order_price.
order_price
Must be included if the order_type is limit.
The price at which to place the Limit order.
Must be a numeric value.
Increase Signal
The Increase signal is used to increase the position size of one or more open positions,
It will increase the size of existing position/s for the specified market and side, that were opened by the Signal Bot.
The following criteria must be met:
The API key and Secret must match those in the Bot Settings.
Exchange and Symbol must be specified.
Example of an Increase signal including all required and optional settings:
{
"api_key": "YOUR_ALTRADY_API_KEY",
"api_secret": "YOUR_ALTRADY_API_SECRET",
"action": "increase",
"side": "long",
"exchange": "BINA",
"symbol": "BINA_USDT_BTC",
"increase_order": {
"quantity_percentage": "100",
"price": "26000"
}
}
Optional Settings for the Increase signal
side is the only optional setting. If omitted, the side will default to long.
The increase_order block must be included.
Its settings are:
"quantity_percentage" will be multiplied by the initial order size and a new order placed for that amount at the specified price.
"price" is the limit order price for the increase position order. If the price is omittted...
Reverse Signal
Only valid for Futures exchanges and positions.
The Reverse signal combines the Close and Open signal actions.
Close: If there is one or more open positions (for the relevant side and market), those positions will be closed.
Once the position/s are closed, a new position is opened for the side specified in the signal.
The settings in the signal are then used to open a new position in the opposite direction.
For a new position to be opened, the filter criteria in the Bot Settings mut be met.
The Settings in the Signal will be used to open the new position.
Other than the "action": "reverse", all settings for the reverse signal are identical to those required and available for the Open signal.
Example of a reverse signal, including only the minimum required settings:
{
"action": "reverse",
"api_key": "YOUR_ALTRADY_API_KEY",
"api_secret": "YOUR_ALTRADY_API_SECRET",
"exchange": "EXCHANGE CODE",
"symbol": "MARKET CODE",
"side": "long"
}
Details about the first four settings are shown above.
For side: valid options are "long" or "short". This will be the side of the new position created. If omitted, it will defailt to "long".
Use long for a position that opens with a Buy entry and closes with Sell exit/s.
Use short for a position that opens with a Sell entry and closes with Buy exit/s.
Example of a Reverse signal including all required and optional settings:
{
"api_key": "YOUR_ALTRADY_API_KEY",
"api_secret": "YOUR_ALTRADY_API_SECRET",
"exchange": "EXCHANGE CODE",
"symbol": "MARKET CODE",
"side": "long",
"test": true,
"action": "reverse",
"signal_id": "string",
"leverage": 0,
"signal_price": 0,
"dca_orders": [
{
"price_percentage": 0,
"quantity_percentage": 0
}
],
"take_profit": [
{
"price_percentage": 0,
"position_percentage": 0
}
],
"stop_loss": {
"stop_percentage": 0,
"cool_down_amount": 0,
"cool_down_time_frame": "minute"
},
}
Details about the optional settings are included in the Open Signal section.
Updated on: 03/12/2023
Thank you!