Skip to Content
DevelopersMarket MakersMarket Maker Quickstart

Market Maker Quickstart

Get a simple market maker running in under 10 minutes. This guide shows how to place two-sided quotes that automatically update with oracle prices.

Prerequisites

  • Node.js + TypeScript project
  • Drift SDK installed: npm i @drift-labs/sdk
  • Funded Solana account with USDC collateral
  • Basic familiarity with async/await

⚠️ RPC choice matters: The default https://api.mainnet-beta.solana.com is rate-limited and unsuitable for production bots. Use a dedicated RPC provider (Helius, Triton, etc.) or you’ll hit 429 errors within minutes. For WebSocket subscriptions, you need a provider that supports accountSubscribe.

Step 1: Initialize DriftClient

Set up your connection and subscribe to market data.

import { Connection } from "@solana/web3.js"; import { Wallet, DriftClient, loadKeypair } from "@drift-labs/sdk"; const connection = new Connection("https://api.mainnet-beta.solana.com"); const wallet = new Wallet(loadKeypair("~/.config/solana/id.json")); const driftClient = new DriftClient({ connection, wallet, env: "mainnet-beta", }); await driftClient.subscribe(); // Initialize your user account (if first time) // const [txSig] = await driftClient.initializeUserAccount(0);
Class DriftClientReference ↗

# DriftClient This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.

PropertyTypeRequired
connection
Connection
Yes
wallet
IWallet
Yes
program
Program<Idl>
Yes
provider
AnchorProvider
Yes
env
DriftEnv
Yes
opts
ConfirmOptions
No
useHotWalletAdmin
boolean
No
users
Map<string, User>
Yes
userStats
UserStats
No
activeSubAccountId
number
Yes
userAccountSubscriptionConfig
UserSubscriptionConfig
Yes
userStatsAccountSubscriptionConfig
UserStatsSubscriptionConfig
Yes
accountSubscriber
DriftClientAccountSubscriber
Yes
eventEmitter
StrictEventEmitter<EventEmitter, DriftClientAccountEvents>
Yes
metricsEventEmitter
StrictEventEmitter<EventEmitter, DriftClientMetricsEvents>
Yes
_isSubscribed
boolean
Yes
txSender
TxSender
Yes
perpMarketLastSlotCache
Map<number, number>
Yes
spotMarketLastSlotCache
Map<number, number>
Yes
mustIncludePerpMarketIndexes
Set<number>
Yes
mustIncludeSpotMarketIndexes
Set<number>
Yes
authority
PublicKey
Yes
marketLookupTable
PublicKey
Yes
lookupTableAccount
AddressLookupTableAccount
Yes
marketLookupTables
PublicKey[]
Yes
lookupTableAccounts
AddressLookupTableAccount[]
Yes
includeDelegates
boolean
No
authoritySubAccountMap
Map<string, number[]>
No
skipLoadUsers
boolean
No
txVersion
TransactionVersion
Yes
txParams
TxParams
Yes
enableMetricsEvents
boolean
No
txHandler
TxHandler
Yes
receiverProgram
Program<PythSolanaReceiver>
No
wormholeProgram
Program<WormholeCoreBridgeSolana>
No
sbOnDemandProgramdId
PublicKey
Yes
sbOnDemandProgram
Program<Idl>
No
sbProgramFeedConfigs
Map<string, any>
No
isSubscribed
boolean
Yes
getPrePlaceOrderIxs
any
Yes
getUserMapKey
(subAccountId: number, authority: PublicKey) => string
Yes
createUser
(subAccountId: number, accountSubscriptionConfig: UserSubscriptionConfig, authority?: PublicKey | undefined) => User
Yes
subscribe
() => Promise<boolean>
Yes
subscribeUsers
() => Promise<boolean>[]
Yes
fetchAccounts
() => Promise<void>
Forces the accountSubscriber to fetch account updates from rpc
Yes
unsubscribe
() => Promise<void>
Yes
unsubscribeUsers
() => Promise<void>[]
Yes
statePublicKey
PublicKey
No
getStatePublicKey
() => Promise<PublicKey>
Yes
signerPublicKey
PublicKey
No
getSignerPublicKey
() => PublicKey
Yes
getStateAccount
() => StateAccount
Yes
forceGetStateAccount
() => Promise<StateAccount>
Forces a fetch to rpc before returning accounts. Useful for anchor tests.
Yes
getPerpMarketAccount
(marketIndex: number) => PerpMarketAccount | undefined
Yes
forceGetPerpMarketAccount
(marketIndex: number) => Promise<PerpMarketAccount | undefined>
Forces a fetch to rpc before returning accounts. Useful for anchor tests.
Yes
getPerpMarketAccounts
() => PerpMarketAccount[]
Yes
getSpotMarketAccount
(marketIndex: number) => SpotMarketAccount | undefined
Yes
forceGetSpotMarketAccount
(marketIndex: number) => Promise<SpotMarketAccount | undefined>
Forces a fetch to rpc before returning accounts. Useful for anchor tests.
Yes
getSpotMarketAccounts
() => SpotMarketAccount[]
Yes
getQuoteSpotMarketAccount
() => SpotMarketAccount
Yes
getOraclePriceDataAndSlot
(oraclePublicKey: PublicKey, oracleSource: OracleSource) => DataAndSlot<OraclePriceData> | undefined
Yes
getSerumV3FulfillmentConfig
(serumMarket: PublicKey) => Promise<SerumV3FulfillmentConfigAccount>
Yes
getSerumV3FulfillmentConfigs
() => Promise<SerumV3FulfillmentConfigAccount[]>
Yes
getPhoenixV1FulfillmentConfig
(phoenixMarket: PublicKey) => Promise<PhoenixV1FulfillmentConfigAccount>
Yes
getPhoenixV1FulfillmentConfigs
() => Promise<PhoenixV1FulfillmentConfigAccount[]>
Yes
getOpenbookV2FulfillmentConfig
(openbookMarket: PublicKey) => Promise<OpenbookV2FulfillmentConfigAccount>
Yes
getOpenbookV2FulfillmentConfigs
() => Promise<OpenbookV2FulfillmentConfigAccount[]>
Yes
fetchMarketLookupTableAccount
() => Promise<AddressLookupTableAccount>
Yes
fetchAllLookupTableAccounts
() => Promise<AddressLookupTableAccount[]>
Yes
getTxVersionForNewWallet
any
Yes
updateWallet
(newWallet: IWallet, subAccountIds?: number[] | undefined, activeSubAccountId?: number | undefined, includeDelegates?: boolean | undefined, authoritySubaccountMap?: Map<string, number[]> | undefined) => Promise<...>
Update the wallet to use for drift transactions and linked user account
Yes
emulateAccount
(emulateAuthority: PublicKey) => Promise<boolean>
Update the subscribed accounts to a given authority, while leaving the connected wallet intact. This allows a user to emulate another user's account on the UI and sign permissionless transactions with their own wallet.
Yes
switchActiveUser
(subAccountId: number, authority?: PublicKey | undefined) => Promise<void>
Yes
addUser
(subAccountId: number, authority?: PublicKey | undefined, userAccount?: UserAccount | undefined) => Promise<boolean>
Yes
addAndSubscribeToUsers
(authority?: PublicKey | undefined) => Promise<boolean>
Adds and subscribes to users based on params set by the constructor or by updateWallet.
Yes
getInitializeUserAccountIxs
(subAccountId?: number | undefined, name?: string | undefined, referrerInfo?: ReferrerInfo | undefined, poolId?: number | undefined) => Promise<[TransactionInstruction[], PublicKey]>
Returns the instructions to initialize a user account and the public key of the user account.
Yes
initializeUserAccount
(subAccountId?: number | undefined, name?: string | undefined, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | undefined) => Promise<[...]>
Initializes a user account and returns the transaction signature and the public key of the user account.
Yes
getInitializeUserStatsIx
(overrides?: { externalWallet?: PublicKey; } | undefined) => Promise<TransactionInstruction>
Yes
initializeSignedMsgUserOrders
(authority: PublicKey, numOrders: number, txParams?: TxParams | undefined) => Promise<[string, PublicKey]>
Yes
getInitializeSignedMsgUserOrdersAccountIx
(authority: PublicKey, numOrders: number, overrides?: { externalWallet?: PublicKey; } | undefined) => Promise<[PublicKey, TransactionInstruction]>
Yes
resizeSignedMsgUserOrders
(authority: PublicKey, numOrders: number, userSubaccountId?: number | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getResizeSignedMsgUserOrdersInstruction
(authority: PublicKey, numOrders: number, userSubaccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
initializeSignedMsgWsDelegatesAccount
(authority: PublicKey, delegates?: PublicKey[] | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getInitializeSignedMsgWsDelegatesAccountIx
(authority: PublicKey, delegates?: PublicKey[] | undefined) => Promise<TransactionInstruction>
Yes
initializeRevenueShare
(authority: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getInitializeRevenueShareIx
(authority: PublicKey, overrides?: { payer?: PublicKey; } | undefined) => Promise<TransactionInstruction>
Yes
initializeRevenueShareEscrow
(authority: PublicKey, numOrders: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getInitializeRevenueShareEscrowIx
(authority: PublicKey, numOrders: number, overrides?: { payer?: PublicKey; } | undefined) => Promise<TransactionInstruction>
Yes
migrateReferrer
(authority: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getMigrateReferrerIx
(authority: PublicKey) => Promise<TransactionInstruction>
Yes
resizeRevenueShareEscrowOrders
(authority: PublicKey, numOrders: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getResizeRevenueShareEscrowOrdersIx
(authority: PublicKey, numOrders: number) => Promise<TransactionInstruction>
Yes
changeApprovedBuilder
(builder: PublicKey, maxFeeTenthBps: number, add: boolean, txParams?: TxParams | undefined) => Promise<string>
Creates the transaction to add or update an approved builder. This allows the builder to receive revenue share from referrals.
Yes
getChangeApprovedBuilderIx
(builder: PublicKey, maxFeeTenthBps: number, add: boolean, overrides?: { authority?: PublicKey; payer?: PublicKey; } | undefined) => Promise<TransactionInstruction>
Creates the transaction instruction to add or update an approved builder. This allows the builder to receive revenue share from referrals.
Yes
addSignedMsgWsDelegate
(authority: PublicKey, delegate: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getAddSignedMsgWsDelegateIx
(authority: PublicKey, delegate: PublicKey) => Promise<TransactionInstruction>
Yes
removeSignedMsgWsDelegate
(authority: PublicKey, delegate: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getRemoveSignedMsgWsDelegateIx
(authority: PublicKey, delegate: PublicKey) => Promise<TransactionInstruction>
Yes
initializeFuelOverflow
(authority?: PublicKey | undefined) => Promise<string>
Yes
getInitializeFuelOverflowIx
(authority?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
sweepFuel
(authority?: PublicKey | undefined) => Promise<string>
Yes
getSweepFuelIx
(authority?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
getInitializeUserInstructions
any
Yes
getNextSubAccountId
() => Promise<number>
Yes
initializeReferrerName
(name: string) => Promise<string>
Yes
updateUserName
(name: string, subAccountId?: number | undefined) => Promise<string>
Yes
updateUserCustomMarginRatio
(updates: { marginRatio: number; subAccountId: number; }[], txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateUserCustomMarginRatioIx
(marginRatio: number, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
getUpdateUserPerpPositionCustomMarginRatioIx
(perpMarketIndex: number, marginRatio: number, subAccountId?: number | undefined, overrides?: { userAccountPublicKey?: PublicKey; authority?: PublicKey; signingAuthority?: PublicKey; } | undefined) => Promise<...>
Yes
updateUserPerpPositionCustomMarginRatio
(perpMarketIndex: number, marginRatio: number, subAccountId?: number | undefined, txParams?: TxParams | undefined, enterHighLeverageMode?: boolean | undefined) => Promise<...>
Yes
getUpdateUserMarginTradingEnabledIx
(marginTradingEnabled: boolean, subAccountId?: number | undefined, userAccountPublicKey?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
updateUserMarginTradingEnabled
(updates: { marginTradingEnabled: boolean; subAccountId: number; }[]) => Promise<string>
Yes
getUpdateUserDelegateIx
(delegate: PublicKey, overrides: { subAccountId?: number; userAccountPublicKey?: PublicKey; authority?: PublicKey; }) => Promise<TransactionInstruction>
Yes
updateUserDelegate
(delegate: PublicKey, subAccountId?: number | undefined) => Promise<string>
Yes
updateUserAdvancedLp
(updates: { advancedLp: boolean; subAccountId: number; }[]) => Promise<string>
Yes
getUpdateAdvancedDlpIx
(advancedLp: boolean, subAccountId: number) => Promise<TransactionInstruction>
Yes
updateUserReduceOnly
(updates: { reduceOnly: boolean; subAccountId: number; }[]) => Promise<string>
Yes
getUpdateUserReduceOnlyIx
(reduceOnly: boolean, subAccountId: number) => Promise<TransactionInstruction>
Yes
updateUserPoolId
(updates: { poolId: number; subAccountId: number; }[]) => Promise<string>
Yes
getUpdateUserPoolIdIx
(poolId: number, subAccountId: number) => Promise<TransactionInstruction>
Yes
fetchAllUserAccounts
(includeIdle?: boolean | undefined) => Promise<ProgramAccount<UserAccount>[]>
Yes
getUserAccountsForDelegate
(delegate: PublicKey) => Promise<UserAccount[]>
Yes
getUserAccountsAndAddressesForAuthority
(authority: PublicKey) => Promise<ProgramAccount<UserAccount>[]>
Yes
getUserAccountsForAuthority
(authority: PublicKey) => Promise<UserAccount[]>
Yes
getReferredUserStatsAccountsByReferrer
(referrer: PublicKey) => Promise<UserStatsAccount[]>
Yes
getReferrerNameAccountsForAuthority
(authority: PublicKey) => Promise<ReferrerNameAccount[]>
Yes
deleteUser
(subAccountId?: number | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getUserDeletionIx
(userAccountPublicKey: PublicKey) => Promise<TransactionInstruction>
Yes
forceDeleteUser
(userAccountPublicKey: PublicKey, userAccount: UserAccount, txParams?: TxParams | undefined) => Promise<string>
Yes
getForceDeleteUserIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount) => Promise<TransactionInstruction>
Yes
deleteSignedMsgUserOrders
(txParams?: TxParams | undefined) => Promise<string>
Yes
getSignedMsgUserOrdersDeletionIx
(authority: PublicKey) => Promise<TransactionInstruction>
Yes
isSignedMsgUserOrdersAccountInitialized
(authority: PublicKey) => Promise<boolean>
Checks if a SignedMsg User Orders account exists for the given authority. The account pubkey is derived using the program ID and authority as seeds. Makes an RPC call to check if the account exists on-chain.
Yes
reclaimRent
(subAccountId?: number | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getReclaimRentIx
(userAccountPublicKey: PublicKey) => Promise<TransactionInstruction>
Yes
getUser
(subAccountId?: number | undefined, authority?: PublicKey | undefined) => User
Yes
hasUser
(subAccountId?: number | undefined, authority?: PublicKey | undefined) => boolean
Yes
getUsers
() => User[]
Yes
getUserStats
() => UserStats
Yes
fetchReferrerNameAccount
(name: string) => Promise<ReferrerNameAccount | undefined>
Yes
userStatsAccountPublicKey
PublicKey
Yes
getUserStatsAccountPublicKey
() => PublicKey
Yes
getUserAccountPublicKey
(subAccountId?: number | undefined, authority?: PublicKey | undefined) => Promise<PublicKey>
Yes
getUserAccount
(subAccountId?: number | undefined, authority?: PublicKey | undefined) => UserAccount | undefined
Yes
forceGetUserAccount
(subAccountId?: number | undefined, authority?: PublicKey | undefined) => Promise<UserAccount | undefined>
Forces a fetch to rpc before returning accounts. Useful for anchor tests.
Yes
getUserAccountAndSlot
(subAccountId?: number | undefined, authority?: PublicKey | undefined) => DataAndSlot<UserAccount> | undefined
Yes
getSpotPosition
(marketIndex: number, subAccountId?: number | undefined) => SpotPosition | undefined
Yes
getQuoteAssetTokenAmount
() => BN
Yes
getIsolatedPerpPositionTokenAmount
(perpMarketIndex: number, subAccountId?: number | undefined) => BN
Yes
getTokenAmount
(marketIndex: number) => BN
Returns the token amount for a given market. The spot market precision is based on the token mint decimals. Positive if it is a deposit, negative if it is a borrow.
Yes
convertToSpotPrecision
(marketIndex: number, amount: any) => BN
Converts an amount to the spot precision for a given market. The spot market precision is based on the token mint decimals.
Yes
convertToPerpPrecision
(amount: any) => BN
Converts an amount to the perp precision. The perp market precision is BASE_PRECISION (1e9).
Yes
convertToPricePrecision
(amount: any) => BN
Converts an amount to the price precision. The perp market precision is PRICE_PRECISION (1e6).
Yes
mustIncludeMarketsInIx
({ perpMarketIndexes, spotMarketIndexes, }: { perpMarketIndexes: number[]; spotMarketIndexes: number[]; }) => void
Each drift instruction must include perp and sport market accounts in the ix remaining accounts. Use this function to force a subset of markets to be included in the remaining accounts for every ix
Yes
getRemainingAccounts
(params: RemainingAccountParams) => AccountMeta[]
Yes
addPerpMarketToRemainingAccountMaps
(marketIndex: number, writable: boolean, oracleAccountMap: Map<string, AccountMeta>, spotMarketAccountMap: Map<number, AccountMeta>, perpMarketAccountMap: Map<...>) => void
Yes
addSpotMarketToRemainingAccountMaps
(marketIndex: number, writable: boolean, oracleAccountMap: Map<string, AccountMeta>, spotMarketAccountMap: Map<number, AccountMeta>) => void
Yes
addBuilderToRemainingAccounts
(builders: PublicKey[], remainingAccounts: AccountMeta[]) => void
Yes
getRemainingAccountMapsForUsers
(userAccounts: UserAccount[]) => { oracleAccountMap: Map<string, AccountMeta>; spotMarketAccountMap: Map<number, AccountMeta>; perpMarketAccountMap: Map<...>; }
Yes
getOrder
(orderId: number, subAccountId?: number | undefined) => Order | undefined
Yes
getOrderByUserId
(userOrderId: number, subAccountId?: number | undefined) => Order | undefined
Yes
getAssociatedTokenAccount
(marketIndex: number, useNative?: boolean | undefined, tokenProgram?: PublicKey | undefined, authority?: PublicKey | undefined, allowOwnerOffCurve?: boolean | undefined) => Promise<...>
Get the associated token address for the given spot market
Yes
createAssociatedTokenAccountIdempotentInstruction
(account: PublicKey, payer: PublicKey, owner: PublicKey, mint: PublicKey, tokenProgram?: PublicKey | undefined) => TransactionInstruction
Yes
getDepositTxnIx
(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number | undefined, reduceOnly?: boolean | undefined, overrides?: { authority?: PublicKey; } | undefined) => Promise<...>
Yes
buildSwiftDepositTx
(signedOrderParams: SignedMsgOrderParams, takerInfo: { taker: PublicKey; takerStats: PublicKey; takerUserAccount: UserAccount; signingAuthority: PublicKey; }, depositAmount: BN, depositSpotMarketIndex: number, tradePerpMarketIndex: number, subAccountId: number, takerAssociatedTokenAccount: PublicKey, initSwiftAccoun...
Yes
createDepositTxn
(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number | undefined, reduceOnly?: boolean | undefined, txParams?: TxParams | undefined, initSwiftAccount?: boolean | undefined, overrides?: { ...; } | undefined) => Promise<...>
Yes
deposit
(amount: BN, marketIndex: number, associatedTokenAccount: PublicKey, subAccountId?: number | undefined, reduceOnly?: boolean | undefined, txParams?: TxParams | undefined, initSwiftAccount?: boolean | undefined, overrides?: { ...; } | undefined) => Promise<...>
Deposit funds into the given spot market
Yes
getDepositInstruction
(amount: BN, marketIndex: number, userTokenAccount: PublicKey, subAccountId?: number | undefined, reduceOnly?: boolean | undefined, userInitialized?: boolean | undefined, overrides?: { ...; } | undefined) => Promise<...>
Yes
checkIfAccountExists
any
Yes
getWrappedSolAccountCreationIxs
(amount: BN, includeRent?: boolean | undefined, overrides?: { authority?: PublicKey; } | undefined) => Promise<{ ixs: TransactionInstruction[]; signers: Signer[]; pubkey: PublicKey; }>
Yes
getTokenProgramForSpotMarket
(spotMarketAccount: SpotMarketAccount) => PublicKey
Yes
isToken2022
(spotMarketAccount: SpotMarketAccount) => boolean
Yes
isTransferHook
(spotMarketAccount: SpotMarketAccount) => boolean
Yes
addTokenMintToRemainingAccounts
(spotMarketAccount: SpotMarketAccount, remainingAccounts: AccountMeta[]) => void
Yes
addExtraAccountMetasToRemainingAccounts
(mint: PublicKey, remainingAccounts: AccountMeta[]) => Promise<void>
Yes
getAssociatedTokenAccountCreationIx
(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey, tokenProgram: PublicKey) => TransactionInstruction
Yes
createInitializeUserAccountAndDepositCollateralIxs
(amount: BN, userTokenAccount: PublicKey, marketIndex?: number | undefined, subAccountId?: number | undefined, name?: string | undefined, fromSubAccountId?: number | undefined, referrerInfo?: ReferrerInfo | undefined, donateAmount?: any, customMaxMarginRatio?: number | undefined, poolId?: number | undefined, overrid...
Yes
createInitializeUserAccountAndDepositCollateral
(amount: BN, userTokenAccount: PublicKey, marketIndex?: number | undefined, subAccountId?: number | undefined, name?: string | undefined, fromSubAccountId?: number | undefined, referrerInfo?: ReferrerInfo | undefined, donateAmount?: any, txParams?: TxParams | undefined, customMaxMarginRatio?: number | undefined, poo...
Yes
initializeUserAccountAndDepositCollateral
(amount: BN, userTokenAccount: PublicKey, marketIndex?: number | undefined, subAccountId?: number | undefined, name?: string | undefined, fromSubAccountId?: number | undefined, referrerInfo?: ReferrerInfo | undefined, donateAmount?: any, txParams?: TxParams | undefined, customMaxMarginRatio?: number | undefined, poo...
Creates the User account for a user, and deposits some initial collateral
Yes
initializeUserAccountForDevnet
(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | undefined) => Promise<...>
Yes
getWithdrawalIxs
(amount: BN, marketIndex: number, associatedTokenAddress: PublicKey, reduceOnly?: boolean | undefined, subAccountId?: number | undefined, _updateFuel?: boolean | undefined) => Promise<...>
Yes
withdraw
(amount: BN, marketIndex: number, associatedTokenAddress: PublicKey, reduceOnly?: boolean | undefined, subAccountId?: number | undefined, txParams?: TxParams | undefined, updateFuel?: boolean | undefined) => Promise<...>
Withdraws from a user account. If deposit doesn't already exist, creates a borrow
Yes
withdrawAllDustPositions
(subAccountId?: number | undefined, txParams?: TxParams | undefined, opts?: { dustPositionCountCallback?: (count: number) => void; } | undefined) => Promise<string | undefined>
Yes
getWithdrawIx
(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean | undefined, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
transferDeposit
(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number, txParams?: TxParams | undefined) => Promise<string>
Withdraws from the fromSubAccount and deposits into the toSubAccount
Yes
getTransferDepositIx
(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number) => Promise<TransactionInstruction>
Yes
transferPools
(depositFromMarketIndex: number, depositToMarketIndex: number, borrowFromMarketIndex: number, borrowToMarketIndex: number, depositAmount: any, borrowAmount: any, fromSubAccountId: number, toSubAccountId: number, txParams?: TxParams | undefined) => Promise<...>
Yes
getTransferPoolsIx
(depositFromMarketIndex: number, depositToMarketIndex: number, borrowFromMarketIndex: number, borrowToMarketIndex: number, depositAmount: any, borrowAmount: any, fromSubAccountId: number, toSubAccountId: number, isToNewSubAccount?: boolean | undefined) => Promise<...>
Yes
transferPerpPosition
(fromSubAccountId: number, toSubAccountId: number, marketIndex: number, amount: BN, txParams?: TxParams | undefined) => Promise<string>
Yes
getTransferPerpPositionIx
(fromSubAccountId: number, toSubAccountId: number, marketIndex: number, amount: BN) => Promise<TransactionInstruction>
Yes
depositIntoIsolatedPerpPosition
(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getDepositIntoIsolatedPerpPositionIx
(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
transferIsolatedPerpPositionDeposit
(amount: BN, perpMarketIndex: number, subAccountId?: number | undefined, txParams?: TxParams | undefined, trySettle?: boolean | undefined, noBuffer?: boolean | undefined) => Promise<...>
Yes
getTransferIsolatedPerpPositionDepositIx
(amount: BN, perpMarketIndex: number, subAccountId?: number | undefined, noAmountBuffer?: boolean | undefined, signingAuthority?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
withdrawFromIsolatedPerpPosition
(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getWithdrawFromIsolatedPerpPositionIxsBundle
(amount: BN, perpMarketIndex: number, subAccountId?: number | undefined, userTokenAccount?: PublicKey | undefined) => Promise<TransactionInstruction[]>
Yes
getWithdrawFromIsolatedPerpPositionIx
(amount: BN, perpMarketIndex: number, userTokenAccount: PublicKey, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
updateSpotMarketCumulativeInterest
(marketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
updateSpotMarketCumulativeInterestIx
(marketIndex: number) => Promise<TransactionInstruction>
Yes
settleLP
(settleeUserAccountPublicKey: PublicKey, marketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
settleLPIx
(settleeUserAccountPublicKey: PublicKey, marketIndex: number) => Promise<TransactionInstruction>
Yes
removePerpLpShares
(marketIndex: number, sharesToBurn?: any, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<string>
Yes
removePerpLpSharesInExpiringMarket
(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: any, txParams?: TxParams | undefined) => Promise<string>
Yes
getRemovePerpLpSharesInExpiringMarket
(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: any) => Promise<TransactionInstruction>
Yes
getRemovePerpLpSharesIx
(marketIndex: number, sharesToBurn?: any, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
addPerpLpShares
(amount: BN, marketIndex: number, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<string>
Yes
getAddPerpLpSharesIx
(amount: BN, marketIndex: number, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
getQuoteValuePerLpShare
(marketIndex: number) => BN
Yes
openPosition
(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: any, subAccountId?: number | undefined) => Promise<string>
Yes
sendSignedTx
(tx: VersionedTransaction | Transaction, opts?: ConfirmOptions | undefined) => Promise<string>
Yes
prepareMarketOrderTxs
(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[] | undefined, txParams?: TxParams | undefined, bracketOrdersParams?: OptionalOrderParams[] | undefined, referrerInfo?: ReferrerInfo | undefined, cancelExistingOrders?: boolean | undefined,...
Yes
sendMarketOrderAndGetSignedFillTx
(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount, makerInfo?: MakerInfo | MakerInfo[] | undefined, txParams?: TxParams | undefined, bracketOrdersParams?: OptionalOrderParams[] | undefined, referrerInfo?: ReferrerInfo | undefined, cancelExistingOrders?: boolean | undefined,...
Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
Yes
placePerpOrder
(orderParams: OptionalOrderParams, txParams?: TxParams | undefined, subAccountId?: number | undefined, isolatedPositionDepositAmount?: any) => Promise<...>
Yes
getPlacePerpOrderIx
(orderParams: OptionalOrderParams, subAccountId?: number | undefined, depositToTradeArgs?: { isMakingNewAccount: boolean; depositMarketIndex: number; } | undefined) => Promise<...>
Yes
updateAMMs
(marketIndexes: number[], txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateAMMsIx
(marketIndexes: number[]) => Promise<TransactionInstruction>
Yes
settleExpiredMarket
(marketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getSettleExpiredMarketIx
(marketIndex: number) => Promise<TransactionInstruction>
Yes
settleExpiredMarketPoolsToRevenuePool
(marketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getSettleExpiredMarketPoolsToRevenuePoolIx
(perpMarketIndex: number) => Promise<TransactionInstruction>
Yes
cancelOrder
(orderId?: number | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined, overrides?: { withdrawIsolatedDepositAmount?: any; } | undefined) => Promise<...>
Yes
getCancelOrderIx
(orderId?: number | undefined, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
cancelOrderByUserId
(userOrderId: number, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<string>
Yes
getCancelOrderByUserIdIx
(userOrderId: number, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
cancelOrdersByIds
(orderIds?: number[] | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined, user?: User | undefined, overrides?: { authority?: PublicKey; } | undefined) => Promise<...>
Sends a transaction to cancel the provided order ids.
Yes
getCancelOrdersByIdsIx
(orderIds?: number[] | undefined, subAccountId?: number | undefined, user?: User | undefined, overrides?: { authority?: PublicKey; } | undefined) => Promise<TransactionInstruction>
Returns the transaction instruction to cancel the provided order ids.
Yes
cancelOrders
(marketType?: MarketType | undefined, marketIndex?: number | undefined, direction?: PositionDirection | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
getCancelOrdersIx
(marketType: MarketType | null, marketIndex: number | null, direction: PositionDirection | null, subAccountId?: number | undefined) => Promise<...>
Yes
cancelAndPlaceOrders
(cancelOrderParams: { marketType?: MarketType; marketIndex?: number; direction?: PositionDirection; }, placeOrderParams: OrderParams[], txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
placeOrders
(params: OrderParams[], txParams?: TxParams | undefined, subAccountId?: number | undefined, optionalIxs?: TransactionInstruction[] | undefined, isolatedPositionDepositAmount?: any) => Promise<...>
Yes
preparePlaceOrdersTx
(params: OrderParams[], txParams?: TxParams | undefined, subAccountId?: number | undefined, optionalIxs?: TransactionInstruction[] | undefined, isolatedPositionDepositAmount?: any) => Promise<...>
Yes
getPlaceOrdersIx
(params: OptionalOrderParams[], subAccountId?: number | undefined, overrides?: { authority?: PublicKey; } | undefined) => Promise<TransactionInstruction>
Yes
getPlaceOrdersAndSetPositionMaxLevIx
(params: OptionalOrderParams[], positionMaxLev: number, subAccountId?: number | undefined) => Promise<TransactionInstruction[]>
Yes
fillPerpOrder
(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, "marketIndex" | "orderId"> | undefined, makerInfo?: MakerInfo | MakerInfo[] | undefined, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | undefined, fillerSubAccountId?: number | undefined, fillerAuthority?: PublicKey | undefined,...
Yes
getFillPerpOrderIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, "marketIndex" | "orderId">, makerInfo?: MakerInfo | MakerInfo[] | undefined, referrerInfo?: ReferrerInfo | undefined, fillerSubAccountId?: number | undefined, isSignedMsg?: boolean | undefined, fillerAuthority?: PublicKey | undefined, has...
Yes
getRevertFillIx
(fillerPublicKey?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
placeSpotOrder
(orderParams: OptionalOrderParams, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<string>
Yes
preparePlaceSpotOrderTx
(orderParams: OptionalOrderParams, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<{ placeSpotOrderTx: Transaction | VersionedTransaction; }>
Yes
getPlaceSpotOrderIx
(orderParams: OptionalOrderParams, subAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
fillSpotOrder
(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, "marketIndex" | "orderId"> | undefined, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount | undefined, makerInfo?: MakerInfo | ... 1 more ... | undefined, referrerInfo?:...
Yes
getFillSpotOrderIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Pick<Order, "marketIndex" | "orderId"> | undefined, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount | undefined, makerInfo?: MakerInfo | ... 1 more ... | undefined, referre...
Yes
addSpotFulfillmentAccounts
(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig?: SerumV3FulfillmentConfigAccount | PhoenixV1FulfillmentConfigAccount | OpenbookV2FulfillmentConfigAccount | undefined) => void
Yes
addSerumRemainingAccounts
(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount) => void
Yes
addPhoenixRemainingAccounts
(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: PhoenixV1FulfillmentConfigAccount) => void
Yes
addOpenbookRemainingAccounts
(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: OpenbookV2FulfillmentConfigAccount) => void
Yes
swap
({ swapClient, jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, reduceOnly, txParams, v6, quote, onlyDirectRoutes, }: { swapClient?: UnifiedSwapClient | SwapClient; jupiterClient?: JupiterClient; outMarketIndex: number; inMarketIndex: n...
Swap tokens in drift account using titan or jupiter
Yes
getTitanSwapIx
({ titanClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, reduceOnly, userAccountPublicKey, }: { titanClient: TitanClient; outMarketIndex: number; inMarketIndex: number; outAssociatedTokenAccount?: PublicKey; inAssociatedToken...
Yes
getJupiterSwapIxV6
({ jupiterClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, quote, reduceOnly, userAccountPublicKey, }: { jupiterClient: JupiterClient; outMarketIndex: number; inMarketIndex: number; outAssociatedTokenAccount?: PublicKey; inAs...
Yes
getSwapIx
({ outMarketIndex, inMarketIndex, amountIn, inTokenAccount, outTokenAccount, limitPrice, reduceOnly, userAccountPublicKey, }: { outMarketIndex: number; inMarketIndex: number; amountIn: BN; inTokenAccount: PublicKey; outTokenAccount: PublicKey; limitPrice?: any; reduceOnly?: SwapReduceOnly; userAccountPublicKey?: Pub...
Get the drift begin_swap and end_swap instructions
Yes
getSwapIxV2
({ swapClient, outMarketIndex, inMarketIndex, outAssociatedTokenAccount, inAssociatedTokenAccount, amount, slippageBps, swapMode, onlyDirectRoutes, reduceOnly, quote, v6, userAccountPublicKey, }: { swapClient: UnifiedSwapClient; outMarketIndex: number; inMarketIndex: number; outAssociatedTokenAccount?: PublicKey; in...
Yes
stakeForMSOL
({ amount }: { amount: BN; }) => Promise<TxSigAndSlot>
Yes
getStakeForMSOLIx
({ amount, userAccountPublicKey, }: { amount: BN; userAccountPublicKey?: PublicKey; }) => Promise<TransactionInstruction[]>
Yes
triggerOrder
(userAccountPublicKey: PublicKey, user: UserAccount, order: Order, txParams?: TxParams | undefined, fillerPublicKey?: PublicKey | undefined) => Promise<...>
Yes
getTriggerOrderIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, fillerPublicKey?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
forceCancelOrders
(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams | undefined, fillerPublicKey?: PublicKey | undefined) => Promise<...>
Yes
getForceCancelOrdersIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
updateUserIdle
(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams | undefined, fillerPublicKey?: PublicKey | undefined) => Promise<...>
Yes
getUpdateUserIdleIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
logUserBalances
(userAccountPublicKey: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getLogUserBalancesIx
(userAccountPublicKey: PublicKey) => Promise<TransactionInstruction>
Yes
updateUserFuelBonus
(userAccountPublicKey: PublicKey, user: UserAccount, userAuthority: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateUserFuelBonusIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, userAuthority: PublicKey) => Promise<TransactionInstruction>
Yes
updateUserStatsReferrerStatus
(userAuthority: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateUserStatsReferrerStatusIx
(userAuthority: PublicKey) => Promise<TransactionInstruction>
Yes
updateUserOpenOrdersCount
(userAccountPublicKey: PublicKey, user: UserAccount, txParams?: TxParams | undefined, fillerPublicKey?: PublicKey | undefined) => Promise<...>
Yes
getUpdateUserOpenOrdersCountIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, fillerPublicKey?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
placeAndTakePerpOrder
(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[] | undefined, referrerInfo?: ReferrerInfo | undefined, successCondition?: PlaceAndTakeOrderSuccessCondition | undefined, auctionDurationPercentage?: number | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise...
Yes
preparePlaceAndTakePerpOrderWithAdditionalOrders
(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[] | undefined, referrerInfo?: ReferrerInfo | undefined, bracketOrdersParams?: OptionalOrderParams[] | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined, cancelExistingOrders?: boolean | undefined, settlePnl?: boolean | u...
Yes
placeAndTakePerpWithAdditionalOrders
(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[] | undefined, referrerInfo?: ReferrerInfo | undefined, bracketOrdersParams?: OptionalOrderParams[] | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined, cancelExistingOrders?: boolean | undefined, settlePnl?: boolean | u...
Yes
getPlaceAndTakePerpOrderIx
(orderParams: OptionalOrderParams, makerInfo?: MakerInfo | MakerInfo[] | undefined, referrerInfo?: ReferrerInfo | undefined, successCondition?: PlaceAndTakeOrderSuccessCondition | undefined, auctionDurationPercentage?: number | undefined, subAccountId?: number | undefined, overrides?: { ...; } | undefined) => Promis...
Yes
placeAndMakePerpOrder
(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
getPlaceAndMakePerpOrderIx
(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
signSignedMsgOrderParamsMessage
(orderParamsMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, delegateSigner?: boolean | undefined) => SignedMsgOrderParams
Yes
buildDepositAndPlaceSignedMsgOrderRequest
(depositTx: VersionedTransaction, orderParamsMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, delegateSigner?: boolean | undefined) => { ...; }
Builds a deposit and place request for Swift service
Yes
encodeSignedMsgOrderParamsMessage
(orderParamsMessage: SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage, delegateSigner?: boolean | undefined) => Buffer
Yes
decodeSignedMsgOrderParamsMessage
(encodedMessage: Buffer, delegateSigner?: boolean | undefined) => SignedMsgOrderParamsMessage | SignedMsgOrderParamsDelegateMessage
Yes
signMessage
(message: Uint8Array<ArrayBufferLike>, keypair?: Keypair | undefined) => Buffer
Yes
placeSignedMsgTakerOrder
(signedSignedMsgOrderParams: SignedMsgOrderParams, marketIndex: number, takerInfo: { taker: PublicKey; takerStats: PublicKey; takerUserAccount: UserAccount; signingAuthority: PublicKey; }, precedingIxs?: TransactionInstruction[] | undefined, overrideCustomIxIndex?: number | undefined, txParams?: TxParams | undefined...
Yes
getPlaceSignedMsgTakerPerpOrderIxs
(signedSignedMsgOrderParams: SignedMsgOrderParams, marketIndex: number, takerInfo: { taker: PublicKey; takerStats: PublicKey; takerUserAccount: UserAccount; signingAuthority: PublicKey; }, precedingIxs?: TransactionInstruction[] | undefined, overrideCustomIxIndex?: number | undefined) => Promise<...>
Yes
placeAndMakeSignedMsgPerpOrder
(signedSignedMsgOrderParams: SignedMsgOrderParams, signedMsgOrderUuid: Uint8Array<ArrayBufferLike>, takerInfo: { taker: PublicKey; takerStats: PublicKey; takerUserAccount: UserAccount; signingAuthority: PublicKey; }, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | und...
Yes
getPlaceAndMakeSignedMsgPerpOrderIxs
(signedSignedMsgOrderParams: SignedMsgOrderParams, signedMsgOrderUuid: Uint8Array<ArrayBufferLike>, takerInfo: { taker: PublicKey; takerStats: PublicKey; takerUserAccount: UserAccount; signingAuthority: PublicKey; }, orderParams: OptionalOrderParams, referrerInfo?: ReferrerInfo | undefined, subAccountId?: number | u...
Yes
preparePlaceAndTakeSpotOrder
(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | undefined, makerInfo?: MakerInfo | undefined, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
placeAndTakeSpotOrder
(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | undefined, makerInfo?: MakerInfo | undefined, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
getPlaceAndTakeSpotOrderIx
(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | undefined, makerInfo?: MakerInfo | undefined, referrerInfo?: ReferrerInfo | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
placeAndMakeSpotOrder
(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | undefined, referrerInfo?: ReferrerInfo | undefined, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
getPlaceAndMakeSpotOrderIx
(orderParams: OptionalOrderParams, takerInfo: TakerInfo, fulfillmentConfig?: SerumV3FulfillmentConfigAccount | undefined, referrerInfo?: ReferrerInfo | undefined, subAccountId?: number | undefined) => Promise<...>
Yes
closePosition
(marketIndex: number, limitPrice?: any, subAccountId?: number | undefined) => Promise<string>
Yes
modifyPerpOrder
(orderId: number, newBaseAmount?: any, newLimitPrice?: any, newOraclePriceOffset?: number | undefined) => Promise<string>
Modifies an open order by closing it and replacing it with a new order.
Yes
modifyPerpOrderByUserOrderId
(userOrderId: number, newBaseAmount?: any, newLimitPrice?: any, newOraclePriceOffset?: number | undefined) => Promise<string>
Modifies an open order by closing it and replacing it with a new order.
Yes
modifyOrder
(orderParams: { orderId: number; newDirection?: PositionDirection; newBaseAmount?: any; newLimitPrice?: any; newOraclePriceOffset?: number; newTriggerPrice?: any; newTriggerCondition?: OrderTriggerCondition; ... 7 more ...; policy?: number; }, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Pr...
Modifies an open order (spot or perp) by closing it and replacing it with a new order.
Yes
getModifyOrderIx
({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, bitFlags, maxTs, policy, }: { orderId: number; newDirection?: PositionDirection; newBaseAmount?: any; newLimitPrice?: any; new...
Yes
modifyOrderByUserOrderId
(orderParams: { userOrderId: number; newDirection?: PositionDirection; newBaseAmount?: any; newLimitPrice?: any; newOraclePriceOffset?: number; newTriggerPrice?: any; newTriggerCondition?: OrderTriggerCondition; ... 7 more ...; maxTs?: any; }, txParams?: TxParams | undefined, subAccountId?: number | undefined) => Pr...
Modifies an open order by closing it and replacing it with a new order.
Yes
getModifyOrderByUserIdIx
({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, bitFlags, maxTs, policy, }: { userOrderId: number; newDirection?: PositionDirection; newBaseAmount?: any; newLimitPrice?: ...
Yes
settlePNLs
(users: { settleeUserAccountPublicKey: PublicKey; settleeUserAccount: UserAccount; }[], marketIndexes: number[], opts?: { filterInvalidMarkets?: boolean; } | undefined, txParams?: TxParams | undefined) => Promise<...>
Yes
getSettlePNLsIxs
(users: { settleeUserAccountPublicKey: PublicKey; settleeUserAccount: UserAccount; }[], marketIndexes: number[], revenueShareEscrowMap?: RevenueShareEscrowMap | undefined) => Promise<...>
Yes
settlePNL
(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, txParams?: TxParams | undefined, optionalIxs?: TransactionInstruction[] | undefined, revenueShareEscrowMap?: RevenueShareEscrowMap | undefined) => Promise<...>
Yes
settlePNLIx
(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, revenueShareEscrowMap?: RevenueShareEscrowMap | undefined) => Promise<...>
Yes
settleMultiplePNLs
(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, revenueShareEscrowMap?: RevenueShareEscrowMap | undefined, txParams?: TxParams | undefined) => Promise<...>
Yes
settleMultiplePNLsMultipleTxs
(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams | undefined, optionalIxs?: TransactionInstruction[] | undefined, revenueShareEscrowMap?: RevenueShareEscrowMap | undefined) => Promise<...>
Yes
settleMultiplePNLsIx
(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, overrides?: { authority?: PublicKey; } | undefined, revenueShareEscrowMap?: RevenueShareEscrowMap | undefined) => Promise<...>
Yes
getSetUserStatusToBeingLiquidatedIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount) => Promise<TransactionInstruction>
Yes
setUserStatusToBeingLiquidated
(userAccountPublicKey: PublicKey, userAccount: UserAccount) => Promise<string>
Yes
liquidatePerp
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: any, txParams?: TxParams | undefined, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getLiquidatePerpIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN, limitPrice?: any, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
liquidatePerpWithFill
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, makerInfos: MakerInfo[], txParams?: TxParams | undefined, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getLiquidatePerpWithFillIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, makerInfos: MakerInfo[], liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
liquidateSpot
(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: any, txParams?: TxParams | undefined, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getLiquidateSpotIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: any, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getJupiterLiquidateSpotWithSwapIxV6
({ jupiterClient, liabilityMarketIndex, assetMarketIndex, swapAmount, assetTokenAccount, liabilityTokenAccount, slippageBps, swapMode, onlyDirectRoutes, quote, userAccount, userAccountPublicKey, userStatsAccountPublicKey, liquidatorSubAccountId, maxAccounts, }: { jupiterClient: JupiterClient; liabilityMarketIndex: n...
Yes
getLiquidateSpotWithSwapIx
({ liabilityMarketIndex, assetMarketIndex, swapAmount: swapAmount, assetTokenAccount, liabilityTokenAccount, userAccount, userAccountPublicKey, userStatsAccountPublicKey, liquidatorSubAccountId, }: { liabilityMarketIndex: number; assetMarketIndex: number; swapAmount: BN; assetTokenAccount: PublicKey; liabilityTokenA...
Get the drift liquidate_spot_with_swap instructions
Yes
getInsuranceFundSwapIx
({ inMarketIndex, outMarketIndex, amountIn, inTokenAccount, outTokenAccount, }: { inMarketIndex: number; outMarketIndex: number; amountIn: BN; inTokenAccount: PublicKey; outTokenAccount: PublicKey; }) => Promise<{ beginSwapIx: TransactionInstruction; endSwapIx: TransactionInstruction; }>
Yes
liquidateBorrowForPerpPnl
(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: any, txParams?: TxParams | undefined, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getLiquidateBorrowForPerpPnlIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN, limitPrice?: any, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
liquidatePerpPnlForDeposit
(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: any, txParams?: TxParams | undefined, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getLiquidatePerpPnlForDepositIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN, limitPrice?: any, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
resolvePerpBankruptcy
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, txParams?: TxParams | undefined, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getResolvePerpBankruptcyIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, liquidatorSubAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
resolveSpotBankruptcy
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, txParams?: TxParams | undefined, liquidatorSubAccountId?: number | undefined) => Promise<...>
Yes
getResolveSpotBankruptcyIx
(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, liquidatorSubAccountId?: number | undefined) => Promise<TransactionInstruction>
Yes
updateFundingRate
(perpMarketIndex: number, oracle: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateFundingRateIx
(perpMarketIndex: number, oracle: PublicKey) => Promise<TransactionInstruction>
Yes
updatePrelaunchOracle
(perpMarketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdatePrelaunchOracleIx
(perpMarketIndex: number) => Promise<TransactionInstruction>
Yes
updatePerpBidAskTwap
(perpMarketIndex: number, makers: [PublicKey, PublicKey][], txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdatePerpBidAskTwapIx
(perpMarketIndex: number, makers: [PublicKey, PublicKey][]) => Promise<TransactionInstruction>
Yes
settleFundingPayment
(userAccountPublicKey: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getSettleFundingPaymentIx
(userAccountPublicKey: PublicKey) => Promise<TransactionInstruction>
Yes
triggerEvent
(eventName: keyof DriftClientAccountEvents, data?: any) => void
Yes
getOracleDataForPerpMarket
(marketIndex: number) => OraclePriceData
Yes
getMMOracleDataForPerpMarket
(marketIndex: number) => MMOraclePriceData
Yes
getOracleDataForSpotMarket
(marketIndex: number) => OraclePriceData
Yes
initializeInsuranceFundStake
(marketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getInitializeInsuranceFundStakeIx
(marketIndex: number) => Promise<TransactionInstruction>
Yes
getAddInsuranceFundStakeIx
(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey) => Promise<TransactionInstruction>
Yes
addInsuranceFundStake
({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, txParams, }: { marketIndex: number; amount: BN; collateralAccountPublicKey: PublicKey; initializeStakeAccount?: boolean; fromSubaccount?: boolean; txParams?: TxParams; }) => Promise<...>
Add to an insurance fund stake and optionally initialize the account
Yes
getAddInsuranceFundStakeIxs
({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, fromSubaccount, }: { marketIndex: number; amount: BN; collateralAccountPublicKey: PublicKey; initializeStakeAccount?: boolean; fromSubaccount?: boolean; }) => Promise<TransactionInstruction[]>
Get instructions to add to an insurance fund stake and optionally initialize the account
Yes
requestRemoveInsuranceFundStake
(marketIndex: number, amount: BN, txParams?: TxParams | undefined) => Promise<string>
Yes
cancelRequestRemoveInsuranceFundStake
(marketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
removeInsuranceFundStake
(marketIndex: number, collateralAccountPublicKey: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
updateUserQuoteAssetInsuranceStake
(authority: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateUserQuoteAssetInsuranceStakeIx
(authority: PublicKey) => Promise<TransactionInstruction>
Yes
updateUserGovTokenInsuranceStake
(authority: PublicKey, txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateUserGovTokenInsuranceStakeIx
(authority: PublicKey) => Promise<TransactionInstruction>
Yes
settleRevenueToInsuranceFund
(spotMarketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getSettleRevenueToInsuranceFundIx
(spotMarketIndex: number) => Promise<TransactionInstruction>
Yes
resolvePerpPnlDeficit
(spotMarketIndex: number, perpMarketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getResolvePerpPnlDeficitIx
(spotMarketIndex: number, perpMarketIndex: number) => Promise<TransactionInstruction>
Yes
getDepositIntoSpotMarketRevenuePoolIx
(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey) => Promise<TransactionInstruction>
Yes
depositIntoSpotMarketRevenuePool
(marketIndex: number, amount: BN, userTokenAccountPublicKey: PublicKey) => Promise<string>
This ix will donate your funds to drift revenue pool. It does not deposit into your user account
Yes
getPerpMarketExtendedInfo
(marketIndex: number) => PerpMarketExtendedInfo
Yes
getMarketFees
(marketType: MarketType, marketIndex?: number | undefined, user?: User | undefined, enteringHighLeverageMode?: boolean | undefined) => { takerFee: number; makerFee: number; }
Calculates taker / maker fee (as a percentage, e.g. .001 = 10 basis points) for particular marketType
Yes
getMarketIndexAndType
(name: string) => { marketIndex: number; marketType: MarketType; } | undefined
Returns the market index and type for a given market name E.g. "SOL-PERP" -> &#123; marketIndex: 0, marketType: MarketType.PERP &#125;
Yes
getReceiverProgram
() => Program<PythSolanaReceiver>
Yes
getSwitchboardOnDemandProgram
() => Promise<Program<Idl>>
Yes
postPythPullOracleUpdateAtomic
(vaaString: string, feedId: string) => Promise<string>
Yes
postMultiPythPullOracleUpdatesAtomic
(vaaString: string, feedIds: string[]) => Promise<string>
Yes
getPostPythPullOracleUpdateAtomicIxs
(vaaString: string, feedIds: string | string[], numSignatures?: number | undefined) => Promise<TransactionInstruction[]>
Yes
getSinglePostPythPullOracleAtomicIx
any
Yes
updatePythPullOracle
(vaaString: string, feedId: string) => Promise<string>
Yes
getUpdatePythPullOracleIxs
(params: { merklePriceUpdate: { message: Buffer; proof: number[][]; }; }, feedId: string, encodedVaaAddress: PublicKey) => Promise<TransactionInstruction>
Yes
postPythLazerOracleUpdate
(feedIds: number[], pythMessageHex: string) => Promise<string>
Yes
getPostPythLazerOracleUpdateIxs
(feedIds: number[], pythMessageHex: string, precedingIxs?: TransactionInstruction[] | undefined, overrideCustomIxIndex?: number | undefined) => Promise<TransactionInstruction[]>
Yes
getPostManySwitchboardOnDemandUpdatesAtomicIxs
(feeds: PublicKey[], recentSlothash?: Slothash | undefined, numSignatures?: number | undefined) => Promise<TransactionInstruction[] | undefined>
Yes
getPostSwitchboardOnDemandUpdateAtomicIx
(feed: PublicKey, recentSlothash?: Slothash | undefined, numSignatures?: number | undefined) => Promise<TransactionInstruction | undefined>
Yes
postSwitchboardOnDemandUpdate
(feed: PublicKey, recentSlothash?: Slothash | undefined, numSignatures?: number | undefined) => Promise<string>
Yes
getBuildEncodedVaaIxs
any
Yes
enableUserHighLeverageMode
(subAccountId: number, txParams?: TxParams | undefined) => Promise<string>
Yes
getEnableHighLeverageModeIx
(subAccountId: number, depositToTradeArgs?: { isMakingNewAccount: boolean; depositMarketIndex: number; orderMarketIndex: number; } | undefined, overrides?: { user?: User; signingAuthority?: PublicKey; } | undefined) => Promise<...>
Yes
disableUserHighLeverageMode
(user: PublicKey, userAccount?: UserAccount | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getDisableHighLeverageModeIx
(user: PublicKey, userAccount?: UserAccount | undefined, maintenance?: boolean | undefined) => Promise<TransactionInstruction>
Yes
fetchHighLeverageModeConfig
() => Promise<HighLeverageModeConfig>
Yes
fetchProtectedMakerModeConfig
() => Promise<ProtectedMakerModeConfig>
Yes
updateUserProtectedMakerOrders
(subAccountId: number, protectedOrders: boolean, authority?: PublicKey | undefined, txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateUserProtectedMakerOrdersIx
(subAccountId: number, protectedOrders: boolean, authority?: PublicKey | undefined) => Promise<TransactionInstruction>
Yes
getPauseSpotMarketDepositWithdrawIx
(spotMarketIndex: number) => Promise<TransactionInstruction>
Yes
pauseSpotMarketDepositWithdraw
(spotMarketIndex: number, txParams?: TxParams | undefined) => Promise<string>
Yes
updateMmOracleNative
(marketIndex: number, oraclePrice: BN, oracleSequenceId: BN) => Promise<string>
Yes
getUpdateMmOracleNativeIx
(marketIndex: number, oraclePrice: BN, oracleSequenceId: BN) => Promise<TransactionInstruction>
Yes
updateAmmSpreadAdjustmentNative
(marketIndex: number, ammSpreadAdjustment: number) => Promise<string>
Yes
getUpdateAmmSpreadAdjustmentNativeIx
(marketIndex: number, ammSpreadAdjustment: number) => TransactionInstruction
Yes
getLpPoolAccount
(lpPoolId: number) => Promise<LPPoolAccount>
Yes
getConstituentTargetBaseAccount
(lpPoolId: number) => Promise<ConstituentTargetBaseAccount>
Yes
getAmmCache
() => Promise<AmmCache>
Yes
updateLpConstituentTargetBase
(lpPoolId: number, constituents: PublicKey[], txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateLpConstituentTargetBaseIx
(lpPoolId: number, constituents: PublicKey[]) => Promise<TransactionInstruction>
Yes
updateLpPoolAum
(lpPool: LPPoolAccount, spotMarketIndexOfConstituents: number[], txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateLpPoolAumIxs
(lpPool: LPPoolAccount, spotMarketIndexOfConstituents: number[]) => Promise<TransactionInstruction>
Yes
updateAmmCache
(perpMarketIndexes: number[], txParams?: TxParams | undefined) => Promise<string>
Yes
getUpdateAmmCacheIx
(perpMarketIndexes: number[]) => Promise<TransactionInstruction>
Yes
updateConstituentOracleInfo
(constituent: ConstituentAccount) => Promise<string>
Yes
getUpdateConstituentOracleInfoIx
(constituent: ConstituentAccount) => Promise<TransactionInstruction>
Yes
lpPoolSwap
(inMarketIndex: number, outMarketIndex: number, inAmount: BN, minOutAmount: BN, lpPool: PublicKey, userAuthority: PublicKey, txParams?: TxParams | undefined) => Promise<...>
Yes
getLpPoolSwapIx
(inMarketIndex: number, outMarketIndex: number, inAmount: BN, minOutAmount: BN, lpPool: PublicKey, userAuthority: PublicKey) => Promise<TransactionInstruction>
Yes
viewLpPoolSwapFees
(inMarketIndex: number, outMarketIndex: number, inAmount: BN, inTargetWeight: BN, outTargetWeight: BN, lpPool: PublicKey, constituentTargetBase: PublicKey, constituentInTokenAccount: PublicKey, constituentOutTokenAccount: PublicKey, inConstituent: PublicKey, outConstituent: PublicKey, txParams?: TxParams | undefined...
Yes
getViewLpPoolSwapFeesIx
(inMarketIndex: number, outMarketIndex: number, inAmount: BN, inTargetWeight: BN, outTargetWeight: BN, lpPool: PublicKey, constituentTargetBase: PublicKey, constituentInTokenAccount: PublicKey, constituentOutTokenAccount: PublicKey, inConstituent: PublicKey, outConstituent: PublicKey) => Promise<...>
Yes
getCreateLpPoolTokenAccountIx
(lpPool: LPPoolAccount) => Promise<TransactionInstruction>
Yes
createLpPoolTokenAccount
(lpPool: LPPoolAccount, txParams?: TxParams | undefined) => Promise<string>
Yes
lpPoolAddLiquidity
({ inMarketIndex, inAmount, minMintAmount, lpPool, txParams, }: { inMarketIndex: number; inAmount: BN; minMintAmount: BN; lpPool: LPPoolAccount; txParams?: TxParams; }) => Promise<string>
Yes
getLpPoolAddLiquidityIx
({ inMarketIndex, inAmount, minMintAmount, lpPool, }: { inMarketIndex: number; inAmount: BN; minMintAmount: BN; lpPool: LPPoolAccount; }) => Promise<TransactionInstruction[]>
Yes
viewLpPoolAddLiquidityFees
({ inMarketIndex, inAmount, lpPool, txParams, }: { inMarketIndex: number; inAmount: BN; lpPool: LPPoolAccount; txParams?: TxParams; }) => Promise<string>
Yes
getViewLpPoolAddLiquidityFeesIx
({ inMarketIndex, inAmount, lpPool, }: { inMarketIndex: number; inAmount: BN; lpPool: LPPoolAccount; }) => Promise<TransactionInstruction>
Yes
lpPoolRemoveLiquidity
({ outMarketIndex, lpToBurn, minAmountOut, lpPool, txParams, }: { outMarketIndex: number; lpToBurn: BN; minAmountOut: BN; lpPool: LPPoolAccount; txParams?: TxParams; }) => Promise<string>
Yes
getLpPoolRemoveLiquidityIx
({ outMarketIndex, lpToBurn, minAmountOut, lpPool, }: { outMarketIndex: number; lpToBurn: BN; minAmountOut: BN; lpPool: LPPoolAccount; }) => Promise<TransactionInstruction[]>
Yes
viewLpPoolRemoveLiquidityFees
({ outMarketIndex, lpToBurn, lpPool, txParams, }: { outMarketIndex: number; lpToBurn: BN; lpPool: LPPoolAccount; txParams?: TxParams; }) => Promise<string>
Yes
getViewLpPoolRemoveLiquidityFeesIx
({ outMarketIndex, lpToBurn, lpPool, }: { outMarketIndex: number; lpToBurn: BN; lpPool: LPPoolAccount; }) => Promise<TransactionInstruction>
Yes
getAllLpPoolAddLiquidityIxs
({ inMarketIndex, inAmount, minMintAmount, lpPool, }: { inMarketIndex: number; inAmount: BN; minMintAmount: BN; lpPool: LPPoolAccount; }, constituentMap: ConstituentMap, includeUpdateConstituentOracleInfo?: boolean | undefined, view?: boolean | undefined) => Promise<...>
Yes
getAllLpPoolRemoveLiquidityIxs
({ outMarketIndex, lpToBurn, minAmountOut, lpPool, }: { outMarketIndex: number; lpToBurn: BN; minAmountOut: BN; lpPool: LPPoolAccount; }, constituentMap: ConstituentMap, includeUpdateConstituentOracleInfo?: boolean | undefined, view?: boolean | undefined) => Promise<...>
Yes
getAllUpdateLpPoolAumIxs
(lpPool: LPPoolAccount, constituentMap: ConstituentMap, includeUpdateConstituentOracleInfo?: boolean | undefined) => Promise<TransactionInstruction[]>
Yes
getAllUpdateConstituentTargetBaseIxs
(perpMarketIndexes: number[], lpPool: LPPoolAccount, constituentMap: ConstituentMap, includeUpdateConstituentOracleInfo?: boolean | undefined) => Promise<...>
Yes
getAllLpPoolSwapIxs
(lpPool: LPPoolAccount, constituentMap: ConstituentMap, inMarketIndex: number, outMarketIndex: number, inAmount: BN, minOutAmount: BN, userAuthority: PublicKey) => Promise<...>
Yes
settlePerpToLpPool
(lpPoolId: number, perpMarketIndexes: number[]) => Promise<string>
Yes
getSettlePerpToLpPoolIx
(lpPoolId: number, perpMarketIndexes: number[]) => Promise<TransactionInstruction>
Yes
getAllSettlePerpToLpPoolIxs
(lpPoolId: number, marketIndexes: number[]) => Promise<TransactionInstruction[]>
Yes
handleSignedTransaction
any
Below here are the transaction sending functions
Yes
handlePreSignedTransaction
any
Yes
isVersionedTransaction
any
Yes
sendTransaction
(tx: VersionedTransaction | Transaction, additionalSigners?: Signer[] | undefined, opts?: ConfirmOptions | undefined, preSigned?: boolean | undefined) => Promise<...>
Send a transaction.
Yes
buildTransaction
(instructions: TransactionInstruction | TransactionInstruction[], txParams?: TxParams | undefined, txVersion?: TransactionVersion | undefined, lookupTables?: AddressLookupTableAccount[] | undefined, forceVersionedTransaction?: boolean | undefined, recentBlockhash?: Readonly<...> | undefined, optionalIxs?: Transactio...
Yes
buildBulkTransactions
(instructions: (TransactionInstruction | TransactionInstruction[])[], txParams?: TxParams | undefined, txVersion?: TransactionVersion | undefined, lookupTables?: AddressLookupTableAccount[] | undefined, forceVersionedTransaction?: boolean | undefined) => Promise<...>
Yes
buildTransactionsMap
(instructionsMap: Record<string, TransactionInstruction | TransactionInstruction[]>, txParams?: TxParams | undefined, txVersion?: TransactionVersion | undefined, lookupTables?: AddressLookupTableAccount[] | undefined, forceVersionedTransaction?: boolean | undefined) => Promise<...>
Yes
buildAndSignTransactionsMap
(instructionsMap: Record<string, TransactionInstruction | TransactionInstruction[]>, txParams?: TxParams | undefined, txVersion?: TransactionVersion | undefined, lookupTables?: AddressLookupTableAccount[] | undefined, forceVersionedTransaction?: boolean | undefined) => Promise<...>
Yes
isOrderIncreasingPosition
(orderParams: OptionalOrderParams, subAccountId: number) => boolean
Yes

Step 2: Get oracle price

Read the current oracle price to calculate your bid/ask spread.

import { PRICE_PRECISION, convertToNumber } from "@drift-labs/sdk"; const marketIndex = 0; // SOL-PERP const oracle = driftClient.getOracleDataForPerpMarket(marketIndex); const oraclePrice = convertToNumber(oracle.price, PRICE_PRECISION); console.log(`Oracle price: $${oraclePrice}`);
Method DriftClient.getOracleDataForPerpMarketReference ↗
ParameterTypeRequired
marketIndex
number
Yes
Returns
OraclePriceData

Step 3: Place two-sided quotes

Place a bid (buy) below oracle and an ask (sell) above oracle. Using PostOnlyParams.MUST_POST_ONLY ensures your orders never cross and you always earn maker rebates.

import { PRICE_PRECISION, convertToNumber, MarketType, OrderType, PositionDirection, PostOnlyParams } from "@drift-labs/sdk"; const marketIndex = 0; // SOL-PERP const spread = 0.5; // $0.50 spread on each side const size = 0.1; // 0.1 SOL per order // Fetch oracle price for spread calculation const oracle = driftClient.getOracleDataForPerpMarket(marketIndex); const oraclePrice = convertToNumber(oracle.price, PRICE_PRECISION); const bidPrice = oraclePrice - spread; const askPrice = oraclePrice + spread; await driftClient.placeOrders([ { orderType: OrderType.LIMIT, marketType: MarketType.PERP, marketIndex, direction: PositionDirection.LONG, baseAssetAmount: driftClient.convertToPerpPrecision(size), price: driftClient.convertToPricePrecision(bidPrice), postOnly: PostOnlyParams.MUST_POST_ONLY, }, { orderType: OrderType.LIMIT, marketType: MarketType.PERP, marketIndex, direction: PositionDirection.SHORT, baseAssetAmount: driftClient.convertToPerpPrecision(size), price: driftClient.convertToPricePrecision(askPrice), postOnly: PostOnlyParams.MUST_POST_ONLY, }, ]); console.log(`Placed bid @ $${bidPrice}, ask @ $${askPrice}`);
Method DriftClient.placeOrdersReference ↗
ParameterTypeRequired
params
OrderParams[]
Yes
txParams
TxParams
No
subAccountId
number
No
optionalIxs
TransactionInstruction[]
No
isolatedPositionDepositAmount
any
No
Returns
Promise<string>

Step 4: Monitor and update

Check for fills and cancel/replace orders when the oracle moves. This complete example runs a loop that refreshes quotes every 10 seconds.

import { PRICE_PRECISION, BASE_PRECISION, convertToNumber, MarketType, OrderType, PositionDirection, PostOnlyParams, } from "@drift-labs/sdk"; const marketIndex = 0; const spread = 0.5; const size = 0.1; setInterval(async () => { try { // Check current position const user = driftClient.getUser(); const position = user.getPerpPosition(marketIndex); if (position) { const posSize = convertToNumber(position.baseAssetAmount, BASE_PRECISION); console.log(`Current position: ${posSize} SOL`); } // Cancel all existing orders for this market await driftClient.cancelOrders(MarketType.PERP, marketIndex); // Re-fetch oracle price const oracle = driftClient.getOracleDataForPerpMarket(marketIndex); const oraclePrice = convertToNumber(oracle.price, PRICE_PRECISION); const bidPrice = oraclePrice - spread; const askPrice = oraclePrice + spread; // Place fresh two-sided quotes await driftClient.placeOrders([ { orderType: OrderType.LIMIT, marketType: MarketType.PERP, marketIndex, direction: PositionDirection.LONG, baseAssetAmount: driftClient.convertToPerpPrecision(size), price: driftClient.convertToPricePrecision(bidPrice), postOnly: PostOnlyParams.MUST_POST_ONLY, }, { orderType: OrderType.LIMIT, marketType: MarketType.PERP, marketIndex, direction: PositionDirection.SHORT, baseAssetAmount: driftClient.convertToPerpPrecision(size), price: driftClient.convertToPricePrecision(askPrice), postOnly: PostOnlyParams.MUST_POST_ONLY, }, ]); console.log(`Updated quotes: bid $${bidPrice.toFixed(2)} / ask $${askPrice.toFixed(2)}`); } catch (err) { console.error("Error updating quotes:", err); } }, 10_000); // Update every 10 seconds
Method DriftClient.cancelOrdersReference ↗
ParameterTypeRequired
marketType
MarketType
No
marketIndex
number
No
direction
PositionDirection
No
txParams
TxParams
No
subAccountId
number
No
Returns
Promise<string>

Tip: This cancel-and-replace approach sends ~2 transactions every 10 seconds. For production, consider oracle offset orders which float with the oracle automatically and require only ~30 txs/day.

Next steps

This basic example gets you started, but production market makers need:

  • Oracle offset orders , orders that automatically track oracle price, drastically reducing transactions (Normal MM)
  • Inventory management , adjust spread based on position size (Normal MM)
  • Risk controls , position limits, health checks, emergency cancel (Bot Architecture)
  • JIT participation , compete in auctions for better fills (JIT-only MM)
  • Efficient subscriptions , WebSocket or gRPC for lower latency (Bot Architecture)
  • Multiple markets , quote across markets simultaneously

Common pitfalls

  • Forgetting PostOnlyParams , without it, your “maker” orders can cross the spread and execute as taker, paying fees instead of earning rebates
  • Using PRICE_PRECISION wrong , oracle prices are in PRICE_PRECISION (1e6), base amounts in BASE_PRECISION (1e9). Mixing them up causes orders at wildly wrong prices
  • Not initializing user account , first-time users must call driftClient.initializeUserAccount() before placing orders. The SDK will throw User account not found otherwise
  • 32-order limit , each Drift subaccount supports a maximum of 32 open orders. Cancel stale orders or use multiple subaccounts for multi-market strategies

For production patterns and best practices, see:

Last updated on