68 lines
2.3 KiB
Plaintext
68 lines
2.3 KiB
Plaintext
# Transfers
|
|
|
|
Transfers let you move balances and positions between subaccounts owned by the same authority.
|
|
|
|
## Why Use Subaccount Transfers?
|
|
|
|
Subaccounts let you isolate risk and organize trading strategies. Common use cases for transfers include:
|
|
|
|
- **Strategy isolation**: Separate market making from directional trading to prevent one strategy's losses from affecting another's collateral
|
|
- **Risk management**: Move profits from an active trading account to a safer holding account
|
|
- **Rebalancing**: Redistribute collateral when one subaccount needs more margin
|
|
- **Bot separation**: Isolate automated trading bots on separate subaccounts while keeping manual trades separate
|
|
- **Experimentation**: Test new strategies on a subaccount with limited capital, then transfer funds if successful
|
|
|
|
All subaccounts under the same wallet share cross-margin, but transfers let you explicitly move balances and positions to reorganize your capital.
|
|
|
|
## SDK Usage
|
|
|
|
### Transfer a Spot Deposit Between Subaccounts
|
|
|
|
<SDKDoc>
|
|
<TypeScript name="transferDeposit" type="method" owner="DriftClient">
|
|
```js
|
|
const marketIndex = 0; // e.g. USDC
|
|
const amount = driftClient.convertToSpotPrecision(marketIndex, 100);
|
|
|
|
// transferDeposit(amount, marketIndex, fromSubAccountId, toSubAccountId)
|
|
await driftClient.transferDeposit(amount, marketIndex, 0, 1);
|
|
```
|
|
</TypeScript>
|
|
</SDKDoc>
|
|
|
|
### Transfer a Perp Position Between Subaccounts
|
|
|
|
<SDKDoc>
|
|
<TypeScript name="transferPerpPosition" type="method" owner="DriftClient">
|
|
```js
|
|
import { BASE_PRECISION, BN } from "@drift-labs/sdk";
|
|
|
|
// transferPerpPosition(fromSubAccountId, toSubAccountId, marketIndex, amount)
|
|
const amount = new BN(1).mul(BASE_PRECISION); // 1 base unit
|
|
await driftClient.transferPerpPosition(0, 1, 0, amount);
|
|
```
|
|
</TypeScript>
|
|
</SDKDoc>
|
|
|
|
### Transfer Between Insurance Fund Pools
|
|
|
|
<SDKDoc>
|
|
<TypeScript name="transferPools" type="method" owner="DriftClient">
|
|
```js
|
|
// Transfer between insurance fund pools (admin only)
|
|
await driftClient.transferPools();
|
|
```
|
|
</TypeScript>
|
|
</SDKDoc>
|
|
|
|
### Transfer Isolated Perp Position Deposit
|
|
|
|
<SDKDoc>
|
|
<TypeScript name="transferIsolatedPerpPositionDeposit" type="method" owner="DriftClient">
|
|
```js
|
|
// Move deposits associated with an isolated perp position between subaccounts
|
|
await driftClient.transferIsolatedPerpPositionDeposit(0, 1, 0);
|
|
```
|
|
</TypeScript>
|
|
</SDKDoc>
|