Search in sources :

Example 1 with BaseYoBitResponse

use of org.knowm.xchange.yobit.dto.BaseYoBitResponse in project XChange by knowm.

the class YoBitTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    Integer count = 1000;
    if (params instanceof TradeHistoryParamLimit) {
        count = ((TradeHistoryParamLimit) params).getLimit();
    }
    Long offset = 0L;
    if (params instanceof TradeHistoryParamOffset) {
        offset = ((TradeHistoryParamOffset) params).getOffset();
    }
    String market = null;
    if (params instanceof TradeHistoryParamCurrencyPair) {
        CurrencyPair currencyPair = ((TradeHistoryParamCurrencyPair) params).getCurrencyPair();
        market = YoBitAdapters.adaptCcyPairToUrlFormat(currencyPair);
    }
    Long fromTransactionId = null;
    Long endTransactionId = null;
    if (params instanceof TradeHistoryParamsIdSpan) {
        TradeHistoryParamsIdSpan tradeHistoryParamsIdSpan = (TradeHistoryParamsIdSpan) params;
        String startId = tradeHistoryParamsIdSpan.getStartId();
        if (startId != null)
            fromTransactionId = Long.valueOf(startId);
        String endId = tradeHistoryParamsIdSpan.getEndId();
        if (endId != null)
            endTransactionId = Long.valueOf(endId);
    }
    String order = "DESC";
    if (params instanceof TradeHistoryParamsSorted) {
        order = ((TradeHistoryParamsSorted) params).getOrder().equals(TradeHistoryParamsSorted.Order.desc) ? "DESC" : "ASC";
    }
    Long fromTimestamp = null;
    Long toTimestamp = null;
    if (params instanceof TradeHistoryParamsTimeSpan) {
        TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
        Date startTime = tradeHistoryParamsTimeSpan.getStartTime();
        if (startTime != null)
            fromTimestamp = DateUtils.toUnixTimeNullSafe(startTime);
        Date endTime = tradeHistoryParamsTimeSpan.getEndTime();
        if (endTime != null)
            toTimestamp = DateUtils.toUnixTimeNullSafe(endTime);
    }
    BaseYoBitResponse response = tradeHistory(count, offset, market, fromTransactionId, endTransactionId, order, fromTimestamp, toTimestamp);
    List<UserTrade> trades = new ArrayList<>();
    if (response.returnData != null) {
        for (Object key : response.returnData.keySet()) {
            Map tradeData = (Map) response.returnData.get(key);
            trades.add(YoBitAdapters.adaptUserTrade(key, tradeData));
        }
    }
    return new UserTrades(trades, Trades.TradeSortType.SortByTimestamp);
}
Also used : TradeHistoryParamOffset(org.knowm.xchange.service.trade.params.TradeHistoryParamOffset) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) ArrayList(java.util.ArrayList) TradeHistoryParamsIdSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsIdSpan) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Date(java.util.Date) UserTrades(org.knowm.xchange.dto.trade.UserTrades) TradeHistoryParamsSorted(org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted) BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) Map(java.util.Map) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 2 with BaseYoBitResponse

use of org.knowm.xchange.yobit.dto.BaseYoBitResponse in project XChange by knowm.

the class YoBitTradeServiceRaw method activeOrders.

public BaseYoBitResponse activeOrders(OpenOrdersParamCurrencyPair params) throws IOException {
    CurrencyPair currencyPair = params.getCurrencyPair();
    String market = YoBitAdapters.adaptCcyPairToUrlFormat(currencyPair);
    BaseYoBitResponse response = service.activeOrders(exchange.getExchangeSpecification().getApiKey(), signatureCreator, "ActiveOrders", exchange.getNonceFactory(), market);
    if (!response.success)
        throw new ExchangeException("failed to get open orders");
    return response;
}
Also used : BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) NotYetImplementedForExchangeException(org.knowm.xchange.exceptions.NotYetImplementedForExchangeException) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)

Example 3 with BaseYoBitResponse

use of org.knowm.xchange.yobit.dto.BaseYoBitResponse in project XChange by knowm.

the class YoBitAccountServiceRaw method getInfo.

public AccountInfo getInfo() throws IOException {
    BaseYoBitResponse response = service.getInfo(exchange.getExchangeSpecification().getApiKey(), signatureCreator, "getInfo", exchange.getNonceFactory());
    if (!response.success)
        throw new ExchangeException("failed to get account info");
    Map walletData = response.returnData;
    Map funds = (Map) walletData.get("funds");
    if (funds == null)
        funds = new HashMap();
    Map fundsIncludingOrders = (Map) walletData.get("funds_incl_orders");
    if (fundsIncludingOrders == null)
        fundsIncludingOrders = new HashMap();
    Collection<Wallet> wallets = new ArrayList<>();
    for (Object key : funds.keySet()) {
        Currency currency = YoBitAdapters.adaptCurrency(key.toString());
        BigDecimal amountAvailable = new BigDecimal(funds.get(key).toString());
        BigDecimal amountIncludingOrders = new BigDecimal(fundsIncludingOrders.get(key).toString());
        Balance balance = new Balance(currency, amountIncludingOrders, amountAvailable, amountIncludingOrders.subtract(amountAvailable), BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO);
        wallets.add(Wallet.Builder.from(Arrays.asList(balance)).id(currency.getCurrencyCode()).build());
    }
    return new AccountInfo(wallets);
}
Also used : HashMap(java.util.HashMap) Wallet(org.knowm.xchange.dto.account.Wallet) Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) ExchangeException(org.knowm.xchange.exceptions.ExchangeException) HashMap(java.util.HashMap) Map(java.util.Map) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 4 with BaseYoBitResponse

use of org.knowm.xchange.yobit.dto.BaseYoBitResponse in project XChange by knowm.

the class YoBitAccountServiceRaw method withdrawCoinsToAddress.

public BaseYoBitResponse withdrawCoinsToAddress(DefaultWithdrawFundsParams params) throws IOException {
    DefaultWithdrawFundsParams defaultWithdrawFundsParams = params;
    BaseYoBitResponse response = service.withdrawCoinsToAddress(exchange.getExchangeSpecification().getApiKey(), signatureCreator, "WithdrawCoinsToAddress", exchange.getNonceFactory(), defaultWithdrawFundsParams.getCurrency().getCurrencyCode(), defaultWithdrawFundsParams.getAmount(), defaultWithdrawFundsParams.getAddress());
    if (!response.success)
        throw new ExchangeException("failed to withdraw funds");
    return response;
}
Also used : DefaultWithdrawFundsParams(org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams) BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) ExchangeException(org.knowm.xchange.exceptions.ExchangeException)

Example 5 with BaseYoBitResponse

use of org.knowm.xchange.yobit.dto.BaseYoBitResponse in project XChange by knowm.

the class YoBitTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
    if (params instanceof OpenOrdersParamCurrencyPair) {
        BaseYoBitResponse response = activeOrders((OpenOrdersParamCurrencyPair) params);
        List<LimitOrder> orders = new ArrayList<>();
        if (response.returnData != null) {
            for (Object key : response.returnData.keySet()) {
                Map tradeData = (Map) response.returnData.get(key);
                orders.add(YoBitAdapters.adaptOrder(key.toString(), tradeData));
            }
        }
        return new OpenOrders(orders);
    }
    throw new IllegalStateException("Need to specify currency pair");
}
Also used : ArrayList(java.util.ArrayList) BaseYoBitResponse(org.knowm.xchange.yobit.dto.BaseYoBitResponse) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) Map(java.util.Map) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)

Aggregations

BaseYoBitResponse (org.knowm.xchange.yobit.dto.BaseYoBitResponse)7 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)4 OpenOrdersParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair)3 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)2 NotYetImplementedForExchangeException (org.knowm.xchange.exceptions.NotYetImplementedForExchangeException)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Currency (org.knowm.xchange.currency.Currency)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 OpenOrders (org.knowm.xchange.dto.trade.OpenOrders)1 UserTrade (org.knowm.xchange.dto.trade.UserTrade)1 UserTrades (org.knowm.xchange.dto.trade.UserTrades)1 DefaultWithdrawFundsParams (org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams)1