Client - Allocate Assets

Overview

Allocate assets in your Go Network account to a connected-partner platform. Allocated assets are locked with BitGo and available for trading on the connected partner's platform. Allocations occur synchronously. You can view your allocated balance from the BitGo web application or programmatically, as well as from your account on the connected-partner platform.

Prerequisites

1. Get Allocation Payload

Endpoint: Get Signing Payload for Client Allocations

export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"
export CONNECTION_ID="<YOUR_CONNECTION_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
  https://app.bitgo-test.com/api/network/v1/enterprises/$ENTERPRISE_ID/clients/connections/$CONNECTION_ID/allocations/signing \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "amount": {
      "currency": "string",
      "quantity": "string"
    },
    "clientExternalId": "string",
    "nonce": "string",
    "notes": "string"
  }'

Step Result

{
  "payload": "string"
}

2. Create Allocation Request

Endpoint: Allocate Funds to Partner Connection

export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"
export CONNECTION_ID="<YOUR_CONNECTION_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
  https://app.bitgo-test.com/api/network/v1/enterprises/$ENTERPRISE_ID/clients/connections/$CONNECTION_ID/allocations \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "amount": {
      "currency": "string",
      "quantity": "string"
    },
    "clientExternalId": "string",
    "payload": "string", # The payload string received in the previous step
    "signature": "string",
    "nonce": "string",
    "notes": "string"
  }'
import { BitGoAPI } from '@bitgo/sdk-api';
import { TradingAccount } from '@bitgo/sdk-core/dist/src/bitgo/trading/trading';
import { coins } from '@bitgo/sdk-core';
import * as dotenv from 'dotenv';

// --- Required Constants ---
const accessToken = process.env.ACCESS_TOKEN;
const walletId = process.env.TRADING_WALLET_ID;
const enterpriseId = process.env.ENTERPRISE_ID;
const walletPassphrase = process.env.WALLET_PASSPHRASE;
const connectionId = process.env.CONNECTION_ID;

const bitgo = new BitGoAPI({
  accessToken: accessToken,
  env: 'test',
  customRootURI: 'https://app.bitgo-test.com',
});

const coin = 'ofc';
bitgo.register(coin, coins.Ofc.createInstance);

async function createAllocation() {
  try {
    // 1. Get the wallet and instantiate the trading account
    console.log(`Fetching wallet: ${walletId}...`);
    const wallet = await bitgo.coin(coin).wallets().get({ id: walletId });
    const tradingAccount = new TradingAccount(enterpriseId, wallet, bitgo);
    const network = tradingAccount.toNetwork();

    // 2. Prepare the allocation, which creates the payload and signature
    console.log('Preparing allocation...');
    const allocationParams = await network.prepareAllocation({
      walletPassphrase,
      connectionId,
      amount: {
        currency: 'ofctbtc',
        quantity: '100000',
      },
      notes: 'Initial allocation for Project Phoenix',
    });

    // 3. Create the allocation using the prepared parameters
    console.log('Creating allocation...');
    const allocation = await network.createAllocation(allocationParams);

    console.log('Allocation created successfully:');
    console.dir(allocation, { depth: null });

  } catch (error) {
    console.error('Failed to create allocation:', error);
  }
}

createAllocation();

Step Result

{
  "allocation": {
    "status": "cleared",
    "id": "string",
    "amount": {
      "currency": "string",
      "quantity": "string"
    },
    "connectionId": "string",
    "clientExternalId": "string",
    "partnerExternalId": "string",
    "initiatedBy": "string",
    "notes": "string",
    "createdAt": "2019-08-24",
    "updatedAt": "2019-08-24"
  }
}

Next

  • You can trade your allocated assets on the connected partner's platform.
  • Deallocate Assets

See Also

API Reference: Allocate assets to Partner Connection