Developer Tutorial
๐ Summary #
This strategy is a simple bot that places a series of limit orders on an exchange, while allowing users to control order size, price, and duration.
We recommend this strategy as a starting point for developers looking to build their own strategies, and it is used as reference for articles in Developer Reference: Strategies.
๐ฆ Exchanges supported #
spot
exchanges
๐ ๏ธ Strategy configs #
Parameter | Type | Default | Prompt New? | Prompt |
---|---|---|---|---|
connector | string | True | Enter the name of spot connector | |
trading_pair | string | True | Enter the token trading pair you would like to trade on [connector] | |
trade_side | string | buy | True | What operation will be executed? (buy/sell) |
target_asset_amount | decimal | 1 | True | What is the total amount of [base_token] to be traded? |
order_step_size | decimal | 1 | True | What is the amount of each individual order (denominated in the base asset, default is 1) |
order_price | decimal | True | What is the price for the limit orders? | |
order_delay_time | decimal | 10 | True | How many seconds do you want to wait between each individual order? |
cancel_order_wait_time | decimal | 60 | True | How long do you want to wait before cancelling your limit order (in seconds). |
is_time_span_execution | bool | False | False | Do you want to specify a start time and an end time for the execution? |
start_datetime | decimal | False | Please enter the start date and time | |
end_datetime | decimal | False | Please enter the end date and time |
๐ Description #
Approximation only
The description below is a general approximation of this strategy. Please inspect the strategy code in Trading Logic above to understand exactly how it works.
The TWAP strategy is a common algorithmic execution strategy used for splitting up large orders over time. Specifically, the TWAP strategy helps traders minimize slippage when buying or selling large orders. These features make the strategy more useful to traders and will help when creating future, more complex strategies:
- Incrementing / maintaining states over clock ticks
- Quantizing (rounding down to nearest tradable value) order size
- Dividing an order into segments
- Incorporating time delays between segmented orders
Overview #
The TWAP strategy divides a large user order into chunks according to the following user configurations:
- Total order size
- number of individual orders
- time delay between orders
The orders are then split into tradable (quantized) amounts and executed sequentially with the indicated time delay in between orders. There is no time delay before the first order. Because only one order is placed in a clock tick, a state machine is needed to emit multiple orders over different clock ticks. To see the executed orders, type history into the command prompt.
Config #
Here are the additional user configurable parameters for the TWAP strategy (fields are added to config_map
file):
time_delay
: Change the question to ask for the number of seconds to delay each individual order. (e.g. How many seconds do you want to wait between each individual order?)num_individual_orders
: a new field added to the config map. It should ask for the number of individual orders that an order should be split up into. (e.g.Into how many individual orders do you want to split this order?)
Strategy #
The TWAP strategy logic is trying to split a large order into smaller ones over time, and it does that by maintaining important information about the state when processing orders by adding state variables.
๐บ Demo #
Warning
This demo is for instructional and educational purposes only. Any parameters used are purely for demo purposes only. We are not giving any legal, tax, financial, or investment advice. Every user is responsible for their use and configuration of Nonstop Algo.
https://www.loom.com/embed/8b36e590272c479fa0ccf69b011433e1
โน๏ธ More Resources #
Advanced TWAP Strategy: The โtwap_plusโ strategy highly involves the Relative Strength Indicator (RSI) trend of a certain trading pair to execute trades. This way users can setup bots to match whenever the RSI levels are theoretically giving โBuyโ signals or โSellโ signals and decide potential entry and exit points.