Drift Protocol v2

โŒ˜K
๐Ÿ‘พWelcome to Drift Protocol
๐ŸงฎDrift DEX
๐Ÿ‘‹Getting Started
๐Ÿ“ˆPerpetual Futures
๐Ÿ“ŠSpot Margin Trading
๐ŸฆBorrow & Lend
๐Ÿ›๏ธStaking
๐Ÿ”ฌTechnical Explanations
๐Ÿ“Accounting and Settlement
โž—Borrow Interest Rate
๐Ÿ“œDelisting Process
โ›ฒDrift AMM
๐ŸƒJust-In-Time (JIT) Auctions
๐Ÿ“šKeepers & Decentralised Orderbook
โ˜ ๏ธLiquidators
๐Ÿ’งLiquidity Providers (LPs)
๐Ÿ“‹Protocol Guard Rails
๐Ÿ“Risks
๐Ÿ–ฅ๏ธDeveloper Resources
๐Ÿ“”Overview
โŒจ๏ธSDK Documentation
โŒจ๏ธTutorial: Bots
โš ๏ธTroubleshooting
๐Ÿ› ๏ธKeeper Bots
๐Ÿ› ๏ธTrading Bots
โŒจ๏ธHistorical Data (v1)
โŒจ๏ธAPI
๐Ÿ›ก๏ธSecurity
๐Ÿ›ก๏ธAudits
๐Ÿ›ก๏ธBug Bounty
โš–๏ธLegal and Regulations
๐Ÿ“Terms of Use
๐Ÿ“Disclaimer
๐Ÿ“Privacy Policy
๐Ÿ“Competition Terms and Conditions
๐Ÿ“šGlossary
Docs powered byย archbeeย 
11min

Tutorial: Order Matching Bot

Introduction

Order Matching Bots (Matching Bots) are responsible for matching two orders that cross or a taker order against the DAMM. Specifically, this includes:

  • Market Orders: Market Buy and Market Sell
  • Limit Orders: Limit Buy and Limit Sell

Matching Bots receive a small compensation for each order that they successfuly fill.

See ๏ปฟ๏ปฟ๏ปฟ๏ปฟKeepers & Decentralised Orderbook for a technical explanation of how the decentralised orderbook (DLOB) and matching incentives work.

Matching Bots are similar to Trigger Bots in that they:

  • also maintain a local copy of the Decentralised Limit Orderbook (DLOB);
  • do not require the operator to manage collateral; and
  • receive a small reward for performing their duties.

Getting Started

The reference implementation of the Order Matching Bot is available here.

Follow the instructions at ๏ปฟ๏ปฟKeeper Bots to set the required environment variables and make sure a ClearingHouseUser is initialized.

Start the Matching Bot:

Shell
|

๏ปฟ

Technical Explanation

1. Get nodes from the DLOB that are ready to be filled

Market orders that are sent on the Drift Protocol first go through the Just-In-Time (JIT) Auctions. After the auction period, Matching Bots step in to fill orders for a small reward.

The DLOB implementation includes a method for getting orders ready to be filled:

TypeScript
|

2. Filter for Fillable Nodes

To avoid trying to fill orders that aren't ready to be filled, filter out orders that are too small to fill

TypeScript
|

3. Call fill_order on ClearingHouse

TypeScript
|
Updated 20 Oct 2022
Did this page help you?
Yes
No
UP NEXT
Tutorial: Order Trigger Bot
Docs powered byย archbeeย 
TABLE OF CONTENTS
Introduction
Getting Started
Technical Explanation
1. Get nodes from the DLOB that are ready to be filled
2. Filter for Fillable Nodes
3. Call fill_order on ClearingHouse