> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kaleidoswap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Node SDK Utilities

> Node SDK helper functions for amount conversion, precision handling, and asset mapping across bitcoin and Bitcoin L2 assets

## Amount Conversion

### `parseRawAmount` / `parse_raw_amount`

Convert a display amount to the raw (smallest) unit (e.g., BTC to satoshis).

```typescript TypeScript theme={null}
import { parseRawAmount } from 'kaleido-sdk';

const sats = parseRawAmount(0.001, 8);   // 100000
const usdt = parseRawAmount(10.50, 2);   // 1050
```

```python Python theme={null}
from kaleido_sdk import parse_raw_amount

sats = parse_raw_amount(0.001, 8)   # 100000
usdt = parse_raw_amount(10.50, 2)   # 1050
```

### `toDisplayAmount` / `to_display_amount`

Convert a raw (smallest-unit) amount back to a display amount.

```typescript TypeScript theme={null}
import { toDisplayAmount } from 'kaleido-sdk';

const display = toDisplayAmount(50000000, 8);  // 0.5
```

```python Python theme={null}
from kaleido_sdk import to_display_amount

display = to_display_amount(50000000, 8)  # 0.5
```

## PrecisionHandler

The `PrecisionHandler` manages amount conversions for multiple assets, using their metadata to look up precision automatically.

### Creating a PrecisionHandler

```typescript TypeScript theme={null}
import { createPrecisionHandler } from 'kaleido-sdk';

// MappedAsset objects with asset_id and precision
const assets = [
  { asset_id: 'btc-asset-id', ticker: 'BTC', precision: 8, /* ... */ },
  { asset_id: 'usdt-asset-id', ticker: 'USDT', precision: 2, /* ... */ },
];

const handler = createPrecisionHandler(assets);
```

```python Python theme={null}
from kaleido_sdk import create_precision_handler

assets = [
    {"asset_id": "btc-asset-id", "ticker": "BTC", "precision": 8},
    {"asset_id": "usdt-asset-id", "ticker": "USDT", "precision": 2},
]

handler = create_precision_handler(assets)
```

### Methods

#### `toRawAmount` / `to_raw_amount`

Convert display amount to raw, using the asset's precision.

```typescript TypeScript theme={null}
const raw = handler.toRawAmount(0.5, 'btc-asset-id');  // 50000000
```

```python Python theme={null}
raw = handler.to_raw_amount(0.5, "btc-asset-id")  # 50000000
```

#### `toDisplayAmount` / `to_display_amount`

Convert raw amount to display.

```typescript TypeScript theme={null}
const display = handler.toDisplayAmount(50000000, 'btc-asset-id');  // 0.5
```

```python Python theme={null}
display = handler.to_display_amount(50000000, "btc-asset-id")  # 0.5
```

#### `getAssetPrecision` / `get_asset_precision`

Get the precision for a specific asset.

```typescript TypeScript theme={null}
const precision = handler.getAssetPrecision('btc-asset-id');  // 8
```

```python Python theme={null}
precision = handler.get_asset_precision("btc-asset-id")  # 8
```

#### `formatDisplayAmount` / `format_display_amount`

Format a display amount with the correct number of decimal places.

```typescript TypeScript theme={null}
const formatted = handler.formatDisplayAmount(0.5, 'btc-asset-id');  // "0.50000000"
```

```python Python theme={null}
formatted = handler.format_display_amount(0.5, "btc-asset-id")  # "0.50000000"
```

#### `validateOrderSize` / `validate_order_size`

Validate an order amount against min/max limits.

```typescript TypeScript theme={null}
const result = handler.validateOrderSize(0.001, btcAsset);
// Returns: { valid: boolean, error?: string, rawAmount, minRawAmount, maxRawAmount }
```

```python Python theme={null}
result = handler.validate_order_size(0.001, btc_asset)
# Returns: ValidationResult { valid, error, raw_amount, min_raw_amount, max_raw_amount }
```

#### `getOrderSizeLimits` / `get_order_size_limits`

Get the min/max order size for an asset.

```typescript TypeScript theme={null}
const limits = handler.getOrderSizeLimits(btcAsset);
// Returns: { minDisplayAmount, maxDisplayAmount, minRawAmount, maxRawAmount, precision }
```

```python Python theme={null}
limits = handler.get_order_size_limits(btc_asset)
# Returns: OrderSizeLimits { min_display_amount, max_display_amount, min_raw_amount, max_raw_amount, precision }
```

## AssetPairMapper (TypeScript)

The `AssetPairMapper` helps look up assets and trading pairs from the `listPairs` response. This utility is available in the TypeScript SDK.

### Creating a Mapper

```typescript theme={null}
import { createAssetPairMapper } from 'kaleido-sdk';

const pairsResponse = await client.maker.listPairs();
const mapper = createAssetPairMapper(pairsResponse);
```

### Methods

#### `findByTicker`

Find an asset by its ticker symbol.

```typescript theme={null}
const btc = mapper.findByTicker('BTC');
// Returns: MappedAsset | undefined
```

#### `findById`

Find an asset by its asset ID.

```typescript theme={null}
const asset = mapper.findById('btc-asset-id');
// Returns: MappedAsset | undefined
```

#### `getAllAssets`

Get all assets.

```typescript theme={null}
const allAssets = mapper.getAllAssets();
// Returns: MappedAsset[]
```

#### `canTrade` / `canTradeByTicker`

Check if two assets can be traded.

```typescript theme={null}
const canTrade = mapper.canTrade('btc-asset-id', 'usdt-asset-id');  // boolean
const canTradeByTicker = mapper.canTradeByTicker('BTC', 'USDT');     // boolean
```

#### `getTradingPartners`

Get all assets that can be traded with a given asset.

```typescript theme={null}
const partners = mapper.getTradingPartners('btc-asset-id');
// Returns: MappedAsset[]
```

#### `getActivePairs`

Get all active trading pairs.

```typescript theme={null}
const activePairs = mapper.getActivePairs();
// Returns: TradingPairResponseModel[]
```

#### `findPairByTickers`

Find a specific pair by base and quote tickers.

```typescript theme={null}
const pair = mapper.findPairByTickers('BTC', 'USDT');
// Returns: TradingPairResponseModel | undefined
```

## SDK Info

### `getVersion` / `get_version`

Get the SDK version string.

```typescript TypeScript theme={null}
import { getVersion } from 'kaleido-sdk';
console.log(getVersion());  // "0.1.0" -- returns a hardcoded value, not the package version
```

```python Python theme={null}
from kaleido_sdk import get_version
print(get_version())  # "0.1.23"
```

> [!NOTE]
>
> The TypeScript `getVersion()` currently returns a hardcoded `"0.1.0"` rather than the installed package version. To read the real version, check `package.json` for the `kaleido-sdk` dependency.

### `getSdkName` / `get_sdk_name`

Get the SDK package name.

```typescript TypeScript theme={null}
import { getSdkName } from 'kaleido-sdk';
console.log(getSdkName());  // "kaleido-sdk"
```

```python Python theme={null}
from kaleido_sdk import get_sdk_name
print(get_sdk_name())  # "kaleido-sdk"
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.