-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished ticker handler, reorganized packages
- Loading branch information
1 parent
a3d6bf0
commit 29170e4
Showing
11 changed files
with
231 additions
and
55 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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/cf/client/poloniex/wss/model/PoloniexWSSSubscription.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,29 @@ | ||
package com.cf.client.poloniex.wss.model; | ||
|
||
import com.google.gson.Gson; | ||
|
||
/** | ||
* | ||
* @author David | ||
*/ | ||
public class PoloniexWSSSubscription { | ||
|
||
public final static transient PoloniexWSSSubscription TICKER = new PoloniexWSSSubscription("1002"); | ||
public final static transient PoloniexWSSSubscription HEARTBEAT = new PoloniexWSSSubscription("1010"); | ||
public final static transient PoloniexWSSSubscription BASE_COIN_DAILY_VOLUME_STATS = new PoloniexWSSSubscription("1003"); | ||
public final static transient PoloniexWSSSubscription USDT_BTC = new PoloniexWSSSubscription("121"); | ||
public final static transient PoloniexWSSSubscription USDT_ETH = new PoloniexWSSSubscription("149"); | ||
|
||
public final String command; | ||
public final String channel; | ||
|
||
public PoloniexWSSSubscription(String channel) { | ||
this.command = "subscribe"; | ||
this.channel = channel; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new Gson().toJson(this); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
src/main/java/com/cf/client/poloniex/wss/model/PoloniexWSSTicker.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,111 @@ | ||
package com.cf.client.poloniex.wss.model; | ||
|
||
import com.google.gson.Gson; | ||
import java.math.BigDecimal; | ||
|
||
/** | ||
* | ||
* @author David | ||
*/ | ||
public class PoloniexWSSTicker { | ||
|
||
public final Double currencyPair; | ||
public final BigDecimal lastPrice; | ||
public final BigDecimal lowestAsk; | ||
public final BigDecimal highestBid; | ||
public final BigDecimal percentChange; | ||
public final BigDecimal baseVolume; | ||
public final BigDecimal quoteVolume; | ||
public final Boolean isFrozen; | ||
public final BigDecimal twentyFourHourHigh; | ||
public final BigDecimal twentyFourHourLow; | ||
|
||
public PoloniexWSSTicker(Double currencyPair, BigDecimal lastPrice, BigDecimal lowestAsk, BigDecimal highestBid, BigDecimal percentChange, BigDecimal baseVolume, BigDecimal quoteVolume, Boolean isFrozen, BigDecimal twentyFourHourHigh, BigDecimal twentyFourHourLow) { | ||
this.currencyPair = currencyPair; | ||
this.lastPrice = lastPrice; | ||
this.lowestAsk = lowestAsk; | ||
this.highestBid = highestBid; | ||
this.percentChange = percentChange; | ||
this.baseVolume = baseVolume; | ||
this.quoteVolume = quoteVolume; | ||
this.isFrozen = isFrozen; | ||
this.twentyFourHourHigh = twentyFourHourHigh; | ||
this.twentyFourHourLow = twentyFourHourLow; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new Gson().toJson(this); | ||
} | ||
|
||
public static class PoloniexWSSTickerBuilder { | ||
|
||
private Double currencyPair; | ||
private BigDecimal lastPrice; | ||
private BigDecimal lowestAsk; | ||
private BigDecimal highestBid; | ||
private BigDecimal percentChange; | ||
private BigDecimal baseVolume; | ||
private BigDecimal quoteVolume; | ||
private Boolean isFrozen; | ||
private BigDecimal twentyFourHourHigh; | ||
private BigDecimal twentyFourHourLow; | ||
|
||
public PoloniexWSSTickerBuilder() { | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setCurrencyPair(Double currencyPair) { | ||
this.currencyPair = currencyPair; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setLastPrice(BigDecimal lastPrice) { | ||
this.lastPrice = lastPrice; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setLowestAsk(BigDecimal lowestAsk) { | ||
this.lowestAsk = lowestAsk; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setHighestBid(BigDecimal highestBid) { | ||
this.highestBid = highestBid; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setPercentChange(BigDecimal percentChange) { | ||
this.percentChange = percentChange; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setBaseVolume(BigDecimal baseVolume) { | ||
this.baseVolume = baseVolume; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setQuoteVolume(BigDecimal quoteVolume) { | ||
this.quoteVolume = quoteVolume; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setIsFrozen(Boolean isFrozen) { | ||
this.isFrozen = isFrozen; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setTwentyFourHourHigh(BigDecimal twentyFourHourHigh) { | ||
this.twentyFourHourHigh = twentyFourHourHigh; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTickerBuilder setTwentyFourHourLow(BigDecimal twentyFourHourLow) { | ||
this.twentyFourHourLow = twentyFourHourLow; | ||
return this; | ||
} | ||
|
||
public PoloniexWSSTicker buildPoloniexTicker() { | ||
return new PoloniexWSSTicker(currencyPair, lastPrice, lowestAsk, highestBid, percentChange, baseVolume, quoteVolume, isFrozen, twentyFourHourHigh, twentyFourHourLow); | ||
} | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/java/com/cf/client/wss/handler/OrderBookMessageHandler.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 com.cf.client.wss.handler; | ||
|
||
/** | ||
* | ||
* @author David | ||
*/ | ||
public class OrderBookMessageHandler implements IMessageHandler { | ||
|
||
@Override | ||
public void handle(String message) { | ||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/com/cf/client/wss/handler/TickerMessageHandler.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,50 @@ | ||
package com.cf.client.wss.handler; | ||
|
||
import com.cf.client.poloniex.wss.model.PoloniexWSSTicker; | ||
import com.google.gson.Gson; | ||
import java.math.BigDecimal; | ||
import java.util.List; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
/** | ||
* | ||
* @author David | ||
*/ | ||
public class TickerMessageHandler implements IMessageHandler { | ||
|
||
private final static Logger LOG = LogManager.getLogger(); | ||
private final Gson gson; | ||
|
||
public TickerMessageHandler() { | ||
this.gson = new Gson(); | ||
} | ||
|
||
@Override | ||
public void handle(String message) { | ||
LOG.trace(message); | ||
PoloniexWSSTicker ticker = this.mapMessageToPoloniexTicker(message); | ||
LOG.trace(ticker); | ||
|
||
} | ||
|
||
protected PoloniexWSSTicker mapMessageToPoloniexTicker(String message) { | ||
List results = gson.fromJson(message, List.class); | ||
if (results.size() < 3) return null; | ||
|
||
List olhc = (List) results.get(2); | ||
return new PoloniexWSSTicker.PoloniexWSSTickerBuilder() | ||
.setCurrencyPair((Double) olhc.get(0)) | ||
.setLastPrice(new BigDecimal((String) olhc.get(1))) | ||
.setLowestAsk(new BigDecimal((String) olhc.get(2))) | ||
.setHighestBid(new BigDecimal((String) olhc.get(3))) | ||
.setPercentChange(new BigDecimal((String) olhc.get(4))) | ||
.setBaseVolume(new BigDecimal((String) olhc.get(5))) | ||
.setQuoteVolume(new BigDecimal((String) olhc.get(6))) | ||
.setIsFrozen(((double) olhc.get(7)) == 1) | ||
.setTwentyFourHourHigh(new BigDecimal((String) olhc.get(8))) | ||
.setTwentyFourHourLow(new BigDecimal((String) olhc.get(9))) | ||
.buildPoloniexTicker(); | ||
} | ||
|
||
} |
29 changes: 0 additions & 29 deletions
29
src/main/java/com/cf/client/wss/subscription/Subscription.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.