use of org.knowm.xchange.exceptions.NotAvailableFromExchangeException in project XChange by knowm.
the class BitbayAccountService method withdrawFunds.
@Override
public String withdrawFunds(WithdrawFundsParams params) throws IOException {
if (params instanceof DefaultWithdrawFundsParams) {
DefaultWithdrawFundsParams defaultParams = (DefaultWithdrawFundsParams) params;
transfer(defaultParams.getCurrency(), defaultParams.getAmount(), defaultParams.getAddress());
return "Success";
} else if (params instanceof BitbayWithdrawFundsSwiftParams) {
BitbayWithdrawFundsSwiftParams bicParams = (BitbayWithdrawFundsSwiftParams) params;
withdraw(bicParams.getCurrency(), bicParams.getAmount(), bicParams.getAccount(), bicParams.isExpress(), bicParams.getBic());
return "Success";
}
throw new NotAvailableFromExchangeException();
}
use of org.knowm.xchange.exceptions.NotAvailableFromExchangeException in project XChange by knowm.
the class Account method fill.
public void fill(UserTrade userTrade, boolean reserved) {
BigDecimal counterAmount = userTrade.getOriginalAmount().multiply(userTrade.getPrice());
switch(userTrade.getType()) {
case ASK:
balance(userTrade.getCurrencyPair().base).updateAndGet(b -> Balance.Builder.from(b).available(reserved ? b.getAvailable() : b.getAvailable().subtract(userTrade.getOriginalAmount())).frozen(reserved ? b.getFrozen().subtract(userTrade.getOriginalAmount()) : b.getFrozen()).total(b.getTotal().subtract(userTrade.getOriginalAmount())).build());
balance(userTrade.getCurrencyPair().counter).updateAndGet(b -> Balance.Builder.from(b).total(b.getTotal().add(counterAmount)).available(b.getAvailable().add(counterAmount)).build());
break;
case BID:
balance(userTrade.getCurrencyPair().base).updateAndGet(b -> Balance.Builder.from(b).total(b.getTotal().add(userTrade.getOriginalAmount())).available(b.getAvailable().add(userTrade.getOriginalAmount())).build());
balance(userTrade.getCurrencyPair().counter).updateAndGet(b -> Balance.Builder.from(b).available(reserved ? b.getAvailable() : b.getAvailable().subtract(counterAmount)).frozen(reserved ? b.getFrozen().subtract(counterAmount) : b.getFrozen()).total(b.getTotal().subtract(counterAmount)).build());
break;
default:
throw new NotAvailableFromExchangeException("Order type " + userTrade.getType() + " not supported");
}
}
use of org.knowm.xchange.exceptions.NotAvailableFromExchangeException in project XChange by knowm.
the class Account method checkBalance.
public void checkBalance(Order order, BigDecimal bidAmount) {
switch(order.getType()) {
case ASK:
BigDecimal askAmount = order.getRemainingAmount();
Balance askBalance = balances.computeIfAbsent(order.getCurrencyPair().base, this::defaultBalance).get();
checkBalance(order, askAmount, askBalance);
break;
case BID:
Balance bidBalance = balances.computeIfAbsent(order.getCurrencyPair().counter, this::defaultBalance).get();
checkBalance(order, bidAmount, bidBalance);
break;
default:
throw new NotAvailableFromExchangeException("Order type " + order.getType() + " not supported");
}
}
use of org.knowm.xchange.exceptions.NotAvailableFromExchangeException in project XChange by knowm.
the class TradeDemo method generic.
private static void generic(TradeService tradeService) throws NotAvailableFromExchangeException, NotYetImplementedForExchangeException, IOException {
printOpenOrders(tradeService);
// place a limit buy order
LimitOrder limitOrder = new LimitOrder(Order.OrderType.BID, BigDecimal.ONE, new CurrencyPair(Currency.GHs, Currency.BTC), "", null, new BigDecimal("0.00015600"));
System.out.println("Trying to place: " + limitOrder);
String orderId = "0";
try {
orderId = tradeService.placeLimitOrder(limitOrder);
System.out.println("New Limit Order ID: " + orderId);
} catch (ExchangeException e) {
System.out.println(e);
}
printOpenOrders(tradeService);
// Cancel the added order
boolean cancelResult = tradeService.cancelOrder(orderId);
System.out.println("Canceling order id=" + orderId + " returned " + cancelResult);
printOpenOrders(tradeService);
}
use of org.knowm.xchange.exceptions.NotAvailableFromExchangeException in project cassandre-trading-bot by cassandre-tech.
the class BasicTa4jCassandreStrategyTestMock method marketService.
@Bean
@Primary
public MarketService marketService() {
MarketService service = mock(MarketService.class);
// We don't use the getTickers method.
given(service.getTickers(any())).willThrow(new NotAvailableFromExchangeException("Not available in test"));
// Returns three values.
given(service.getTicker(BTC_USDT)).willReturn(Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(1)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(2)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(3)).open(new BigDecimal(110)).high(new BigDecimal(110)).low(new BigDecimal(110)).last(new BigDecimal(110)).volume(new BigDecimal(1070)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(4)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(5)).open(new BigDecimal(140)).high(new BigDecimal(140)).low(new BigDecimal(140)).last(new BigDecimal(140)).volume(new BigDecimal(1080)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(6)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(7)).open(new BigDecimal(119)).high(new BigDecimal(119)).low(new BigDecimal(119)).last(new BigDecimal(119)).volume(new BigDecimal(1090)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(8)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(9)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1100)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(10)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(11)).open(new BigDecimal(110)).high(new BigDecimal(110)).low(new BigDecimal(110)).last(new BigDecimal(110)).volume(new BigDecimal(1100)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(12)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(13)).open(new BigDecimal(120)).high(new BigDecimal(120)).low(new BigDecimal(120)).last(new BigDecimal(120)).volume(new BigDecimal(1120)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(14)).open(new BigDecimal(100)).high(new BigDecimal(100)).low(new BigDecimal(100)).last(new BigDecimal(100)).volume(new BigDecimal(1060)).build()), Optional.of(TickerDTO.builder().currencyPair(BTC_USDT).timestamp(BaseTest.createZonedDateTime(15)).open(new BigDecimal(130)).high(new BigDecimal(130)).low(new BigDecimal(130)).last(new BigDecimal(130)).volume(new BigDecimal(1130)).build()), Optional.empty());
return service;
}
Aggregations