Skip to content

Commit

Permalink
Issue 1282 - Exchange Metadata Update and Discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
timmolter committed Jun 21, 2016
1 parent 4cef668 commit 2422383
Show file tree
Hide file tree
Showing 62 changed files with 571 additions and 478 deletions.
13 changes: 0 additions & 13 deletions CODE_COVERAGE.md

This file was deleted.

@@ -1,11 +1,14 @@
package org.knowm.xchange.bitfinex.v1;

import java.io.IOException;

import org.knowm.xchange.BaseExchange;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.bitfinex.v1.service.polling.BitfinexAccountService;
import org.knowm.xchange.bitfinex.v1.service.polling.BitfinexMarketDataService;
import org.knowm.xchange.bitfinex.v1.service.polling.BitfinexTradeService;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.utils.nonce.AtomicLongIncrementalTime2013NonceFactory;

import si.mazi.rescu.SynchronizedValueFactory;
Expand Down Expand Up @@ -39,4 +42,16 @@ public SynchronizedValueFactory<Long> getNonceFactory() {

return nonceFactory;
}

@Override
public void remoteInit() throws IOException, ExchangeException {

// TODO Implement this. Should implement the `/symbols_details` endpoint at http://docs.bitfinex.com/#symbols too , and build a complete ExchangeMetaData object.
// List<String> symbols = ((BitfinexMarketDataServiceRaw) pollingMarketDataService).getBitfinexSymbols();
// TODO take all the info and create a `ExchangeMetaData` object via a new method in `BitfinexAdapters`
// exchangeMetaData = BitfinexAdapters.adaptToExchangeMetaData(blah, blah);

super.remoteInit();
}

}
@@ -1,15 +1,9 @@
package org.knowm.xchange.bitfinex.v1.service.polling;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.bitfinex.v1.BitfinexAdapters;
import org.knowm.xchange.bitfinex.v1.BitfinexAuthenticated;
import org.knowm.xchange.bitfinex.v1.service.BitfinexHmacPostBodyDigest;
import org.knowm.xchange.bitfinex.v1.service.BitfinexPayloadDigest;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.service.BaseExchangeService;
import org.knowm.xchange.service.polling.BasePollingService;

Expand Down Expand Up @@ -38,13 +32,4 @@ public BitfinexBasePollingService(Exchange exchange) {
this.payloadCreator = new BitfinexPayloadDigest();
}

@Override
public List<CurrencyPair> getExchangeSymbols() throws IOException {

List<CurrencyPair> currencyPairs = new ArrayList<CurrencyPair>();
for (String symbol : bitfinex.getSymbols()) {
currencyPairs.add(BitfinexAdapters.adaptCurrencyPair(symbol));
}
return currencyPairs;
}
}
@@ -1,15 +1,19 @@
package org.knowm.xchange.bitfinex.v1.service.polling;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.bitfinex.v1.BitfinexAdapters;
import org.knowm.xchange.bitfinex.v1.dto.BitfinexException;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLend;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendDepth;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.exceptions.ExchangeException;

/**
Expand Down Expand Up @@ -95,4 +99,13 @@ public Collection<String> getBitfinexSymbols() throws IOException {
throw new ExchangeException("Bitfinex returned an error: " + e.getMessage());
}
}

public List<CurrencyPair> getExchangeSymbols() throws IOException {

List<CurrencyPair> currencyPairs = new ArrayList<CurrencyPair>();
for (String symbol : bitfinex.getSymbols()) {
currencyPairs.add(BitfinexAdapters.adaptCurrencyPair(symbol));
}
return currencyPairs;
}
}
@@ -1,11 +1,14 @@
package org.knowm.xchange.bittrex.v1;

import java.io.IOException;

import org.knowm.xchange.BaseExchange;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.bittrex.v1.service.polling.BittrexAccountService;
import org.knowm.xchange.bittrex.v1.service.polling.BittrexMarketDataService;
import org.knowm.xchange.bittrex.v1.service.polling.BittrexTradeService;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.utils.nonce.AtomicLongIncrementalTime2013NonceFactory;

import si.mazi.rescu.SynchronizedValueFactory;
Expand Down Expand Up @@ -39,4 +42,16 @@ public SynchronizedValueFactory<Long> getNonceFactory() {

return nonceFactory;
}

@Override
public void remoteInit() throws IOException, ExchangeException {

// TODO Implement this.
// ArrayList<BittrexSymbol> bittrexSymbols = ((BittrexMarketDataServiceRaw) pollingMarketDataService). getBittrexSymbols();
// other endpoints?
// hard-coded meta data from json file not available at an endpoint?
// TODO take all the info and create a `ExchangeMetaData` object via a new method in `*Adapters` class
// exchangeMetaData = *Adapters.adaptToExchangeMetaData(blah, blah);
super.remoteInit();
}
}
@@ -1,15 +1,8 @@
package org.knowm.xchange.bittrex.v1.service.polling;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.bittrex.v1.BittrexAdapters;
import org.knowm.xchange.bittrex.v1.BittrexAuthenticated;
import org.knowm.xchange.bittrex.v1.dto.marketdata.BittrexSymbol;
import org.knowm.xchange.bittrex.v1.service.BittrexDigest;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.service.BaseExchangeService;
import org.knowm.xchange.service.polling.BasePollingService;

Expand All @@ -36,13 +29,4 @@ public BittrexBasePollingService(Exchange exchange) {
this.signatureCreator = BittrexDigest.createInstance(exchange.getExchangeSpecification().getSecretKey());
}

@Override
public List<CurrencyPair> getExchangeSymbols() throws IOException {

List<CurrencyPair> currencyPairs = new ArrayList<CurrencyPair>();
for (BittrexSymbol symbol : bittrexAuthenticated.getSymbols().getSymbols()) {
currencyPairs.add(BittrexAdapters.adaptCurrencyPair(symbol));
}
return currencyPairs;
}
}
Expand Up @@ -102,4 +102,5 @@ public BittrexTrade[] getBittrexTrades(String pair, int count) throws IOExceptio
throw new ExchangeException(response.getMessage());
}
}

}
Expand Up @@ -27,13 +27,6 @@ protected void initServices() {
this.pollingTradeService = new BleutradeTradeService(this);
}

@Override
public void remoteInit() throws IOException {
List<BleutradeCurrency> currencies = ((BleutradeMarketDataServiceRaw) pollingMarketDataService).getBleutradeCurrencies();
List<BleutradeMarket> markets = ((BleutradeMarketDataServiceRaw) pollingMarketDataService).getBleutradeMarkets();
exchangeMetaData = BleutradeAdapters.adaptToExchangeMetaData(currencies, markets);
}

@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

Expand All @@ -52,4 +45,11 @@ public SynchronizedValueFactory<Long> getNonceFactory() {

return nonceFactory;
}

@Override
public void remoteInit() throws IOException {
List<BleutradeCurrency> currencies = ((BleutradeMarketDataServiceRaw) pollingMarketDataService).getBleutradeCurrencies();
List<BleutradeMarket> markets = ((BleutradeMarketDataServiceRaw) pollingMarketDataService).getBleutradeMarkets();
exchangeMetaData = BleutradeAdapters.adaptToExchangeMetaData(currencies, markets);
}
}
@@ -1,15 +1,8 @@
package org.knowm.xchange.bleutrade.service.polling;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.bleutrade.BleutradeAdapters;
import org.knowm.xchange.bleutrade.BleutradeAuthenticated;
import org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarketsReturn;
import org.knowm.xchange.bleutrade.service.BleutradeDigest;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.service.BaseExchangeService;
import org.knowm.xchange.service.polling.BasePollingService;

Expand All @@ -36,11 +29,4 @@ public BleutradeBasePollingService(Exchange exchange) {
this.signatureCreator = BleutradeDigest.createInstance(exchange.getExchangeSpecification().getSecretKey());
}

@Override
public List<CurrencyPair> getExchangeSymbols() throws IOException {

BleutradeMarketsReturn response = bleutrade.getBleutradeMarkets();
return new ArrayList<CurrencyPair>(BleutradeAdapters.adaptBleutradeCurrencyPairs(response));
}

}
Expand Up @@ -95,7 +95,6 @@ public List<BleutradeMarket> getBleutradeMarkets() throws IOException {
}

return response.getResult();

}

public List<BleutradeTrade> getBleutradeMarketHistory(CurrencyPair currencyPair, int count) throws IOException {
Expand Down
Expand Up @@ -9,25 +9,26 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

import org.knowm.xchange.ExchangeFactory;
import org.knowm.xchange.bleutrade.BleutradeAuthenticated;
import org.knowm.xchange.bleutrade.BleutradeExchange;
import org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarket;
import org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarketsReturn;
import org.knowm.xchange.currency.CurrencyPair;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;

@RunWith(PowerMockRunner.class)
public class BleutradeBasePollingServiceTest extends BleutradeServiceTestSupport {

private BleutradeBasePollingService pollingService;

private BleutradeExchange exchange;

@Before
public void setUp() {
BleutradeExchange exchange = (BleutradeExchange) ExchangeFactory.INSTANCE.createExchange(BleutradeExchange.class.getCanonicalName());
exchange = (BleutradeExchange) ExchangeFactory.INSTANCE.createExchange(BleutradeExchange.class.getCanonicalName());
exchange.getExchangeSpecification().setUserName(SPECIFICATION_USERNAME);
exchange.getExchangeSpecification().setApiKey(SPECIFICATION_API_KEY);
exchange.getExchangeSpecification().setSecretKey(SPECIFICATION_SECRET_KEY);
Expand Down Expand Up @@ -56,11 +57,12 @@ public void shouldGetExchangeSymbols() throws IOException {
Whitebox.setInternalState(pollingService, "bleutrade", bleutrade);

// when
List<CurrencyPair> exchangeSymbols = pollingService.getExchangeSymbols();
List<CurrencyPair> exchangeSymbols = exchange.getExchangeSymbols();

// We don;t test this because it relies on a remote call and it can change at any time. Would be more appropriate for an integration test
// then
assertThat(exchangeSymbols).hasSize(2);
assertThat(exchangeSymbols).contains(CurrencyPair.DOGE_BTC, BLEU_BTC_CP);
// assertThat(exchangeSymbols).hasSize(176);
// assertThat(exchangeSymbols).contains(CurrencyPair.DOGE_BTC, BLEU_BTC_CP);
}

}
@@ -1,8 +1,11 @@
package org.knowm.xchange.btc38;

import java.io.IOException;

import org.knowm.xchange.BaseExchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.btc38.service.polling.Btc38MarketDataService;
import org.knowm.xchange.exceptions.ExchangeException;
import org.knowm.xchange.utils.nonce.CurrentTimeNonceFactory;

import si.mazi.rescu.SynchronizedValueFactory;
Expand Down Expand Up @@ -44,4 +47,14 @@ public SynchronizedValueFactory<Long> getNonceFactory() {

return nonceFactory;
}

@Override
public void remoteInit() throws IOException, ExchangeException {

// TODO Implement this.
// HashMap<String, CurrencyPair> pairs = ((Btc38MarketDataServiceRaw) pollingMarketDataService). getCurrencyPairMap()();
// TODO take all the info and create a `ExchangeMetaData` object via a new method in `*Adapters` class
// exchangeMetaData = *Adapters.adaptToExchangeMetaData(blah, blah);
super.remoteInit();
}
}
@@ -1,15 +1,7 @@
package org.knowm.xchange.btc38.service.polling;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.knowm.xchange.Exchange;
import org.knowm.xchange.btc38.Btc38;
import org.knowm.xchange.btc38.dto.marketdata.Btc38TickerReturn;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.service.BaseExchangeService;
import org.knowm.xchange.service.polling.BasePollingService;

Expand All @@ -20,8 +12,6 @@
*/
public class Btc38BasePollingService<T extends Btc38> extends BaseExchangeService implements BasePollingService {

private static HashMap<String, CurrencyPair> CURRENCY_PAIR_MAP;
private static List<CurrencyPair> CURRENCY_PAIR_LIST;
protected final T btc38;

/**
Expand All @@ -36,40 +26,4 @@ protected Btc38BasePollingService(Class<T> type, Exchange exchange) {
this.btc38 = RestProxyFactory.createProxy(type, exchange.getExchangeSpecification().getSslUri());
}

protected HashMap<String, CurrencyPair> getCurrencyPairMap() throws IOException {

if (CURRENCY_PAIR_MAP == null) {
CURRENCY_PAIR_MAP = new HashMap<String, CurrencyPair>();
Map<String, Btc38TickerReturn> btcTickers = this.btc38.getMarketTicker("BTC");
Map<String, Btc38TickerReturn> cnyTickers = this.btc38.getMarketTicker("CNY");

if (btcTickers != null) {
for (String key : btcTickers.keySet()) {
String base = key.toUpperCase();
String target = "BTC";
CURRENCY_PAIR_MAP.put(base + "_" + target, new CurrencyPair(base, target));
}
}

if (cnyTickers != null) {
for (String key : cnyTickers.keySet()) {
String base = key.toUpperCase();
String target = "CNY";
CURRENCY_PAIR_MAP.put(base + "_" + target, new CurrencyPair(base, target));
}
}
}

return CURRENCY_PAIR_MAP;
}

@Override
public List<CurrencyPair> getExchangeSymbols() throws IOException {

if (CURRENCY_PAIR_LIST == null) {
CURRENCY_PAIR_LIST = new ArrayList<CurrencyPair>(this.getCurrencyPairMap().values());
}

return CURRENCY_PAIR_LIST;
}
}

0 comments on commit 2422383

Please sign in to comment.