Automating your trading strategies by connecting TradingView alerts to Gate.io can significantly enhance your trading efficiency. This guide provides a step-by-step approach to setting up this automation, detailing the command syntax, parameters, and supported commands to ensure seamless trading for your futures and spot trades with Gate.io.
Command Syntax
The structure of commands used to automate trades on Gate.io is as follows:
Command Symbol Param=Value
Example : Sell BTC/USDT Q=0.05
Where:
- Command: Specifies the action to be executed, such as
buy
orsell
. - Symbol: Indicates the trading pair or instrument, like
BTC/USDT
. Note: Gate.io requires a/
between symbols (e.g.,DOGE/USDT
, notDOGEUSDT
). - Param: Defines specific parameters for the trade, such as quantity, leverage, or stop-loss.
- Value: Assigns the value to the specified parameter.
Parameters
Several parameters can be customized within commands to control trade execution:
- Q (Quantity): Specifies the order size as a fixed quantity or percentage of your balance. For example,
Q=0.01
for 0.01 BTC orQ=50%
for 50% of your available balance. Can also be sent as OQ (Opening Quantity). Default:Q=100%
. - B (Balance): Specifies which balance to use when opening a position. Options are
free
(uncommitted funds) ortotal
(entire balance). Default:B=free
. - C (Category): Specifies the trading category. Options are
spot
orfutures
. Default:C=spot
. - L (Leverage): Sets the leverage multiplier for futures trades. For example,
L=10
for 10x leverage. Default: Cross leverage (configurable in account settings). - P (Price): Entry price for limit orders, either as an actual price or percentage. For example,
P=50000
orP=10%
. - SL (Stop-Loss): Sets the stop-loss target as an actual price or percentage. For example,
SL=49000
orSL=5%
. - TP (Take-Profit): Sets the take-profit target as an actual price or percentage. For example,
TP=51000
orTP=5%
. - T (Type): Specifies the order type. For example,
T=market
orT=limit
. - H (Hedge): Indicates if the account is in hedge mode for futures trading, e.g.,
buy BTC/USDT c=futures h=true
. Can also be used without a value, e.g.,buy BTC/USDT c=futures hedge
. - D (Delay): Delays command execution by up to 5 seconds. For example,
D=3
for a 3-second delay. - :Ignore: Used to ignore text following a command.
Important Notes
-
Commands are not case-sensitive. For example,
buy BTC/USDT Q=50%
andBuy btc/usdt q=50%
are both valid. -
You can use either the full parameter name or its first letter. For example,
Q=50%
andquantity=50%
is the same thing. -
Ensure there is no space between the parameter and its value. For example,
Q=0.5
is correct, while
Q = 0.5
is incorrect.
-
Symbol Format: Always use a
/
between symbols for Gate.io (e.g.,DOGE/USDT
). -
Multi-Commands: You can include up to 5 commands in a single alert. Each command should start on a new line for clarity.
Example:buy CAT/USDT q=50% sell CAT/USDT p=10% quantity=10 c=futures Cancel CAT/USDT long DOGE/USDT q=50% p=10% l=3 c=futures balance B=free C=futures
Supported Commands
The following commands are supported for automating trades on Gate.io:
1. Opening a Position
Required Parameters: Action (buy
, long
, 1
for buy; sell
, short
, -1
for sell) and Symbol
Optional Parameters: Q, C, P, TP, SL, L, D, H and B.
Buy Command
Initiates a buy (long) position.
Examples:
buy BTC/USDT Q=0.01 C=spot
Buys 0.01 BTC at the market price in the spot market.long CAT/USDT Q=50%
Buys CAT worth 50% of the available USDT balance in the spot account.1 DOGE/USDT Q=10 L=10 C=futures hedge
Opens a long position with 10% of the balance at 10x leverage in futures (hedge mode).
Sell Command
Initiates a sell (short) position.
Examples:
sell BTC/USDT Q=0.01 L=10 SL=5% TP=5% C=futures hedge
Opens a short position on BTC/USDT with 0.01 BTC at 10x leverage, a 5% stop-loss, and a 5% take-profit in futures.sell CAT/USDT Q=50% P=10%
Places a sell limit order at 10% above the current price in spot. If the price is below this, it executes as a market order.
Strategy Alerts
- Long and Short Strategy:
Buys or sells 0.01 BTC based on the strategy direction in the spot market.{{strategy.order.action}} BTC/USDT Q=0.01 C=spot
- Long, Short, and Exit Strategy:
Buys or sells 0.01 BTC based on the strategy direction in the futures market. When a{{strategy.order.action}} BTC/USDT Q=0.01 C=futures
flat
command is generated, the position is closed.
More on generating and automating Dynamic Alerts
2. Closing a Position (Futures)
Required Parameters: Action (close
, flat
, or 0
) and Symbol
Optional Parameters: Q, C, T, P
Examples:
close BTC/USDT Q=0.01 C=futures
Closes 0.01 BTC in the futures market.flat DOGE/USDT C=futures
Closes all DOGE/USDT positions in futures.close DOGE/USDT Q=50% P=0.16100 T=long C=futures
Places a limit close order for 50% of the long position at 0.16100 in futures.
3. Cancelling a Limit Order
Required Parameters: Action (cancel
or exit
) and Symbol
Optional Parameters: C
Examples:
cancel BTC/USDT C=futures
Cancels all pending orders for BTC/USDT in futures.exit CAT/USDT
Cancels all pending orders for CAT/USDT in spot.
4. Checking Account Balance
Required Parameters: Balance command (balance
, bal
, or funds
)
Optional Parameters: C, B (free or total)
Examples:
balance
Returns the balance in the spot account.balance B=free C=futures
Returns the free balance in the futures account.balance USDT B=total C=spot
Returns the total USDT balance in the spot account.
Setting Up Automation
To automate TradingView alerts with Gate.io, follow these steps:
-
Create an API Key on Gate.io
- Navigate to the “API Management” tab on Gate.io.
- Generate an API key-secret pair with trading permissions.
- Copy the API key and secret for use in the next steps.
-
Connect to Tradingview To Gateio
- Submit your API key and the secret key copied previously.
- Select whether your account is a testnet account (demo) or a live account. Leave the box unchecked for a live account.
-
Test and Monitor
- Test your setup using the Send a Test option provided in your Webhook Dashboard.
- Enter a sample command in the Send a Test box, e.g,
BUY XRP/USDT Q=50% C=FUTURES
- Monitor the execution to ensure commands are processed correctly.
-
Configure TradingView Alerts
- In TradingView, create an alert based on your strategy or indicator.
- Set the webhook URL provided by Tradingview to Anywhere in the Webhook URL section.
- Include the command syntax (e.g.,
buy BTC/USDT Q=0.01 C=spot
) in the alert message.
That is it, you are fully set!
Happy trading!