Trung tâm hỗ trợ
Bot
Bot CTA - Chuyên gia

Custom Bots Trading Tutorial

2025-07-10 UTC
36832 Số lượt đọc
9

1.What are Custom Bots?

Custom bots allow investors to set their own trading rules, which are suitable for all users. For newbies, Custom Bots can combine simple trading rules, such as "Sell the held GT at 10 USDT when the GT spot price is higher than 10 USDT."

For professional bot users, Custom Bots can also accommodate complex trading logic, such as:

"When the spot price of BTC is above 50,000 USDT and the ratio of BTC Futures price to the index price is above 1, sell 4 BTC Futures and simultaneously buy 0.01 BTC at 51,000 USDT."

2.Custom Bots Parameters Explanations

Newly-Created Rules

The rules consist mainly of two parts: conditions and execution logic.

Conditions Conditions are specific criteria set to trigger the execution logic. Users can combine Gate's existing market data, the bot's financial data, and mathematical functions provided by the platform to create conditions that meet their needs.

Click the icon to choose all the data that can be provided Click on "Function Instructions" to view the specific usage methods for all data.

For example: The rule is triggered when the BTC spot price exceeds 50,000 USDT. The condition is: price("BTC_USDT", 0, "spot") > 50,000. More complex bots can also be accommodated, such as those requiring multiple conditions:

1.When the BTC_USDT Futures price is below 50,000 USDT

2.When the premium of the BTC_USDT Futures price to the index price is greater than 1

3.When the BTC_USDT position is 0 The condition is: price(“BTC_USDT”, 0, "usdt") < 50000 and premium(“BTC_USDT”, 0, "usdt") > 1 and (position_net(“BTC_USDT”, "usdt") == 0)

Execution Logic Execution logic presets what orders will be executed when conditions are triggered. Users can use the execution logic provided by Gate to execute spot and Futures orders and create their own functions (variables). "Type" means users can select the trading type: Spot Trading or Futures Trading. "Market" means users can choose the market for the bots. A single rule can support multiple execution logic setups for different markets, with a maximum of 20 markets to be selected. The "Order" types offer various options, including Limit Orders, Market Orders, Take Profit, and Stop Loss.

For example: Sell BTC after the BTC spot price exceeds 50,000 USDT. The execution logic is: Open a long position with 5x leverage after the BTC Futures price falls below 5,000 USDT. The execution logic is:

A single rule supports multiple execution logics simultaneously, with a maximum of 20 logics to be executed together.

New Variables

Variables mainly consist of two parts: conditions and variable values. Users can store any variables and get the value of "variable_namex" through "get-value" when they need to use them.

Conditions A condition is a specific condition preset to trigger the calculation of variable values. Users can combine the conditions that meet their needs with Gate's existing market data, the Bots' capital data, and the mathematical functions provided by the platform.

Click on the icon to select all the data provided.

Click "How to use functions" to view how to use all the data Example: The method of how to use conditions in the same rule.

Variable Value

This presets what variable values will be stored when the condition is triggered. Users can create variable values from the data provided by Gate. Example: keep getting the EMA 10-minute indicator of spot BTC, the variable value is:

After each trigger, the value of the variable is increased by 10, and the variable value is: When adding a variable or rule, if the variable value or condition and execution logic has referred to other variables, you need to add the variable at the same time, otherwise the correct variable value or condition or execution logic cannot be obtained.

Execution Order

Custom Bots cycle every 10 seconds and execute all the rules and variables from low to high in the execution order. If there is a reference relationship between the variables or between the rules, you need to add the referenced variables first, otherwise you will not be able to get the bot effect you preset.

For example, if ema-BTC is used as a condition in "buy BTC and sell BTC," and when the conditions are met, the bot needs to buy BTC first and then sell BTC. The order in the bot should be ema-BTC, buy BTC, and sell BTC.

Save and Run

1.The user can select "Save" to save the newly created robot to the robot library, and then run the robot later. When running a bot, you can run the bot by simply clicking in the bot library, and the bot saved in the bot library can be run multiple times.

2.You can also choose "Save and Run" to save the newly created bot to the bot library and deposit funds to deploy it.

Enable and Disable After creating a bot, the rules and variables are enabled by default. When editing the bot, you can disable or enable them. The change will take effect immediately after clicking "Save," affecting the running bot directly.

1.When disabling rules and variables:

"Disable" refers to not using the specific rule or variable within the bot.

"Disable All" refers to not using all rules or variables within the bot.

Case of Custom Bots

1."Break Range" Bot This example focuses on how to create a bot with custom rules. Opening Positions:

Long Position: Open when the price breaks above the highest point of the last 60 minutes

Short Position: Open when the price drops below the lowest point of the last 60 minutes

Closing Positions:

Close Long: Close when the price drops below the lowest point of the last 10 minutes

Close Short: Close when the price breaks above the highest point of the last 10 minutes

1.1 New Rules

Rules of Opening Long Positions

Conditions

price(“BTC_USDT”, 0, “usdt”) > max_price(“BTC_USDT”, 60, “usdt”) and order_collateral(“usdt”) ==0 and position(“BTC_USDT”, “usdt”) == 0

(1)price(“BTC_USDT”, 0, “usdt”) > max_price(“BTC_USDT”, 60, “usdt”) This condition indicates that the latest price of BTC Perpetual Futures is greater than the highest price of BTC Perpetual Futures in the last 60 minutes.

(2)and order_collateral(“usdt”) ==0 This condition indicates that the bot does not have open orders. The "order_collateral" is a preset function retrieving the margin for unfinished orders. If this function returns a value of 0, the bot has no ongoing orders.

(3)and position(“BTC_USDT”, “usdt”) == 0 This condition indicates that the bot currently has no positions. The "position" here is a preset function that returns the quantity of the bot's current position in the specified market.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Long

Limit Price: ask_price("BTC_USDT", 1, "usdt")

Quantity: 1

Rules of Opening Short Positions

Conditions

price(“BTC_USDT”, 0, “usdt”) < min_price(“BTC_USDT”, 60, “usdt”) and order_collateral(“usdt”) ==0 and position(“BTC_USDT”, “usdt”) == 0

(1)price(“BTC_USDT”, 0, “usdt”) < min_price(“BTC_USDT”, 60, “usdt”) This condition indicates that the latest price of BTC Perpetual Futures is less than the lowest price of BTC Perpetual Futures in the last 60 minutes.

(2)and order_collateral(“usdt”) ==0 This condition means the bot does not have any ongoing orders.

(3)and position(“BTC_USDT”, “usdt”) == 0

This condition indicates that the bot currently has no positions.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Short

Limit Price: ask_price("BTC_USDT", 1, "usdt")

Quantity: 1

Rules of Closing long Positions

Conditions

price(“BTC_USDT”, 0, “usdt”) < min_price(“BTC_USDT”, 10, “usdt”) and order_collateral(“usdt”) ==0 and position(“BTC_USDT”, “usdt”) > 0

(1)price(“BTC_USDT”, 0, “usdt”) < min_price(“BTC_USDT”, 10, “usdt”) This condition indicates that the latest price of BTC Perpetual Futures is less than the lowest price of BTC Perpetual Futures in the last 60 minutes.

(2)and order_collateral(“usdt”) ==0 This condition means the bot does not have any ongoing orders.

(3)and position(“BTC_USDT”, “usdt”) > 0 This condition indicates that the bot has previously established a position and is now performing a closing operation based on that existing position.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Short

Limit Price: ask_price("BTC_USDT", 1, "usdt")

Quantity: 1

Rules of Closing Short Positions

Conditions

price(“BTC_USDT”, 0, “usdt”) > max_price(“BTC_USDT”, 10, “usdt”) and order_collateral(“usdt”) ==0 and position(“BTC_USDT”, “usdt”) < 0

(1)price(“BTC_USDT”, 0, “usdt”) > max_price(“BTC_USDT”, 10, “usdt”) This condition indicates that the latest price of BTC Perpetual Futures is higher than the highest price of BTC Perpetual Futures in the last 60 minutes.

(2)and order_collateral(“usdt”) ==0 This condition means the bot does not have any ongoing orders.

(3)and position(“BTC_USDT”, “usdt”) < 0 This condition indicates that the bot has previously established a position and is now performing a closing operation based on that existing position.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Long

Limit Price: ask_price("BTC_USDT", 1, "usdt")

Quantity: 1

1.2 Creating a Bot

Add the rules in the following execution order: "Long Position Opening Conditions" - "Short Position Opening Conditions" - "Close Long Position" - "Close Short Position."

2."Break Extreme Value" Bot

This example focuses on how to create a robot using custom variables.

Open Long Position / Close Short Position

Here, price(t) stands for the latest price at the current moment

close(t-1) represents the closing price at the previous moment

Open Short Position / Close Long Position

2.1 New Rules

Variable Name: range

Condition: true

Variable Value: max_price(“BTC_USDT”, 10, “usdt”) - min_price(“BTC_USDT”, 10, “usdt”)

2.2 New Rules

1.Rules of Opening Long Positions

Conditions

price(“BTC_USDT”, 0, “usdt”)>price(“BTC_USDT”, 1, “usdt”)+get_value(“range”)*0.5 and order_collateral(“usdt”) ==0 and position(“BTC_USDT”, “usdt”) == 0

(1)price(“BTC_USDT”, 0, “usdt”)>price(“BTC_USDT”, 1, “usdt”)+get_value(“range”)0.5 This condition stands for the condition of opening long positions price(t) > Close(t-1) + 0.5range The custom variable "range" is accessed using the "get_value" function.

(2)and order_collateral(“usdt”) ==0 This condition indicates that there are no open orders currently.

(3)and position(“BTC_USDT”, “usdt”) == 0 This condition indicates there are no open positions.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Long

Limit Price: ask_price("BTC_USDT", 1, "usdt")

Quantity: 1

2.Rules of Opening Short Positions

Conditions

price(“BTC_USDT”, 0, “usdt”)<price(“BTC_USDT”, 1, “usdt”) - get_value(“range”)*0.5 and order_collateral(“usdt”) ==0 and position(“BTC_USDT”, “usdt”) == 0

(1)price(“BTC_USDT”, 0, “usdt”)<price(“BTC_USDT”, 1, “usdt”) - get_value(“range”)*0.5

This condition stands for the condition of opening short positions.

The custom variable "range" is accessed using the "get_value" function. (2)and order_collateral(“usdt”) ==0

This condition indicates that there are no open orders currently. (3)and position(“BTC_USDT”, “usdt”) == 0 This condition indicates that there are no open positions.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Short

Limit Price: ask_price("BTC_USDT", 1, "usdt")

Quantity: 1

3.Rules of Closing Long Positions

Conditions

price(“BTC_USDT”, 0, “usdt”) 0

(1)price(“BTC_USDT”, 0, “usdt”)< price(“BTC_USDT”, 1, “usdt”) - get_value(“range”)*0.5

This condition stands for the condition of closing long positions. The custom variable "range" is accessed using the "get_value" function.

(2)and order_collateral(“usdt”) ==0

(3)and order_collateral(“usdt”) ==0

This condition indicates that there are no open orders currently.

(4)and position(“BTC_USDT”, “usdt”) > 0

This condition indicates that there is an existing long position, on the basis of which the closing operation will be done.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Short

Limit Price: ask_price("BTC_USDT", 1, "usdt")

Quantity: 1

4.Rules of Closing Short Positions

Condition

This condition stands for the conditions for opening short positions:

The custom variable "range" is accessed using the "get_value" function.

(2)and order_collateral(“usdt”) ==0

This condition indicates that there are no open orders currently.

(3)and position(“BTC_USDT”, “usdt”) < 0

This condition indicates that there is an existing short position, on the basis of which the closing operation will be done.

Execution Logic

Type: Futures Trading

Market: BTC/USDT Perpetual Futures

Order Type: Limit Order

Leverage: 5x

Direction: Long

Limit Price: bid_price("BTC_USDT", 1, "usdt")

Quantity: 1

2.3 Create a Bot When using custom variables, you should set the execution order of custom variables before the rules. For example, if the execution order of the custom variable ‘range’ is 1, then the execution order of the open and close rules should be set to 2 through 5.

3.How to Create Custom Bots?

Note: Custom Bots are only available on web. Bots - Bot Pool - Create a Bot - Customize - Custom Bots - Parameters Setup - Create

Gate reserves the final right to interpret the product. For further assistance, please visit the Gate official support page or contact our customer support team.

Đăng ký ngay để có cơ hội giành tới $10,000!
signup-tips