Skip to content

Commit

Permalink
Replace SimpleMetaData with ExchangeMetaData
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalkrupinski committed Jul 7, 2015
1 parent 6af9a46 commit e2d4d3d
Show file tree
Hide file tree
Showing 94 changed files with 330 additions and 713 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.xeiam.xchange.anx.v2.dto.marketdata.ANXOrder;
import com.xeiam.xchange.anx.v2.dto.marketdata.ANXTicker;
import com.xeiam.xchange.anx.v2.dto.marketdata.ANXTrade;
import com.xeiam.xchange.anx.v2.dto.meta.ANXMarketMetaData;
import com.xeiam.xchange.anx.v2.dto.meta.ANXMetaData;
import com.xeiam.xchange.anx.v2.dto.trade.polling.ANXOpenOrder;
import com.xeiam.xchange.anx.v2.dto.trade.polling.ANXTradeResult;
Expand All @@ -19,8 +18,6 @@
import com.xeiam.xchange.dto.marketdata.Trade;
import com.xeiam.xchange.dto.marketdata.Trades;
import com.xeiam.xchange.dto.marketdata.Trades.TradeSortType;
import com.xeiam.xchange.dto.meta.ExchangeMetaData;
import com.xeiam.xchange.dto.meta.MarketMetaData;
import com.xeiam.xchange.dto.trade.LimitOrder;
import com.xeiam.xchange.dto.trade.UserTrade;
import com.xeiam.xchange.dto.trade.UserTrades;
Expand Down Expand Up @@ -241,7 +238,7 @@ private static UserTrade adaptUserTrade(ANXTradeResult aNXTradeResult, ANXMetaDa

BigDecimal tradedCurrencyFillAmount = aNXTradeResult.getTradedCurrencyFillAmount();
CurrencyPair currencyPair = adaptCurrencyPair(aNXTradeResult.getCurrencyPair());
int priceScale = meta.currencyPair.get(currencyPair).priceScale;
int priceScale = meta.currencyPair.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.
Expand All @@ -264,17 +261,4 @@ private static OrderType adaptSide(String side) {

return SIDE_BID.equals(side) ? OrderType.BID : OrderType.ASK;
}

public static ExchangeMetaData adaptMetaData(ANXMetaData anx) {
HashMap<CurrencyPair, MarketMetaData> marketMetaDataMap = new HashMap<CurrencyPair, MarketMetaData>();
for (Map.Entry<CurrencyPair, ANXMarketMetaData> e : anx.currencyPair.entrySet()) {
MarketMetaData meta = adaptMarketMetaData(anx, e.getValue());
marketMetaDataMap.put(e.getKey(), meta);
}
return new ExchangeMetaData(marketMetaDataMap, anx.currencies, 1000 / Math.min(anx.maxPrivatePollRatePerSecond, anx.maxPublicPollRatePerSecond));
}

private static MarketMetaData adaptMarketMetaData(ANXMetaData metaData, ANXMarketMetaData marketMetaData) {
return new MarketMetaData(metaData.takerTradingFee, marketMetaData.minimumAmount, marketMetaData.priceScale);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,13 @@ public SynchronizedValueFactory<Long> getNonceFactory() {

private ANXMetaData anxMetaData;

public ANXMetaData getANXMetaData(){
public ANXMetaData getANXMetaData() {
return anxMetaData;
}

@Override
protected void loadMetaData(InputStream is) {
anxMetaData = loadMetaData(is, ANXMetaData.class);
if (anxMetaData != null)
metaData = ANXAdapters.adaptMetaData(anxMetaData);
metaData = anxMetaData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import java.math.BigDecimal;

public class ANXMarketMetaData {
public BigDecimal minimumAmount;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.xeiam.xchange.dto.meta.MarketMetaData;

public class ANXMarketMetaData extends MarketMetaData{
public BigDecimal maximumAmount;
public int priceScale;

public ANXMarketMetaData() {
}
public ANXMarketMetaData(@JsonProperty("tradingFee") BigDecimal tradingFee, @JsonProperty("minAmount") BigDecimal minimumAmount, @JsonProperty("maxAmount") BigDecimal maximumAmount, @JsonProperty("priceScale") int priceScale) {
super(tradingFee, minimumAmount, priceScale);

public ANXMarketMetaData(BigDecimal minimumAmount, BigDecimal maximumAmount, int priceScale) {
this.minimumAmount = minimumAmount;
this.maximumAmount = maximumAmount;
this.priceScale = priceScale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,27 @@

import java.math.BigDecimal;
import java.util.Map;
import java.util.Set;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.meta.CurrencyMetaData;
import com.xeiam.xchange.dto.meta.ExchangeMetaData;
import com.xeiam.xchange.dto.meta.RateLimit;

public class ANXMetaData {
@JsonProperty("currencyPair")
public class ANXMetaData extends ExchangeMetaData {
public Map<CurrencyPair, ANXMarketMetaData> currencyPair;

@JsonProperty("currencies")
public Map<String, CurrencyMetaData> currencies;

@JsonProperty("makerTradingFee")
public BigDecimal makerTradingFee;

@JsonProperty("takerTradingFee")
public BigDecimal takerTradingFee;

@JsonProperty("max_private_poll_rate_per_second")
public Integer maxPrivatePollRatePerSecond;

@JsonProperty("max_private_poll_rate_per_10_second")
public Integer maxPrivatePollRatePer10Second;

@JsonProperty("max_private_poll_rate_per_hour")
public Integer maxPrivatePollRatePerHour;

@JsonProperty("max_public_poll_rate_per_second")
public Integer maxPublicPollRatePerSecond;

public ANXMetaData() {
}
public ANXMetaData(@JsonProperty("currencyPair") Map<CurrencyPair, ANXMarketMetaData> currencyPairs, @JsonProperty("currency") Map<String, CurrencyMetaData> currency,
@JsonProperty("publicRateLimits") Set<RateLimit> publicRateLimits, @JsonProperty("privateRateLimits") Set<RateLimit> privateRateLimits,
@JsonProperty("shareRateLimits") Boolean shareRateLimits,
@JsonProperty("makerTradingFee") BigDecimal makerTradingFee, @JsonProperty("takerTradingFee") BigDecimal takerTradingFee) {
super((Map) currencyPairs, currency, publicRateLimits, privateRateLimits, shareRateLimits);

public ANXMetaData(Map<CurrencyPair, ANXMarketMetaData> currencyPair, Map<String, CurrencyMetaData> currencies, BigDecimal makerTradingFee, BigDecimal takerTradingFee,
int maxPrivatePollRatePerSecond, int maxPrivatePollRatePer10Second, int maxPrivatePollRatePerHour, int maxPublicPollRatePerSecond) {
this.currencyPair = currencyPair;
this.currencies = currencies;
this.currencyPair = currencyPairs;
this.makerTradingFee = makerTradingFee;
this.takerTradingFee = takerTradingFee;
this.maxPrivatePollRatePerSecond = maxPrivatePollRatePerSecond;
this.maxPrivatePollRatePer10Second = maxPrivatePollRatePer10Second;
this.maxPrivatePollRatePerHour = maxPrivatePollRatePerHour;
this.maxPublicPollRatePerSecond = maxPublicPollRatePerSecond;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,4 @@ public TradeHistoryParams createTradeHistoryParams() {

return new DefaultTradeHistoryParamsTimeSpan();
}

@Override
public void verifyOrder(LimitOrder limitOrder) {
verifyOrder2(limitOrder);
}

@Override
public void verifyOrder(MarketOrder marketOrder) {
verifyOrder2(marketOrder);
}
}
26 changes: 21 additions & 5 deletions xchange-anx/src/main/resources/anxpro.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"priceScale": 8
}
},
"currencies": {
"currency": {
"AUD": {
"scale": 2
},
Expand Down Expand Up @@ -195,8 +195,24 @@
},
"makerTradingFee": 0.003,
"takerTradingFee": 0.006,
"max_private_poll_rate_per_second": 30,
"max_private_poll_rate_per_10_second": 60,
"max_private_poll_rate_per_hour": 50000,
"max_public_poll_rate_per_second": 5
"privateRateLimits": [
{
"calls": 30,
"timeUnit": "seconds"
},
{
"calls": 60,
"timeSpan": 10,
"timeUnit": "seconds"
},
{
"calls": 50000,
"timeUnit": "hours"
}
],
"publicRateLimits": [
{
"calls": 5
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private void run() throws IOException {
for (CurrencyPair pair : pairs) {
handleCurrencyPair(map, pair);
}

ANXMetaData metaData = new ANXMetaData(map, currencyMap, fee.divide(new BigDecimal(2), RoundingMode.UNNECESSARY), fee, 30, 60, 50000, 5);
// TODO add RateLimits, fees
ANXMetaData metaData = new ANXMetaData(map, currencyMap, null, null, null, null, null);

mapper.writeValue(out, metaData);
out.println();
Expand All @@ -107,7 +107,7 @@ private void handleCurrencyPair(Map<CurrencyPair, ANXMarketMetaData> map, Curren
int amountScale = amountScale(currencyPair);
BigDecimal minimumAmount = scaled(minAmount.get(currencyPair.baseSymbol), amountScale);
BigDecimal maximumAmount = scaled(maxAmount.get(currencyPair.baseSymbol), amountScale);
ANXMarketMetaData mmd = new ANXMarketMetaData(minimumAmount, maximumAmount, priceScale(currencyPair));
ANXMarketMetaData mmd = new ANXMarketMetaData(fee, minimumAmount, maximumAmount, priceScale(currencyPair));
map.put(currencyPair, mmd);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testCurrencies() throws Exception {
Exchange exchange = ExchangeFactory.INSTANCE.createExchange(ANXExchange.class.getName());
ANXMetaData anxMetaData = ((ANXExchange) exchange).getANXMetaData();

assertEquals(wallets.keySet(), anxMetaData.currencies.keySet());
assertEquals(wallets.keySet(), anxMetaData.getCurrencyMetaDataMap().keySet());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,4 @@ public SynchronizedValueFactory<Long> getNonceFactory() {
// No private API implemented. Not needed for this exchange at the moment.
return null;
}

@Override
protected void loadMetaData(InputStream is) {
loadExchangeMetaData(is);
}
}
3 changes: 1 addition & 2 deletions xchange-bitbay/src/main/resources/bitbay.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@
"USD": {
"scale": 2
}
},
"minPollDelay": 0
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.xeiam.xchange.bitcoinaverage;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -10,6 +11,7 @@
import com.xeiam.xchange.bitcoinaverage.dto.meta.BitcoinAverageMetaData;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.marketdata.Ticker;
import com.xeiam.xchange.dto.meta.CurrencyMetaData;
import com.xeiam.xchange.dto.meta.ExchangeMetaData;
import com.xeiam.xchange.dto.meta.MarketMetaData;

Expand All @@ -31,8 +33,6 @@ private BitcoinAverageAdapters() {
* Adapts a BitcoinAverageTicker to a Ticker Object
*
* @param bitcoinAverageTicker
* @param currency
* @param tradableIdentifier
* @return Ticker
*/
public static Ticker adaptTicker(BitcoinAverageTicker bitcoinAverageTicker, CurrencyPair currencyPair) {
Expand All @@ -50,6 +50,6 @@ public static ExchangeMetaData adaptMetaData(BitcoinAverageTickers tickers, Bitc
Map<CurrencyPair, MarketMetaData> currencyPairs = new HashMap<CurrencyPair, MarketMetaData>();
for (String currency : tickers.getTickers().keySet())
currencyPairs.put(new CurrencyPair(BTC, currency), new MarketMetaData(null, null, bAMetaData.priceScale));
return new ExchangeMetaData(currencyPairs, null, 0);
return new ExchangeMetaData(currencyPairs, Collections.<String, CurrencyMetaData>emptyMap(), null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.xeiam.xchange.bitcoincharts.dto.marketdata.BitcoinChartsTicker;
import com.xeiam.xchange.currency.Currencies;
import com.xeiam.xchange.currency.CurrencyPair;
import com.xeiam.xchange.dto.marketdata.Ticker;
import com.xeiam.xchange.dto.meta.ExchangeMetaData;
import com.xeiam.xchange.dto.meta.MarketMetaData;
import com.xeiam.xchange.dto.meta.SimpleMetaData;

/**
* Various adapters for converting from BitcoinCharts DTOs to XChange DTOs
Expand Down Expand Up @@ -53,7 +51,7 @@ public static Ticker adaptTicker(BitcoinChartsTicker[] bitcoinChartsTickers, Cur
return null;
}

public static ExchangeMetaData adaptMetaData(SimpleMetaData simpleMetaData, BitcoinChartsTicker[] tickers) {
public static ExchangeMetaData adaptMetaData(ExchangeMetaData exchangeMetaData, BitcoinChartsTicker[] tickers) {
Map<CurrencyPair, MarketMetaData> pairs = new HashMap<CurrencyPair, MarketMetaData>();

for (BitcoinChartsTicker ticker : tickers) {
Expand All @@ -62,7 +60,8 @@ public static ExchangeMetaData adaptMetaData(SimpleMetaData simpleMetaData, Bitc
pairs.put(new CurrencyPair(Currencies.BTC, ticker.getSymbol()), new MarketMetaData(null, null, scale));
}

return new ExchangeMetaData(pairs, null, (int) TimeUnit.MINUTES.toMillis(60 / simpleMetaData.getMaxPublicPollRatePerHour()));
return new ExchangeMetaData(pairs, exchangeMetaData.getCurrencyMetaDataMap(), exchangeMetaData.getPublicRateLimits(), exchangeMetaData.getPrivateRateLimits(),
exchangeMetaData.isShareRateLimits());
}

private static <T> T firstNonNull(T... objects) {
Expand Down
7 changes: 6 additions & 1 deletion xchange-bitcoincharts/src/main/resources/bitcoincharts.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
"max_public_poll_rate_per_hour":4
"privateRateLimits": [
{
"calls": 4,
"timeUnit": "hours"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,4 @@ public SynchronizedValueFactory<Long> getNonceFactory() {
// moment.
return null;
}

@Override
protected void loadMetaData(InputStream is) {
loadExchangeMetaData(is);
}
}
17 changes: 15 additions & 2 deletions xchange-bitcoinde/src/main/resources/bitcoinde.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
"tradingFee": 0.5
}
},
"currency":{},
"minPollDelay": 30
"currency": {},
"publicRateLimits": [
{
"calls": 2,
"timeSpan": 1,
"timeUnit": "minutes"
}
],
"privateRateLimits": [
{
"calls": 1,
"timeSpan": 1,
"timeUnit": "minutes"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ public ExchangeSpecification getDefaultExchangeSpecification() {
return exchangeSpecification;
}

@Override
protected void loadMetaData(InputStream is) {
loadExchangeMetaData(is);
}

@Override
public SynchronizedValueFactory<Long> getNonceFactory() {
// No private API implemented. Not needed for this exchange at the moment.
Expand Down
Loading

0 comments on commit e2d4d3d

Please sign in to comment.