Search in sources :

Example 1 with LatokenException

use of org.knowm.xchange.latoken.dto.LatokenException in project XChange by knowm.

the class LatokenAccountService method getAccountInfo.

@Override
public AccountInfo getAccountInfo() throws IOException {
    try {
        List<LatokenBalance> latokenBalances = getLatokenBalances();
        List<Balance> balances = latokenBalances.stream().map(latokenBalance -> LatokenAdapters.adaptBalance(latokenBalance)).collect(Collectors.toList());
        Wallet wallet = Wallet.Builder.from(balances).build();
        return new AccountInfo(null, TRADING_FEE, Arrays.asList(wallet), new Date());
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : AccountInfo(org.knowm.xchange.dto.account.AccountInfo) Arrays(java.util.Arrays) AccountService(org.knowm.xchange.service.account.AccountService) LatokenException(org.knowm.xchange.latoken.dto.LatokenException) Wallet(org.knowm.xchange.dto.account.Wallet) Date(java.util.Date) LatokenBalance(org.knowm.xchange.latoken.dto.account.LatokenBalance) IOException(java.io.IOException) Exchange(org.knowm.xchange.Exchange) Collectors(java.util.stream.Collectors) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) List(java.util.List) LatokenErrorAdapter(org.knowm.xchange.latoken.LatokenErrorAdapter) LatokenAdapters(org.knowm.xchange.latoken.LatokenAdapters) LatokenException(org.knowm.xchange.latoken.dto.LatokenException) LatokenBalance(org.knowm.xchange.latoken.dto.account.LatokenBalance) Wallet(org.knowm.xchange.dto.account.Wallet) LatokenBalance(org.knowm.xchange.latoken.dto.account.LatokenBalance) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) Date(java.util.Date)

Example 2 with LatokenException

use of org.knowm.xchange.latoken.dto.LatokenException in project XChange by knowm.

the class LatokenMarketDataService method getTrades.

@Override
public Trades getTrades(CurrencyPair pair, Object... args) throws IOException {
    try {
        int limit = maxTrades;
        if (args != null && args.length == 1) {
            Object arg0 = args[0];
            if (!(arg0 instanceof Integer)) {
                throw new ExchangeException("Maximal number of trades must be an Integer!");
            } else {
                limit = (Integer) arg0;
            }
        }
        LatokenTrades latokenTrades = getLatokenTrades(pair, limit);
        return LatokenAdapters.adaptTrades(this.exchange, latokenTrades);
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenException(org.knowm.xchange.latoken.dto.LatokenException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) LatokenTrades(org.knowm.xchange.latoken.dto.marketdata.LatokenTrades)

Example 3 with LatokenException

use of org.knowm.xchange.latoken.dto.LatokenException in project XChange by knowm.

the class LatokenTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    if (params instanceof TradeHistoryParamCurrencyPair == false) {
        throw new ExchangeException("CurrencyPair must be provided to get user trades.");
    }
    TradeHistoryParamCurrencyPair pairParams = (TradeHistoryParamCurrencyPair) params;
    CurrencyPair pair = pairParams.getCurrencyPair();
    if (pair == null) {
        throw new ExchangeException("CurrencyPair must be provided to get user trades.");
    }
    // Limit is an optional parameter
    Integer limit = null;
    if (params instanceof TradeHistoryParamLimit) {
        TradeHistoryParamLimit limitParams = (TradeHistoryParamLimit) params;
        limit = limitParams.getLimit();
    }
    try {
        LatokenUserTrades latokenTrades = getLatokenUserTrades(pair, limit);
        return LatokenAdapters.adaptUserTrades(this.exchange, latokenTrades);
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenException(org.knowm.xchange.latoken.dto.LatokenException) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) LatokenUserTrades(org.knowm.xchange.latoken.dto.trade.LatokenUserTrades) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 4 with LatokenException

use of org.knowm.xchange.latoken.dto.LatokenException in project XChange by knowm.

the class LatokenTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
    try {
        if (params instanceof OpenOrdersParamCurrencyPair == false) {
            throw new ExchangeException("CurrencyPair is must be provided to get open orders.");
        }
        OpenOrdersParamCurrencyPair pairParams = (OpenOrdersParamCurrencyPair) params;
        CurrencyPair pair = pairParams.getCurrencyPair();
        if (pair == null) {
            throw new ExchangeException("CurrencyPair is must be provided to get open orders.");
        }
        List<LatokenOrder> latokenOpenOrders = getLatokenOpenOrders(pair, Integer.MAX_VALUE);
        return LatokenAdapters.adaptOpenOrders(this.exchange, latokenOpenOrders);
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenException(org.knowm.xchange.latoken.dto.LatokenException) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 5 with LatokenException

use of org.knowm.xchange.latoken.dto.LatokenException in project XChange by knowm.

the class LatokenTradeService method getOrder.

@Override
public Collection<Order> getOrder(OrderQueryParams... params) throws IOException {
    try {
        Collection<Order> orders = new ArrayList<>();
        // pair/status (via LatokenQueryOrderParams)
        for (OrderQueryParams param : params) {
            if (param instanceof OrderQueryParamCurrencyPair) {
                OrderQueryParamCurrencyPair orderQueryParamCurrencyPair = (OrderQueryParamCurrencyPair) param;
                CurrencyPair pair = orderQueryParamCurrencyPair.getCurrencyPair();
                if (pair == null) {
                    throw new ExchangeException("CurrencyPair must be provided to query an order.");
                }
                LatokenOrderStatus status = LatokenOrderStatus.active;
                Integer limit = null;
                if (param instanceof LatokenQueryOrderParams) {
                    LatokenQueryOrderParams latokenParam = (LatokenQueryOrderParams) param;
                    status = latokenParam.getStatus();
                    limit = latokenParam.getLimit();
                }
                List<LatokenOrder> latokenOrders = getLatokenOrders(pair, status, limit);
                latokenOrders.forEach(latokenOrder -> orders.add(LatokenAdapters.adaptOrder(this.exchange, latokenOrder)));
            } else {
                if (param.getOrderId() == null) {
                    throw new ExchangeException("OrderId must be provided to query an order.");
                }
                LatokenOrder latokenOrder = getLatokenOrder(param.getOrderId());
                orders.add(LatokenAdapters.adaptOrder(this.exchange, latokenOrder));
            }
        }
        return orders;
    } catch (LatokenException e) {
        throw LatokenErrorAdapter.adapt(e);
    }
}
Also used : LatokenNewOrder(org.knowm.xchange.latoken.dto.trade.LatokenNewOrder) Order(org.knowm.xchange.dto.Order) LatokenTestOrder(org.knowm.xchange.latoken.dto.trade.LatokenTestOrder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) LatokenException(org.knowm.xchange.latoken.dto.LatokenException) LatokenOrder(org.knowm.xchange.latoken.dto.trade.LatokenOrder) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) ArrayList(java.util.ArrayList) LatokenOrderStatus(org.knowm.xchange.latoken.dto.trade.LatokenOrderStatus) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) OrderQueryParams(org.knowm.xchange.service.trade.params.orders.OrderQueryParams) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Aggregations

LatokenException (org.knowm.xchange.latoken.dto.LatokenException)6 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)5 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)3 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)3 DefaultOpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair)3 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)3 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)3 LatokenOrder (org.knowm.xchange.latoken.dto.trade.LatokenOrder)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Exchange (org.knowm.xchange.Exchange)1 Order (org.knowm.xchange.dto.Order)1 AccountInfo (org.knowm.xchange.dto.account.AccountInfo)1 Balance (org.knowm.xchange.dto.account.Balance)1 Wallet (org.knowm.xchange.dto.account.Wallet)1