Comments (3)
doubles are not stored exactly some times if i am correct.
you need to round it.
I solved this on a really dirty way:
`public double determineRoundingPrice(String tickSize, double desired){
String decimalformat = "";
String out = "";
char splitter = '"';
String splt = "" + splitter;
String[] ssSplitted = tickSize.split(splt);
System.out.println("tickSize: "+tickSize);
String firstchar = ""+ssSplitted[1].charAt(0);
String secondchar = ""+ssSplitted[1].charAt(1);
if (Objects.equals(firstchar, "0")) {
System.out.println("ts: " + ssSplitted[1]);
System.out.println("desired: " + desired);
String regex = "\\.";
String[] decimalsSplit = ssSplitted[1].split(regex);
for (int i = 0; i < decimalsSplit[0].length(); i++) {
decimalformat += "#";
}
decimalformat += ".";
int amountofhastags = 0;
for (int i = 0; i < decimalsSplit[1].length(); i++) {
String one = ""+decimalsSplit[1].charAt(i);
if (Objects.equals(one, "1")) {
amountofhastags=i+1;
i = ssSplitted[1].length();
}
}
for (int i = 0; i < amountofhastags; i++) {
decimalformat += "#";
}
System.out.println(desired);
DecimalFormat df = new DecimalFormat(decimalformat);
df.setRoundingMode(RoundingMode.FLOOR);
String resultString = df.format(desired);
System.out.println(resultString);
String[] resultarray = resultString.split(",");
if (resultarray.length>1) {
out = resultarray[0] + "." + resultarray[1];
}
else if (resultarray.length==1){
out = resultarray[0];
}
}
else if (Objects.equals(firstchar, "1")){
int whole = (int) desired;
System.out.println(whole);
out = String.valueOf(whole);
if (Objects.equals(secondchar, "0")){
String temp = "";
for (int i = 0; i<out.length()-1; i++){
temp+=""+out.charAt(i);
}
out=temp;
System.out.println(out);
}
}
double result = Double.parseDouble(out);
System.out.println(result);
return result;
}
public String getPriceFilter(String desiredSymbol) {
System.out.println(desiredSymbol);
String result = "";
BinanceExchangeInfo binanceExchangeInfo = null;
try {
binanceExchangeInfo = new BinanceApi().exchangeInfo();
List symbols = binanceExchangeInfo.getSymbols();
for (int i = 0; i<symbols.size(); i++) {
if (desiredSymbol.equals(symbols.get(i).getBaseAsset() + symbols.get(i).getQuoteAsset())) {
result = symbols.get(i).getPriceFilter().get("tickSize").toString();
System.out.println(symbols.get(i).getPriceFilter().toString());
System.out.println();
i=symbols.size();
}
}
} catch (BinanceApiException e) {
e.printStackTrace();
String method = " getPriceFilter";
errors.add( new Error(e.toString()+method, LocalDateTime.now()));
}
return result;
}`
Don't mind the variable names and the print lines!
double desired is the inserted price, String tickSize in the first method. is actually the outcome of the method below AKA Price_filter (sorry about that), So thats why i split it up a couple of times.
Keep in mind its a messy solution! (was in a hurry)
from java-binance-api.
For those still have the same issue here's how i solved it...
double validatePrice(double price) {
if (price < minTradePrice)
return 0;
price -= (price - minTradePrice) % tickSize;
Double toBeTruncated = new Double(price);
price = BigDecimal.valueOf(toBeTruncated).setScale(assetPrecision, RoundingMode.HALF_UP).doubleValue();
return price;
}
double validateAmount(double amount, double price) {
amount -= (amount - minTradeQty) % stepSize;
if (amount < minTradeQty || amount * price <= minNotional)
return 0;
return amount;
}
from java-binance-api.
How do you get the assetPrecision?
if i use:
int assetPrecision = client.getExchangeInfo().getSymbolInfo(symbol).getBaseAssetPrecision();
it always returns 8 for every coin.
from java-binance-api.
Related Issues (20)
- ERROR: -1111, Precision is over the maximum defined for this asset. HOT 2
- Logback HOT 2
- Websocket API depth with level doesn't work
- BinanceApiException: timestamp for this request is outside of recwindow HOT 1
- UserDataStream disconnecting?
- ORDER_WOULD_TRIGGER_IMMEDIATELY not present in OrderRejectReason
- Binance api update
- Exception throws with the latest Binance update when calling exchangeInfo
- Trade with PAX or TUSD
- Cannot deserialize value of type `java.lang.Long` from String "9534.95000000"
- Get price market into websocket
- Placing a TAKE_PROFIT_LIMIT order
- Guys whats the long value for StartTime/EndTime in Aggtrades call ? is is "secondssince1970' as usual ?
- Use this library on testnet
- What is MIN_NOTIONAL Error
- How to get all historical data from a specific asset?
- getting connection refused Exception using web socket
- MARKET_LOT_SIZE error (code = -1013 HOT 1
- help!
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-binance-api.