Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

better

  • Loading branch information...
commit 11f9b9e2efe5e704ca22cbe0a6f71813eb060382 1 parent bde644d
@mikedanese mikedanese authored
View
7 src/main/java/com/raskol/tradebot/TickerService.java
@@ -2,6 +2,7 @@
import com.codahale.metrics.ExponentiallyDecayingReservoir;
import com.codahale.metrics.Snapshot;
+import com.fasterxml.jackson.databind.ObjectWriter;
import com.google.common.util.concurrent.AbstractScheduledService;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.bitstamp.BitstampExchange;
@@ -15,8 +16,6 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
-import static java.lang.Math.exp;
-
public class TickerService extends AbstractScheduledService {
private static final int INTERVAL = 5;
public static final int SAMPLE_SIZE = 1024;
@@ -32,7 +31,7 @@
private final List<ExponentiallyDecayingReservoir> reservoirs = Arrays.asList(oneMinute, oneHour, oneDay, fiveDays, oneMonth);
public List<Snapshot> getSnapshots() {
- final ArrayList<Snapshot> snapshots = new ArrayList<Snapshot>();
+ final ArrayList<Snapshot> snapshots = new ArrayList<>();
for (ExponentiallyDecayingReservoir reservoir : reservoirs) {
snapshots.add(reservoir.getSnapshot());
}
@@ -58,6 +57,6 @@ protected Scheduler scheduler() {
}
private double getAlpha(Integer duration, TimeUnit timeUnit) {
- return 1 - exp(-INTERVAL / timeUnit.toSeconds(duration));
+ return 1 - Math.exp(-INTERVAL / timeUnit.toSeconds(duration));
}
}
View
1  src/main/java/com/raskol/tradebot/TradeBotApplication.java
@@ -19,5 +19,6 @@ public void run(Configuration config, Environment env) throws Exception {
final ManagedServiceManager guavaServiceManager = new ManagedServiceManager(tickerService);
env.manage(guavaServiceManager);
+
}
}
View
25 src/main/java/com/raskol/tradebot/dao/TradeDAO.java
@@ -1,4 +1,29 @@
package com.raskol.tradebot.dao;
+import com.raskol.tradebot.dto.TradeDTO;
+
+import java.io.*;
+
public class TradeDAO {
+ public void save(TradeDTO tradeDTO) throws IOException {
+ final ObjectOutputStream tradeWriter = new ObjectOutputStream(new OutputStream() {
+ @Override
+ public void write(int b) throws IOException {
+
+ }
+ });
+
+ tradeWriter.writeObject(tradeDTO);
+ }
+
+ public void recall(long id) throws IOException, ClassNotFoundException {
+ final ObjectInputStream tradeReader = new ObjectInputStream(new InputStream() {
+ @Override
+ public int read() throws IOException {
+ return 0;
+ }
+ });
+
+ final TradeDTO trade = (TradeDTO) tradeReader.readObject(); /* i feel dirty */
+ }
}
View
62 src/main/java/com/raskol/tradebot/dto/TradeDTO.java
@@ -2,33 +2,22 @@
import org.joda.money.BigMoney;
-import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
-public class TradeDTO implements Serializable, Comparable<TradeDTO> {
+public class TradeDTO implements java.io.Serializable, Comparable<TradeDTO> {
+ private final long id;
/* Amount that was traded */
private final BigDecimal tradableAmount;
-
/* An identifier that uniquely identifies the tradable */
private final String tradableIdentifier;
-
/* The currency used to settle the market order transaction */
private final String transactionCurrency;
private final BigMoney price;
private final Date timestamp;
- private final long id;
- /**
- * @param tradableAmount The depth of this trade
- * @param tradableIdentifier The exchange identifier (e.g. "BTC/USD")
- * @param transactionCurrency The transaction currency (e.g. USD in BTC/USD)
- * @param price The price (either the bid or the ask)
- * @param timestamp The timestamp when the order was placed. Exchange matching is
- * usually price first then timestamp asc to clear older orders
- * @param id The id of the trade
- */
- public TradeDTO(BigDecimal tradableAmount, String tradableIdentifier, String transactionCurrency, BigMoney price, Date timestamp, long id) {
+ public TradeDTO(BigDecimal tradableAmount, String tradableIdentifier, String transactionCurrency, BigMoney price,
+ Date timestamp, long id) {
this.tradableAmount = tradableAmount;
this.tradableIdentifier = tradableIdentifier;
@@ -38,6 +27,10 @@ public TradeDTO(BigDecimal tradableAmount, String tradableIdentifier, String tra
this.id = id;
}
+ public long getId() {
+ return id;
+ }
+
public BigDecimal getTradableAmount() {
return tradableAmount;
}
@@ -58,19 +51,15 @@ public Date getTimestamp() {
return timestamp;
}
- public long getId() {
- return id;
- }
-
@Override
public String toString() {
return "TradeDTO{" +
- "tradableAmount=" + tradableAmount +
+ "id=" + id +
+ ", tradableAmount=" + tradableAmount +
", tradableIdentifier='" + tradableIdentifier + '\'' +
", transactionCurrency='" + transactionCurrency + '\'' +
", price=" + price +
", timestamp=" + timestamp +
- ", id=" + id +
'}';
}
@@ -78,4 +67,35 @@ public String toString() {
public int compareTo(TradeDTO trade) {
return getTimestamp().compareTo(trade.getTimestamp());
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ TradeDTO tradeDTO = (TradeDTO) o;
+
+ if (id != tradeDTO.id) return false;
+ if (price != null ? !price.equals(tradeDTO.price) : tradeDTO.price != null) return false;
+ if (timestamp != null ? !timestamp.equals(tradeDTO.timestamp) : tradeDTO.timestamp != null) return false;
+ if (tradableAmount != null ? !tradableAmount.equals(tradeDTO.tradableAmount) : tradeDTO.tradableAmount != null)
+ return false;
+ if (tradableIdentifier != null ? !tradableIdentifier.equals(tradeDTO.tradableIdentifier) : tradeDTO.tradableIdentifier != null)
+ return false;
+ if (transactionCurrency != null ? !transactionCurrency.equals(tradeDTO.transactionCurrency) : tradeDTO.transactionCurrency != null)
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = (int) (id ^ (id >>> 32));
+ result = 31 * result + (tradableAmount != null ? tradableAmount.hashCode() : 0);
+ result = 31 * result + (tradableIdentifier != null ? tradableIdentifier.hashCode() : 0);
+ result = 31 * result + (transactionCurrency != null ? transactionCurrency.hashCode() : 0);
+ result = 31 * result + (price != null ? price.hashCode() : 0);
+ result = 31 * result + (timestamp != null ? timestamp.hashCode() : 0);
+ return result;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.