Skip to content

Commit

Permalink
Merge pull request #4451 from chimp1984/add-check-for-option-trade
Browse files Browse the repository at this point in the history
Add check for option trade
  • Loading branch information
sqrrm authored Sep 1, 2020
2 parents 4d32da7 + ebecd20 commit 43ad831
Show file tree
Hide file tree
Showing 11 changed files with 330 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,13 @@ public void startShutDownInterval(GracefulShutDownHandler gracefulShutDownHandle
UserThread.runAfter(() -> {
// We check every hour if we are in the target hour.
UserThread.runPeriodically(() -> {
int currentHour = ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("GMT0")).getHour();
int currentHour = ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("UTC")).getHour();
if (currentHour == target) {
log.warn("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" +
"Shut down node at hour {}" +
"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n", target);
"Shut down node at hour {} (UTC time is {})" +
"\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n",
target,
ZonedDateTime.ofInstant(Instant.now(), ZoneId.of("UTC")).toString());
shutDown(gracefulShutDownHandler);
}
}, TimeUnit.MINUTES.toSeconds(10));
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/java/bisq/core/monetary/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ public Price subtract(Price other) {
}

public String toFriendlyString() {
return monetary instanceof Altcoin ? ((Altcoin) monetary).toFriendlyString() : ((Fiat) monetary).toFriendlyString();
return monetary instanceof Altcoin ?
((Altcoin) monetary).toFriendlyString() + "/BTC" :
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "BTC/" + ((Fiat) monetary).currencyCode;
}

public String toPlainString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public class PriceFeedService {
private final StringProperty currencyCodeProperty = new SimpleStringProperty();
private final IntegerProperty updateCounter = new SimpleIntegerProperty(0);
private long epochInMillisAtLastRequest;
private Map<String, Long> timeStampMap = new HashMap<>();
private long retryDelay = 1;
private long requestTs;
@Nullable
Expand Down Expand Up @@ -126,6 +125,10 @@ public void initialRequestPriceFeed() {
request(false);
}

public boolean hasPrices() {
return !cache.isEmpty();
}

public void requestPriceFeed(Consumer<Double> resultHandler, FaultHandler faultHandler) {
this.priceConsumer = resultHandler;
this.faultHandler = faultHandler;
Expand Down Expand Up @@ -156,7 +159,7 @@ private void request(boolean repeatRequests) {
// At applyPriceToConsumer we also check if price is not exceeding max. age for price data.
boolean success = applyPriceToConsumer();
if (success) {
final MarketPrice marketPrice = cache.get(currencyCode);
MarketPrice marketPrice = cache.get(currencyCode);
if (marketPrice != null)
log.debug("Received new {} from provider {} after {} sec.",
marketPrice,
Expand Down Expand Up @@ -326,7 +329,7 @@ private boolean applyPriceToConsumer() {
boolean result = false;
String errorMessage = null;
if (currencyCode != null) {
final String baseUrl = priceProvider.getBaseUrl();
String baseUrl = priceProvider.getBaseUrl();
if (cache.containsKey(currencyCode)) {
try {
MarketPrice marketPrice = cache.get(currencyCode);
Expand Down Expand Up @@ -383,14 +386,12 @@ private void requestAllPrices(PriceProvider provider, Runnable resultHandler, Fa
public void onSuccess(@Nullable Tuple2<Map<String, Long>, Map<String, MarketPrice>> result) {
UserThread.execute(() -> {
checkNotNull(result, "Result must not be null at requestAllPrices");
timeStampMap = result.first;

// Each currency rate has a different timestamp, depending on when
// the pricenode aggregate rate was calculated
// However, the request timestamp is when the pricenode was queried
epochInMillisAtLastRequest = System.currentTimeMillis();

final Map<String, MarketPrice> priceMap = result.second;
Map<String, MarketPrice> priceMap = result.second;

cache.putAll(priceMap);

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/bisq/core/support/SupportManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ public SupportManager(P2PService p2PService, WalletsSetup walletsSetup) {

// We get first the message handler called then the onBootstrapped
p2PService.addDecryptedDirectMessageListener((decryptedMessageWithPubKey, senderAddress) -> {
// As decryptedDirectMessageWithPubKeys is a CopyOnWriteArraySet we do not need to check if it was
// already stored
decryptedDirectMessageWithPubKeys.add(decryptedMessageWithPubKey);
tryApplyMessages();
});
p2PService.addDecryptedMailboxListener((decryptedMessageWithPubKey, senderAddress) -> {
// As decryptedMailboxMessageWithPubKeys is a CopyOnWriteArraySet we do not need to check if it was
// already stored
decryptedMailboxMessageWithPubKeys.add(decryptedMessageWithPubKey);
tryApplyMessages();
});
Expand Down
Loading

0 comments on commit 43ad831

Please sign in to comment.