Skip to content

Ladder Algorithm Explained

David Murasov edited this page May 2, 2023 · 13 revisions

Abbreviations

  • hb — highest bid
  • la — lowest ask
  • COIN1/COIN2 — a bot’s trade pair
  • ld — ladder module order type

Ladder orders

Ladder orders are intended to realize trading grid strategy, where the bot places many orders to buy and sell tokens with prices starting from the spread:

Screenshot 2023-04-26 at 10 00 42 PM

When closest to spread ladder order is filled, a bot adds the same order to the opposite side. For example, if someone takes 0.105 100 ladder sell-order:

Screenshot 2023-04-26 at 10 00 12 PM

Purpose

Ladder orders offers:

  • Make order book rich
  • Gives a profit, as a bot sells higher than is buys, or buys lower than it sells

Work algorithm

You can see the algorithm here: https://github.com/Adamant-im/adamant-coinoptimus/blob/master/modules/commandTxs.js

Example

Current order book:

Screenshot 2023-04-26 at 9 59 14 PM

Command: /start ld 100 USDT 6 1%

Bot steps:

  • Calculate middle price: (0.100 + 0.090) /2 = 0.095
  • Place the first bid as 0.095 – 1% = 0.094, amount ~99 USDT
  • Place the second bid as 0.094 – 1% = 0.093, amount ~100 USDT
  • Place the third bid as 0.093 – 1% = 0.092, amount ~101 USDT
  • Place the 4th bid as 0.092 – 1% = 0.091, amount ~101 USDT
  • Place the 5th bid as 0.091 – 1% = 0.090, amount ~100 USDT
  • Place the 6th bid as 0.090 – 1% = 0.089, amount ~100 USDT
  • Place the first ask as 0.095 + 1% = 0.096, amount ~99 USDT
  • Place the second ask as 0.096 + 1% = 0.097, amount ~100 USDT
  • Place the third ask as 0.097 + 1% = 0.098, amount ~101 USDT
  • Place the 4th ask as 0.098 + 1% = 0.099, amount ~101 USDT
  • Place the 5th ask as 0.099 + 1% = 0.100, amount ~101 USDT
  • Place the 6th ask as 0.100 + 1% = 0.101, amount ~101 USDT

Result order book:

Screenshot 2023-04-26 at 9 58 04 PM
  • ld-orders are stored in local DB with their states:
    • Not placed, with a reason:
    • Unable to calculate amount
    • Not enough balances
    • No order id returned
    • Open
    • Filled
    • Partly filled
    • Cancelled
    • Missed
    • To be removed
    • Removed
  • A bot constantly checks if all of ld-orders open
    • If not, it restores orders in Cancelled and Not placed states
      • Also on bot restart
    • If there is not enough balance to place ld-order, a bot notifies, set them in ‘Not placed’ state and try to place it again on next check
  • A bot replaces fully filled orders according to ladder/grid strategy
    • Ld-order can be filled not only by a third party, but by a bot itself—for example by MM with ‘orderbook’ strategy, or by the /make price command. It doesn’t influence strategy.
  • /clear all and /clear ld commands closes all open ld-orders
    • Set them in Cancelled state
    • If ladder module is active, it will restore ld-orders on next check
  • /stop ld will disable the module, and reset all ladder orders state and history
    • It will not close opened ld-order. To close them, user can run /clear all or /clear ld additionally
    • Next /start ld will create a new grid of ld-orders, not connected to previous one

Enable & disable ladder module

Command to enable ladder module has parameters:

/start ld {AMOUNT} {COIN} {COUNT} {STEP%} [mid {MIDPRICE} COIN2]

  • AMOUNT — order value in COIN. Amount will be with random factor 2%. It’s a float number with precision depending on exchange. AMOUNT can be in COIN1 or COIN2
  • COUNT — number of orders each side, buy and sell
  • STEP% — how much consequent orders will differ by price
  • Price is a float number with precision depending on exchange
  • [mid {MIDPRICE} COIN2] — optional middle price setting. If not set, midprice will be (hb + la) / 2

The command asks for a confirmation before run.

Example

/start ld 100 USDT 30 1%

To disable ladder module:

  • /stop ld This command stops the module, but keeps ld-type orders open To close open ld orders, admin runs /clear cl command

These features will work on all supported exchanges.

Clone this wiki locally