Create Portfolio Allocations
curl --request POST \
--url https://api.prime.coinbase.com/v1/allocations \
--header 'Content-Type: application/json' \
--data '
{
"allocation_id": "<string>",
"source_portfolio_id": "<string>",
"product_id": "<string>",
"order_ids": [
"<string>"
],
"allocation_legs": [
{
"allocation_leg_id": "<string>",
"destination_portfolio_id": "<string>",
"amount": "<string>"
}
],
"remainder_destination_portfolio": "<string>"
}
'import requests
url = "https://api.prime.coinbase.com/v1/allocations"
payload = {
"allocation_id": "<string>",
"source_portfolio_id": "<string>",
"product_id": "<string>",
"order_ids": ["<string>"],
"allocation_legs": [
{
"allocation_leg_id": "<string>",
"destination_portfolio_id": "<string>",
"amount": "<string>"
}
],
"remainder_destination_portfolio": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
allocation_id: '<string>',
source_portfolio_id: '<string>',
product_id: '<string>',
order_ids: ['<string>'],
allocation_legs: [
{
allocation_leg_id: '<string>',
destination_portfolio_id: '<string>',
amount: '<string>'
}
],
remainder_destination_portfolio: '<string>'
})
};
fetch('https://api.prime.coinbase.com/v1/allocations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.prime.coinbase.com/v1/allocations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'allocation_id' => '<string>',
'source_portfolio_id' => '<string>',
'product_id' => '<string>',
'order_ids' => [
'<string>'
],
'allocation_legs' => [
[
'allocation_leg_id' => '<string>',
'destination_portfolio_id' => '<string>',
'amount' => '<string>'
]
],
'remainder_destination_portfolio' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.prime.coinbase.com/v1/allocations"
payload := strings.NewReader("{\n \"allocation_id\": \"<string>\",\n \"source_portfolio_id\": \"<string>\",\n \"product_id\": \"<string>\",\n \"order_ids\": [\n \"<string>\"\n ],\n \"allocation_legs\": [\n {\n \"allocation_leg_id\": \"<string>\",\n \"destination_portfolio_id\": \"<string>\",\n \"amount\": \"<string>\"\n }\n ],\n \"remainder_destination_portfolio\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.prime.coinbase.com/v1/allocations")
.header("Content-Type", "application/json")
.body("{\n \"allocation_id\": \"<string>\",\n \"source_portfolio_id\": \"<string>\",\n \"product_id\": \"<string>\",\n \"order_ids\": [\n \"<string>\"\n ],\n \"allocation_legs\": [\n {\n \"allocation_leg_id\": \"<string>\",\n \"destination_portfolio_id\": \"<string>\",\n \"amount\": \"<string>\"\n }\n ],\n \"remainder_destination_portfolio\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.prime.coinbase.com/v1/allocations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"allocation_id\": \"<string>\",\n \"source_portfolio_id\": \"<string>\",\n \"product_id\": \"<string>\",\n \"order_ids\": [\n \"<string>\"\n ],\n \"allocation_legs\": [\n {\n \"allocation_leg_id\": \"<string>\",\n \"destination_portfolio_id\": \"<string>\",\n \"amount\": \"<string>\"\n }\n ],\n \"remainder_destination_portfolio\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"body": {
"success": true,
"allocation_id": "<string>",
"failure_reason": "<string>"
}
}Allocations
Create Portfolio Allocations
Create allocation for a given portfolio.
POST
/
v1
/
allocations
Create Portfolio Allocations
curl --request POST \
--url https://api.prime.coinbase.com/v1/allocations \
--header 'Content-Type: application/json' \
--data '
{
"allocation_id": "<string>",
"source_portfolio_id": "<string>",
"product_id": "<string>",
"order_ids": [
"<string>"
],
"allocation_legs": [
{
"allocation_leg_id": "<string>",
"destination_portfolio_id": "<string>",
"amount": "<string>"
}
],
"remainder_destination_portfolio": "<string>"
}
'import requests
url = "https://api.prime.coinbase.com/v1/allocations"
payload = {
"allocation_id": "<string>",
"source_portfolio_id": "<string>",
"product_id": "<string>",
"order_ids": ["<string>"],
"allocation_legs": [
{
"allocation_leg_id": "<string>",
"destination_portfolio_id": "<string>",
"amount": "<string>"
}
],
"remainder_destination_portfolio": "<string>"
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
allocation_id: '<string>',
source_portfolio_id: '<string>',
product_id: '<string>',
order_ids: ['<string>'],
allocation_legs: [
{
allocation_leg_id: '<string>',
destination_portfolio_id: '<string>',
amount: '<string>'
}
],
remainder_destination_portfolio: '<string>'
})
};
fetch('https://api.prime.coinbase.com/v1/allocations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.prime.coinbase.com/v1/allocations",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'allocation_id' => '<string>',
'source_portfolio_id' => '<string>',
'product_id' => '<string>',
'order_ids' => [
'<string>'
],
'allocation_legs' => [
[
'allocation_leg_id' => '<string>',
'destination_portfolio_id' => '<string>',
'amount' => '<string>'
]
],
'remainder_destination_portfolio' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.prime.coinbase.com/v1/allocations"
payload := strings.NewReader("{\n \"allocation_id\": \"<string>\",\n \"source_portfolio_id\": \"<string>\",\n \"product_id\": \"<string>\",\n \"order_ids\": [\n \"<string>\"\n ],\n \"allocation_legs\": [\n {\n \"allocation_leg_id\": \"<string>\",\n \"destination_portfolio_id\": \"<string>\",\n \"amount\": \"<string>\"\n }\n ],\n \"remainder_destination_portfolio\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.prime.coinbase.com/v1/allocations")
.header("Content-Type", "application/json")
.body("{\n \"allocation_id\": \"<string>\",\n \"source_portfolio_id\": \"<string>\",\n \"product_id\": \"<string>\",\n \"order_ids\": [\n \"<string>\"\n ],\n \"allocation_legs\": [\n {\n \"allocation_leg_id\": \"<string>\",\n \"destination_portfolio_id\": \"<string>\",\n \"amount\": \"<string>\"\n }\n ],\n \"remainder_destination_portfolio\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.prime.coinbase.com/v1/allocations")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"allocation_id\": \"<string>\",\n \"source_portfolio_id\": \"<string>\",\n \"product_id\": \"<string>\",\n \"order_ids\": [\n \"<string>\"\n ],\n \"allocation_legs\": [\n {\n \"allocation_leg_id\": \"<string>\",\n \"destination_portfolio_id\": \"<string>\",\n \"amount\": \"<string>\"\n }\n ],\n \"remainder_destination_portfolio\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"body": {
"success": true,
"allocation_id": "<string>",
"failure_reason": "<string>"
}
}Use the Prime SDK or CLI to test this endpoint by following the quickstart guide and running with the following examples
For more information, please visit the Prime Java SDK.For more information, please visit the Prime .NET SDK.For more information, please visit the Prime Go SDK.For more information, please visit the Prime Python SDK.For more information, please visit the Prime CLI.For more information, please visit the Prime TS SDK.
- Java
- .NET
- Go
- Python
- CLI
- TS/JS
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);
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);
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)
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)
primectl create-allocation --help
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);
})
Body
application/json
The ID of the allocation
The source portfolio id for the allocation
The product for the allocation
The list of order ids in the allocation
The list of allocation_legs for the allocation
Show child attributes
Show child attributes
Available options:
BASE, QUOTE, PERCENT The portfolio where to allocate the remainder of the size
Response
200 - application/json
A successful response.
Show child attributes
Show child attributes
Was this page helpful?
⌘I