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

# Create Portfolio Allocations

> Create allocation for a given portfolio.

Use the Prime SDK or CLI to test this endpoint by following the [quickstart](/prime/introduction/quickstart) guide and running with the following examples

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    AllocationsService allocationsService = PrimeServiceFactory.createAllocationsService(client);

    String allocationId = UUID.randomUUID().toString();
    String allocationLegId = UUID.randomUUID().toString();

    AllocationLeg allocationLeg = new AllocationLeg.Builder()
            .allocationLegId(allocationLegId)
            .amount("100")
            .destinationPortfolioId("DESTINATION_PORTFOLIO_ID_HERE")
            .build();

    CreateAllocationRequest request = new CreateAllocationRequest.Builder()
            .sourcePortfolioId("SOURCE_PORTFOLIO_ID_HERE")
            .allocationId(allocationId)
            .allocationLegs(new AllocationLeg[]{allocationLeg})
            .productId("ETH-USD")
            .build();

    CreateAllocationResponse response = allocationsService.createAllocation(request);
    ```

    For more information, please visit the [Prime Java SDK](https://github.com/coinbase-samples/prime-sdk-java).
  </Tab>

  <Tab title=".NET">
    ```csharp wrap theme={null}
    var allocationsService = new AllocationsService(client);

    var allocationId = Guid.NewGuid();
    var allocationLegId = Guid.NewGuid();

    var allocationLeg = new AllocationLeg()
    {
        AllocationLegId = allocationLegId.ToString(),
        Amount = "100",
        DestinationPortfolioId = "ADD_DESTINATION_PORTFOLIO_ID_HERE",
    };

    var request = new CreateAllocationRequest()
    {
        AllocationId = allocationId.ToString(),
        ProductId = "ETH-USD",
        SourcePortfolioId = "ADD_SOURCE_PORTFOLIO_ID_HERE",
        AllocationLegs = [ allocationLeg ],
        SizeType = Prime.Model.SizeType.PERCENT,
    };

    var response = allocationsService.CreateAllocation(request);
    ```

    For more information, please visit the [Prime .NET SDK](https://github.com/coinbase-samples/prime-sdk-dotnet).
  </Tab>

  <Tab title="Go">
    ```go wrap theme={null}
    allocationsService := allocations.NewAllocationsService(client)

    allocationId := uuid.New().String()
    allocationLegId := uuid.New().String()

    allocationLeg := &model.AllocationLeg{
        LegId:                  allocationLegId,
        DestinationPortfolioId: "DESTINATION_PORTFOLIO_ID_GOES_HERE",
        Amount:                 "100.0",
    }

    request := &allocations.CreatePortfolioAllocationsRequest{
        AllocationId:      allocationId,
        SourcePortfolioId: "SOURCE_PORTFOLIO_ID_GOES_HERE",
        ProductId:         "ETH-USD",
        AllocationLegs:    []*model.AllocationLeg{allocationLeg},
        OrderIds:          []string{"ORDER_IDS_TO_BE_ALLOCATED_HERE"},
        SizeType:          "PERCENT",
    }

    response, err := allocationsService.CreatePortfolioAllocations(context.Background(), request)
    ```

    For more information, please visit the [Prime Go SDK](https://github.com/coinbase-samples/prime-sdk-go).
  </Tab>

  <Tab title="Python">
    ```python wrap theme={null}
    prime_client = PrimeClient(credentials)

    allocation_id = uuid.uuid4()
    allocation_leg_id = uuid.uuid4()

    product_id = 'ETH-USD'
    size_type = 'PERCENT'

    allocation_leg = AllocationLeg(
        leg_id=allocation_leg_id,
        destination_portfolio_id='DESTINATION_PORTFOLIO_ID_GOES_HERE',
        amount='100.0',
    )

    request = CreatePortfolioAllocationsRequest(
        allocation_id=allocation_id,
        source_portfolio_id='SOURCE_PORTFOLIO_ID_GOES_HERE',
        product_id=product_id,
        order_ids=['ORDER_ID_GOES_HERE'],
        allocation_legs=[allocation_leg],
        size_type=size_type,
    )

    response = prime_client.create_portfolio_allocations(request)
    ```

    For more information, please visit the [Prime Python SDK](https://github.com/coinbase-samples/prime-sdk-py).
  </Tab>

  <Tab title="CLI">
    ```bash wrap theme={null}
    primectl create-allocation --help
    ```

    For more information, please visit the [Prime CLI](https://github.com/coinbase-samples/prime-cli).
  </Tab>

  <Tab title="TS/JS">
    ```typescript wrap theme={null}
    const allocationService = new AllocationService(client);

    allocationService.createAllocation({
        allocationId: uuidv4(),
        sourcePortfolioId: "SOURCE_PORTFOLIO_ID_GOES_HERE"
        productId: "ETH-USD",
        orderIds: ["ORDER_ID_GOES_HERE"],
        allocationLegs: [{
            legId:                  uuidv4(),
            destinationPortfolioId: "DESTINATION_PORTFOLIO_ID_GOES_HERE",
            amount:                 "100.0",
        }]
        sizeType: AllocationSizeType.Percent
    }).then(async (response) => {
        console.log('Order allocated: ', response);
    })
    ```

    For more information, please visit the [Prime TS SDK](https://github.com/coinbase-samples/prime-sdk-ts).
  </Tab>
</Tabs>


## OpenAPI

````yaml POST /v1/allocations
openapi: 3.0.1
info:
  title: REST API
  description: >-
    The Coinbase Prime REST API provides programmatic access to trading,
    custody, staking, market data, and account management functionality.
  version: '0.1'
servers:
  - url: https://api.prime.coinbase.com/
security: []
tags:
  - name: PrimeRESTAPI
paths:
  /v1/allocations:
    post:
      tags:
        - Allocations
      summary: Create Portfolio Allocations
      description: Create allocation for a given portfolio.
      operationId: PrimeRESTAPI_CreateAllocation
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/public_rest_apiCreateAllocationRequest'
        required: true
      responses:
        '200':
          description: A successful response.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/coinbase.public_rest_api.CreateAllocationResponse
components:
  schemas:
    public_rest_apiCreateAllocationRequest:
      type: object
      properties:
        allocation_id:
          type: string
          description: The ID of the allocation
        source_portfolio_id:
          type: string
          description: The source portfolio id for the allocation
        product_id:
          type: string
          description: The product for the allocation
        order_ids:
          type: array
          description: The list of order ids in the allocation
          items:
            type: string
        allocation_legs:
          type: array
          description: The list of allocation_legs for the allocation
          items:
            $ref: '#/components/schemas/coinbase.public_rest_api.AllocationLeg'
        size_type:
          $ref: '#/components/schemas/coinbase.public_rest_api.AllocationSizeType'
        remainder_destination_portfolio:
          type: string
          description: The portfolio where to allocate the remainder of the size
    coinbase.public_rest_api.CreateAllocationResponse:
      type: object
      properties:
        body:
          $ref: >-
            #/components/schemas/coinbase.public_rest_api.CreateAllocationResponseBody
    coinbase.public_rest_api.AllocationLeg:
      required:
        - allocation_leg_id
        - amount
        - destination_portfolio_id
      type: object
      properties:
        allocation_leg_id:
          type: string
          description: The ID of the portfolio of the allocation leg
        destination_portfolio_id:
          type: string
          description: The ID of the destination portfolio of the allocation leg
        amount:
          type: string
          description: The amount size for the allocation leg
    coinbase.public_rest_api.AllocationSizeType:
      type: string
      enum:
        - BASE
        - QUOTE
        - PERCENT
    coinbase.public_rest_api.CreateAllocationResponseBody:
      required:
        - allocation_id
        - failure_reason
        - success
      type: object
      properties:
        success:
          type: boolean
          description: The success boolean for the post allocation
        allocation_id:
          type: string
          description: The allocation id for the post allocation
        failure_reason:
          type: string
          description: The failure reason for the post allocation

````