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ย 
7min

Tutorial: Arbitrage Bot

View Full GitHub example:

๏ปฟ๏ปฟ๏ปฟhttps://github.com/drift-labs/example-bots/blob/master/src/arbitrage-bot.ts๏ปฟ

Getting Started

1. Create a connection and wallet object.

It's important to safely load your private key outside of the code to ensure privacy.

JS
|

2. Install the @drift-labs/sdk.

For more details, peek through ๏ปฟ๏ปฟSDK Documentation.

JS
|

2. Initialize an account and deposit collateral (USDC) on Drift.

JS
|

3. Pick a market and load the price.

JS
|

4. Based on the current price, make a trade by passing a direction (LONG, SHORT) and size (USDC notional).

Optionally: You can set a limitPrice to place an Immediate or Cancel (IOC) order to help ensure your entryPrice comes as expected.

JS
|

Advanced

Take advantage of the SDK helpers that we've written for more measured trading:

For instance,calculateTargetPriceTradecalculate the liquidity available between the current markPrice to your targetPrice.

This function is highly recommended for arbitrageurs.

JS
|
Updated 20 Oct 2022
Did this page help you?
Yes
No
UP NEXT
Tutorial: JIT Maker Bot
Docs powered byย archbeeย 
TABLE OF CONTENTS
View Full GitHub example:
Getting Started
Advanced