7min

Tutorial: Trading Bot

View Full GitHub example:

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 Drift 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 11 Mar 2022
Did this page help?
Yes
No