HMAC Authentication (for accessing your own account)
Start by [enabling an API Key on your account](https://bitso.com/api_setup)
Next, build an instance of the client by passing your API Key, and Secret to a Bitso object.
```java
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.
Print all your balances
```java
BitsoBalance bitsoBalance = bitso.getAccountBalance();
HashMap balances = bitsoBalance.getBalances();
System.out.println(balances.get("mxn"));
System.out.println(balances.get("eth"));
System.out.println(balances.get("btc"));
System.out.println(balances.get("xrp"));
System.out.println(balances.get("bch"));
```
Print Available books
```java
BookInfo[] availableBooks = bitso.getAvailableBooks();
for (BookInfo bookInfo : availableBooks) {
System.out.println(bookInfo);
}
```
Print tickers
```java
BitsoTicker[] tickers = bitso.getTicker();
for (Ticker ticker : tickers) {
System.out.println(ticker);
}
```
Get user account status
```java
BitsoAccountStatus bitsoAccountStatus = bitso.getAccountStatus();
System.out.println(bitsoAccountStatus);
```
Get user fees
```java
BitsoFee bitsoFee = bitso.getFees();
HashMap tradeFees = bitsoFee.getTradeFees();
System.out.println(tradeFees.get("eth_mxn"));
System.out.println(tradeFees.get("btc_mxn"));
System.out.println(tradeFees.get("xrp_mxn"));
System.out.println(tradeFees.get("bch_btc"));
System.out.println(tradeFees.get("xrp_btc"));
System.out.println(tradeFees.get("eth_btc"));
HashMap withdrawalFees = bitsoFee.getWithdrawalFees();
System.out.println("BTC fee: " + withdrawalFees.get("btc"));
System.out.println("ETH fee: " + withdrawalFees.get("eth"));
```
Iterate over all user operations
```java
BitsoOperation[] defaultLedger = bitso.getLedger("");
for (BitsoOperation bitsoOperation : defaultLedger) {
System.out.println(bitsoOperation);
}
```
Iterate over particular user ledger operation
```java
String[] operations = { "trades", "fees", "fundings", "withdrawals" };
for (String operationType : operations) {
BitsoOperation[] specificLedger = bitso.getLedger(operationType);
for (BitsoOperation bitsoOperation : specificLedger) {
System.out.println(bitsoOperation);
}
}
```
Withdraw 1.00 BTC to the following address: 31yTCKDHTqNXF5eZcsddJDe76BzBh8pVLb
```java
String address = "31yTCKDHTqNXF5eZcsddJDe76BzBh8pVLb";
BigDecimal amount = new BigDecimal("1.00");
boolean saveAccount = false;
BitsoWithdrawal btcWithdrawal = bitso.bitcoinWithdrawal(amount, address, saveAccount);
// Save/update an account with an alias
saveAccount = true;
BitsoWithdrawal btcWithdrawalAlias = bitso.bitcoinWithdrawal(amount, address, saveAccount, "new alias");
```
Withdraw 1.00 ETH to the following address: 0xc83adea9e8fea3797139942a5939b961f67abfb8
```java
String address = "0xc83adea9e8fea3797139942a5939b961f67abfb8";
BigDecimal amount = new BigDecimal("1.00");
boolean saveAccount = false;
BitsoWithdrawal ethWithdrawal = bitso.etherWithdrawal(amount, address, saveAccount);
// Save/update an account with an alias
saveAccount = true;
BitsoWithdrawal ethWithdrawalAlias = bitso.etherWithdrawal(amount, address, saveAccount, "new Alias");
```
Place and cancel orders
```java
String buyOrderId = bitso.placeOrder("btc_mxn", BitsoOrder.SIDE.BUY, BitsoOrder.TYPE.LIMIT,
new BigDecimal("0.1"), null, new BigDecimal("90000"));
String sellOrderId = bitso.placeOrder("btc_mxn", BitsoOrder.SIDE.SELL, BitsoOrder.TYPE.LIMIT,
new BigDecimal("0.00016"), null, new BigDecimal("150000"));
String canceledOrders[] = bitso.cancelOrder(buyOrderId, sellOrderId);
```