Precision & Types
The Drift SDK uses integer big numbers (BN) for most values. Always convert using the SDK’s precision constants and helpers.
Margin system (high-level)
At a high level, Drift checks:
- Initial margin: can you open/increase positions?
- Maintenance margin: should you be liquidated?
The system uses weighted collateral and weighted liabilities. The exact weights/inputs depend on margin category (initial vs maintenance) and oracle vs oracle-twap pricing.
Precision constants
import { QUOTE_PRECISION } from "@drift-labs/sdk";Variable QUOTE_PRECISIONReference ↗TypeScript docs unavailable for
QUOTE_PRECISION.import { BASE_PRECISION } from "@drift-labs/sdk";Variable BASE_PRECISIONReference ↗TypeScript docs unavailable for
BASE_PRECISION.import { PRICE_PRECISION } from "@drift-labs/sdk";Variable PRICE_PRECISIONReference ↗TypeScript docs unavailable for
PRICE_PRECISION.import { MARGIN_PRECISION } from "@drift-labs/sdk";Variable MARGIN_PRECISIONReference ↗TypeScript docs unavailable for
MARGIN_PRECISION.Token math helpers
import { getTokenAmount } from "@drift-labs/sdk";Function getTokenAmountReference ↗import { getSignedTokenAmount } from "@drift-labs/sdk";Function getSignedTokenAmountReference ↗| Name | Type | Default |
|---|---|---|
tokenAmount | anyThe token amount to convert (from | |
balanceType | SpotBalanceTypeThe balance type to determine the sign of the token amount. |
Core enums you’ll use in bots
import { OrderType } from "@drift-labs/sdk";
// OrderType.MARKET / LIMIT / TRIGGER_MARKET / TRIGGER_LIMIT / ORACLEEnum OrderTypeReference ↗TypeScript docs unavailable for
OrderType.import { MarketType } from "@drift-labs/sdk";
// MarketType.PERP / MarketType.SPOTClass MarketTypeReference ↗TypeScript docs unavailable for
MarketType.import { PositionDirection } from "@drift-labs/sdk";
// PositionDirection.LONG / PositionDirection.SHORTClass PositionDirectionReference ↗TypeScript docs unavailable for
PositionDirection.import { PostOnlyParams } from "@drift-labs/sdk";
// PostOnlyParams.NONE / MUST_POST_ONLY / TRY_POST_ONLY / SLIDEClass PostOnlyParamsReference ↗TypeScript docs unavailable for
PostOnlyParams.import { OrderTriggerCondition } from "@drift-labs/sdk";Class OrderTriggerConditionReference ↗TypeScript docs unavailable for
OrderTriggerCondition.Last updated on