-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'knowm-develop' into code-cleanup
- Loading branch information
Showing
33 changed files
with
496 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"default": { | ||
"api_host": "https://api.binance.com", | ||
"data_api_host": "https://data-api.binance.vision" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
xchange-binance/src/main/java/org/knowm/xchange/binance/BinanceUsExchange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...c/main/java/org/knowm/xchange/binance/config/converter/StringToCurrencyPairConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.knowm.xchange.binance.config.converter; | ||
|
||
import com.fasterxml.jackson.databind.util.StdConverter; | ||
import org.knowm.xchange.binance.BinanceAdapters; | ||
import org.knowm.xchange.currency.CurrencyPair; | ||
|
||
/** Converts string to {@code CurrencyPair} */ | ||
public class StringToCurrencyPairConverter extends StdConverter<String, CurrencyPair> { | ||
|
||
@Override | ||
public CurrencyPair convert(String value) { | ||
return BinanceAdapters.toCurrencyPair(value); | ||
} | ||
} |
63 changes: 16 additions & 47 deletions
63
xchange-binance/src/main/java/org/knowm/xchange/binance/dto/marketdata/BinancePrice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,28 @@ | ||
package org.knowm.xchange.binance.dto.marketdata; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import java.math.BigDecimal; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.knowm.xchange.binance.config.converter.StringToCurrencyPairConverter; | ||
import org.knowm.xchange.currency.CurrencyPair; | ||
import org.knowm.xchange.utils.Assert; | ||
import org.knowm.xchange.utils.jackson.CurrencyPairDeserializer; | ||
|
||
public final class BinancePrice implements Comparable<BinancePrice> { | ||
@Data | ||
@Builder | ||
@Jacksonized | ||
public class BinancePrice { | ||
|
||
private final CurrencyPair pair; | ||
private final BigDecimal price; | ||
@JsonProperty("symbol") | ||
@JsonDeserialize(converter = StringToCurrencyPairConverter.class) | ||
CurrencyPair currencyPair; | ||
|
||
public BinancePrice( | ||
@JsonProperty("symbol") String symbol, @JsonProperty("price") BigDecimal price) { | ||
this(CurrencyPairDeserializer.getCurrencyPairFromString(symbol), price); | ||
} | ||
|
||
public BinancePrice(CurrencyPair pair, BigDecimal price) { | ||
Assert.notNull(price, "Null price"); | ||
Assert.notNull(pair, "Null pair"); | ||
this.pair = pair; | ||
this.price = price; | ||
} | ||
|
||
public CurrencyPair getCurrencyPair() { | ||
return pair; | ||
} | ||
|
||
public BigDecimal getPrice() { | ||
return price; | ||
} | ||
|
||
@Override | ||
public int compareTo(BinancePrice o) { | ||
if (pair.compareTo(o.pair) == 0) return price.compareTo(o.price); | ||
return pair.compareTo(o.pair); | ||
} | ||
@JsonProperty("price") | ||
BigDecimal price; | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = 1; | ||
result = 31 * result + ((pair == null) ? 0 : pair.hashCode()); | ||
result = 31 * result + ((price == null) ? 0 : price.hashCode()); | ||
return result; | ||
public boolean isValid() { | ||
return currencyPair != null && price != null; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (!(obj instanceof BinancePrice)) return false; | ||
BinancePrice other = (BinancePrice) obj; | ||
return pair.equals(other.pair) && price.equals(other.price); | ||
} | ||
|
||
public String toString() { | ||
return "[" + pair + "] => " + price; | ||
} | ||
} |
Oops, something went wrong.