Poloniex returnChartData Feature Request
Poloniex offeres a returnChartData depending on your start time, end time, and currency. I was hoping someone could implement this particular api funciton? This function would help in creating self defined technical analysis. Also, thanks everyone this is a very nice project!
So I have gone ahead and created a PoloniexChartData dto in marketdata, added the @Get in Poloniex.java, and added the function to call the chart data in PoloniexMarketDataServiceRaw. I have tested it against poloniex's site and it works correctly. Sorry for the handholding, my question is do I still go as far as creating an adaptor in PoloniexAdaptors for XChange object that does not exist? I guess what I am asking is this as far as I can go with implementing this functionality? I would rather not have to write something for the core class as that would be beyond my abilities and confidence level lol. Other than that, if what I have done is acceptable I can go to the next step and learn how to submit for merging.
@madwicket What you did at the Raw level sounds perfect! Since there is no corresponding functionality at the core level, there's nothing more you need to do. We'd be happy to accept a PR from you containing the new functionality.
Kraken has a similar functionality using https://api.kraken.com/0/public/OHLC which I would need. Would it make sense to create common logic for this on the core level? Or should this be implemented in a similar PR on Raw level?
We could add a method in *Raw, getOHCL or similar. But how many exchanges offer it. Just two isn;t really enough to justify a generic method to me.
I just had a look at Poloniex and Kraken. You may be right for the others. The PR will be merged into develop branch, right (i.e. this is the branch one should work on)?
Yes, develop branch.
https://github.com/timmolter/XChange/wiki/New-Implementation-Best-Practices
Bitstamp also has an OHLC API. They don't list it in the API docs though, but their Tradeview webapp connects to it.
Please in what format and range should the start time and end time in poloniex returnChartData method be in. I have tried implementing it in the time format that is in the API documentation but it doesn't seem to return the desired data. It only returns data when the start time is the unix epoch. Thanks for your response.
I use DateUtils from com.xeiam.xchange.utils.DateUtils; DateUtils.toUnixTime(startTime.getTime()) DateUtils.toUnixTime(endTime.getTime())
Here is an example usage PoloniexMarketDataServiceRaw rawDataService = (PoloniexMarketDataServiceRaw) PoloniexMain.getDataService(); PoloniexChartData[] t = rawDataService.getPoloniexChartData(PoloniexMain.getCurrencyPair(), PoloniexMain.getPeriod(), DateUtils.toUnixTime(startTime.getTime()), DateUtils.toUnixTime(endTime.getTime()));
Hope this helps!
And sorry to everyone not doing a PR. I fail at GitHub and tried to do it but utterly messed up.
@madwicket Please keep trying. It's hard at first, but once you figure it out its easy (like most things in programming).
Please make PR or give code here, need this
I have moved from Poloniex to GDAX so I haven't worked on this code but it should still work. This should be all you need to get started... Here is the DTO: package com.xeiam.xchange.poloniex.dto.marketdata;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonInclude.Include; import java.math.BigDecimal;
@JsonInclude(Include.NON_NULL) @JsonPropertyOrder({"date", "high", "low", "open", "close", "volume", "quoteVolume", "weightedAverage"}) public class PoloniexChartData { @JsonProperty("date") private String date; @JsonProperty("high") private BigDecimal high; @JsonProperty("low") private BigDecimal low; @JsonProperty("open") private BigDecimal open; @JsonProperty("close") private BigDecimal close; @JsonProperty("volume") private BigDecimal volume; @JsonProperty("quoteVolume") private BigDecimal quoteVolume; @JsonProperty("weightedAverage") private BigDecimal weightedAverage;
public PoloniexChartData() {
}
@JsonProperty("date")
public String getDate() {
return this.date;
}
@JsonProperty("date")
public void setDate(String date) {
this.date = date;
}
@JsonProperty("high")
public BigDecimal getHigh() {
return this.high;
}
@JsonProperty("high")
public void setHigh(BigDecimal high) {
this.high = high;
}
@JsonProperty("low")
public BigDecimal getLow() {
return this.low;
}
@JsonProperty("low")
public void setLow(BigDecimal low) {
this.low = low;
}
@JsonProperty("open")
public BigDecimal getOpen() {
return this.open;
}
@JsonProperty("open")
public void setOpen(BigDecimal open) {
this.open = open;
}
@JsonProperty("close")
public BigDecimal getClose() {
return this.close;
}
@JsonProperty("close")
public void setClose(BigDecimal close) {
this.close = close;
}
@JsonProperty("volume")
public BigDecimal getVolume() {
return this.volume;
}
@JsonProperty("volume")
public void setVolume(BigDecimal volume) {
this.volume = volume;
}
@JsonProperty("quoteVolume")
public BigDecimal getQuoteVolume() {
return this.quoteVolume;
}
@JsonProperty("quoteVolume")
public void setQuoteVolume(BigDecimal quoteVolume) {
this.quoteVolume = quoteVolume;
}
@JsonProperty("weightedAverage")
public BigDecimal getWeightedAverage() {
return this.weightedAverage;
}
@JsonProperty("weightedAverage")
public void setWeightedAverage(BigDecimal weightedAverage) {
this.weightedAverage = weightedAverage;
}
public String toString() {
return "PoloniexPublicTrade [date=" + this.date + ", high=" + this.high + ", low=" + this.low + ", open=" + this.open + ", close=" + this.close + ", volume=" + this.volume + ", quoteVolume=" + this.quoteVolume + ", weightedAverage=" + this.weightedAverage + "]";
}
}
Here is the @Get to go in Poloniex.java @GET PoloniexChartData[] getChartData(@QueryParam("command") String command, @QueryParam("period") Integer period, @QueryParam("currencyPair") String currencyPair, @QueryParam("start") Long startTime, @QueryParam("end") Long endTime) throws PoloniexException, IOException;
Also put this in poloniexmarketdataserviceraw
public PoloniexChartData[] getPoloniexChartData(CurrencyPair currencyPair, Integer period, Long startTime, Long endTime) throws IOException { String command = "returnChartData"; String pairString = PoloniexUtils.toPairString(currencyPair);
try {
PoloniexChartData[] chartData = poloniex.getChartData(command, period, pairString, startTime, endTime);
return chartData;
} catch (PoloniexException e) {
throw new ExchangeException(e.getError());
}
}
It looks like this is now added to XChange.