Search in sources :

Example 1 with NotAvailableFromExchangeException

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();
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) DefaultWithdrawFundsParams(org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams) BitbayWithdrawFundsSwiftParams(org.knowm.xchange.bitbay.service.account.params.BitbayWithdrawFundsSwiftParams)

Example 2 with 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");
    }
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) BigDecimal(java.math.BigDecimal)

Example 3 with NotAvailableFromExchangeException

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");
    }
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal)

Example 4 with NotAvailableFromExchangeException

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);
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 5 with NotAvailableFromExchangeException

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;
}
Also used : NotAvailableFromExchangeException(org.knowm.xchange.exceptions.NotAvailableFromExchangeException) BigDecimal(java.math.BigDecimal) MarketService(tech.cassandre.trading.bot.service.MarketService) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Aggregations

NotAvailableFromExchangeException (org.knowm.xchange.exceptions.NotAvailableFromExchangeException)21 BigDecimal (java.math.BigDecimal)16 Date (java.util.Date)5 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)4 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)4 Bean (org.springframework.context.annotation.Bean)4 Primary (org.springframework.context.annotation.Primary)4 MarketService (tech.cassandre.trading.bot.service.MarketService)4 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)3 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)3 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)3 TradeService (org.knowm.xchange.service.trade.TradeService)3 Ticker (org.knowm.xchange.dto.marketdata.Ticker)2 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)2 DefaultWithdrawFundsParams (org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 BitbayWithdrawFundsSwiftParams (org.knowm.xchange.bitbay.service.account.params.BitbayWithdrawFundsSwiftParams)1 BitstampWithdrawal (org.knowm.xchange.bitstamp.dto.account.BitstampWithdrawal)1 CoinMarketCapCurrency (org.knowm.xchange.coinmarketcap.deprecated.v2.dto.marketdata.CoinMarketCapCurrency)1