DEXBot Staggered Orders Strategy

in #dexbot5 years ago

https://github.com/Codaone/DEXBot/wiki/The-Staggered-Orders-Strategy

22.0 The Staggered Orders Strategy

Staggered-Orders

22.0.1 Places a large amount of buy and sell orders at certain intervals, covering the orderbook from very low prices to very high prices.

22.0.2 The range is supposed to cover all conceivable prices for as long as the user intends to run the strategy. That could be from -100x to +100x (-99% to +10000%).

22.0.3 Profits will be made from price movements, and the strategy introduces friction to such movements. It gives markets depth, and makes them look better. It never "sells at a loss", but always at a profit.

22.0.4 This strategy works well on laptops and computers that aren't on(line) all the time. It works perfectly well if you run it a few times a day, once a week or once a month. More profits will likely be made if it's online all the time, but even that is not sure. It depends on market conditions.

22.1 Parameters and Configuration

  • 22.1.1 Mode: mountain, neutral, valley, buy slope, or sell slope. Explained lower.

  • 22.1.2 Spread: Spread between your highest bid and lowest ask (%)

  • 22.1.3 Increment: At which increments will orders be placed (%)

  • 22.1.4 Lower bound: How low do you expect the price to ever go? Buy orders will be placed from center price down to this price. Price of Quote asset as measured in Base asset.

  • 22.1.5 Upper bound: How high do you expect price to ever reach? Sell orders will be placed from center price up to this price. Price of Quote asset as measured in Base asset.

  • 22.1.5.1 Allow instant fill: When several orders fill and the price immediately returns, the bot will have to place orders that will likely fill instantly.

22.1.5.1.1 If this option is enabled, the target spread will be recovered easily, and some immediate profit will be made.

22.1.5.1.2 If this is disabled, the bot will have to remove some orders to get the necessary funds to keep going. Default is on, and we recommend keeping it so.

  • 22.1.6 Operational depth: Actual number of orders to maintain on the books. Instead of placing all orders to cover full range, maintain only N orders deep.

22.2 Logic

22.2.1 Initial orders placement

22.2.1.1 On each start the strategy checks whether there are buy and sell orders on the specified market.

22.2.1.2 If there are no orders, the strategy will start to place buy and sell orders one-by-one starting from the far end (lower bound and upper bound). This should result in getting the best possible prices even if the center price isn't where expected or moves after starting.

22.2.1.3 The orders are placed on price * (1 + increment) distance from each order. Order amounts are calculated automatically. Bigger range decreases order sizes. Smaller increment decreases order sizes.

22.3 How profits are made

22.3.1 The bot makes orders to buy back more of what it sold, for the same total price, and to sell back all of what it bought, for a higher price.

22.3.1.1 This way every time the price moves in an opposite direction, profits are realized. As the price moves back and forth, a little or much, small profits are made and immediately reinvested to increase future compound profits.

22.3.1.2 This can continue as long as the price ever moves anywhere, and the price stays within assigned range.

22.4 Spread, increment and profits

22.4.1 Increment is a distance between orders and spread is the distance between the highest buy orders and the lowest sell orders of the strategy.

22.4.2 The actual profit will not be equal to defined spread as you may think. The profit will be somewhere between spread and spread - increment. Why? Because the resulting profits is a combination of spread trades and volatility trades.

22.4.3 Lets take a look at a simple example to understand this:

22.4.3.1 Example setup:

  • 22.4.3.2 spread: 10%
  • 22.4.3.3 increment: 4%
  • 22.4.3.4 orders prices: 83 87 91 95 <center> 105 109 113 117

22.4.4 While price is not moving anywhere, you may take profits from spread (105-95 = 10), this will give the max profit %.

22.4.4.1 Then imagine that buy order at 95 was filled. The next sell order will be placed at price 101. If it is also filled, the realized profit will be 101-95 = 6

22.4.5 Note: on significant price movements non-slope modes can actually bring bigger profit than just usual spread - increment. This may happen because newly obtained liquidity from trades is distributed across ALL range, increasing far orders.

22.5 Filled orders

22.5.1 Fully filled order on the one side will result in placing a next closer-to-center order on the opposite side. It will be closer by price * (1 + increment).

22.6 Partially filled orders

22.6.1 When there is a partially filled order on the one side, the strategy will not immediately allocate the newly obtained funds. Instead, it will reserve the amount needed to place a next closer-to-center order.

22.6.2 Also, if there are both buy and sell trades resulting in partially filled orders on the both sides, the strategy will replace these orders with a new full-sized orders if there is enough funds.

22.7 Allocation of excess funds

22.7.1 New available funds may come from trading profits and/or from the transfer from another account. In both cases these funds will be allocated by expanding the range if needed, or/and by increasing existing orders in size.

22.8 Operational depth

22.8.1 Staggered Orders strategy is intended to work on a wide range like -100x to +100x. To cover such a wide range, it may require hundreds or even thousands of orders. Maintaining such orders count puts a significant overhead on the strategy execution time, on the blockchain (by order placements and cancellation transactions), and also lots of time is needed for initial orders placement. Furthermore, playing with spread and increment also requires replacing of all orders.

22.8.2 As actual trading is happening around market center price, it's enough to keep only N orders around the center to handle price movements in near-center range.

22.9 The basic factors to consider while setting operational depth:

  • 22.9.1 Worker online %. The less worker is online, the more depth it needs to handle price movements.
  • 22.9.2 Increment size. The less increment is being used, the more depth it needs. Otherwise, worker may not benefit from catching a large buy or sell candle.

22.9.3 The logic of operational depth is following:

  • 22.9.3.1 When initial orders placement is happening, only N-depth orders are placed to orderbook, and remaining orders are kept in memory as "virtual" orders.

  • 22.9.3.2 On each restart the strategy will restore all virtual orders based on the amount of the current furthest real order

  • 22.9.3.3 On price movements, virtual orders are replaced with real orders on as-needed basis to keep no less than N real orders on market

  • 22.9.3.4 When price movement is directed to one side, the opposite side may accumulate excessive orders (N + x).

22.9.3.4.1 These excessive orders will be automatically replaced with virtual orders one-by-one if the actual number of orders on this side will exceed N + threshold (threshold is defined in code and can be changed later, so current value is omitted here).

22.9.3.4.2 Note that furthest real order will be replaced only if it's amount is the same as next order closer to the center. This condition is a must to not break normal asset balance distribution inside a trading side.

22.10 Range expanding

22.10.1 At any time the user can adjust range bounds. The strategy will place additional orders to cover the new range using trade profits or funds transferred from outside. If boundaries are narrowed, newly available funds will be used to increase order sizes.

22.11 Fallback logic when target spread is not reached

22.11.1 In some rare cases there may be a situation when all funds are allocated, but target spread is not reached. In this case the strategy will cancel furthest buy or sell order and use these funds to place next closer-to-center order to reach the target spread.

22.12 Modes

22.12.1 Mountain Mode

  • 22.12.1.1 Buy orders same QUOTE
  • 22.12.1.2 Sell orders same BASE

22.12.1.3 Mountain mode concentrates funds more to the center, so it makes more profit "right now" and compounds profits faster, but it's less good if the price decides to drift significantly.

22.12.1.4 Orders size increase: maximize order size as close to center as possible. When all orders are max, the new increase round is started from the furthest order.

22.12.2 Valley Mode

  • 22.12.2.1 Buy orders same BASE
  • 22.12.2.2 Sell orders same QUOTE

22.12.2.3 Valley mode is for bootstrapping a market or highly-volatile one. It makes very little profit if price stays where it started, but can withstand a massive change and loves volatility.

22.12.2.4 Orders size increase: maximize order sizes as far as possible from center first. When all orders are max, the new increase round is started from the closest-to-center order.

22.12.3 Buy slope

  • 22.12.3.1 All orders same BASE (profit comes in QUOTE)

22.12.3.2 Buy and sell slope is good for accumulating the other asset. You could for instance invest $50k with this strategy and reap profits with $100 sized orders over a massive range. It's like milking the market or "financial independence mode"

22.12.3.3 Orders size increase: maximize order size as low as possible. Buy orders maximized as far as possible (same as valley), and sell orders as close as possible to the center price (same as mountain mode).

22.12.4 Sell Slope Mode

  • 22.12.4.1 All orders same QUOTE (profit made in BASE)

22.12.4.2 Orders size increase: maximize order size as high as possible. Buy orders as close to the center price (same as mountain mode), and sell orders as far as possible from the center price (same as valley mode).

22.12.5 Neutral

  • 22.12.5.1 Buy orders, from far end towards center: lower_order_base * sqrt(1 + increment)
  • 22.12.5.2 Sell orders, from far end towards center: higher_order_quote * sqrt(1 + increment)

22.12.5.3 Neutral mode is for any market, and it is a nice balance between Valley mode and the Mountain mode, because order amounts slightly bigger towards the center. It will work well in stable times and also with extreme movements, giving you peace of mind at all times.

22.12.5.4 Orders size increase: try to flatten everything by increasing order sizes to neutral. When everything is correct, maximize closest orders and then increase other orders to match that.

22.13 Other features

22.13.1 Crash resilience

22.13.1.1 The strategy doesn't require any "state" to be remembered, and rely solely on the actual data from the blockchain. This might allow you to start the strategy with one computer, interrupt it at any point, and continue with another. You only need to have the same settings. Though you can also change the settings and continue and the strategy will place new orders according to the new settings.

22.13.2 Diligent re-evaluation

22.13.2.1 After every single action the bot will re-evaluate the whole situation and act accordingly. It won't assume that an order has been successfully made, but look at the situation with new eyes every time. This eliminates several tricky situations and weird behavior.

22.13.3 Operating mode and range can be changed at any time

22.13.3.1 If these are changed, the bot removes orders outside of defined range, and allocates all funds according to current configuration. If range is increased, it caused the bot to spend any profits to create new orders to fill the new range. Changing operating mode leaves all orders as they are, and will only change future behavior.

22.13.4 One-sided start

22.13.4.1 If the user starts with only base or quote, the bot will place orders closer to the market price and wait until one fills, and the game begins. Profits will be used to add orders to the other side until the strategy is completely balanced (according to the configuration).

22.14 Considerations

22.14.1 Range

22.14.1.1 The most important thing is to make the range (upper and lower bounds) wide enough.

22.14.1.1.1 If you don't do this, you will end up with only the worst of the assets. Do you want that to happen? If not, use a massive range. We suggest +-100x. Yes, 10,000x range.

22.14.1.1.2 With mountain and neutral mode it will cost very little to increase your range from 10x to 100x, so do it. With valley mode it costs much, but if you are using it to begin with you expect huge volatility, so do it. With buy slope it's cheap to extend upper bound, and with sell slope the opposite.

22.14.2 Increment and spread

22.14.2.1 The smaller the increments the more often orders will be filled, but the smaller the profit per order. (With same amount of funds).

22.14.2.2 The smaller the spread the more orders will fill, but the smaller the profit also. There is likely a sweet spot somewhere. You can also use a massive spread like 10,000% if you like, but it is questionable whether you need a bot for that, as an order might fill once per year or so.

22.14.2.3 If you intend to run the strategy on an always-on computer, then smaller spreads and increments might make sense. If you expect to run the bot once a day, try the default spread (6%) and increment (4%). If you intend to run the bot once a week, sane values might be 20% spread and 10% increment.

22.14.3 Note: avoid changing increment and spread without cancelling all orders. This may result in losses. See the "Spread, increment and profits" section.

22.15 Starting balances

22.15.1 It is best to start the strategy with an 'equal' amount of both assets (if you have a symmetric range). 'quote-amount / price' should be 'base-amount'.

Sort:  

Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://github.com/Codaone/DEXBot/wiki/The-Staggered-Orders-strategy