Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added snapshot viewing resource

  • Loading branch information...
commit fe47ece82499c6cff65e62bd4d3604a2811c0092 1 parent c899415
@mikedanese mikedanese authored
View
44 src/main/java/com/raskol/tradebot/StatusResource.java
@@ -0,0 +1,44 @@
+package com.raskol.tradebot;
+
+import com.codahale.metrics.Snapshot;
+import com.google.common.base.Joiner;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import java.util.ArrayList;
+
+@Path("/transaction")
+public class StatusResource {
+ private final TickerService tickerService;
+
+ public StatusResource(TickerService tickerService) {
+ this.tickerService = tickerService;
+ }
+
+ @GET
+ @Produces("text/plain")
+ public String getInfos() {
+ final ArrayList<String> snapshots = new ArrayList<String>();
+ for (Snapshot snapshot : tickerService.getSnapshots()) {
+ snapshots.add(printHistogram(snapshot));
+ }
+ return Joiner.on("\n\n\n\n").join(snapshots);
+ }
+
+
+ private String printHistogram(Snapshot snapshot) {
+ final ArrayList<String> sb = new ArrayList<>();
+ sb.add(String.format(" min = %d%n", snapshot.getMin()));
+ sb.add(String.format(" max = %d%n", snapshot.getMax()));
+ sb.add(String.format(" mean = %2.2f%n", snapshot.getMean()));
+ sb.add(String.format(" stddev = %2.2f%n", snapshot.getStdDev()));
+ sb.add(String.format(" median = %2.2f%n", snapshot.getMedian()));
+ sb.add(String.format(" 75%% <= %2.2f%n", snapshot.get75thPercentile()));
+ sb.add(String.format(" 95%% <= %2.2f%n", snapshot.get95thPercentile()));
+ sb.add(String.format(" 98%% <= %2.2f%n", snapshot.get98thPercentile()));
+ sb.add(String.format(" 99%% <= %2.2f%n", snapshot.get99thPercentile()));
+ sb.add(String.format(" 99.9%% <= %2.2f%n", snapshot.get999thPercentile()));
+ return Joiner.on("\n").join(sb);
+ }
+}
View
2  src/main/java/com/raskol/tradebot/TradeBotApplication.java
@@ -20,5 +20,7 @@ public void run(Configuration config, Environment env) throws Exception {
env.manage(guavaServiceManager);
+ env.addResource(new StatusResource(tickerService));
+
}
}
View
7 src/main/java/com/raskol/tradebot/dto/TradeDTO.java
@@ -1,19 +1,26 @@
package com.raskol.tradebot.dto;
+import com.fasterxml.jackson.annotation.JsonProperty;
import org.joda.money.BigMoney;
import java.math.BigDecimal;
import java.util.Date;
public class TradeDTO implements java.io.Serializable, Comparable<TradeDTO> {
+ @JsonProperty
private final long id;
/* Amount that was traded */
+ @JsonProperty
private final BigDecimal tradableAmount;
/* An identifier that uniquely identifies the tradable */
+ @JsonProperty
private final String tradableIdentifier;
/* The currency used to settle the market order transaction */
+ @JsonProperty
private final String transactionCurrency;
+ @JsonProperty
private final BigMoney price;
+ @JsonProperty
private final Date timestamp;
public TradeDTO(BigDecimal tradableAmount, String tradableIdentifier, String transactionCurrency, BigMoney price,
Please sign in to comment.
Something went wrong with that request. Please try again.