Giter VIP home page Giter VIP logo

coinbase-pro-client's Introduction

coinbase-pro-client

Java 7 Coinbase pro client. Using API spec: https://docs.pro.coinbase.com/

Build Status License: LGPL v3

Features

  • Object oriented requests and responses
  • Proxy Support (Using Java configuration or HTTPClient configuration)
  • Custom exceptions
  • Logging API

Dependencies

Maven project

Include the dependency in the maven dependencies. All requirements will be downloaded by maven for you.

		<dependency>
			<groupId>com.github.dubasdey</groupId>
			<artifactId>coinbase-pro-client</artifactId>
			<version>0.0.4</version>
		</dependency>

I recommend to use the last version published in maven central.

Java project

Dependencies are not included with jar. The client requires the following dependencies (or upper compatible version):

  • Commons Logging
    • commons-logging-1.2.jar
  • Commons Codec
    • commons-codec-1.10.jar
  • Jackson
    • jackson-core-2.9.1.jar
    • jackson-annotations-2.9.0-jar
    • jacksing-databind-2.9.1.jar
  • Apache HTTP Client
    • httpclient-4.5.6.jar
    • httpcore-4.4.10.jar

Client

The project provides a REST Client but the clients structure allows the posibility of other future clients (maybe Websocket?)

All clients use the common interface Client and the same model objets

REST API Client

Instance the Client class at org.erc.coinbase.pro.rest.Client to create a new API Client.

Instance the client

The client required connection parameters to build the object using a ClientConfig object

    ClientConfig config = new ClientConfig();
	 config.setBaseUrl( baseUrl );
		config.setPublicKey( publicKey );
		config.setSecretKey( secretKey );
		config.setPassphrase( passphrase );
    

Example

Get and list accounts example

import java.util.List;
import org.erc.coinbase.pro.exceptions.CoinbaseException;
import org.erc.coinbase.pro.model.Account;
import org.erc.coinbase.pro.rest.RESTClient;
import org.erc.coinbase.pro.Client;
import org.erc.coinbase.pro.rest.ClientConfig;
import org.erc.coinbase.pro.rest.ProxyConfig;

public class Start {

	public static void main(String[] args) throws CoinbaseException {
		
		ClientConfig config = new ClientConfig();
		config.setBaseUrl("https://api.pro.coinbase.com");
		config.setPublicKey(< your public key >);
		config.setSecretKey(< your secret >);
		config.setPassphrase(< your passphrase >);
		
		ProxyConfig proxyConfig = new ProxyConfig();
		proxyConfig.setHost("127.0.0.1");
		proxyConfig.setPort(8080);
		proxyConfig.setUser("myuser");
		proxyConfig.setPass("mypassword");
		config.setProxy(proxyConfig);
		
		Client client = new RESTClient(config);
		List<Account> accounts = client.getAccounts(null);
		for (Account account: accounts){
			System.out.println(account.toString());
		}
	}
}
		

Client Usage

Working with exceptions

The API converts some HTTP error codes in different exceptions that a developer can use. All the exceptions contains the original JSON data and have CoinbaseException as parent

  • SignatureException: The signature is not correct when building
  • InvalidRequestException: The request is invalid. HTTP error 400 (See JSON for more information)
  • InvalidAPIKeyException: The request API is not valid when calling. HTTP error 401
  • ForbiddenException: The request is not allowed. HTTP error 403
  • NotFoundException: The endpoint not exists. HTTP error 404
  • TooManyRequestException: Too many request to the server. HTTP error 429
  • ServerException: Any other exception

Donate

Buy me a coffe to help me continue supporting this project. Buy me a coffe

coinbase-pro-client's People

Contributors

dependabot[bot] avatar dubasdey avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.