Problems getting GDAXTradeHistoryParams
I'm trying to list historical trades but I'm having issues with the call to createTradeHistoryParams(), it returns null:
ExchangeSpecification specification = new ExchangeSpecification(GDAXExchange.class.getName()); specification.setApiKey(apiKey); specification.setSecretKey(apiSecret); specification.setExchangeSpecificParametersItem("passphrase", passphrase); coinbase = ExchangeFactory.INSTANCE.createExchange(specification); coinbase.applySpecification(specification); GDAXTradeHistoryParams params = (GDAXTradeHistoryParams) coinbase.getPollingTradeService().createTradeHistoryParams();
So the params here is null.
Hey man did you ever figure this out? I am running into the same issue. The createTradeHistoryParams() just returns null
Figured it out for anyone else.
The code below will get your trades and output your very last one.
You have to set the params.setOrderID to something otherwise it will complain about being null.
GDAXTradeHistoryParams params = new GDAXTradeHistoryParams(); params.setOrderId(""); UserTrades trades = gdaxTradeService.getTradeHistory(params); System.out.println(trades.getTrades().get(trades.getTrades().size()-1));
yes exactly, that's what i ended up doing, sorry i didn't follow up here. so eventually my code became:
PollingTradeService tradeService = coinbase.getPollingTradeService();
GDAXTradeHistoryParams params = new GDAXTradeHistoryParams();
params.setOrderId("-1");
GDAXFill[] fills = ((GDAXTradeService) tradeService).getCoinbaseExFills(params);
if (fills != null) {
boolean atLeastOne = false;
for (int i = 0; i < fills.length; i++) {
GDAXFill fill = fills[i];
String tradeId = fill.getTradeId();
if (!fillMap.containsKey(tradeId)) {
atLeastOne = true;
GFill gfill = GFill.from(fill);
fillMap.put(tradeId, gfill);
String orderId = fill.getOrderId();
List<GFill> partials = new ArrayList<>();
if (orderIdMap.containsKey(orderId)) {
partials = orderIdMap.get(orderId);
}
partials.add(gfill);
orderIdMap.put(orderId, partials);
Map<String, Object> r = new HashMap<>();
r.put("ts", Instant.now());
r.put("gfill", gfill);
mapdb.add(tradeId, "r", r);
}
}
logger.info("fillMap: " + fillMap);
logger.info("orderIdMap: " + orderIdMap);
if (atLeastOne) {
logger.info("Persist to storage");
mapdb.commit();
}
}
@unk1911 where do you get the passphrase from?
When you create the API key. The web page asks for a passphrase.
Hey guys, I don't mean to hijack this thread but how exactly are you getting the tick history from GDAX? I am pretty stumped as the page retrieve function has not been set up.
Are you referring to the Get Historic Rates query here? If so, then it does not fit into the common XChange set of method calls, you'd have to implement and access it directly from GDAXMarketDataServiceRaw (it is not currently there).
@madwicket I get it by querying the trades and creating my own tickers from that. Otherwise you could follow @ww3456 's advice.
I have started on @ww3456 advice but have hit a snag and was wondering if I could get some help?
I have added this to GDAX.java @GET @Path("products/{baseCurrency}-{targetCurrency}/candles?start={startTime}&end={endTime}&granularity={granularityInSecs}") GDAXHistoricRates[] getHistoricRates(@PathParam("baseCurrency") String baseCurrency, @PathParam("targetCurrency") String targetCurrency, @PathParam("startTime") String startTime, @PathParam("endTime") String endTime, @PathParam("granularityInSecs") String granularityInSecs) throws IOException;
Added a class of GDAXHistoricRates: package org.knowm.xchange.gdax.dto.marketdata;
import java.math.BigDecimal;
/**
- Created by MadWicket on 7/1/2017. */ public class GDAXHistoricRates {
private final Long time; private final BigDecimal low; private final BigDecimal high; private final BigDecimal open; private final BigDecimal close; private final BigDecimal volume;
/* public GDAXHistoricRates(@JsonProperty("time") String time, @JsonProperty("low") BigDecimal low, @JsonProperty("high") BigDecimal high, @JsonProperty("open") BigDecimal open, @JsonProperty("close") BigDecimal close, @JsonProperty("volume") BigDecimal volume) {*/ public GDAXHistoricRates(Long time,BigDecimal low, BigDecimal high, BigDecimal open, BigDecimal close, BigDecimal volume) { this.time = time; this.low = low; this.high = high; this.open = open; this.close = close; this.volume = volume; }
public Long getTime() { return time; }
public BigDecimal getLow() { return low; }
public BigDecimal getHigh() { return high; }
public BigDecimal getOpen() { return open; }
public BigDecimal getClose() { return close; }
public BigDecimal getVolume() { return volume; }
@Override public String toString() { return "GDAXHistoricRates [time=" + time + ", low=" + low + ", high=" + high + ", open=" + open + ", close=" + close + ", volume=" + volume + "]"; } }
Also have added this function to GDAXMarketServiceRaw public GDAXHistoricRates[] getHistoricRates(CurrencyPair currencyPair, String startTime, String endTime, String granularityInSecs) throws IOException { return this.coinbaseEx.getHistoricRates(currencyPair.base.getCurrencyCode(), currencyPair.counter.getCurrencyCode(), startTime, endTime, granularityInSecs); }
When I test the code with: CurrencyPair btcUSDPair = new CurrencyPair(Currency.BTC, Currency.USD); String startTime = "2017-07-01T10:00:00.000000-0500"; String endTime = "2017-07-01T11:00:00.000000-0500"; String granularity = "60"; GDAXHistoricRates[] rates = gdaxMarketDataServiceRaw.getHistoricRates(btcUSDPair, startTime, endTime, granularity);
I am getting an error: Exception in thread "main" si.mazi.rescu.HttpStatusIOException: Can not deserialize instance of org.knowm.xchange.gdax.dto.marketdata.GDAXHistoricRates out of START_ARRAY token at [Source: [[1498924740,2465.98,2468.06,2465.98,2467.83,1.51111634],[1498924680,2465,2470.49,2468.6,2465,22.22688688000002],[1498924620,2467.58,2472.3,2472.3,2467.58,3.8412693099999995],[1498924560,2471.01,2473.81,2473.81,2471.04,2.601899999999999],[1498924500,2472.8,2474.02,2472.8,2473.76,4.348945669999999],[1498924440,2471.17,2474.99,2474.98,2471.33,6.413041009999999],[1498924380,2472.06,2475,2472.06,2475,0.95145589],[1498924320,2469.99,2472.06,2469.99,2472.06,2.777323000000001],[1498924260,2469.98,2469.99,2469.99,2469.98,3.27080923],[1498924200,2469.99,2469.99,2469.99,2469.99,3.73715842],[1498924140,2469.98,2469.98,2469.98,2469.98,0.4433263],[1498924080,2467.52,2469.98,2467.78,2469.98,6.6533103],[1498924020,2467.52,2469.98,2469.44,2467.52,4.722014950000001],[1498923960,2467.77,2469.99,2469.02,2467.83,18.09031563],[1498923900,2468.95,2469.99,2469.99,2468.95,20.984654690000003],[1498923840,2469.23,2469.99,2469.23,2469.95,0.80937389],[1498923780,2468.61,2469.97,2468.61,2468.95,2.7652663399999997],[1498923720,2468.61,2468.61,2468.61,2468.61,0.8389],[1498923660,2468.61,2469,2469,2468.61,2.6861],[1498923600,2468.85,2469.01,2468.86,2469,0.6688000000000001],[1498923540,2469.01,2469.98,2469.98,2469.01,1.16738877],[1498923480,2469.29,2469.99,2469.98,2469.98,1.82293339],[1498923420,2467.99,2469.99,2469.97,2469.99,2.3856853399999993],[1498923360,2468.74,2469.99,2469.44,2469.99,1.83640219],[1498923300,2468.12,2469.99,2468.99,2468.12,9.15815478],[1498923240,2465.32,2469,2468.89,2468.99,1.97067207],[1498923180,2468.97,2469.11,2469.11,2468.99,0.75413867],[1498923120,2465.21,2469.11,2466.58,2469.07,13.527611269999996],[1498923060,2466.57,2466.58,2466.57,2466.58,6.374597879999998],[1498923000,2465.01,2466.57,2465.39,2466.57,3.5704083599999996],[1498922940,2465.32,2465.47,2465.46,2465.39,5.396296830000001],[1498922880,2464.89,2465.47,2465.24,2465.47,8.66986411],[1498922820,2463.98,2465.96,2465.56,2465.24,4.514513849999999],[1498922760,2463.99,2466.45,2465.24,2465.73,2.73812368],[1498922700,2463.18,2465.22,2463.18,2465.22,1.7727281],[1498922640,2460,2464.28,2463.09,2464.05,4.078915359999999],[1498922580,2461.99,2464.28,2464.24,2464.28,3.3786699499999986],[1498922520,2464.25,2464.27,2464.27,2464.25,2.26559554],[1498922460,2464.07,2465.45,2464.07,2464.28,2.09086203],[1498922400,2461.93,2464.19,2463.54,2464.1,2.84171432],[1498922340,2461.16,2464.42,2464.42,2463.55,4.548074169999997],[1498922280,2458.24,2466.64,2458.24,2464.44,6.322822399999999],[1498922220,2455.34,2458.24,2455.4,2458.19,4.9823014799999985],[1498922160,2455.28,2455.92,2455.9,2455.28,1.33220846],[1498922100,2455.16,2456.99,2455.88,2455.28,2.08494906],[1498922040,2454.65,2455.87,2455.58,2455.85,3.1533982600000003],[1498921980,2454.65,2455.88,2455.88,2454.65,8.257270729999998],[1498921920,2454.65,2455.88,2454.65,2455.88,2.8405079300000002],[1498921860,2454.32,2454.66,2454.32,2454.66,1.5852210500000001],[1498921800,2453.36,2454.62,2453.37,2453.36,2.6746598600000002],[1498921740,2452.93,2454.59,2454.57,2453.45,2.8144810200000006],[1498921680,2454.87,2455.88,2454.87,2455.46,0.7601],[1498921620,2454.47,2454.71,2454.47,2454.68,3.2206431899999997],[1498921560,2454.4,2454.68,2454.4,2454.52,0.94935581],[1498921500,2454.55,2455.8,2455.8,2454.55,0.47332071000000003],[1498921440,2451.51,2455.77,2454.32,2455.77,3.41248868],[1498921380,2454.66,2455.85,2454.66,2455.85,1.72702815],[1498921320,2454.11,2454.66,2454.11,2454.64,2.8339],[1498921260,2450,2454.1,2452.64,2454.1,9.362184749999996],[1498921200,2450.76,2459.35,2459.35,2450.76,22.831026350000005]]; line: 1, column: 2] (through reference chain: Object[][0]) at si.mazi.rescu.ResponseReader.read(ResponseReader.java:104) at si.mazi.rescu.RestInvocationHandler.mapInvocationResult(RestInvocationHandler.java:169) at si.mazi.rescu.RestInvocationHandler.receiveAndMap(RestInvocationHandler.java:157) at si.mazi.rescu.RestInvocationHandler.invoke(RestInvocationHandler.java:120) at com.sun.proxy.$Proxy11.getHistoricRates(Unknown Source) at org.knowm.xchange.gdax.service.GDAXMarketDataServiceRaw.getHistoricRates(GDAXMarketDataServiceRaw.java:83) at org.knowm.xchange.gdax.GDAXMain.main(GDAXMain.java:72)
So I can see that it is reaching out and getting the data but for some reason it is not deserializing the data could I possibly get some tips from the pro's?
https://github.com/timmolter/XChange/issues/1580