Product
12.4 min read
TWAP strategy can automate trading and improve liquidity
January 5, 2023
Key points:
- The objective of the strategy is to produce an average price that is close to the time-weighted average price (TWAP) for the period that the user specifies.
- TWAP can mitigate the financial impact of a large order.
- These strategies can tackle the slippage by creating smaller orders and giving arbitrageurs a short window to close any price discrepancies and bring the reserves back to equilibrium.
- Due to recent events in the market that are out of the control of the DeFi community, liquidity crunches are a prominent issue right now, so Orbs integrating dTWAP with SpiritSwap couldn’t have come at a better time.
- TWAP can be used to construct trading strategies in a way that does not require any additional action from the trader other than making sure enough funds are available to complete all trades.
Bids can affect the price of an asset in the order books or liquidity in the pools of liquidity. For instance, order books have multiple bids and offer at different prices. When a large order is placed, the price of an asset increases because all of the cheapest orders are being fulfilled.
For instance, Coin A is currently priced at $10 and has the following:
- 50 buy orders at $10
- 50 buy orders at $11
- 50 buy orders at $13
- 100 buy orders at $15
- 500 buy orders at $17
Trader A places a bid of 300 Coin A tokens for $17. Since the total order amount is greater than the cheaper orders, the protocol will execute the $10, $11, $13, and $15 prices to complete the order.
However, the total order isn't large enough to cover all the bids at $17, so the price of Coin A will stop at that point. This is a 70% increase in price, primarily observed in coins with low liquidity. In most instances, the price increase would be less severe.
Even though most decentralized exchanges lack order books, they have automated market makers (AMMs) that adjust the price of a token based on the size of the order and the liquidity pool. The liquidity is derived from liquidity providers (LPs) who contribute a portion of a token pair in exchange for a share of the fees.
Liquidity in decentralized finance is more dispersed than in more established financial markets, this may lead to a greater impact from a single transaction. SWAP strategies can potentially mitigate the price impact, for example, by executing trades in 4-5 minute intervals over an hour.
Breaking up the larger order can give the DEX time to resolve any price discrepancies within the respective liquidity pools, this will help to bring the asset back to its original price. The strategy can benefit DEXs because larger price fluctuations have a greater effect on the token pairs in the liquidity pool.
For instance, the cheaper token in the pair can have lower liquidity, which will lead to higher slippage (the difference between the expected price of a trade and the actual price it executes at). Increased liquidity can facilitate larger trading volumes for a DEX and provide a more enjoyable experience for traders.
Slippage is typically caused by a lack of liquidity that cannot reach demand, this causes an asset's value to increase. Ran Hammer, the vice president of business development at Orbs, discussed whether TWAP could reduce slippage on DEXs.
TWAP, when employed correctly, can reduce slippage and price discrepancies. These issues occur on DEXes when trades are too large relative to the pool's overall liquidity and have a disproportionate effect.
“TWAP strategies can mitigate this problem by creating smaller orders and giving arbitrageurs a short window to close any price discrepancies and bring the reserves back to equilibrium.”
Deg3ntrades, a member of the undoxxed development team at SpiritSwap — a decentralized exchange and DeFi platform on Fantom — also shared his thoughts, mentioning decentralized TWAP (dTWAP), the version of TWAP implemented on SpiritSwap.
Deg3ntrades explained that dTWAP orders fragment trades into smaller batches, this allows the user to specify the intervals at which these trades are executed over a pre-determined time. This causes the market to be able to absorb and minimize the price impact of large orders across pairs that have low liquidity.
“Due to recent events in the market that are out of the control of the DeFi community, liquidity crunches are a prominent issue right now, so Orbs integrating dTWAP with SpiritSwap couldn’t have come at a better time.”
Based on the feedback above, smaller orders can facilitate liquidity by reducing the number of tokens exchanged and allowing liquidity pools to be replenished between trading periods.
TWAP can facilitate the dollar-cost average process.
The term dollar-cost averaging (DCA) is associated with an investing strategy that involves purchasing a fixed amount of an asset or portfolio of assets (e.g., $100 every week). The DCA strategy is employed when volatility is high or a trader has a limited amount they want to invest at the time.
For instance, if Coin B's price fluctuates every other day for a month, an investor can purchase $250 worth of Coin B every week instead of attempting to buy at the perfect time. This is because the cost will ultimately average out over time, despite the asset's fluctuating price.
TWAP is a method of automatically dollar-cost averaging orders. This can be accomplished by a trader themselves. The strategy is based on placing longer intervals between transactions and a larger overall duration for the trades. For instance, trades can be placed every two weeks, every week, or every month over a few months, a year, or indefinitely.
Decentralized time-weighted average price
The decentralized time-weighted average price is a variant of TWAP that was developed by Orbs for DEXs and AMMs. The protocol facilitates decentralized exchanges, which are already being utilized on the SpiritSwap DEX.
The dTWAP smart contract employs a "maker" and "taker" system. The buyer is the person who places the order, they'll be able to set the price, the order intervals, and the expiration date.
The term "taker" is associated with an independent party that oversees the orders submitted by users (makers) on the DEX. The taker attempts to find the most effective way to execute the batch of orders and bid on those orders when found. Takers receive a fee for bidding on orders and compete with other takers who may be bidding on the same orders.
Takers charge a fee, the minimum amount is sufficient to cover the transaction fee for exchanges. Validators on the Orbs network, called "Guardians," take part in the protocol as takers, automatically bidding on multiple orders for the maker.
The user experience of TWAP is enhanced by the use of the TWAP app
The time-weighted average price protocol is portable, it can be integrated into DEXs. Trades that utilize the protocol can be divided into market orders (which are executed at current market prices) or limit orders (which are executed at a specific price or better).
The dTWAP smart contract will execute trades at the current market price at the user's set intervals. Once a user sets a limit price, trades will only occur if that price is available at the desired intervals. The transaction will not occur if the maximum price is not available. As a result, a directive might only have a portion of its trades executed if the desired prices for the limit aren't reached.
For instance, a user sets a maximum price of $50 or less for Coin C, with seven intervals over four weeks (28 trades total). During the second week, the price did not reach $50 for three days, so four trades were executed (out of seven for the week). All of the trades for the order were completed.
Who gains
TWAP can be beneficial to traders who want to invest in lower liquidity tokens or automate their trading process.
TWAP has two primary purposes that benefit traders. One of the most significant benefits of this is the capacity to make large trades or trades in pairs that are long-tailed and low-volume without affecting the price. Additionally, it can be employed to automate dollar-cost averaging strategies (where the trader purchases a particular asset or group of assets on a regular schedule), Hammer said.
“TWAP can be used to construct such strategies in a way that does not require any additional action from the trader other than making sure enough funds are available to complete all trades.”
Deg3ntrades said, “The capacity to utilize TWAP orders not only minimizes traders' exposure to high slippage/price impacts on large orders or when trading in low-liquid pairs but also opens up and makes available a plethora of new trading strategies to more experienced and advanced DeFi users, such as automated dollar cost averaging.”
Decentralized time-weighted average prices can enhance the experience of both traders and decentralized exchanges. Additionally, the increased liquidity, lower price impact, and trade automation of dTWAP could also increase interaction between users and DEXs.
From the blog
The latest industry news, interviews, technologies, and resources.
If you do not do it right, your investment can disappear within a few seconds. But do not despair—this guide will explain the most efficient ways to protect crypto assets in this constantly shifting environment.