use of org.knowm.xchange.gemini.v1.dto.account.GeminiBalancesResponse in project XChange by knowm.
the class GeminiAccountServiceRaw method getGeminiAccountInfo.
public GeminiBalancesResponse[] getGeminiAccountInfo() throws IOException {
try {
GeminiBalancesRequest request = new GeminiBalancesRequest(String.valueOf(exchange.getNonceFactory().createValue()));
GeminiBalancesResponse[] balances = gemini.balances(apiKey, payloadCreator, signatureCreator, request);
return balances;
} catch (GeminiException e) {
throw handleException(e);
}
}
use of org.knowm.xchange.gemini.v1.dto.account.GeminiBalancesResponse in project XChange by knowm.
the class GeminiAdapters method adaptWallet.
public static Wallet adaptWallet(GeminiBalancesResponse[] response) {
// {total, available}
Map<String, BigDecimal[]> balancesByCurrency = new HashMap<>();
// each of those may be partially frozen/available
for (GeminiBalancesResponse balance : response) {
String currencyName = balance.getCurrency().toUpperCase();
BigDecimal[] balanceDetail = balancesByCurrency.get(currencyName);
if (balanceDetail == null) {
balanceDetail = new BigDecimal[] { balance.getAmount(), balance.getAvailable() };
} else {
balanceDetail[0] = balanceDetail[0].add(balance.getAmount());
balanceDetail[1] = balanceDetail[1].add(balance.getAvailable());
}
balancesByCurrency.put(currencyName, balanceDetail);
}
List<Balance> balances = new ArrayList<>(balancesByCurrency.size());
for (Entry<String, BigDecimal[]> entry : balancesByCurrency.entrySet()) {
String currencyName = entry.getKey();
BigDecimal[] balanceDetail = entry.getValue();
BigDecimal balanceTotal = balanceDetail[0];
BigDecimal balanceAvailable = balanceDetail[1];
balances.add(new Balance(Currency.getInstance(currencyName), balanceTotal, balanceAvailable));
}
return Wallet.Builder.from(balances).build();
}
use of org.knowm.xchange.gemini.v1.dto.account.GeminiBalancesResponse in project XChange by knowm.
the class GeminiAdaptersTest method shouldAdaptBalances.
@Test
public void shouldAdaptBalances() throws IOException {
// Read in the JSON from the example resources
InputStream is = GeminiWalletJSONTest.class.getResourceAsStream("/org/knowm/xchange/gemini/v1/account/example-account-info-balance.json");
// Use Jackson to parse it
ObjectMapper mapper = new ObjectMapper();
GeminiBalancesResponse[] response = mapper.readValue(is, GeminiBalancesResponse[].class);
Wallet wallet = GeminiAdapters.adaptWallet(response);
assertEquals(2, wallet.getBalances().size());
assertEquals(new BigDecimal("105.5"), wallet.getBalance(Currency.USD).getTotal());
assertEquals(new BigDecimal("55.5"), wallet.getBalance(Currency.USD).getAvailable());
assertEquals(new BigDecimal("50"), wallet.getBalance(Currency.BTC).getTotal());
assertEquals(new BigDecimal("30"), wallet.getBalance(Currency.BTC).getAvailable());
}
Aggregations