coinbase-samples / prime-sdk-java

Sample Java SDK for the Coinbase Prime REST APIs

Home Page:https://docs.cdp.coinbase.com/prime/reference/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coinbase Prime Java SDK

Overview

The Coinbase Prime Java SDK is a sample library that demonstrates the structure of a Coinbase Prime driver for the REST APIs.

License

The Coinbase Prime Java SDK sample library is free and open source and released under the Apache License, Version 2.0.

The application and code are only available for demonstration purposes.

Usage

To use the Coinbase Prime Java SDK, initialize the Credentials class and create a new client. The Credentials struct is JSON enabled. Ensure that Prime API credentials are stored in a secure manner. This client can then be used to instantiate Coinbase Prime Services. An example using the PortfoliosService is shown below:

public class Main {
    public static void main(String[] args) {
        String credsStringBlob = System.getenv("COINBASE_PRIME_CREDENTIALS");
        ObjectMapper mapper = new ObjectMapper();

        try {
            CoinbasePrimeCredentials credentials = new CoinbasePrimeCredentials(credsStringBlob);
            CoinbasePrimeClient client = new CoinbasePrimeClient(credentials);

            String portfolioId = System.getenv("COINBASE_PRIME_PORTFOLIO_ID");

            PortfoliosService portfoliosService = PrimeServiceFactory.createPortfoliosService(client);
            GetPortfolioByIdResponse portfolioResponse = portfoliosService.getPortfolioById(
                    new GetPortfolioByIdRequest.Builder()
                            .portfolioId(portfolioId)
                            .build());

            System.out.println(mapper.writeValueAsString(portfolioResponse));
        } catch (Exception e) {
            e.printStackTrace(e);
        }
    }
}

The JSON format expected for COINBASE_PRIME_CREDENTIALS is:

{
  "accessKey": "",
  "passphrase": "",
  "signingKey": ""
}

For a full example on using the SDK, see the Main class under the com.coinbase.examples package.

Warning: this does place a market order for a very small amount of ADA. Please ensure that you have the necessary funds in your account before running this code.

Binaries

Binaries and dependency information for Maven, Gradle, Ivy and others can be found at the Maven Central Repository

Maven example:

<dependency>
    <groupId>com.coinbase.prime</groupId>
    <artifactId>coinbase-prime-sdk-java</artifactId>
    <version>x.y.z</version>
</dependency>

Build

To build the sample library, ensure that Java Development Kit (JDK) 11+ is installed and then run:

mvn clean install

About

Sample Java SDK for the Coinbase Prime REST APIs

https://docs.cdp.coinbase.com/prime/reference/

License:Apache License 2.0


Languages

Language:Java 100.0%