[Bitso's](htt ps://bitso.com) official Java wrapper to interact with the Bitso REST API v3.
Add the following dependency to your project's Maven pom.xml:
<dependency>
<groupId>com.bitso</groupId>
<artifactId>bitso-java</artifactId>
<version>3.0.2</version>
</dependency>The library will automatically be pulled from Maven Central.
For the old Bitso REST API v2, please use:
<dependency>
<groupId>com.bitso</groupId>
<artifactId>bitso-java</artifactId>
<version>2.0.0</version>
</dependency>This library is only supported by OpenJDK 8
Start by enabling an API Key on your account
Next, build an instance of the client by passing your API Key, and Secret to a Bitso object.
import com.bitso.Bitso;
Bitso bitso = new Bitso(System.getenv("BITSO_API_KEY"), System.getenv("BITSO_API_SECRET"));Notice here that we did not hard code the API keys into our codebase, but set them in environment variables instead. This is just one example, but keeping your credentials separate from your code base is a good security practice.
System.out.println(bitso.getBalance());ArrayList<BookInfo> books = bitso.availableBooks();
for (BookInfo bookInfo : books) {
System.out.println(bookInfo);
}BitsoTicker ticker = bitso.getTicker(BitsoBook.BTC_MXN);
System.out.println(ticker);BitsoOrderBook orderBook = bitso.getOrderBook(BitsoBook.BTC_MXN);
PublicOrder[] asks = orderBook.asks;
PublicOrder[] bids = orderBook.bids;BitsoOrder[] orders = bitso.getOpenOrders();
for(BitsoOrder order : orders){
System.out.println(order);
}BitsoAccountStatus status = bitso.getUserAccountStatus();
System.out.println(status);BitsoBalance balance = bitso.getUserAccountBalance();
System.out.println(balance);BitsoFee fees = bitso.getUserFees();
System.out.println(fees);BitsoOperation[] ledger = bitso.getUserLedger(null);
for (BitsoOperation bitsoOperation : fullLedger) {
System.out.println(bitsoOperation);
}// Ledger operations
String[] operations = { "trades", "fees", "fundings", "withdrawals" };
for (String operationType : operations) {
BitsoOperation[] specificLedger = bitso.getUserLedger(operationType);
for (BitsoOperation bitsoOperation : specificLedger) {
System.out.println(bitsoOperation);
}
}BitsoWithdrawal[] withdrawals = bitso.getUserWithdrawals();
for (BitsoWithdrawal bitsoWithdrawal : withdrawals) {
System.out.println(bitsoWithdrawal);
}String address = "31yTCKDHTqNXF5eZcsddJDe76BzBh8pVLb";
BitsoWithdrawal btcWithdrawal = bitso.bitcoinWithdrawal(new BigDecimal("1.00"), address);String address = "0xc83adea9e8fea3797139942a5939b961f67abfb8");
BitsoWithdrawal ethWithdrawal = bitso.etherWithdrawal(new BigDecimal("1.00"), address);BitsoWithdrawal speiWithdrawal = bitso.speiWithdrawal(new BigDecimal("50.00"),
"Name", "Surname", "044180801959660729", "Reference", "5706");// Get available banks
Map<String, String> bitsoBanks = bitso.getBanks();
String bankCode = bitsoBanks.get("Banregio");
// Debit card withdrawal
BitsoWithdrawal debitCardWithdrawal = bitso.debitCardWithdrawal(new BigDecimal("50.00"),
"name test", "surname test", "5579214571039769", bankCode);BitsoFunding[] fundings = bitso.getUserFundings();
for (BitsoFunding bitsoFunding : fundings) {
System.out.println(bitsoFunding);
}BitsoTrade[] trades = bitso.getUserTrades();
for (BitsoTrade bitsoTrade : trades) {
System.out.println(bitsoTrade);
}// Get detail of an specific order
String[] values = { "kRrcjsp5n9og98qa", "V4RVg7OJ1jl5O5Om", "4fVvpQrR59M26ojl", "Rhvak2cOOX552s69", "n8JvMOl4iO8s22r2" };
BitsoOrder[] specificOrder = bitso.lookupOrders(values[0]);
// Get details of multiple orders
BitsoOrder[] multipleOrders = bitso.lookupOrders(values);String[] cancelParticularOrder = bitso.cancelOrder("pj251R8m6im5lO82");String orderId = bitso.placeOrder(BitsoBook.BTC_MXN, BitsoOrder.SIDE.BUY,
BitsoOrder.TYPE.LIMIT, new BigDecimal("15.4"), null,
new BigDecimal("20854.4"));This artifact relies on the JDK BigDecimal class for arithmetic to maintain decimal precision for all values returned.
When working with currency values in your application, it's important to remember that floating point arithmetic is prone to rounding errors. We recommend you always use BigDecimal.
Tests for this java can run against the actual server or using mocked responses.
Server responses are mocked using the mockito framework.
To run mocked tests, use the following command:
mvn -Dtest=**/BitsoMockTest.java testTo run many of these tests against the server, you will need to identify using an API Keey/Secret. Refer to the "HMAC Authentication section" for more information.
To run tests against the server, use the following command:
mvn -Dtest=**/BitsoServerTest.java testKeep in mind that a couple of environment variables are required to run the tests against the server:
- BITSO_DEV_PUBLIC_KEY
- BITSO_DEV_PRIVATE