use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexExchange method remoteInit.
@Override
public void remoteInit() throws IOException, ExchangeException {
try {
BitfinexMarketDataServiceRaw dataService = (BitfinexMarketDataServiceRaw) this.marketDataService;
List<CurrencyPair> currencyPairs = dataService.getExchangeSymbols();
exchangeMetaData = BitfinexAdapters.adaptMetaData(currencyPairs, exchangeMetaData);
// Get the last-price of each pair. It is needed to infer XChange's priceScale out of
// Bitfinex's pricePercision
Map<CurrencyPair, BigDecimal> lastPrices = Arrays.stream(dataService.getBitfinexTickers(null)).map(BitfinexAdapters::adaptTicker).collect(Collectors.toMap(t -> t.getCurrencyPair(), t -> t.getLast()));
final List<BitfinexSymbolDetail> symbolDetails = dataService.getSymbolDetails();
exchangeMetaData = BitfinexAdapters.adaptMetaData(exchangeMetaData, symbolDetails, lastPrices);
if (exchangeSpecification.getApiKey() != null && exchangeSpecification.getSecretKey() != null) {
// Bitfinex does not provide any specific wallet health info
// So instead of wallet status, fetch platform status to get wallet health
Integer bitfinexPlatformStatusData = dataService.getBitfinexPlatformStatus()[0];
boolean bitfinexPlatformStatusPresent = bitfinexPlatformStatusData != null;
int bitfinexPlatformStatus = bitfinexPlatformStatusPresent ? bitfinexPlatformStatusData : 0;
// Additional remoteInit configuration for authenticated instances
BitfinexAccountService accountService = (BitfinexAccountService) this.accountService;
final BitfinexAccountFeesResponse accountFees = accountService.getAccountFees();
exchangeMetaData = BitfinexAdapters.adaptMetaData(accountFees, bitfinexPlatformStatus, bitfinexPlatformStatusPresent, exchangeMetaData);
BitfinexTradeService tradeService = (BitfinexTradeService) this.tradeService;
final BitfinexAccountInfosResponse[] bitfinexAccountInfos = tradeService.getBitfinexAccountInfos();
exchangeMetaData = BitfinexAdapters.adaptMetaData(bitfinexAccountInfos, exchangeMetaData);
}
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexMarketDataService method getOrderBook.
/**
* @param args If two integers are provided, then those count as limit bid and limit ask count
*/
@Override
public OrderBook getOrderBook(CurrencyPair currencyPair, Object... args) throws IOException {
try {
// null will cause fetching of full order book, the default behavior in XChange
Integer limitBids = null;
Integer limitAsks = null;
if (args != null && args.length == 2) {
Object arg0 = args[0];
if (!(arg0 instanceof Integer)) {
throw new ExchangeException("Argument 0 must be an Integer!");
} else {
limitBids = (Integer) arg0;
}
Object arg1 = args[1];
if (!(arg1 instanceof Integer)) {
throw new ExchangeException("Argument 1 must be an Integer!");
} else {
limitAsks = (Integer) arg1;
}
}
BitfinexDepth bitfinexDepth = getBitfinexOrderBook(BitfinexUtils.toPairStringV1(currencyPair), limitBids, limitAsks);
OrderBook orderBook = BitfinexAdapters.adaptOrderBook(bitfinexDepth, currencyPair);
return orderBook;
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexTradeService method placeLimitOrder.
@Override
public String placeLimitOrder(LimitOrder limitOrder) throws IOException {
try {
BitfinexOrderType type = BitfinexAdapters.adaptOrderFlagsToType(limitOrder.getOrderFlags());
BitfinexOrderStatusResponse newOrder = placeBitfinexLimitOrder(limitOrder, type);
return String.valueOf(newOrder.getId());
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexAccountService method getFundingHistory.
@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
try {
String currency = null;
Long startTime = null;
Long endTime = null;
Integer limit = null;
if (params instanceof TradeHistoryParamCurrencyPair && ((TradeHistoryParamCurrencyPair) params).getCurrencyPair() != null) {
currency = BitfinexAdapters.adaptCurrencyPair(((TradeHistoryParamCurrencyPair) params).getCurrencyPair());
}
if (params instanceof TradeHistoryParamsTimeSpan) {
TradeHistoryParamsTimeSpan paramsTimeSpan = (TradeHistoryParamsTimeSpan) params;
startTime = DateUtils.toMillisNullSafe(paramsTimeSpan.getStartTime());
endTime = DateUtils.toMillisNullSafe(paramsTimeSpan.getEndTime());
}
if (params instanceof TradeHistoryParamLimit) {
TradeHistoryParamLimit tradeHistoryParamLimit = (TradeHistoryParamLimit) params;
if (tradeHistoryParamLimit.getLimit() != null) {
limit = Integer.valueOf(tradeHistoryParamLimit.getLimit());
}
}
return BitfinexAdapters.adaptFundingHistory(getMovementHistory(currency, startTime, endTime, limit));
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
use of org.knowm.xchange.bitfinex.dto.BitfinexException in project XChange by knowm.
the class BitfinexMarketDataService method getLendOrderBook.
public LoanOrderBook getLendOrderBook(String currency, Object... args) throws IOException {
try {
// According to API docs, default is 50
int limitBids = 50;
int limitAsks = 50;
if (args != null && args.length == 2) {
Object arg0 = args[0];
if (!(arg0 instanceof Integer)) {
throw new ExchangeException("Argument 0 must be an Integer!");
} else {
limitBids = (Integer) arg0;
}
Object arg1 = args[1];
if (!(arg1 instanceof Integer)) {
throw new ExchangeException("Argument 1 must be an Integer!");
} else {
limitAsks = (Integer) arg1;
}
}
BitfinexLendDepth bitfinexLendDepth = getBitfinexLendBook(currency, limitBids, limitAsks);
List<FixedRateLoanOrder> fixedRateAsks = BitfinexAdapters.adaptFixedRateLoanOrders(bitfinexLendDepth.getAsks(), currency, "ask", "");
List<FixedRateLoanOrder> fixedRateBids = BitfinexAdapters.adaptFixedRateLoanOrders(bitfinexLendDepth.getBids(), currency, "bid", "");
List<FloatingRateLoanOrder> floatingRateAsks = BitfinexAdapters.adaptFloatingRateLoanOrders(bitfinexLendDepth.getAsks(), currency, "ask", "");
List<FloatingRateLoanOrder> floatingRateBids = BitfinexAdapters.adaptFloatingRateLoanOrders(bitfinexLendDepth.getBids(), currency, "bid", "");
return new LoanOrderBook(null, fixedRateAsks, fixedRateBids, floatingRateAsks, floatingRateBids);
} catch (BitfinexException e) {
throw BitfinexErrorAdapter.adapt(e);
}
}
Aggregations