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);
}
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;
}
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);
}
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;
}
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");
}
Aggregations