Skip to content

Commit

Permalink
Added pagination, JavaDoc and Sources
Browse files Browse the repository at this point in the history
  • Loading branch information
dubasdey committed Sep 25, 2018
1 parent c95dea3 commit abb7859
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 28 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ Dependencies are not included with jar. The client requires the following depend
* httpclient-4.5.6.jar
* httpcore-4.4.10.jar


## 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

Client(String publicKey, String secretKey, String passphrase, String baseUrl)

* _publicKey_ : The API Public Key
* _secretKey_: The API Secret key
* _passphrase_: Your API passphrase
* _baseUrl_ : The URL to point the API (real URL or Sandbox)
* Sandbox API points to: https://api-public.sandbox.pro.coinbase.com
* Real API points to: https://api-public.pro.coinbase.com


4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<breakiterator>true</breakiterator>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -83,6 +86,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand Down
132 changes: 109 additions & 23 deletions src/main/java/org/erc/coinbase/pro/rest/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.erc.coinbase.pro.rest;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -94,60 +93,147 @@ private Map<String,Object> initParameters(PaginationFilter filter){
}

/**
* Accounts.
*
* <p>
* <b>Get a list of trading accounts</b><br>
* Your trading accounts are separate from your Coinbase accounts.
* See the Deposits section for documentation on how to deposit funds to begin trading.
* </p>
* <p>
* <b>HTTP Request</b><br>
* <code>GET /accounts</code>
* </p>
* <p>
* <b>API Key Permissions</b><br>
* This endpoint requires either the “view” or “trade” permission.
* </p>
* <p>
* <b>Account Fields</b><br>
* <br>
* Field Description<br>
* id Account ID<br>
* currency the currency of the account<br>
* balance total funds in the account<br>
* holds funds on hold (not available for use)<br>
* available funds available to withdraw or trade<br>
* </p>
* <p>
* <b>Funds on Hold</b><br>
* When you place an order, the funds for the order are placed on hold.
* They cannot be used for other orders or withdrawn. Funds will remain on hold until the order is
* filled or canceled.
*</p>
* @param filter the filter
* @return the list
* @throws CoinbaseException the coinbase exception
*/
public List<Account> getAccounts(AccountFilter filter) throws CoinbaseException {
List<Account> result = new ArrayList<>();
if (filter!=null && filter.getId() !=null ) {
Account acc = http.get(String.format("/account/%s",filter.getId()), new TypeReference<Account>() {},null, true);
result.add(acc);
} else {
Map<String,Object> params = initParameters(filter);
result = http.get("/accounts", new TypeReference<List<Account>>() {},params, true);
}
return result;
Map<String,Object> params = initParameters(filter);
return http.get("/accounts", new TypeReference<List<Account>>() {},params, true);
}

/**
* Accounts.
* Get an Account
*
* @param id the id
* @return account
* @throws CoinbaseException the coinbase exception
*/
public Account getAccount(String id) throws CoinbaseException {
if( id == null || id.isEmpty()) {
throw new RequiredParameterException("accountId");
}
return http.get(String.format("/account/%s",id), new TypeReference<Account>() {},null, true);
}


/**
* Gets the account history.
* <p>
* <b>List account activity.</b><br>
*
* @param id the id
* Account activity either increases or decreases your account balance.
* Items are paginated and sorted latest first. See the Pagination section for retrieving
* additional entries after the first page.
* </p>
* <p>
* <b>HTTP request</b><br>
* <code>GET /accounts/[account-id]/ledger</code>
* </p>
* <p>
* API Key Permissions
* This endpoint requires either the “view” or “trade” permission.
* </p>
* <p>
* <b>Entry Types</b><br>
*
* Entry type indicates the reason for the account change.<br>
*
* Type Description<br>
* transfer Funds moved to/from Coinbase to Coinbase Pro<br>
* match Funds moved as a result of a trade<br>
* fee Fee as a result of a trade<br>
* rebate Fee rebate as per our fee schedule<br>
* </p>
* <p>
* <b>Details</b><br>
* If an entry is the result of a trade (match, fee), the details field will contain additional
* information about the trade.
*
* This request is paginated
* </p>
* @param filter the filter
* @return the account history
* @throws CoinbaseException the coinbase exception
*/
public List<AccountHistory> getAccountHistory(String id) throws CoinbaseException {
return http.get(String.format("/account/%s/ledger",id), new TypeReference<List<AccountHistory>>() {},null, true);
public List<AccountHistory> getAccountHistory(AccountHistoryFilter filter) throws CoinbaseException {
if( filter == null || filter.getAccountId() == null || filter.getAccountId().isEmpty()) {
throw new RequiredParameterException("accountId");
}
Map<String,Object> params = initParameters(filter);
return http.get(String.format("/account/%s/ledger",filter.getAccountId()), new TypeReference<List<AccountHistory>>() {},params, true);
}

/**
* Gets the account holds.
*
* @param id the id
* <p>
* <b>Gets the account holds.</b>
*
* Holds are placed on an account for any active orders or pending withdraw requests. As an order
* is filled, the hold amount is updated. If an order is canceled, any remaining hold is removed.
* For a withdraw, once it is completed, the hold is removed.
*</p>
*<p>
* <b>HTTP Request</b><br>
* <code>GET /accounts/[account_id]/holds</code>
*</p>
*<p>
* <b>API Key Permissions</b><br>
* This endpoint requires either the “view” or “trade” permission.
*</p>
*<p>
* This request is paginated
*</p>
*<p>
* <b>Type</b><br>
* The type of the hold will indicate why the hold exists. The hold type is order for holds
* related to open orders and transfer for holds related to a withdraw.
* <br>
* <b>Ref</b><br>
* The ref field contains the id of the order or transfer which created the hold.
*</p>
* @param filter the filter
* @return the account holds
* @throws CoinbaseException the coinbase exception
*/
public List<Hold> getAccountHolds(String id) throws CoinbaseException {
return http.get(String.format("/account/%s/holds",id), new TypeReference<List<Hold>>() {},null, true);
public List<Hold> getAccountHolds(AccountHoldFilter filter) throws CoinbaseException {
if( filter == null || filter.getAccountId() == null || filter.getAccountId().isEmpty()) {
throw new RequiredParameterException("accountId");
}
Map<String,Object> params = initParameters(filter);
return http.get(String.format("/account/%s/holds",filter.getAccountId()), new TypeReference<List<Hold>>() {},params, true);
}

/**
* You can place two types of orders: limit and market.
*
* Orders can only be placed if your account has sufficient funds.
* Once an order is placed, your account funds will be put on hold for the duration of the order.
* How much and which funds are put on hold depends on the order type and parameters specified.
Expand Down Expand Up @@ -330,7 +416,7 @@ public List<Hold> getAccountHolds(String id) throws CoinbaseException {
* @throws CoinbaseException the coinbase exception
*/
public Order placeOrder(OrderRequest request) throws CoinbaseException {
return http.post("", new TypeReference<Order>() {}, request);
return http.post("/orders", new TypeReference<Order>() {}, request);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
*/
@Data
@EqualsAndHashCode(callSuper=true)
public class AccountFilter extends PaginationFilter{
public class AccountFilter extends PaginationFilter {

/** The id. */
private String id;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
This file is part of coinbase-pro-client.
coinbase-pro-client is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with coinbase-pro-client. If not, see <https://www.gnu.org/licenses/>.
*/
package org.erc.coinbase.pro.rest.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* The Class AccountHistoryFilter.
*/
@Data
@EqualsAndHashCode(callSuper=true)
public class AccountHistoryFilter extends PaginationFilter {

/** The account id. */
private String accountId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
This file is part of coinbase-pro-client.
coinbase-pro-client is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Foobar is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with coinbase-pro-client. If not, see <https://www.gnu.org/licenses/>.
*/
package org.erc.coinbase.pro.rest.model;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
* Instantiates a new account hold filter.
*/
@Data
@EqualsAndHashCode(callSuper=true)
public class AccountHoldFilter extends PaginationFilter {

/** The account id. */
private String accountId;
}

0 comments on commit abb7859

Please sign in to comment.