Introduction to Trading bot Mode

Published on Jan 9, 2023Updated on Apr 4, 202426 min read

All strategies in the current document are temporarily not supported under portfolio accounts

Contents

I. Spot Grid

II. Futures Grid

III. Recurring Buy

IV. Smart Portfolio

V. Arbitrage

VI. Iceberg

VII. Time-weighted Average Price (TWAP)

I. Spot Grid

1. What is Spot Grid trading?

Spot grid trading is an automated strategy to buy and sell assets in a configured price range. It creates a grid of gradual orders (i.e., at incrementally increasing and decreasing prices) with preset intervals, placing them above and below a base price you set.

2. Use cases of Spot Grid trading

The essence of spot grid trading strategy is to profit by "buying low, selling high", and this strategy performs the best in a oscillating bullish market. However, in bearish market using Spot Grid trading might results in losses.

3. How do I set up a spot grid trading bot?

3.1. Steps Overview

  1. Enter OKX on your PC or mobile and navigate to Trade, select Trading bot mode (at the top left corner on the web and top right corner on the mobile app), and click Spot grid.

  2. Enter parameters manually or use backtested AI parameters on the trading interface, and confirm the total investment amount to create a grid trading bot(After you create a bot, the initial funds will be isolated from your trading account and used for grid trading only).

  3. You can view and manage your bots on the Bots page.

  4. After the bot starts running, you can withdraw your earnings or stop the bot anytime.

3.2. Options and parameters

Setup Options

Set myself: Set parameters based on your own analysis of the market.

AI strategy: Use the parameters recommended by backtested strategy (The recommended parameters are selected based on the backtesting results over past 7 days using a proprietary smart algorithm)

Grid Trading Parameters

Lower price: The bot will stop placing orders when the market price is lower than the lowest price.

Upper price: The bot will stop placing orders when the market price is higher than the highest price.

Grid quantity: The number of grids represents the corresponding shares divided within the price range. For example, if the price range is 100-400, the mode is arithmetic, and the number of grids is 3, it is divided into three grids: 100-200, 200-300, and 300-400.

Grid - Arithmetic grid: It keeps the same common difference between each grid. (For example: 1, 2, 3, 4.)

Grid - Geometric grid: It keeps the same common ratio between each grid. (For example: 1, 2, 4, 8.)

Asset: Users can choose to invest either in the base currency or the quote currency or invest in both.

Amount: It refers to the amount of quote currency invested in the Trading bot. The maximum available amount of each quote currency equals the current maximum transferable amount of that currency in the Trading account.

Take-profit (TP) price: The Bot will stop working when the price reaches TP price, and the bot will close the position at TP price.

Stop-loss (SL) price: The Bot will stop working when the price falls to the SL price, and the bot will close the position at SL price.

3.3. Sample Case (BTC/USDT)

Bot Parameters

The lower price: 50,000 USDT

The upper price: 100,000 USDT

Grid quantity: 50

Grid mode: Arithmetic

Investment Amount: 5,000 USDT

BTC price when activate strategy: 60,100 USDT

Run the Bot

  1. Stage 1 - Initial order placement: The system will calculate the price of each grid, which are 50,000 USDT, 51,000 USDT, 52,000 USDT...98,000 USDT, 99,000 USDT, 100,000 USDT, and then place buy orders in each grid. If the market depth is great, the sell order will be opened in the nearest grid above upon the completion of the buy order, and the buy order will be opened in the nearest grid below. That is, after the Bot starts, there is a buy order at each grid from 50,000 USDT to 60,000 USDT and a sell order at each grid from 62,000 USDT to 100,000 USDT.

  2. Stage 2 - Bot operation: A buy order will be executed when the price drops below 60,000 USDT, and in the meantime, a sell order will be opened in the nearest grid above (61,000 USDT). If prices rise above 61,000 USDT, the sell order will be executed, and in the meantime, a buy order (60,000 USDT) will be opened in the nearest grid below.

In this way, the Trading bot helps you make profits by buying and selling orders at predefined price intervals. It allows you to take advantage of fluctuating market prices.

4. Risk reminder and notes

  1. If the price falls below the lower price of the defined price range, the bot will not continue to place additional orders. If the price continues to fall and does not return back to the pre-defined range, the crypto asset held at this time will suffer losses. Therefore, it is recommended to set a stop-loss price below the lower price to avoid taking excessive risk on your position.

  2. The fund invested in the grid will be isolated from your Trading account and used independently for the Trading bot. Therefore, users need to pay attention to the risk of overall positions in your Trading account after transferring funds.

  3. Our system will sell your assets at market price when the Bot is stopped manually or when the stop-loss price is triggered. If the risk management system judges that it will bring risks to the market, it may fail to sell your assets, but you can still decide whether to sell them manually or not.

  4. While the spot grid bot is running, if encounters unpredictable circumstances such as suspension or delisting of the underlying crypto asset, the bot will be automatically stopped.

II. Futures Grid

1. What is Futures Grid trading?

Futures grid trading is an automated strategy that trades futures contracts with preset intervals within a specific price range. The strategy will continuously buy low and sell high for each grid defined, and profit from the volatile market.

The futures grid currently supports all USDT-margined contracts and will support crypto-margined contracts in the future.

2. Use cases of Futures Grid trading

The essence of futures grid is "volatility arbitrage", so the strategy is suitable when the market is sideways or volatile with the price continuously fluctuate within a range. Meanwhile, the futures grid strategy can be directional, in which:

  1. Long Futures Grid: The bot only possess long positions and earn profit by closing it when the price increases. It works the best in volatile market with bullish outlook.

  2. Short Futures Grid: The bot only possess short positions and earn profit by closing it when the price drops. It works the best in volatile market with bearish outlook.

  3. Neutral Futures Grid: The both possess both long and short positions, in which the bot will short the futures contracts when price is above the base price and long the futures contracts when the price is below the base price.

User can select the corresponding futures grid strategy based on its insight on the market outlook.

3. How do I set up a Futures Grid trading bot?

3.1. Steps Overview

  1. Enter OKX on your PC or mobile and navigate to Trade, select Trading bot mode (at the top left corner on the web and top right corner on the mobile app), and click Futures grid.

  2. Enter parameters manually or use backtested AI parameters on the trading interface, and confirm the total investment amount to create a grid trading bot(After you create a bot, the initial funds will be isolated from your trading account and used for grid trading only).

  3. You can view and manage your bots on the Bots page.

3.2. Options and parameters

Setup Options

Set myself: Set parameters based on your own analysis of the market.

Set myself - Auto fill: Automatically fill in parameters recommended by the trading bot, based on backtested strategy.

AI strategy: Use the parameters recommended by backtested strategy (These parameters are based on a weekly backtest of this pair).

Grid Trading Parameters

Lower price: The bot will stop placing orders when the market price is lower than the lowest price.

Upper price: The bot will stop placing orders when the market price is higher than the highest price.

Grid quantity: The number of grids represents the number of pending orders divided in the price range. For example, if the price range is 100-400, the mode is arithmetic, and the number of grids is 3, it is divided into three grids: 100-200, 200-300, and 300-400.

Grid - Arithmetic grid: It keeps the same common difference between each grid. (For example: 1, 2, 3, 4.)

Grid - Geometric grid: It keeps the same common ratio between each grid. (For example: 1, 2, 4, 8.)

Leverage: The leverage used when trading contracts in the strategy. The maximum leverage currently allowed is 5x.

Used margin: The actual amount that was invested in this grid strategy. It will be separately used after grid starts working

Advanced - Take-profit (TP)/Stop-loss (SL) price: The bot will stop working when prices reach a predefined TP/SL value, and close all positions by placing a market order.

Open a position when strategy activates: You can open your first position when activating strategy. For example, if you open a position in long grid, the position price will automatically be higher than the current market price. You can profit from closing long when the price increases. Likewise for short position.

Total amount: Total amount with leverage, calculated as Used margin * Leverage.

Estimated liquidation price (Long): Estimated liquidation price of the long position with the maximum opening amount, on the assumption that all long orders in the grid are filled.

Estimated liquidation price (Short): Estimated liquidation price of the short position with the maximum opening amount, on the assumption that all short orders in the grid are filled.

(Order parameter) Estimated liquidation price: Estimated liquidation price of current positions.

(Order parameter) Actual leverage: Measure the actual leverage risk of current positions, calculated as Current positions value / Equity of strategy account.

3.3. Sample Case (BTC/USDT Futures)

Bot Parameters

Grid property: Long grid

Lowest price in range: 50,000 USDT

Highest price in range: 100,000 USDT

Grid Quantity: 50

Grid mode: Arithmetic

Leverage: 2x

Used amount: 5,000 USDT

Open the first position: Yes

BTCUSDT futures price when activate strategy: 60,100 USDT

Run the Bot

  1. Stage 1 - Initial order placement: The system will calculate the price of each grid, which are 50,000, 51,000, 52,000...98,000, 99,000, 100,000 USDT, and then place buy orders with 2x leverage in each grid. If the market depth is great, the buy orders will be filled above the market price and position opened, and the close sell orders will be placed at the price of each higher grid.

So, after the Bot starts, there are buy orders at each grid from 50,000 to 60,000 USDT and sell orders at each grid from 62,000 to 100,000 USDT.

  1. Stage 2 - Bot operation: A buy order will be filled when prices drop below 60,000 USDT, and in the meanwhile, a sell order will be automatically placed at the price of 61,000 USDT (which is the nearest grid above 60,000 to 61,000 range). If prices rise, after a sell order is filled, in the meanwhile, a buy order will be placed in the nearest grid below.

In this way, the Trading bot helps you make profits by placing and filling orders in a price range. It allows you to take advantage of a volatile market.

4. Risk reminder and notes

  1. If the current price falls below the 'Lower Price' defined, the bot will stop placing new orders. If the price continues to fall and is not recovering back to the grid price range, the position held by you will suffer losses, and might result in forced liquidation if leverage is applied. Therefore, it is recommended to set a stop-loss price below the 'Lower Price' of the grid to avoid massive loss under worst scenario.

  2. The fund invested in the grid will be isolated from your Trading account and used independently for the Trading bot. Therefore, users need to pay attention to the risk of overall positions in your Trading account after transferring funds.

  3. While the futures grid bot is running, if encounters unpredictable circumstances such as suspension or delisting of the underlying crypto asset, the bot will be automatically stopped.

III. Recurring Buy

1. What is Recurring Buy?

Recurring Buy is a dollar-cost averaging (DCA) strategy for investing a fixed amount in crypto at your defined fixed intervals. An appropriate recurring approach in volatile markets allows you to buy crypto at a lower cost.

2. How do I set up a Recurring Buy bot?

2.1. Steps Overview

  1. Enter OKX on your PC or mobile and navigate to Trade, select Trading bot mode (at the top left corner on the web or top right corner on the mobile app), then click Recurring buy.

  2. Select the asset to be invested and specify your allocation for each asset, then confirm the Frequency, Time, and Amount to create a Recurring buy bot. After the strategy is created, the fund is not reserved and isolated upfront for each cycle from the trading account. Please ensure sufficient fund in the trading account before each investment period.

  3. You can view and manage your bots on the Bots page.

2.2. Options and parameters

Crypto allocation: You can choose the crypto assets from the Recurring buy bot, either a single-pair or multi-pairs up to 20 assets. The Recurring buy bot will proportionally invest using the allocation parameters in each period.

Frequency: The frequency of each Recurring buy cycle. You can pick to buy in daily, weekly or monthly manner.

Local Time: The specific timing when the asset will be bought from local time on that day.

Amount: The investment amount used to buy the crypto assets at each recurring buy period. Currently, only USDT and USDC are supported as the quote currency. It will soon be further extended to other quote curencies.

Backtesting of last 2 years: when the sum of the crypto allocation equals to 100%, the bot will calculate the annual percentage yield using the given parameters within 2 years timeframe.

3. Risk reminder and notes

  1. Recurring buy won't preempt other assets in your accounts. In each investment cycle, please reserve sufficient funds to avoid the failure operation. In case of insufficient funds, the Recurring buy bot will be halted until the available fund is allocated in the trading account for the next investment cycle.

  2. While the Recurring buy bot is running, if encounters unpredictable circumstances such as suspension or delisting of the underlying crypto asset, the bot will be automatically stopped.

  3. Recurring buy uses the assets in your Trading account to buy crypto. Please be aware of the forced liquidation risk caused by assets changes in your Trading account.

IV. Smart Portfolio

1. What is Smart Portfolio?

The Smart Portfolio bot is an automatic strategy for dynamically rebalancing the position of user-selected crypto pairs. Dynamic rebalancing will assist in keeping a consistent proportion of each crypto in the user's portfolio. Users can select from two triggering modes of position rebalancing, one is based on a scheduled interval and the other one is based on a rebalancing threshold on the proportion ratio deviation of each crypto.

This bot takes the gains from exchange rate fluctuations to earn and stock crypto.

2. Use cases of Smart Portfolio

In the crypto market, prices of different crypto pairs may fluctuate at a different pace, so quite often investors may see the price of some crypto pairs falling while others are surging. If investors just hold the crypto, they may miss the profit when there is a large correction happening in the market. Whereas, if the user proceeds with the Smart Portfolio bot, it will help the user to sell crypto gradually when the price is increasing and re-invest those funds into pairs that have temporarily lagged behind but may have a high potential later. In this case, Smart Portfolio locks in the profit while increasing the position of high potential cryptos when the price is relatively low, and continuously earns extra returns over the long run.

3. Create a Smart Portfolio bot, Set the parameters and Examples

3.1 Create a Smart Portfolio bot

(1) After you enter OKX Web or App, select "Trading bot" on the "Trade" page (In the upper left corner of Web, and the upper right corner of App), then select Smart portfolio.

(2) Input the parameters on the order placement page, set the investment amount, and then a Smart portfolio will be created. (The assets invested in the Smart portfolio will be isolated from the manual trading account)

(3) Once created, you can view and manage bots in "Bots" at the bottom of the trading page.

3.2 Terms and parameters

Crypto allocation: You can choose the crypto portfolio for dynamic rebalancing, and then decide the market cap ratio of each crypto. During the bot is running, the position will be rebalanced with the preset ratio as the goal (up to 10 crypto selections, and available in USDT quoted pairs only)

Rebalance mode: There're two modes, Proportional and Scheduled

Proportional: The rebalancing is triggered according to the changed ratio of the market cap of the crypto. When more than 1 crypto was found to deviate from the preset ratio and exceeds the preset threshold, the rebalancing is triggered. (In order to avoid an extremely frequent position rebalancing, the next ratio-testing will be triggered every 5 minutes after the last rebalancing)

Scheduled: Monitor the degree of deviation and the rebalancing is triggered based on a fixed time period. After setting an interval, the bot will monitor whether the market value ratio of one or more crypto deviates from the preset ratio and exceeds the threshold, and if so, the balance will be triggered. (In order to avoid an extremely frequent position rebalancing, rebalancing will be triggered when the deviation ratio exceeds 3%)

Investment amount: The amount of funds invested in Smart Portfolio. After being invested, the funds will be traded into the crypto in the portfolio.

3.3 Examples

Example 1 - Proportional

Parameter settings

Crypto allocation: BTC | 50%; ETH | 30%; SOL | 20%

Rebalance mode: Proportional | 10%

Investment amount: 10,000 USDT

Running bot

Phase 1 - Exchanged into target crypto. The invested amount was traded into 5 BTC worth 5,000 USDT (assume the price of BTC is ₮1,000), 6 ETH worth 3,000 USDT (assume the price of ETH is ₮500), 20 SOL worth 2,000 USDT (assume the price of SOL is ₮100).

Phase 2 - Trigger rebalancing. Assume the price of BTC increases and reach 1,500 USDT, and prices of ETH and SOL are unchanged. Now the market cap proportion of each crypto are 60% : 24% : 16%. The BTC deviation rate ≥ 10%, rebalancing is triggered, so the Smart Portfolio bot will automated sell 0.83334 BTC, buy 2.5 ETH and 5 SOL, to remain the proportion unchanged. After this rebalancing, you will hold 4.16666 BTC (market cap 6,250 USDT), 7.5 ETH (market cap 3,750 USDT),25 SOL (market cap 2,500 USDT), which the ratio is same as initial BTC | 50%; ETH | 30%; SOL | 20%.

Example 2 - Scheduled

Parameter settings

Crypto allocation: BTC | 50%; ETH | 30%; SOL | 20%

Rebalance mode: Scheduled | 4 hours

Investment amount: 10,000 USDT

Running bot

Phase 1 - Exchanged into target crypto. The invested amount was traded into 5 BTC worth 5,000 USDT (assume the price of BTC is ₮1,000), 6 ETH worth 3,000 USDT (assume the price of ETH is ₮500), 20 SOL worth 2,000 USDT (assume the price of SOL is ₮100).

Phase 2 - Trigger rebalancing. Assume after 4 hours of bot creation, the price of BTC increases and reach 1,500 USDT, and prices of ETH and SOL are unchanged. Now the market cap proportion of each crypto are 60% : 24% : 16%. The BTC deviation rate ≥ 3%, rebalancing is triggered, so the Smart Portfolio bot will automated sell 0.83334 BTC, buy 2.5 ETH and 5 SOL, to remain the proportion unchanged. After this rebalancing, you will hold 4.16666 BTC (market cap 6,250 USDT), 7.5 ETH (market cap 3,750 USDT),25 SOL (market cap 2,500 USDT), which the ratio is same as initial BTC | 50%; ETH | 30%; SOL | 20%.

4. Risk reminder and notes:

4.1. After the Smart portfolio is created, the assets invested in Smart Portfolio will be isolated from the manual trading account. Please pay attention to the position risk of manual trading.

4.2 During the running of the Smart Portfolio bot, if the asset encounters unpredictable circumstances such as suspension or delisting, the bor will be automatically suspended.

V. Arbitrage

1. What is Arbitrage?

Arbitrage describes the low-risk act of profiting from the difference of interest rate spreads from different markets by using hedging or swap instruments. The most popular arbitrage strategies are funding rate arbitrage, spot-futures arbitrage and calendar spread arbitrage.

  1. Funding rate arbitrage: Simultaneously buying and selling the same amount of the same spot or perpetual swap to profit from the funding rate spreads in contracts trading.

  2. Spot-futures arbitrage: When the prices spread between spot and futures of a crypto has a big gap, opening positions by buying the instrument with lower price and selling the other one with a higher price. This arbitrage strategy profits from closing positions when the spread gets smaller.

  3. Calendar spread arbitrage: Buying and selling two different dated derivatives of the same crypto, profiting from the spread changes. The calendar spread may not equal to 0, so its risk is higher than Spot-futures arbitrage.

2. Why using Arbitrage Order Strategy?

Usually traders who want to place an arbitrage order need to track two markets simultaneously to avoid slippage. With using the strategy assistance tool that OKX provides, users can improve trading efficiency and accuracy.

3. How do I set up a Arbitrage Order trading bot? (take web for example)

3.1. Steps Overview

Modules of OKX Arbitrage Order Strategy

There are four modules: Portfolio information on the top, Order placement on the left, Order book in the middle, Candlestick charts on the right.

Users can select appropriate arbitrage portfolios based on the arbitrage order placement information which is calculated by OKX.

After selection, the two underlying assets in portfolio will be shown in Order placement, and the arbitrage sides have been selected already.

Assistance functions

  1. The "Switch" button next to underlying assets can help to change the location of left and right leg in Order placement, Order book and Candlestick charts.

  2. When input the price, users can know the trading spread which is the Arbitrage cost, calculated by Price rate tool in the middle of price zone. Users can also calculate right leg price by input left leg price and spread rate.

  3. Make an equivalent amount/total between the legs that have been inputted and not been inputted, by tick "Same amount" or "Same total".

  4. To ensure one leg can be traded successfully when another leg has been filled, tick the checkbox "One leg will be traded under market price once another leg has been filled"

Explanations of 5 prices

The meaning of Limit price, Market price and Counterparty price are identical to the semantics when used in the Manual Trading mode. Limit price is the price users set. Market price the current price the asset is traded and potentially the order can be filled quickly. Counterparty price (BBO) is the best price (bid or ask) from the opposite side of your order.

Surpassed price

Buy: Order price = Best bid price + Taker range * Tick size, Taker range is set by users

Sell: Order price = Best ask price - Taker range * Tick size

Queuing price

Buy: Order price = Best bid price - Maker range * Tick size, Maker range is set by users

Sell: Order price =Best ask price + Maker range * Tick size

Auto-Tracking

When "Auto-tracing" is on, system will auto track the status of orders on every "tracking interval". If orders are still unfilled or partially filled, and the order price is far from the queuing price range, the orders will be queued again at latest price after withdrawing the previous order.

When "Pause auto-tracing" is on, system will stop auto-tracking when the latest queuing price has reached the price threshold for suspending the chasing order. The specific pause price = the first pending order price * (1 + threshold)

After orders are placed, users can view the status of orders or cancel orders under the Arbitrage order tab. Besides, users can still view and act on sub-orders in Current or History orders under Manual trading mode.

Closing Arbitrage Order Bot and Book the profit

For Funding rate arbitrage, fees will be settled into your trading account daily;

For Spot-futures arbitrage, users can profit from closing a position when spread in two-leg market gets smaller

When the funding fees profit fulfills your expectation, or there's no profiting chance, or the profit fulfills due to spread getting smaller in Spot-futures and Calendar spread arbitrages, you can close positions to book your profits. That is, closing the current positions in the opposite side to when the arbitrage orders were placed. The actions and principles are same as the processes above, please be aware to control the slippage. After fully closing positions, congratulations! You have completed an arbitrage trading successfully.

VI. Iceberg strategy

1. What is the Iceberg strategy?

The iceberg strategy is an algorithmic order type allowing users to avoid placing a large order and cause slippage. An iceberg order automatically breaks up users' large order into multiple smaller orders. These orders will be placed in the market according to the latest best bid and ask price as well as the parameters set by the user. When one of the smaller orders has completely filled, or the latest market price has deviated significantly from the price of the current order, the others orders will be executed progressively.

2. Sample Case (BTC/USDT)

A user would like to buy BTC at a price below 20,000 USDT and does not want to increase the cost. He can set an iceberg order

Bot Parameters

Range - Ratio (Price Variance): 0.1%

Price limit: 20,000 USDT

Average amount: 2 BTC

Total amount: 100 BTC

Run the Bot

The system will automatically place an iceberg order. The order price will be the latest buy price*(1-Price variance 0.1%), and the amount of each order will be 50% to 100% of the average amount. Once the order completely filled, a new order will be placed.

When the last market price exceeds the highest buy price of 20,000 USDT, the iceberg order would be temporarily halted. After the price falls back to 20,000 USDT, the iceberg order would be resumed.

When the last market price exceeds 2*(Price variance), the previous order would be canceled, and a new one will be placed.

When the total trading volume equals its total amount, the bot will stop the order and end its operation.

VII. Time-weighted Average Price (TWAP)

1. What is the Time-weighted Average Price?

Time-weighted average price (TWAP) strategy splits your order and places smaller orders at regular time intervals.

It is a strategy that will attempt to execute an order which trades in slices of order quantity at regular intervals of time as specified by users. The purpose of TWAP is to minimize the market impact on basket orders. This bot triggers the order based on the predefined time intervals. It calculates the order price based on the current best bid/offer price,then splits the order into smaller ones and places them on the market(If the order is not fully filled, it will be canceled directly according to the IOC order rules).

2. Sample Case (BTC/USDT)

Assume that user A wants to buy BTC contracts below 10,500 USDT as soon as possible without increasing the purchase cost on the current market, so user A sets up a TWAP bot as follows:

Bot Parameters

Price variance - percentage: 1%

Price limit: 10,500 USDT

Interval: 20s

Average amount: 500 contracts

Total amount: 10,000 contracts

Run the bot

After the order is placed, the system will place orders at regular time intervals. Assuming the order book is as below:

According to the predefined price range, the highest buy price equals the Best Bid Offer (BBO), which is 10029.99*(1+price range 1.0%) = 10130.29 USDT. The total amount of sell orders below 10130.29 USDT is 570+1+200+1+1+1+1=775,and multiply the random number between 0.5 to 1 (e.g., 0.63) to get the order amount=775*63%=488.25 contracts. The order amount is less than the predefined average amount of 500 contracts, so the bot buys 488 contracts of sliced order at 10130.29 USDT. If the order is not fully filled, it will be canceled directly, which means the sliced order is an IOC order.

The bot will place orders constantly based on the predefined time intervals*random ratio (0.5~1) until the total filled amount reaches the predefined total order amount.

The bot will place the order at the limit price if the order price is higher than the predefined limit price.

If the order amount is more than the predefined average amount, the bot will place the order based on the average amount* random ratio (0.5~1).

The order will be suspended when the last price (20,500 USDT) is higher than the limit price and resumed when the last price is below 10,500 USDT again.

The bot will stop when the total filled amount equals the total order amount.