or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

account-management.mderror-handling.mdexchange-management.mdfunding-operations.mdindex.mdmarket-data.mdorder-management.mdtrading-operations.mdutility-functions.mdwebsocket-operations.md
tile.json

account-management.mddocs/

Account Management

Account management provides comprehensive functionality for managing account balances, positions, ledger entries, and account information across different account types and trading environments.

Capabilities

Balance Information

Retrieve account balances showing available, used, and total amounts for all currencies.

/**
 * Fetch account balance for all currencies
 * @param params - Additional exchange-specific parameters
 * @returns Balance object with currency information
 */
fetchBalance(params?: Dict): Promise<Balances>;

interface Balances {
  [currency: string]: BalanceAccount;
  info: any; // Raw exchange-specific balance data
}

interface BalanceAccount {
  free: number;     // Available balance for trading
  used: number;     // Balance currently in use (open orders, etc.)
  total: number;    // Total balance (free + used)
}

Usage Examples:

// Fetch account balance
const balance = await exchange.fetchBalance();

// Check specific currency balance
const btcBalance = balance['BTC'];
if (btcBalance) {
  console.log(`BTC Balance - Free: ${btcBalance.free}, Used: ${btcBalance.used}, Total: ${btcBalance.total}`);
}

// List all non-zero balances
Object.entries(balance).forEach(([currency, account]) => {
  if (account.total > 0) {
    console.log(`${currency}: ${account.total} (${account.free} available)`);
  }
});

// Calculate total portfolio value (requires ticker data)
const tickers = await exchange.fetchTickers();
let totalValue = 0;
Object.entries(balance).forEach(([currency, account]) => {
  if (account.total > 0 && currency !== 'info') {
    if (currency === 'USDT') {
      totalValue += account.total;
    } else {
      const ticker = tickers[`${currency}/USDT`];
      if (ticker) {
        totalValue += account.total * ticker.last;
      }
    }
  }
});
console.log(`Total portfolio value: $${totalValue.toFixed(2)}`);

Account Information

Access detailed account information including account types, permissions, and trading settings.

/**
 * Fetch account information and settings
 * @param params - Additional parameters
 * @returns Array of account objects
 */
fetchAccounts(params?: Dict): Promise<Account[]>;

interface Account {
  id: string;           // Account identifier
  type: AccountType;    // Account type
  currency?: string;    // Account base currency
  info: any;           // Raw account data
}

type AccountType = 'main' | 'trading' | 'margin' | 'future' | 'swap' | 'funding' | 'option';

Position Management

Manage trading positions for margin and derivatives accounts.

/**
 * Fetch open positions
 * @param symbols - Symbols to fetch positions for (optional)
 * @param params - Additional parameters
 * @returns Array of position objects
 */
fetchPositions(symbols?: string[], params?: Dict): Promise<Position[]>;

/**
 * Fetch open positions with risk information
 * @param symbols - Symbols to fetch positions for (optional)
 * @param params - Additional parameters
 * @returns Array of position objects with risk data
 */
fetchPositionsRisk(symbols?: string[], params?: Dict): Promise<Position[]>;

/**
 * Fetch account ledger entries (transaction history)
 * @param code - Currency code to filter by (optional)
 * @param since - Timestamp to fetch entries from (optional)
 * @param limit - Maximum number of entries to fetch (optional)
 * @param params - Additional parameters
 * @returns Array of ledger entry objects
 */
fetchLedger(code?: string, since?: number, limit?: number, params?: Dict): Promise<LedgerEntry[]>;

interface Position {
  id?: string;              // Position identifier
  symbol: string;           // Trading pair symbol
  side: 'long' | 'short';   // Position side
  amount: number;           // Position size
  contracts?: number;       // Number of contracts (derivatives)
  contractSize?: number;    // Contract size
  unrealizedPnl?: number;   // Unrealized P&L
  percentage?: number;      // P&L percentage
  timestamp?: number;       // Position timestamp
  datetime?: string;        // Position datetime
  info: any;               // Raw position data
}

interface LedgerEntry {
  id: string;               // Ledger entry identifier
  timestamp: number;        // Entry timestamp
  datetime: string;         // Entry datetime
  currency: string;         // Currency code
  account: string;          // Account identifier
  referenceId?: string;     // Reference transaction/trade ID
  referenceAccount?: string; // Reference account
  type: 'trade' | 'transaction' | 'fee' | 'rebate' | 'cashback' | 'deposit' | 'withdrawal' | 'transfer'; // Entry type
  amount: number;           // Amount change
  before?: number;          // Balance before entry
  after?: number;           // Balance after entry
  status: 'pending' | 'ok' | 'canceled'; // Entry status
  fee?: {                   // Associated fee
    currency: string;
    cost: number;
  };
  info: any;               // Raw exchange data
}

Usage Examples:

// Fetch all positions
const positions = await exchange.fetchPositions();
console.log(`Open positions: ${positions.length}`);

// Analyze positions
positions.forEach(position => {
  console.log(`${position.symbol}: ${position.side} ${position.amount}`);
  if (position.unrealizedPnl !== undefined) {
    console.log(`  P&L: ${position.unrealizedPnl} (${position.percentage?.toFixed(2)}%)`);
  }
});

// Filter profitable positions
const profitablePositions = positions.filter(p => (p.unrealizedPnl || 0) > 0);
console.log(`Profitable positions: ${profitablePositions.length}`);

Deposit Addresses

Manage cryptocurrency deposit addresses for receiving funds.

/**
 * Create a new deposit address
 * @param code - Currency code (e.g., 'BTC', 'ETH')
 * @param params - Additional parameters (network, etc.)
 * @returns Deposit address object
 */
createDepositAddress(code: string, params?: Dict): Promise<DepositAddress>;

/**
 * Fetch existing deposit address
 * @param code - Currency code
 * @param params - Additional parameters
 * @returns Deposit address object
 */
fetchDepositAddress(code: string, params?: Dict): Promise<DepositAddress>;

interface DepositAddress {
  currency: string;     // Currency code
  address: string;      // Deposit address
  tag?: string;         // Memo/tag for currencies that require it
  network?: string;     // Network name (e.g., 'TRC20', 'ERC20')
  info: any;           // Raw exchange-specific data
}

Usage Examples:

// Get BTC deposit address
const btcAddress = await exchange.fetchDepositAddress('BTC');
console.log(`BTC deposit address: ${btcAddress.address}`);

// Get USDT address on specific network
const usdtTrc20Address = await exchange.fetchDepositAddress('USDT', { network: 'TRC20' });
console.log(`USDT (TRC20) address: ${usdtTrc20Address.address}`);

// Handle currencies with memo/tag
const xlmAddress = await exchange.fetchDepositAddress('XLM');
if (xlmAddress.tag) {
  console.log(`XLM address: ${xlmAddress.address}, memo: ${xlmAddress.tag}`);
}