Search in sources :

Example 26 with CurrencyMetaData

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

the class DsxExchange method remoteInit.

@Override
public void remoteInit() throws IOException {
    DsxMarketDataServiceRaw dataService = ((DsxMarketDataServiceRaw) marketDataService);
    List<DsxSymbol> dsxSymbols = dataService.getDsxSymbols();
    Map<Currency, CurrencyMetaData> currencies = dataService.getDsxCurrencies().stream().collect(Collectors.toMap(dsxCurrency -> new Currency(dsxCurrency.getId()), dsxCurrency -> new CurrencyMetaData(null, dsxCurrency.getPayoutFee())));
    Map<CurrencyPair, CurrencyPairMetaData> currencyPairs = dsxSymbols.stream().collect(Collectors.toMap(dsxSymbol -> new CurrencyPair(new Currency(dsxSymbol.getBaseCurrency()), new Currency(dsxSymbol.getQuoteCurrency())), dsxSymbol -> new CurrencyPairMetaData(null, dsxSymbol.getQuantityIncrement(), null, dsxSymbol.getTickSize().scale(), null)));
    exchangeMetaData = DsxAdapters.adaptToExchangeMetaData(dsxSymbols, currencies, currencyPairs);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Logger(org.slf4j.Logger) DsxMarketDataServiceRaw(org.knowm.xchange.dsx.service.DsxMarketDataServiceRaw) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Exchange(org.knowm.xchange.Exchange) DsxTradeService(org.knowm.xchange.dsx.service.DsxTradeService) Field(java.lang.reflect.Field) Collectors(java.util.stream.Collectors) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BaseExchange(org.knowm.xchange.BaseExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) DsxMarketDataService(org.knowm.xchange.dsx.service.DsxMarketDataService) DsxSymbol(org.knowm.xchange.dsx.dto.DsxSymbol) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) DsxAccountService(org.knowm.xchange.dsx.service.DsxAccountService) InputStream(java.io.InputStream) DsxMetaData(org.knowm.xchange.dsx.dto.DsxMetaData) CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) DsxMarketDataServiceRaw(org.knowm.xchange.dsx.service.DsxMarketDataServiceRaw) Currency(org.knowm.xchange.currency.Currency) DsxSymbol(org.knowm.xchange.dsx.dto.DsxSymbol) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 27 with CurrencyMetaData

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

the class BitmexExchange method updateExchangeMetaData.

public void updateExchangeMetaData() {
    List<BitmexTicker> tickers = ((BitmexMarketDataServiceRaw) marketDataService).getActiveTickers();
    List<CurrencyPair> activeCurrencyPairs = new ArrayList<>();
    Set<Currency> activeCurrencies = new HashSet<>();
    tickers.forEach(ticker -> collectCurrenciesAndPairs(ticker, activeCurrencyPairs, activeCurrencies));
    Map<CurrencyPair, CurrencyPairMetaData> pairsMap = exchangeMetaData.getCurrencyPairs();
    Map<Currency, CurrencyMetaData> currenciesMap = exchangeMetaData.getCurrencies();
    // Remove pairs that are no-longer in use
    pairsMap.keySet().retainAll(activeCurrencyPairs);
    // Remove currencies that are no-longer in use
    currenciesMap.keySet().retainAll(activeCurrencies);
    // Add missing pairs and currencies
    activeCurrencyPairs.forEach(cp -> {
        if (!pairsMap.containsKey(cp)) {
            pairsMap.put(cp, new CurrencyPairMetaData(null, BigDecimal.ONE, null, getPriceScale(tickers, cp), null));
        }
        if (!currenciesMap.containsKey(cp.base)) {
            currenciesMap.put(cp.base, null);
        }
        if (!currenciesMap.containsKey(cp.counter)) {
            currenciesMap.put(cp.counter, null);
        }
    });
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) BitmexMarketDataServiceRaw(org.knowm.xchange.bitmex.service.BitmexMarketDataServiceRaw) ArrayList(java.util.ArrayList) BitmexTicker(org.knowm.xchange.bitmex.dto.account.BitmexTicker) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) HashSet(java.util.HashSet)

Example 28 with CurrencyMetaData

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

the class DeribitExchange method updateExchangeMetaData.

public void updateExchangeMetaData() throws IOException {
    Map<Currency, CurrencyMetaData> currencies = exchangeMetaData.getCurrencies();
    Map<FuturesContract, DerivativeMetaData> futures = exchangeMetaData.getFutures();
    Map<OptionsContract, DerivativeMetaData> options = exchangeMetaData.getOptions();
    List<DeribitCurrency> activeDeribitCurrencies = ((DeribitMarketDataServiceRaw) marketDataService).getDeribitCurrencies();
    currencies.clear();
    futures.clear();
    options.clear();
    for (DeribitCurrency deribitCurrency : activeDeribitCurrencies) {
        currencies.put(new Currency(deribitCurrency.getCurrency()), DeribitAdapters.adaptMeta(deribitCurrency));
        List<DeribitInstrument> deribitInstruments = ((DeribitMarketDataServiceRaw) marketDataService).getDeribitInstruments(deribitCurrency.getCurrency(), null, null);
        for (DeribitInstrument deribitInstrument : deribitInstruments) {
            if (deribitInstrument.getKind() == Kind.future) {
                futures.put(DeribitAdapters.adaptFuturesContract(deribitInstrument), DeribitAdapters.adaptMeta(deribitInstrument));
            } else {
                options.put(DeribitAdapters.adaptOptionsContract(deribitInstrument), DeribitAdapters.adaptMeta(deribitInstrument));
            }
        }
    }
}
Also used : DerivativeMetaData(org.knowm.xchange.dto.meta.DerivativeMetaData) DeribitInstrument(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) FuturesContract(org.knowm.xchange.derivative.FuturesContract) OptionsContract(org.knowm.xchange.derivative.OptionsContract) DeribitCurrency(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitCurrency) Currency(org.knowm.xchange.currency.Currency) DeribitCurrency(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitCurrency) DeribitMarketDataServiceRaw(org.knowm.xchange.deribit.v2.service.DeribitMarketDataServiceRaw)

Example 29 with CurrencyMetaData

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

the class BleutradeExchangeIntegration method shouldMakeRemoteInit.

@Test
public void shouldMakeRemoteInit() throws IOException {
    // given
    BleutradeCurrenciesReturn bleutradeCurrenciesReturn = new BleutradeCurrenciesReturn(asList(createBleutradeCurrency("BTC", "Bitcoin", 2, new BigDecimal("0.00080000"), true, "BITCOIN"), createBleutradeCurrency("LTC", "Litecoin", 4, new BigDecimal("0.02000000"), true, "BITCOIN")));
    BleutradeMarketsReturn bleutradeMarketsReturn = new BleutradeMarketsReturn(asList(createBleutradeMarket("DOGE", "BTC", "Dogecoin", "Bitcoin", new BigDecimal("0.10000000"), "DOGE_BTC", true), createBleutradeMarket("BLEU", "BTC", "Bleutrade Share", "Bitcoin", new BigDecimal("0.00000001"), "BLEU_BTC", true)));
    BleutradeAuthenticated bleutrade = mock(BleutradeAuthenticated.class);
    when(bleutrade.getBleutradeCurrencies()).thenReturn(bleutradeCurrenciesReturn);
    when(bleutrade.getBleutradeMarkets()).thenReturn(bleutradeMarketsReturn);
    IRestProxyFactory restProxyFactory = mock(IRestProxyFactory.class);
    when(restProxyFactory.createProxy(eq(BleutradeAuthenticated.class), any(String.class), any(ClientConfig.class))).thenReturn(bleutrade);
    BleutradeExchange mockExchange = new BleutradeExchange(restProxyFactory);
    mockExchange.applySpecification(mockExchange.getDefaultExchangeSpecification());
    mockExchange.initServices();
    // when
    mockExchange.remoteInit();
    // then
    Map<Currency, CurrencyMetaData> currencyMetaDataMap = mockExchange.getExchangeMetaData().getCurrencies();
    assertThat(currencyMetaDataMap).hasSize(2);
    assertThat(currencyMetaDataMap.get(Currency.BTC).getScale()).isEqualTo(8);
    assertThat(currencyMetaDataMap.get(Currency.LTC).getScale()).isEqualTo(8);
    Map<CurrencyPair, CurrencyPairMetaData> marketMetaDataMap = mockExchange.getExchangeMetaData().getCurrencyPairs();
    assertThat(marketMetaDataMap).hasSize(2);
    assertThat(marketMetaDataMap.get(CurrencyPair.DOGE_BTC).toString()).isEqualTo("CurrencyPairMetaData [tradingFee=0.0025, minimumAmount=0.10000000, maximumAmount=null, baseScale=null, priceScale=8, volumeScale=null, amountStepSize=null, tradingFeeCurrency=null]");
    assertThat(marketMetaDataMap.get(BLEU_BTC_CP).toString()).isEqualTo("CurrencyPairMetaData [tradingFee=0.0025, minimumAmount=1E-8, maximumAmount=null, baseScale=null, priceScale=8, volumeScale=null, amountStepSize=null, tradingFeeCurrency=null]");
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BleutradeMarketsReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarketsReturn) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) IRestProxyFactory(si.mazi.rescu.IRestProxyFactory) BigDecimal(java.math.BigDecimal) Currency(org.knowm.xchange.currency.Currency) ClientConfig(si.mazi.rescu.ClientConfig) BleutradeCurrenciesReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeCurrenciesReturn) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Example 30 with CurrencyMetaData

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

the class BleutradeAdaptersTest method shouldAdaptExchangeMetaData.

@Test
public void shouldAdaptExchangeMetaData() throws IOException {
    // given
    final BleutradeCurrenciesReturn currenciesResponse = parse(BleutradeCurrenciesReturn.class);
    final BleutradeMarketsReturn marketsResponse = parse(BleutradeMarketsReturn.class);
    final CurrencyPairMetaData[] expectedMetaDataList = expectedMetaDataList();
    final String[] expectedMetaDataStr = expectedMetaDataStr();
    // when
    ExchangeMetaData exchangeMetaData = BleutradeAdapters.adaptToExchangeMetaData(currenciesResponse.getResult(), marketsResponse.getResult());
    // then
    Map<Currency, CurrencyMetaData> currencyMetaDataMap = exchangeMetaData.getCurrencies();
    assertThat(currencyMetaDataMap).hasSize(2);
    assertThat(currencyMetaDataMap.get(Currency.BTC).getScale()).isEqualTo(8);
    assertThat(currencyMetaDataMap.get(Currency.LTC).getScale()).isEqualTo(8);
    Map<CurrencyPair, CurrencyPairMetaData> marketMetaDataMap = exchangeMetaData.getCurrencyPairs();
    assertThat(marketMetaDataMap).hasSize(2);
    // there is no reliable information about valid tradingFee calculation formula
    BleutradeAssert.assertEquals(marketMetaDataMap.get(CurrencyPair.DOGE_BTC), expectedMetaDataList[0]);
    assertThat(marketMetaDataMap.get(CurrencyPair.DOGE_BTC).toString()).isEqualTo(expectedMetaDataStr[0]);
    BleutradeAssert.assertEquals(marketMetaDataMap.get(BLEU_BTC_CP), expectedMetaDataList[1]);
    assertThat(marketMetaDataMap.get(BLEU_BTC_CP).toString()).isEqualTo(expectedMetaDataStr[1]);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BleutradeMarketsReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarketsReturn) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) Currency(org.knowm.xchange.currency.Currency) BleutradeCurrenciesReturn(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeCurrenciesReturn) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) Test(org.junit.Test)

Aggregations

CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)42 Currency (org.knowm.xchange.currency.Currency)34 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)32 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)32 BigDecimal (java.math.BigDecimal)19 ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)17 HashMap (java.util.HashMap)14 FeeTier (org.knowm.xchange.dto.meta.FeeTier)7 WalletHealth (org.knowm.xchange.dto.meta.WalletHealth)7 Map (java.util.Map)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 Fee (org.knowm.xchange.dto.account.Fee)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 InputStream (java.io.InputStream)2 Field (java.lang.reflect.Field)2 Modifier (java.lang.reflect.Modifier)2 HttpURLConnection (java.net.HttpURLConnection)2