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