Java based wrapper for the Coinbase Pro API
Coinbase Pro primary data sources and servers run in the Amazon US East data center. To minimize latency for API access, we recommend making requests from servers located near the US East data center. Some of the methods do not yet have tests and so may not work as expected until someone tries them and fixes them at a later date. Please raise an issue in github if you want something in particular as a priority. This codebase is maintained independently of Coinbase. We are not in any way affiliated with coinbase or coinbase pro.
Check the issues on the repo for open items to work on. Please join the gitter channel if you have any questions. Support always welcome. Note the channel uses the legacy name of 'gdax-java' rather than 'coinbase-pro-java'
Please see CONTRIBUTE.md if your interested in getting involved.
If you commit your secure keys, passphrase or secrete, disable/delete them from Coinbase Pro immediately.
./gradlew test
, and ./gradlew integrationTest
.
Test
and run locallyIntegrationTest
and should run against the sandbox api To make use of this library you only need a reference to the Service that you want.
AccountService
See CONTRIBUTING.md for an example of how to do this MarketDataService
, and so on.At present the Services and Data objects returned should match the interface specified in the Coinbase Pro api here: https://docs.pro.coinbase.com/#api
Each Service
class requires the CoinbaseExchange
object (see CONTRIBUTING.md for examples of how to create this) so that methods calling the REST endpoints can be made, using a RestTemplate
that has
the correct headers and signatures is used.
This library is as set up as follows: (Note: this section is likely to change over time)
AccountService.getAccounts()
- returns a List AccountsAccountService.getAccountHistory(String accountId)
- returns the history for a given account as a ListAccountService.getHolds(String accountId)
- returns a List of all held funds for a given account.DepositService.depositViaPaymentMethod(BigDecimal amount, String currency, String paymentMethodId)
- makes a deposit from a stored payment method into your GDAX accountDepositService.coinbaseDeposit(BigDecimal amount, String currency, String coinbaseAccountId)
- makes a deposit from a coinbase account into your GDAX accountMarketDataService.getMarketDataOrderBook(String productId, String level)
- a call to ProductService.getProducts() will return the order book for a given product. You can then use the WebsocketFeed api to keep your orderbook up to date. This is implemented in this codebase. Level can be 1 (top bid/ask only), 2 (top 50 bids/asks only), 3 (entire order book - takes a while to pull the data.)OrderService.getOpenOrders(String accountId)
- returns a List of Orders for any outstanding ordersOrderService.cancelOrder(String orderId)
- cancels a given orderOrderService.createOrder(NewOrderSingle aSingleOrder)
- construct an order and send it to this method to place an order for a given product on the exchange.PaymentService.getCoinbaseAccounts()
- gets the coinbase accounts for the logged in userPaymentService.getPaymentTypes()
- gets the payment types available for the logged in userProductService.getProducts()
- returns a List of Products available from the exchange - BTC-USD, BTC-EUR, BTC-GBP, etc.ReportService.createReport(String product, String startDate, String endDate)
- not certain about this one as its untested but presumably it generates a report of a given product's trade history for the dates supplied - dates are assumed to be ISO 8601 compliantTransferService.transfer(String type, BigDecimal amount, String coinbaseAccountId)
- initiates a transfer to your (standard) Coinbase account. UserAccountService.getTrailingVolume()
- Returns the 30 day trailing volume information from all accountsWithdrawalsService
- methods that enable Withdrawals from a Coinbase-Pro account to a Coinbase Account/Payment methodThe WebsocketFeed is implemented and works. However, there are techniques to using it successfully for production use - e.g. monitoring for 'heartbeats'.
To use the WSF check out the API documentation and look at usages of websocketFeed.subscribe(String)
as an example that already works.
api
code from the spring boot desktop client application so the api can be used and eventually published as a library.model
code so that it can become shared/common for multiple projects and make building out a FIX client potentially easierwebsocketfeed
code from the api implementationsecurity
module so websocketfeed and api can share the Signature
codegui
desktop app - this needs rebuilding properly (with tests)build.gradle
as its easier to manage them in a single locationCoinbase-Pro-java
in the settings.gradle
fileJavaTimeModule
for the ObjectMapper
application.yml
for your live environment and application-test.yml
for your sandbox environment.application.yml
by setting enabled to true
From the GDAX API documentation the Websocket implementation follows the following implementation: Send a subscribe message for the product(s) of interest and the full channel. Queue any messages received over the websocket stream. Make a REST request for the order book snapshot from the REST feed. Playback queued messages, discarding sequence numbers before or equal to the snapshot sequence number. Apply playback messages to the snapshot as needed (see below). After playback is complete, apply real-time stream messages in sequential order, queuing any that arrive out of order for later processing. Discard messages once they've been processed.