Bitso's official Java wrapper to interact with the Bitso REST API v2.
Add the following dependency to your project's Maven pom.xml:
<dependency>
<groupId>com.bitso</groupId>
<artifactId>bitso-java</artifactId>
<version>0.0.35</version>
</dependency>The library will automatically be pulled from Maven Central.
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 Client ID, 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"), System.getenv("BITSO_CLIENT_ID"));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());BigDecimal btcAvailable = bitso.getBalance().btcAvailable;BigDecimal mxnAvailable = bitso.getBalance().mxnAvailable;BigDecimal fee = bitso.getBalance().fee;OrderBook orderBook = bitso.getOrderBook();
for (BookOrder bid : orderBook.bids) {
System.out.println(bid);
}String depositAddress = bitso.getDepositAddress();BigDecimal mxnBought = bitso.placeSellMarketOrder(new BigDecimal("1.23456789"));BigDecimal btcBought = bitso.placeBuyMarketOrder(new BigDecimal("100.00"));BookOrder order = bitso.placeBuyLimitOrder(new BigDecimal("2000.00"), new BigDecimal("3"));BookOrder order = bitso.placeSellLimitOrder(new BigDecimal("10000.00"), new BigDecimal("1"));BookOrder order = bitso.placeSellLimitOrder(new BigDecimal("10000.00"), new BigDecimal("1"));
bitso.cancelOrder(order.id);BitsoOrders openOrders = bitso.getOpenOrders();String btcAddress = "17s4n5L9Lz7qciToYjjs5CJGBGRR7MxjUu";
BigDecimal btcAmount = new BigDecimal("1.00");
boolean success = bitso.withdrawBTC(btcAddress, btcAmount);
if (success) {
System.out.println("Successfully sent " + btcAmount + "BTC to " + btcAddress);
} else {
System.out.println("An error ocurred");
}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.