Share articles to

Academy Beginners Tutorial Article
OKX Trading

How to use the OKX trading bot for automated crypto buys and sells

2021.11.19 OKX

A step-by-step guide for using OKX’s trading bot to automate your strategy

As one of the world’s leading cryptocurrency ecosystems, OKX offers a comprehensive suite of products and services. In addition to our extensive trading pairs, decentralized finance offerings and opportunities to generate passive income, we’ve now introduced a customizable trading bot to help you leverage various automated and manual trading strategies.

Table of contents:

Trading bots modes

The OKX trading bot has four distinct modes — spot grid, arbitrage order, iceberg and TWAP (i.e., time-weighted average price) — suitable for varying purposes and needs. The first mode, called spot grid, is ideal for traders of any volume hoping to lock in additional profits from asset volatility. You can determine the spot grid’s parameters yourself or choose the AI strategy, which is based on previous price movements. 

Arbitrage order simplifies locking in profits from price discrepancies between OKX trading instruments. For example, using the bot in funding rate arbitrage mode enables users to make money from the payments traders must make to keep perpetual swap positions open. Spread arbitrage mode presents opportunities to profit from the price difference between futures contracts with different settlement dates, or between futures and spot prices. 

The third and fourth modes are intended for traders with larger orders. Both TWAP and iceberg orders use the bot to enter or exit a market where price slippage is a risk. These modes are ideal for those wanting to place big trades relative to the size of the chosen market. Large trade sizes can shift the price unfavorably in less liquid markets — like those of smaller market-cap assets listed on OKX. Therefore, these modes can be helpful when placing such relatively large orders.

The tutorial below covers all four modes as well as instructions for accessing and using the OKX trading bot.

Accessing OKX’s trading bot

Visit the OKX homepage and log in to your account using the Login button at the top-right corner of the screen. Enter your email address or telephone number and password, and click Log in. Alternatively, you can scan the QR code using the OKX application. 

Complete any two-factor authentication checks you have active on your account and click Continue

Back on the OKX homepage, hover over Trade and click Trading bot.

You’ll see the different trading bot strategies listed below the chart in the Trade section. 

Using the spot grid mode for automated buys and sells

Spot grid mode enables you to set a manual price range or use a back-tested AI strategy according to which the trading bot will execute automated buys and sells. This mode is handy for high-volatility assets in bullish markets.

Spot grid mode splits your starting capital between the two assets of your chosen trading pair. It then creates a grid of price points between the upper and lower bounds, and divides your starting position equally between the number of grids used. 

Each time the asset price reaches the upper grid line, the bot automatically sells a portion of the asset. When the asset price reaches the lower grid line, the bot automatically buys the asset. The trader profits from the difference between the buys and sells executed as the price swings.

The following example demonstrates how this works in practice:

Maxwell has $10,000 and wants to profit from BTC price volatility as it trades at $60,000. In manual spot grid mode, he sets a lower price of $50,000, an upper price of $70,000 and 20 grids. This places grid lines with buy or sell orders positioned after every $1,000 interval.

The bot divides his starting position — $10,000 — equally between the number of grid lines. In this case, each grid line is allocated $500 (10,000/20). Since the price when he opens his trade is exactly in the middle of his stated range ($60,000), half of his 10,000 USDT is immediately exchanged for BTC. Under this setup, the bot establishes $500 BTC sell orders at $61,000, $62,000, etc., up to $70,000, and $500 BTC buy orders at $59,000, $58,000, etc., down to $50,000. Each time a buy or sell order is hit, the bot rebalances the grid with the starting point at the new price. 

If the BTC price moves up to $61,000 over the next day, the bot sells $500 worth of BTC for USDT. The grid rebalances with BTC sell orders above $61,000 and buy orders below. If then, the price moves down to $60,000 again, it fills a buy trade and nets Maxwell just under $8.20 in profit — while also returning the BTC position to roughly its starting size.

If Maxwell had simply held his position, the price action described above would result in $0 profit.

Click Spot grid from the trading bot menu to access spot grid mode.

Then, select the pair you wish to trade using the top-left menu. 

Using the AI strategy for the spot grid

The easiest way to use the spot grid trading bot is with OKX’s back-tested AI strategy. This strategy determines the number of grids and price range on your behalf based on historical price data. 

In the spot grid section, select AI strategy.

Then, set the amount you want the bot to trade and click Create.

On the next screen, check your order details and click Confirm.

You can then check your open positions in the “Bots” tab on the main trading dashboard. Clicking Stop will exit positions associated with a particular order.

Manually setting the spot grid parameters

OKX’s trading bot allows you to determine the spot grid parameters manually. This is riskier than using the AI strategy — particularly for novice traders. However, it does allow for greater user control and potentially higher profitability. 

Click Set myself in the spot grid section. 

Next, enter the upper and lower price bounds for your desired trading range. Then, enter the number of grids you would like to fill the range. This will determine the size of the buy and sell orders the bot creates. Next, enter the total amount you want to invest.

There is also an option to set how the grid is spaced. “Arithmetic” will position each grid line at fixed price intervals (e.g., every 20 USDT). Meanwhile, “Geometric” sets the grids using a fixed percentage from the current price, resulting in widening grids further out from the starting price. 

Additionally, you can add a price at which to take profit from your trade or a stop loss. These are useful if the asset price increases or decreases beyond the range you set, and they essentially exit your position either in profit or to limit further losses. 

When you have determined the spot grid parameters, click Create.

On the next pop-up window, check the trade details and click Confirm.

You can check your open positions in the “Bots” tab on the main trading dashboard. Clicking Details will show additional information about the trade, including the profits the grid has produced and those occurring because of the price movement itself. 

To exit trades associated with spot grid mode, click Stop next to the relevant order in the “Bots” section or “Order info” section. 

Placing arbitrage orders using the trading bot

OKX’s trading bot features a mode to simplify placing orders to take advantage of arbitrage opportunities between different instruments. Discrepancies between spot and futures contract prices can present profitable situations for traders. This is known as spread arbitrage. 

Similarly, longing an asset in the spot market and shorting with a perpetual swap provides an opportunity to profit via funding rate payments. This is known as funding rate arbitrage. 

If you’ve never traded futures or perpetual swaps before, we recommend you read OKX’s tutorials about each product before attempting to use this arbitrage bot. This will help you understand the risks when trading futures or perpetual swaps.

To get started, click Arbitrage order from the list of trading bot strategies. 

Next, click the arbitrage portfolio at the top and select the portfolio you want to trade. 

Funding rate arbitrage

Select either Crypto-margined to settle trades in your chosen cryptocurrency or USDT-margined to settle in USDT. Next, choose the arbitrage portfolio you want to trade from the list. 

Each funding rate arbitrage portfolio has both a spot pair and an equivalent perpetual swap contract. You’ll also see important information about each arbitrage portfolio here, including its three-day expected revenue (assuming a 10,000 USDT position), expected APY and the three-day cumulative funding rate. 

Next, enter the details of each leg of the order, including whether it is a buy or sell order, the desired USD price and the amount in the crypto asset traded. Check the details and click Both Legs to submit both orders simultaneously. 

If the funding rate is positive, you want to be shorting the perpetual contract because long positions will pay you to keep it open. Conversely, if the funding rate is negative, you want to long the perpetual swap to earn funding rate payments from short positions. 

The strategy is low risk, as the two positions cancel each other out. However, if the funding rate goes against you for a prolonged period, you will pay the opposite side of the perpetual position and may lose money overall. 

Spread arbitrage

Spread arbitrage can be performed between two futures contracts or a futures contract and spot position. In spread arbitrage, we take opposite positions in two markets, profiting from price differences.  

Let’s presume BTC spot price is currently $50,000, and a futures contract is priced at $50,100. If we buy 1 BTC in the spot market and short sell the futures contract, we will profit with minimal risk no matter the price when the futures contract settles. 

For example, the spot price at settlement is now $55,000. We can sell our spot position for a $5,000 profit — minus trading fees. Meanwhile, our futures position will lose money since we agreed to sell BTC for $50,100 at settlement. OKX sells the BTC on our behalf to honor the futures contract, losing us $4,900. So, we have $5,000 in profit from our spot position and a loss of $4,900 from the futures contract, resulting in a net position of just under $100 — minus the trading fees.  

If the price went the other way, we’d still profit. Let’s say the price dropped to $45,000. Our spot position would lose $5,000. However, our futures position would sell BTC at $50,100 above the spot price, locking in a $100 profit (minus trading fees). The only real risk with this strategy is that the price moves so much that your futures position is liquidated. You can read more about OKX’s liquidation rules here

From the arbitrage portfolio screen, select Spread arbitrage

Select the margin mode from Crypto-margined and USDT-margined. Next, click F-F to arbitrage between futures contracts or F-S to arbitrage between futures and spot positions.

Select the arbitrage portfolio you want to trade. You’ll also see various details about the expected profitability of each arbitrage portfolio to help inform your decision.  

Next, fill in your order details for both legs of the order. The portfolio chosen will determine the order type for each leg — either Buy or Sell.

You can choose between “Cross” and “Isolated” margin mode for your derivatives positions. Cross margin mode uses all account funds of the currency traded as a position’s margin. Meanwhile, the Isolated margin mode uses only just funds designated as the margin position. You can also add leverage to your order using the multiplier option. Although leverage can increase your potential profits versus your starting capital, it also increases your liquidation risk. 

For each leg of the trade, enter the price for your limit order and the amount in the crypto asset. Alternatively, you can enter your desired spread size using the “Spread rate” option between the two legs. 

You can further customize your trades using the order types Queuing, Surpassed, BBO and Market. Click the cog button to tweak the “Queuing” and “Surpassed” parameters. These two order types will create a range in which your order will be filled — useful to ensure both legs of the arbitrage are filled at favorable prices. 

When you are happy with your orders, click Both legs to place them simultaneously. You can also use the checkbox to immediately place a market order for the second leg as soon as the initial order fills, guaranteeing that both legs are placed. However, this may reduce the overall spread size, impacting the strategy’s profitability.    

Placing Iceberg orders using the trading bot

Iceberg orders are large buys or sells broken down into many smaller orders. They are particularly useful when making a large trade relative to the size of the market. Even a smaller order can move the asset price in illiquid markets, resulting in a less favorable entry or exit. Iceberg orders attempt to mask large orders and limit the impact of price slippage. 

To enter iceberg mode, click Iceberg from the trading bot options.

In the Iceberg section, select the product and trading pair you want to trade using the menu in the top-left corner. You can use the trading bot in the Spot, Perpetual, Futures, Margin and Options markets. Select the desired instrument and then the trading pair from the list. 

Next, enter the amount of slippage you will tolerate — i.e., the amount by which the price can move when executing your trade —  in the price range field. You can do this in increments of the trading pair’s base asset using the “Var.” option or as a percentage of your order price by using the “Ratio” option. 

Under “Price limit,” enter your ideal exit or entry price. This is the minimum price at which your sell orders will execute or the maximum price of buy orders.

Then, enter the average amount of each of your smaller orders and the total position size. Click Buy (Long) or Sell (Short) to place your iceberg trade. 

Check your trade details on the next pop-up window and click Confirm

Placing TWAP orders using the trading bot 

TWAP mode — short for time-weighted average price — seeks to execute a large trade over a specified period. It is similar to an iceberg order in that it attempts to enter or exit a market with a large position without significantly moving the asset’s price. 

To enter the trading bot’s TWAP mode, click TWAP from the bot selection page. 

Now, once again, select your desired trading pair and instrument using the menu to the top-left of the TWAP section. 

Choose whether you want to buy or sell the first asset listed in the trading pair and input your tolerated price slippage. Selecting “Var.” enables you to enter an amount denoted in the second asset from the trading pair. Meanwhile, “Ratio” allows you to choose your slippage based on a percentage move from the limit price. 

Next, enter your desired limit price, the time interval at which you want the bot to make trades and the size of each buy or sell. Finally, enter the total trade amount and click Buy [asset].

Check your trade details and click Confirm on the next screen to initiate the bot. 

Stopping the trading bot and closing trades

You can check on any trades you have created using the trading bot in the “Bots” tab of the trading dashboard. Here you can view details of your trades, including their profitability to date, and here is also where you can stop the bot manually. 

Just click Stop next to the relevant trade to stop an active bot.

You can then keep the asset traded or exit your position to USDT. Choose the appropriate option and click Confirm.   

Your trade will then disappear from the “Bots” section and appear in your “History.” 

If you experience any difficulties using the trading bot, feel free to contact our support team via the OKX Telegram group or our dedicated Support Center

Not already an OKX trader? Create an account and enjoy a sign-up bonus for joining us!

Catch up on all the latest crypto industry news and subscribe to the OKX Insights podcast, Send It.

Disclaimer: This material should not be taken as the basis for making investment decisions, nor be construed as a recommendation to engage in investment transactions. Trading digital assets involve significant risk and can result in the loss of your invested capital. You should ensure that you fully understand the risk involved and take into consideration your level of experience, investment objectives and seek independent financial advice if necessary.