Search in sources :

Example 16 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class BitflyerAdapters method adaptMetaData.

public static ExchangeMetaData adaptMetaData(List<BitflyerMarket> markets) {
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = new HashMap<>();
    Map<Currency, CurrencyMetaData> currencies = new HashMap<>();
    for (BitflyerMarket market : markets) {
        CurrencyPair pair = adaptCurrencyPair(market.getProductCode());
        currencyPairs.put(pair, null);
    }
    return new ExchangeMetaData(currencyPairs, currencies, null, null, false);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BitflyerMarket(org.knowm.xchange.bitflyer.dto.account.BitflyerMarket) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) HashMap(java.util.HashMap) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 17 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class KucoinMarketDataServiceIntegration method testGetMarketData.

@Test
public void testGetMarketData() throws Exception {
    KucoinExchange exchange = exchange();
    ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData();
    exchangeMetaData.getCurrencyPairs().entrySet().forEach(pair -> {
        assertThat(pair.getValue().getMinimumAmount()).isNotNull();
        assertThat(pair.getValue().getMaximumAmount()).isNotNull();
        assertThat(pair.getValue().getCounterMinimumAmount()).isNotNull();
        assertThat(pair.getValue().getCounterMaximumAmount()).isNotNull();
        assertThat(pair.getValue().getBaseScale()).isNotNull();
        assertThat(pair.getValue().getPriceScale()).isNotNull();
        assertThat(pair.getValue().getTradingFeeCurrency()).isNotNull();
    });
}
Also used : ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Test(org.junit.Test)

Example 18 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class BitfinexAdapters method adaptMetaData.

public static ExchangeMetaData adaptMetaData(List<CurrencyPair> currencyPairs, ExchangeMetaData metaData) {
    Map<CurrencyPair, CurrencyPairMetaData> pairsMap = metaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currenciesMap = metaData.getCurrencies();
    // Remove pairs that are no-longer in use
    pairsMap.keySet().retainAll(currencyPairs);
    // Remove currencies that are no-longer in use
    Set<Currency> currencies = currencyPairs.stream().flatMap(pair -> Stream.of(pair.base, pair.counter)).collect(Collectors.toSet());
    currenciesMap.keySet().retainAll(currencies);
    // Add missing pairs and currencies
    for (CurrencyPair c : currencyPairs) {
        if (!pairsMap.containsKey(c)) {
            pairsMap.put(c, null);
        }
        if (!currenciesMap.containsKey(c.base)) {
            currenciesMap.put(c.base, new CurrencyMetaData(2, // When missing, add default meta-data with scale of 2 (Bitfinex's minimal
            null));
        // scale)
        }
        if (!currenciesMap.containsKey(c.counter)) {
            currenciesMap.put(c.counter, new CurrencyMetaData(2, null));
        }
    }
    return metaData;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) StopOrder(org.knowm.xchange.dto.trade.StopOrder) Arrays(java.util.Arrays) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date) BitfinexBalancesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexBalancesResponse) LoggerFactory(org.slf4j.LoggerFactory) BitfinexLendLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendLevel) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BitfinexDepositWithdrawalHistoryResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexDepositWithdrawalHistoryResponse) Map(java.util.Map) BitfinexTrade(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade) BitfinexPublicTrade(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) Wallet(org.knowm.xchange.dto.account.Wallet) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) MathContext(java.math.MathContext) BitfinexAccountInfosResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse) BitfinexTradeResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse) Collection(java.util.Collection) Set(java.util.Set) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) Stream(java.util.stream.Stream) BitfinexLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel) Entry(java.util.Map.Entry) Optional(java.util.Optional) BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker) BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth) Movement(org.knowm.xchange.bitfinex.v2.dto.account.Movement) CurrencyPairDeserializer(org.knowm.xchange.utils.jackson.CurrencyPairDeserializer) BitfinexUtils(org.knowm.xchange.bitfinex.v1.BitfinexUtils) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) Supplier(java.util.function.Supplier) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) BitfinexTickerFundingCurrency(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerFundingCurrency) Order(org.knowm.xchange.dto.Order) BitfinexSymbolDetail(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Ticker(org.knowm.xchange.dto.marketdata.Ticker) Logger(org.slf4j.Logger) Fee(org.knowm.xchange.dto.account.Fee) BitfinexAccountFeesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Trades(org.knowm.xchange.dto.marketdata.Trades) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder) BitfinexTradingFeeResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Trade(org.knowm.xchange.dto.marketdata.Trade) BitfinexOrderFlags(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderFlags) BitfinexTickerTraidingPair(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerTraidingPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) WalletHealth(org.knowm.xchange.dto.meta.WalletHealth) DateUtils(org.knowm.xchange.utils.DateUtils) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Currency(org.knowm.xchange.currency.Currency) BitfinexTickerFundingCurrency(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerFundingCurrency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 19 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class BitfinexAdapters method adaptMetaData.

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;
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) StopOrder(org.knowm.xchange.dto.trade.StopOrder) Arrays(java.util.Arrays) OrderType(org.knowm.xchange.dto.Order.OrderType) Date(java.util.Date) BitfinexBalancesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexBalancesResponse) LoggerFactory(org.slf4j.LoggerFactory) BitfinexLendLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendLevel) BitfinexOrderType(org.knowm.xchange.bitfinex.v1.BitfinexOrderType) Balance(org.knowm.xchange.dto.account.Balance) BigDecimal(java.math.BigDecimal) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BitfinexDepositWithdrawalHistoryResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexDepositWithdrawalHistoryResponse) Map(java.util.Map) BitfinexTrade(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade) BitfinexPublicTrade(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexPublicTrade) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OrderStatus(org.knowm.xchange.dto.Order.OrderStatus) Wallet(org.knowm.xchange.dto.account.Wallet) FixedRateLoanOrder(org.knowm.xchange.dto.trade.FixedRateLoanOrder) MathContext(java.math.MathContext) BitfinexAccountInfosResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexAccountInfosResponse) BitfinexTradeResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexTradeResponse) Collection(java.util.Collection) Set(java.util.Set) UserTrades(org.knowm.xchange.dto.trade.UserTrades) UserTrade(org.knowm.xchange.dto.trade.UserTrade) Collectors(java.util.stream.Collectors) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) Stream(java.util.stream.Stream) BitfinexLevel(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLevel) Entry(java.util.Map.Entry) Optional(java.util.Optional) BitfinexTicker(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker) BitfinexDepth(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth) Movement(org.knowm.xchange.bitfinex.v2.dto.account.Movement) CurrencyPairDeserializer(org.knowm.xchange.utils.jackson.CurrencyPairDeserializer) BitfinexUtils(org.knowm.xchange.bitfinex.v1.BitfinexUtils) BitfinexOrderStatusResponse(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderStatusResponse) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) Supplier(java.util.function.Supplier) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) TradeSortType(org.knowm.xchange.dto.marketdata.Trades.TradeSortType) BitfinexTickerFundingCurrency(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerFundingCurrency) Order(org.knowm.xchange.dto.Order) BitfinexSymbolDetail(org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexSymbolDetail) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) Ticker(org.knowm.xchange.dto.marketdata.Ticker) Logger(org.slf4j.Logger) Fee(org.knowm.xchange.dto.account.Fee) BitfinexAccountFeesResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexAccountFeesResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Trades(org.knowm.xchange.dto.marketdata.Trades) FloatingRateLoanOrder(org.knowm.xchange.dto.trade.FloatingRateLoanOrder) BitfinexTradingFeeResponse(org.knowm.xchange.bitfinex.v1.dto.account.BitfinexTradingFeeResponse) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) Trade(org.knowm.xchange.dto.marketdata.Trade) BitfinexOrderFlags(org.knowm.xchange.bitfinex.v1.dto.trade.BitfinexOrderFlags) BitfinexTickerTraidingPair(org.knowm.xchange.bitfinex.v2.dto.marketdata.BitfinexTickerTraidingPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) WalletHealth(org.knowm.xchange.dto.meta.WalletHealth) DateUtils(org.knowm.xchange.utils.DateUtils) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 20 with ExchangeMetaData

use of org.knowm.xchange.dto.meta.ExchangeMetaData in project XChange by knowm.

the class CoinbaseProMetadataTest method unmarshalTest.

// @Test
public void unmarshalTest() throws IOException {
    JacksonObjectMapperFactory factory = new DefaultJacksonObjectMapperFactory();
    ObjectMapper mapper = factory.createObjectMapper();
    InputStream is = getClass().getResourceAsStream("/org/knowm/xchange/coinbasepro/dto/products.json");
    CoinbaseProProduct[] products = mapper.readValue(is, CoinbaseProProduct[].class);
    assertThat(products).hasSize(10);
    ExchangeSpecification specification = new ExchangeSpecification(CoinbaseProExchange.class);
    specification.setShouldLoadRemoteMetaData(false);
    Exchange exchange = ExchangeFactory.INSTANCE.createExchange(specification);
    ExchangeMetaData exchangeMetaData = exchange.getExchangeMetaData();
    exchangeMetaData = CoinbaseProAdapters.adaptToExchangeMetaData(exchangeMetaData, products, new CoinbaseProCurrency[] {});
    assertThat(exchangeMetaData.getCurrencyPairs().get(CurrencyPair.ETC_BTC).getPriceScale()).isEqualTo(5);
}
Also used : Exchange(org.knowm.xchange.Exchange) CoinbaseProExchange(org.knowm.xchange.coinbasepro.CoinbaseProExchange) InputStream(java.io.InputStream) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) CoinbaseProCurrency(org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProCurrency) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) JacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.JacksonObjectMapperFactory) DefaultJacksonObjectMapperFactory(si.mazi.rescu.serialization.jackson.DefaultJacksonObjectMapperFactory) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CoinbaseProProduct(org.knowm.xchange.coinbasepro.dto.marketdata.CoinbaseProProduct)

Aggregations

ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)33 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)23 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)22 Currency (org.knowm.xchange.currency.Currency)18 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)18 HashMap (java.util.HashMap)12 BigDecimal (java.math.BigDecimal)11 Test (org.junit.Test)9 Exchange (org.knowm.xchange.Exchange)5 FeeTier (org.knowm.xchange.dto.meta.FeeTier)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 RateLimit (org.knowm.xchange.dto.meta.RateLimit)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Fee (org.knowm.xchange.dto.account.Fee)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 InputStream (java.io.InputStream)2 MathContext (java.math.MathContext)2