public static ExchangeMetaData adaptMetaData( BitfinexAccountInfosResponse[] bitfinexAccountInfos, ExchangeMetaData exchangeMetaData) { final Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs(); // lets go with the assumption that the trading fees are common across all trading pairs for // now. // also setting the taker_fee as the trading_fee for now. final CurrencyPairMetaData metaData = new CurrencyPairMetaData( bitfinexAccountInfos[0].getTakerFees().movePointLeft(2), null, null, null, null); currencyPairs .keySet() .parallelStream() .forEach( currencyPair -> currencyPairs.merge( currencyPair, metaData, (oldMetaData, newMetaData) -> new CurrencyPairMetaData( newMetaData.getTradingFee(), oldMetaData.getMinimumAmount(), oldMetaData.getMaximumAmount(), oldMetaData.getPriceScale(), oldMetaData.getFeeTiers()))); return exchangeMetaData; }
private static CurrencyPairMetaData adaptPair( HuobiAssetPair pair, CurrencyPairMetaData metadata) { BigDecimal minQty = metadata == null ? null : metadata.getMinimumAmount().setScale(Integer.parseInt(pair.getAmountPrecision())); FeeTier[] feeTiers = metadata == null ? null : metadata.getFeeTiers(); return new CurrencyPairMetaData( fee, minQty, // Min amount null, // Max amount new Integer(pair.getPricePrecision()), // Price scale feeTiers); }
private static CurrencyPairMetaData adaptPair( BitmexTicker ticker, CurrencyPairMetaData originalMeta) { if (originalMeta != null) { return new CurrencyPairMetaData( ticker.getTakerFee(), originalMeta.getMinimumAmount(), originalMeta.getMaximumAmount(), Math.max(0, ticker.getTickSize().stripTrailingZeros().scale()), originalMeta.getFeeTiers()); } else { return new CurrencyPairMetaData( ticker.getTakerFee(), null, null, Math.max(0, ticker.getTickSize().stripTrailingZeros().scale()), null); } }
private static CurrencyPairMetaData adaptCurrencyPairMetaData(BxAssetPair assetPair) { return new CurrencyPairMetaData(null, assetPair.getPrimaryMin(), null, 0, null); }
private static CurrencyPairMetaData adaptPair( KrakenAssetPair krakenPair, CurrencyPairMetaData OriginalMeta) { if (OriginalMeta != null) { return new CurrencyPairMetaData( krakenPair.getFees().get(0).getPercentFee().divide(new BigDecimal(100)), OriginalMeta.getMinimumAmount(), OriginalMeta.getMaximumAmount(), krakenPair.getPairScale(), adaptFeeTiers(krakenPair.getFees_maker(), krakenPair.getFees())); } else { return new CurrencyPairMetaData( krakenPair.getFees().get(0).getPercentFee().divide(new BigDecimal(100)), null, null, krakenPair.getPairScale(), adaptFeeTiers(krakenPair.getFees_maker(), krakenPair.getFees())); } }
public static ExchangeMetaData adaptToExchangeMetaData( ExchangeMetaData exchangeMetaData, List<CCEXMarket> products) { Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = new HashMap<>(); Map<CurrencyPair, CurrencyPairMetaData> existingCurrencyPairMetadata = exchangeMetaData.getCurrencyPairs(); Map<Currency, CurrencyMetaData> currencies = new HashMap<>(); for (CCEXMarket product : products) { BigDecimal minSize = product.getMinTradeSize(); CurrencyPair pair = adaptCurrencyPair(product); CurrencyPairMetaData existingMetaForPair = existingCurrencyPairMetadata.get(pair); FeeTier[] existingFeeTiers = null; if (existingMetaForPair != null) { existingFeeTiers = existingMetaForPair.getFeeTiers(); } CurrencyPairMetaData cpmd = new CurrencyPairMetaData(null, minSize, null, 0, existingFeeTiers); currencyPairs.put(pair, cpmd); currencies.put(pair.base, null); currencies.put(pair.counter, null); } return new ExchangeMetaData(currencyPairs, currencies, null, null, true); }
public void verifyOrder(LimitOrder limitOrder) { ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData(); verifyOrder(limitOrder, exchangeMetaData); BigDecimal price = limitOrder.getLimitPrice().stripTrailingZeros(); if (price.scale() > exchangeMetaData.getCurrencyPairs().get(limitOrder.getCurrencyPair()).getPriceScale()) { throw new IllegalArgumentException("Unsupported price scale " + price.scale()); } }
protected final void verifyOrder(Order order, ExchangeMetaData exchangeMetaData) { CurrencyPairMetaData metaData = exchangeMetaData.getCurrencyPairs().get(order.getCurrencyPair()); if (metaData == null) { throw new IllegalArgumentException("Invalid CurrencyPair"); } BigDecimal originalAmount = order.getOriginalAmount(); if (originalAmount == null) { throw new IllegalArgumentException("Missing originalAmount"); } BigDecimal amount = originalAmount.stripTrailingZeros(); BigDecimal minimumAmount = metaData.getMinimumAmount(); if (minimumAmount != null) { if (amount.scale() > minimumAmount.scale()) { throw new IllegalArgumentException("Unsupported amount scale " + amount.scale()); } else if (amount.compareTo(minimumAmount) < 0) { throw new IllegalArgumentException("Order amount less than minimum"); } } } }
: currencyPairs .get(currencyPair) .getTradingFee(), // Take tradingFee from static metaData if exists bitfinexSymbolDetail .getMinimum_order_size()
public static ExchangeMetaData adaptMetadata(List<ZaifMarket> markets) { Map<CurrencyPair, CurrencyPairMetaData> pairMeta = new HashMap<>(); for (ZaifMarket zaifMarket : markets) { pairMeta.put(zaifMarket.getName(), new CurrencyPairMetaData(null, null, null, null, null)); } return new ExchangeMetaData(pairMeta, null, null, null, null); } }
public static ExchangeMetaData adaptToExchangeMetaData( List<HitbtcSymbol> symbols, Map<Currency, CurrencyMetaData> currencies, Map<CurrencyPair, CurrencyPairMetaData> currencyPairs) { if (symbols != null) { for (HitbtcSymbol symbol : symbols) { CurrencyPair pair = adaptSymbol(symbol); BigDecimal tickSize = symbol.getTickSize(); int priceScale = tickSize.scale(); // not 100% sure this is correct BigDecimal tradingFee = symbol.getTakeLiquidityRate(); BigDecimal minimumAmount = symbol.getQuantityIncrement(); BigDecimal maximumAmount = null; FeeTier[] feeTiers = null; if (currencyPairs.containsKey(pair)) { CurrencyPairMetaData existing = currencyPairs.get(pair); minimumAmount = existing.getMinimumAmount(); maximumAmount = existing.getMaximumAmount(); feeTiers = existing.getFeeTiers(); } CurrencyPairMetaData meta = new CurrencyPairMetaData( tradingFee, minimumAmount, maximumAmount, priceScale, feeTiers); currencyPairs.put(pair, meta); } } return new ExchangeMetaData(currencyPairs, currencies, null, null, null); }
private static CurrencyPairMetaData adaptPair( KrakenAssetPair krakenPair, CurrencyPairMetaData OriginalMeta) { if (OriginalMeta != null) { return new CurrencyPairMetaData( krakenPair.getFees().get(0).getPercentFee().divide(new BigDecimal(100)), OriginalMeta.getMinimumAmount(), OriginalMeta.getMaximumAmount(), krakenPair.getPairScale(), adaptFeeTiers(krakenPair.getFees_maker(), krakenPair.getFees())); } else { return new CurrencyPairMetaData( krakenPair.getFees().get(0).getPercentFee().divide(new BigDecimal(100)), null, null, krakenPair.getPairScale(), adaptFeeTiers(krakenPair.getFees_maker(), krakenPair.getFees())); } }
public static ExchangeMetaData adaptToExchangeMetaData( ExchangeMetaData exchangeMetaData, CoinbaseProProduct[] products) { Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs(); Map<Currency, CurrencyMetaData> currencies = exchangeMetaData.getCurrencies(); for (CoinbaseProProduct product : products) { BigDecimal minSize = product.getBaseMinSize(); BigDecimal maxSize = product.getBaseMaxSize(); CurrencyPair pair = adaptCurrencyPair(product); CurrencyPairMetaData staticMetaData = exchangeMetaData.getCurrencyPairs().get(pair); int priceScale = numberOfDecimals(product.getQuoteIncrement()); CurrencyPairMetaData cpmd = new CurrencyPairMetaData( null, minSize, maxSize, priceScale, staticMetaData != null ? staticMetaData.getFeeTiers() : null); currencyPairs.put(pair, cpmd); if (!currencies.containsKey(pair.base)) currencies.put(pair.base, null); if (!currencies.containsKey(pair.counter)) currencies.put(pair.counter, null); } return new ExchangeMetaData( currencyPairs, currencies, exchangeMetaData.getPublicRateLimits(), exchangeMetaData.getPrivateRateLimits(), true); }
private static UserTrade adaptUserTrade(ANXTradeResult aNXTradeResult, ANXMetaData meta) { BigDecimal tradedCurrencyFillAmount = aNXTradeResult.getTradedCurrencyFillAmount(); CurrencyPair currencyPair = adaptCurrencyPair(aNXTradeResult.getCurrencyPair()); int priceScale = meta.getCurrencyPairs().get(currencyPair).getPriceScale(); BigDecimal price = aNXTradeResult .getSettlementCurrencyFillAmount() .divide(tradedCurrencyFillAmount, priceScale, BigDecimal.ROUND_HALF_EVEN); OrderType type = adaptSide(aNXTradeResult.getSide()); // for fees, getWalletHistory should be used. return new UserTrade( type, tradedCurrencyFillAmount, currencyPair, price, aNXTradeResult.getTimestamp(), aNXTradeResult.getTradeId(), aNXTradeResult.getOrderId(), null, null); }
protected final void verifyOrder(Order order, ExchangeMetaData exchangeMetaData) { CurrencyPairMetaData metaData = exchangeMetaData.getCurrencyPairs().get(order.getCurrencyPair()); if (metaData == null) { throw new IllegalArgumentException("Invalid CurrencyPair"); } BigDecimal originalAmount = order.getOriginalAmount(); if (originalAmount == null) { throw new IllegalArgumentException("Missing originalAmount"); } BigDecimal amount = originalAmount.stripTrailingZeros(); BigDecimal minimumAmount = metaData.getMinimumAmount(); if (minimumAmount != null) { if (amount.scale() > minimumAmount.scale()) { throw new IllegalArgumentException("Unsupported amount scale " + amount.scale()); } else if (amount.compareTo(minimumAmount) < 0) { throw new IllegalArgumentException("Order amount less than minimum"); } } } }
: currencyPairs .get(currencyPair) .getTradingFee(), // Take tradingFee from static metaData if exists bitfinexSymbolDetail .getMinimum_order_size()
@Override public void remoteInit() { Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = exchangeMetaData.getCurrencyPairs(); CoindirectMarketDataService coindirectMarketDataService = (CoindirectMarketDataService) marketDataService; try { List<CoindirectMarket> coindirectMarketList = coindirectMarketDataService.getCoindirectMarkets(1000); for (CoindirectMarket market : coindirectMarketList) { CurrencyPair currencyPair = CoindirectAdapters.toCurrencyPair(market.symbol); CurrencyPairMetaData staticMeta = currencyPairs.get(currencyPair); CurrencyPairMetaData adaptedMeta = new CurrencyPairMetaData( staticMeta.getTradingFee(), market.minimumQuantity, market.maximumQuantity, staticMeta.getPriceScale(), staticMeta.getFeeTiers()); currencyPairs.put(currencyPair, adaptedMeta); } } catch (IOException exception) { } } }
private static CurrencyPairMetaData adaptCurrencyPairMetadata( KucoinTicker tick, KucoinCoin coin) { // trading scale is determined by the base currency's trade precision return new CurrencyPairMetaData(tick.getFeeRate(), null, null, coin.getTradePrecision(), null); }
private static CurrencyPairMetaData adaptPair( BitmexTicker ticker, CurrencyPairMetaData originalMeta) { if (originalMeta != null) { return new CurrencyPairMetaData( ticker.getTakerFee(), originalMeta.getMinimumAmount(), originalMeta.getMaximumAmount(), Math.max(0, ticker.getTickSize().stripTrailingZeros().scale()), originalMeta.getFeeTiers()); } else { return new CurrencyPairMetaData( ticker.getTakerFee(), null, null, Math.max(0, ticker.getTickSize().stripTrailingZeros().scale()), null); } }
public void verifyOrder(LimitOrder limitOrder) { ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData(); verifyOrder(limitOrder, exchangeMetaData); BigDecimal price = limitOrder.getLimitPrice().stripTrailingZeros(); if (price.scale() > exchangeMetaData.getCurrencyPairs().get(limitOrder.getCurrencyPair()).getPriceScale()) { throw new IllegalArgumentException("Unsupported price scale " + price.scale()); } }