Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/bitget-api/llms.txt

Use this file to discover all available pages before exploring further.

The RestClientV2 class supports both cross and isolated margin trading through a consistent API surface. Every margin method accepts a marginType parameter of type MarginType — either 'crossed' or 'isolated' — which is validated at runtime and routes the request to the appropriate endpoint path (/api/v2/margin/crossed/... or /api/v2/margin/isolated/...). All methods in this section require authentication.
Cross vs. isolated margin: In 'crossed' mode, all margin positions share a single pool of collateral. In 'isolated' mode, each position has its own dedicated margin allocation, limiting losses to that amount. Pass marginType as the first argument to every margin method to select the correct mode.

Account

MethodDescription
getMarginCurrencies()Lists all supported margin trading currencies (no marginType required)
getMarginAccountAssets(marginType, params?)Returns asset balances; optionally filter by coin
getMarginRiskRate(marginType)Returns risk rate ratios across your margin positions
getMarginMaxBorrowable(marginType, params)Maximum borrowable amount for a given coin
getMarginMaxTransferable(marginType, params)Maximum transferable amount for a given coin
getMarginInterestRateAndMaxBorrowable(marginType, params)Current interest rate and borrowing limits per coin
getMarginTierConfiguration(marginType, params)Risk tier table for a coin
getMarginLoanGrowthRate(params)Loan growth rate data from the market insights endpoint
getMarginFinancialHistory(marginType, params)Paginated financial records (transfers, fees, interest)

Orders

MethodDescription
marginSubmitOrder(marginType, params)Places a single margin order
marginCancelOrder(marginType, params)Cancels an order by orderId or clientOid
marginBatchSubmitOrders(marginType, params)Places multiple orders in one call
marginBatchCancelOrders(marginType, params)Cancels multiple orders by ID list
getMarginOpenOrders(marginType, params)Lists currently open orders
getMarginHistoricOrders(marginType, params)Paginated order history
getMarginHistoricOrderFills(marginType, params)Paginated fill records
getMarginTransactionRecords(params)Tax/accounting transaction records via /api/v2/tax/margin-record

MarginPlaceOrderRequestV2 parameters

symbol
string
required
Trading pair symbol, e.g. "BTCUSDT".
side
'buy' | 'sell'
required
Order direction.
orderType
'limit' | 'market'
required
Execution type.
force
'gtc' | 'post_only' | 'fok' | 'ioc'
required
Time-in-force policy.
loanType
'normal' | 'autoLoan' | 'autoRepay' | 'autoLoanAndRepay'
required
Controls automatic borrowing and repayment behavior. Use 'autoLoan' to borrow automatically when placing an order, 'autoRepay' to repay automatically on fill, or 'autoLoanAndRepay' for both.
baseSize
string
Order quantity in base currency. Either baseSize or quoteSize must be provided.
quoteSize
string
Order quantity in quote currency. Either baseSize or quoteSize must be provided.
price
string
Limit price. Required when orderType is 'limit'.
clientOid
string
Optional client-assigned order ID.

Borrow / Repay

MethodDescription
marginBorrow(marginType, params)Borrows a specific coin amount against collateral
marginRepay(marginType, params)Repays a specific borrow via repayId
marginFlashRepay(marginType, params)Instantly repays all debt for a coin using available balance
getMarginFlashRepayResult(marginType, params)Polls the result of a flash repay operation
getMarginBorrowHistory(marginType, params)Paginated borrow history
getMarginRepayHistory(marginType, params)Paginated repayment history
getMarginInterestHistory(marginType, params)Paginated interest charge history
getMarginLiquidationHistory(marginType, params)Paginated liquidation event history
getMarginLiquidationOrders(marginType, params)Paginated liquidation order records

Borrow → Trade → Repay workflow

The following example demonstrates the full manual borrow-trade-repay cycle using isolated margin on the BTCUSDT pair.
import { RestClientV2 } from 'bitget-api';

const client = new RestClientV2({
  apiKey: process.env.API_KEY,
  apiSecret: process.env.API_SECRET,
  apiPass: process.env.API_PASS,
});

const marginType = 'isolated';

// Check how much USDT we can borrow
const maxBorrow = await client.getMarginMaxBorrowable(marginType, {
  coin: 'USDT',
});
console.log('Max borrowable USDT:', maxBorrow.data);

// Borrow USDT for margin trading
const borrow = await client.marginBorrow(marginType, {
  loanId: `loan-${Date.now()}`,
  symbol: 'BTCUSDT',
  coin: 'USDT',
  borrowAmount: '100',
});
console.log('Borrow result:', borrow.data);
Monitor your risk rate regularly when running leveraged margin positions. A riskRateRatio near 1.0 triggers liquidation. Consider using 'autoLoanAndRepay' as the loanType to automate debt management.

Build docs developers (and LLMs) love