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

Adapt to new Poloniex API. #21

Merged
merged 5 commits into from Sep 12, 2023
Merged
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
20 changes: 5 additions & 15 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,17 @@ spring-boot-starter-web-lib = { strictly = '2.5.6' }
[libraries]
junit-jupiter = { module = 'org.junit.jupiter:junit-jupiter', version.ref = 'junit-jupiter-lib' }
knowm-xchange-binance = { module = 'org.knowm.xchange:xchange-binance', version.ref = 'knowm-xchange-lib' }
knowm-xchange-bitbay = { module = 'org.knowm.xchange:xchange-bitbay', version.ref = 'knowm-xchange-lib' }
known-xchange-bitfinex = { module = 'org.knowm.xchange:xchange-bitfinex', version.ref = 'knowm-xchange-lib' }
known-xchange-bitflyer = { module = 'org.knowm.xchange:xchange-bitflyer', version.ref = 'knowm-xchange-lib' }
known-xchange-bitstamp = { module = 'org.knowm.xchange:xchange-bitstamp', version.ref = 'knowm-xchange-lib' }
known-xchange-btcmarkets = { module = 'org.knowm.xchange:xchange-btcmarkets', version.ref = 'knowm-xchange-lib' }
known-xchange-cexio = { module = 'org.knowm.xchange:xchange-cexio', version.ref = 'knowm-xchange-lib' }
known-xchange-coinbasepro = { module = 'org.knowm.xchange:xchange-coinbasepro', version.ref = 'knowm-xchange-lib' }
known-xchange-coinmarketcap = { module = 'org.knowm.xchange:xchange-coinmarketcap', version.ref = 'knowm-xchange-lib' }
known-xchange-coinmate = { module = 'org.knowm.xchange:xchange-coinmate', version.ref = 'knowm-xchange-lib' }
known-xchange-coinone = { module = 'org.knowm.xchange:xchange-coinone', version.ref = 'knowm-xchange-lib' }
known-xchange-exmo = { module = 'org.knowm.xchange:xchange-exmo', version.ref = 'knowm-xchange-lib' }
known-xchange-hitbtc = { module = 'org.knowm.xchange:xchange-hitbtc', version.ref = 'knowm-xchange-lib' }
known-xchange-huobi = { module = 'org.knowm.xchange:xchange-huobi', version.ref = 'knowm-xchange-lib' }
known-xchange-independentreserve = { module = 'org.knowm.xchange:xchange-independentreserve', version.ref = 'knowm-xchange-lib' }
known-xchange-kraken = { module = 'org.knowm.xchange:xchange-kraken', version.ref = 'knowm-xchange-lib' }
known-xchange-luno = { module = 'org.knowm.xchange:xchange-luno', version.ref = 'knowm-xchange-lib' }
known-xchange-mercadobitcoin = { module = 'org.knowm.xchange:xchange-mercadobitcoin', version.ref = 'knowm-xchange-lib' }
known-xchange-paribu = { module = 'org.knowm.xchange:xchange-paribu', version.ref = 'knowm-xchange-lib' }
known-xchange-poloniex = { module = 'org.knowm.xchange:xchange-poloniex', version.ref = 'knowm-xchange-lib' }
known-xchange-quoine = { module = 'org.knowm.xchange:xchange-quoine', version.ref = 'knowm-xchange-lib' }
logback-core = { module = 'ch.qos.logback:logback-core', version.ref = 'logback-lib' }
logback-classic = { module = 'ch.qos.logback:logback-classic', version.ref = 'logback-lib' }
lombok = { module = 'org.projectlombok:lombok', version.ref = 'lombok-lib' }
Expand All @@ -51,12 +42,11 @@ spring-boot-starter-webflux = { module = 'org.springframework.boot:spring-boot-s

[bundles]
knowm-xchange-libs = [
'knowm-xchange-binance', 'knowm-xchange-bitbay', 'known-xchange-bitfinex',
'known-xchange-bitflyer', 'known-xchange-bitstamp', 'known-xchange-btcmarkets', 'known-xchange-cexio',
'known-xchange-coinbasepro', 'known-xchange-coinmarketcap', 'known-xchange-coinmate', 'known-xchange-coinone',
'known-xchange-exmo', 'known-xchange-hitbtc', 'known-xchange-huobi', 'known-xchange-independentreserve',
'known-xchange-kraken', 'known-xchange-luno', 'known-xchange-mercadobitcoin', 'known-xchange-paribu',
'known-xchange-poloniex', 'known-xchange-quoine'
'knowm-xchange-binance', 'known-xchange-bitfinex',
'known-xchange-bitflyer', 'known-xchange-bitstamp', 'known-xchange-btcmarkets',
'known-xchange-coinbasepro', 'known-xchange-coinone',
'known-xchange-independentreserve',
'known-xchange-kraken', 'known-xchange-luno', 'known-xchange-mercadobitcoin', 'known-xchange-paribu'
]

[plugins]
Expand Down
60 changes: 51 additions & 9 deletions src/main/java/bisq/price/spot/providers/Poloniex.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,69 @@

import bisq.price.spot.ExchangeRate;
import bisq.price.spot.ExchangeRateProvider;

import org.knowm.xchange.poloniex.PoloniexExchange;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.core.env.Environment;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

import java.math.BigDecimal;
import java.time.Duration;

import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Component
class Poloniex extends ExchangeRateProvider {

private static final List<String> SUPPORTED_CURRENCIES =
List.of("DASH", "DCR", "DOGE", "ETC", "ETH", "LTC", "XMR", "ZEC");
private static final String POLONIEX_URL = "https://api.poloniex.com/markets/price";
private static final String PROVIDER_NAME = "POLO";
public Poloniex(Environment env) {
super(env, "POLO", "poloniex", Duration.ofMinutes(1));
super(env, PROVIDER_NAME, "poloniex", Duration.ofMinutes(1));
}

@Override
public Set<ExchangeRate> doGet() {
// Supported fiat: -
// Supported alts: DASH, DCR, DOGE, ETC, ETH, LTC, XMR, ZEC
return doGet(PoloniexExchange.class);
Flux<PoloniexTicker> poloniexTickerFlux = WebClient.create()
.get()
.uri(POLONIEX_URL)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToFlux(PoloniexTicker.class);

return poloniexTickerFlux.filter(PoloniexTicker::isSupportedCurrency)
.map(PoloniexTicker::toExchangeRate)
.collect(Collectors.toSet())
.block();
}

@JsonIgnoreProperties(ignoreUnknown = true)
private static class PoloniexTicker {
public String symbol;
public String price;

This conversation was marked as resolved.
Show resolved Hide resolved
public ExchangeRate toExchangeRate() {
return new ExchangeRate(getCurrency(), getPrice(), new Date(), PROVIDER_NAME);
}

public BigDecimal getPrice() {
return new BigDecimal(price);
}

public String getCurrency() {
This conversation was marked as resolved.
Show resolved Hide resolved
// DASH_BTC, DOGE_BTC, LTC_BTC, ...
return symbol.split("_")[0];
}

private boolean isBtcPair() {
return symbol.endsWith("_BTC");
}

public boolean isSupportedCurrency() {
return isBtcPair() && SUPPORTED_CURRENCIES.contains(getCurrency());
}
}
}