Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MaxNotional and PriceStepSize #4947

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,11 @@ public static void adaptFutureExchangeMetaData(
BigDecimal maxQty = null;
BigDecimal stepSize = null;

BigDecimal priceStepSize = null;

BigDecimal counterMinQty = null;
BigDecimal counterMaxQty = null;
BigDecimal counterMaxQtyFallback = null;

Instrument currentCurrencyPair =
new FuturesContract(
Expand All @@ -494,39 +497,57 @@ public static void adaptFutureExchangeMetaData(
for (Filter filter : futureSymbol.getFilters()) {
switch (filter.getFilterType()) {
case "PRICE_FILTER":
priceStepSize = new BigDecimal(filter.getTickSize()).stripTrailingZeros();
pairPrecision = Math.min(pairPrecision, numberOfDecimals(filter.getTickSize()));
counterMaxQty = new BigDecimal(filter.getMaxPrice()).stripTrailingZeros();
// why was here maxPrice as maxQty? used as fallback, but...
counterMaxQtyFallback = new BigDecimal(filter.getMaxPrice()).stripTrailingZeros();
break;
case "LOT_SIZE":
amountPrecision = Math.min(amountPrecision, numberOfDecimals(filter.getStepSize()));
minQty = new BigDecimal(filter.getMinQty()).stripTrailingZeros();
maxQty = new BigDecimal(filter.getMaxQty()).stripTrailingZeros();
stepSize = new BigDecimal(filter.getStepSize()).stripTrailingZeros();
break;
// US Binance
case "MIN_NOTIONAL":
counterMinQty =
(filter.getMinNotional() != null)
? new BigDecimal(filter.getMinNotional()).stripTrailingZeros()
: null;
break;
// NOT US Binance
case "NOTIONAL":
counterMinQty =
(filter.getMinNotional() != null)
? new BigDecimal(filter.getMinNotional()).stripTrailingZeros()
: null;
counterMaxQty =
(filter.getMaxNotional() != null)
? new BigDecimal(filter.getMaxNotional()).stripTrailingZeros()
: null;
break;
}
}

if (counterMaxQty == null) {
counterMaxQty = counterMaxQtyFallback;
}

exchangeMetaData
.getInstruments()
.put(
currentCurrencyPair,
new InstrumentMetaData.Builder()
.minimumAmount(minQty)
.maximumAmount(maxQty)
.counterMinimumAmount(counterMinQty)
.counterMaximumAmount(counterMaxQty)
.volumeScale(amountPrecision)
.priceScale(pairPrecision)
.amountStepSize(stepSize)
.marketOrderEnabled(
Arrays.asList(futureSymbol.getOrderTypes()).contains("MARKET"))
.build());
.minimumAmount(minQty)
.maximumAmount(maxQty)
.counterMinimumAmount(counterMinQty)
.counterMaximumAmount(counterMaxQty)
.volumeScale(amountPrecision)
.priceScale(pairPrecision)
.priceStepSize(priceStepSize)
.amountStepSize(stepSize)
.marketOrderEnabled(Arrays.asList(futureSymbol.getOrderTypes()).contains("MARKET"))
.build());
}
}
}
Expand All @@ -550,30 +571,54 @@ public static ExchangeMetaData adaptExchangeMetaData(
BigDecimal maxQty = null;
BigDecimal stepSize = null;

BigDecimal priceStepSize = null;

BigDecimal counterMinQty = null;
BigDecimal counterMaxQty = null;
BigDecimal counterMaxQtyFallback = null;

CurrencyPair currentCurrencyPair =
new CurrencyPair(symbol.getBaseAsset(), symbol.getQuoteAsset());
new CurrencyPair(symbol.getBaseAsset(), symbol.getQuoteAsset());

for (Filter filter : symbol.getFilters()) {
switch (filter.getFilterType()) {
case "PRICE_FILTER":
priceStepSize = new BigDecimal(filter.getTickSize()).stripTrailingZeros();
pairPrecision = Math.min(pairPrecision, numberOfDecimals(filter.getTickSize()));
counterMaxQty = new BigDecimal(filter.getMaxPrice()).stripTrailingZeros();
// why was here maxPrice as maxQty? used as fallback, but...
counterMaxQtyFallback = new BigDecimal(filter.getMaxPrice()).stripTrailingZeros();
break;
case "LOT_SIZE":
amountPrecision = Math.min(amountPrecision, numberOfDecimals(filter.getStepSize()));
minQty = new BigDecimal(filter.getMinQty()).stripTrailingZeros();
maxQty = new BigDecimal(filter.getMaxQty()).stripTrailingZeros();
stepSize = new BigDecimal(filter.getStepSize()).stripTrailingZeros();
break;
// US Binance
case "MIN_NOTIONAL":
counterMinQty = new BigDecimal(filter.getMinNotional()).stripTrailingZeros();
counterMinQty =
(filter.getMinNotional() != null)
? new BigDecimal(filter.getMinNotional()).stripTrailingZeros()
: null;
break;
// NOT US Binance
case "NOTIONAL":
counterMinQty =
(filter.getMinNotional() != null)
? new BigDecimal(filter.getMinNotional()).stripTrailingZeros()
: null;
counterMaxQty =
(filter.getMaxNotional() != null)
? new BigDecimal(filter.getMaxNotional()).stripTrailingZeros()
: null;
break;
}
}

if (counterMaxQty == null) {
counterMaxQty = counterMaxQtyFallback;
}

instruments.put(
currentCurrencyPair,
new InstrumentMetaData.Builder()
Expand All @@ -584,6 +629,7 @@ public static ExchangeMetaData adaptExchangeMetaData(
.counterMaximumAmount(counterMaxQty)
.volumeScale(amountPrecision)
.priceScale(pairPrecision)
.priceStepSize(priceStepSize)
.amountStepSize(stepSize)
.marketOrderEnabled(Arrays.asList(symbol.getOrderTypes()).contains("MARKET"))
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class Filter {

private String minNotional;

private String maxNotional;

public String getMaxPrice() {
return maxPrice;
}
Expand Down Expand Up @@ -81,6 +83,14 @@ public void setMinNotional(String minNotional) {
this.minNotional = minNotional;
}

public String getMaxNotional() {
return maxNotional;
}

public void setMaxNotional(String maxNotional) {
this.maxNotional = maxNotional;
}

@Override
public String toString() {
return "Filter{"
Expand Down Expand Up @@ -108,6 +118,9 @@ public String toString() {
+ ", minNotional='"
+ minNotional
+ '\''
+ ", maxNotional='"
+ maxNotional
+ '\''
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ public static void fetchMetaData() throws Exception {
public void testEthBtcPairMetaData() {
InstrumentMetaData pairMetaData = metaData.getInstruments().get(CurrencyPair.ETH_BTC);
assertThat(pairMetaData.getPriceScale()).isEqualByComparingTo(5);
assertThat(pairMetaData.getPriceStepSize()).isEqualByComparingTo("0.00001");
assertThat(pairMetaData.getMinimumAmount()).isEqualByComparingTo("0.0001");
assertThat(pairMetaData.getMaximumAmount().longValueExact()).isEqualTo(100000);
assertThat(pairMetaData.getCounterMinimumAmount()).isEqualByComparingTo("0.0001");
assertThat(pairMetaData.getAmountStepSize()).isEqualByComparingTo("0.0001");
}

@Test
public void testLtcBtcPairMetaData() {
InstrumentMetaData pairMetaData = metaData.getInstruments().get(new CurrencyPair("LTC/BTC"));
assertThat(pairMetaData.getPriceScale()).isEqualByComparingTo(6);
assertThat(pairMetaData.getPriceStepSize()).isEqualByComparingTo("0.000001");
assertThat(pairMetaData.getMinimumAmount()).isEqualByComparingTo("0.001");
assertThat(pairMetaData.getMaximumAmount().longValueExact()).isEqualTo(100000);
assertThat(pairMetaData.getCounterMinimumAmount()).isEqualByComparingTo("0.0001");
assertThat(pairMetaData.getAmountStepSize()).isEqualByComparingTo("0.001");
}
}