Skip to content

Commit

Permalink
[bittrex] changed date parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
andre77 committed Nov 7, 2016
1 parent a30e505 commit ab527c7
Showing 1 changed file with 15 additions and 33 deletions.
@@ -1,53 +1,35 @@
package org.knowm.xchange.bittrex.v1;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import javax.xml.bind.DatatypeConverter;

import org.knowm.xchange.currency.CurrencyPair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A central place for shared Bittrex properties
*/
public final class BittrexUtils {

private static final Date EPOCH = new Date(0);

private static final Logger logger = LoggerFactory.getLogger(BittrexUtils.class);

/**
* private Constructor
*/
private BittrexUtils() {
private static final String TIMEZONE = "UTC";

}
/**
* private Constructor
*/
private BittrexUtils() {

public static String toPairString(CurrencyPair currencyPair) {

return currencyPair.counter.getCurrencyCode().toUpperCase() + "-" + currencyPair.base.getCurrencyCode().toUpperCase();
}

public static Date toDate(String datetime) {
// Bittrex can truncate the millisecond component of datetime fields (e.g. 2015-12-20T02:07:51.5)
// to the point where if the milliseconds are zero then they are not shown (e.g. 2015-12-26T09:55:23).
}

SimpleDateFormat sdf;
if (datetime.length() == 19) {
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
} else {
sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
public static String toPairString(CurrencyPair currencyPair) {
return currencyPair.counter.getCurrencyCode().toUpperCase() + "-" + currencyPair.base.getCurrencyCode().toUpperCase();
}
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));

try {
return sdf.parse(datetime);
} catch (ParseException e) {
logger.warn("Unable to parse datetime={}", datetime, e);
return EPOCH;
public static Date toDate(String date) {
Calendar cal = DatatypeConverter.parseDateTime(date);
cal.setTimeZone(TimeZone.getTimeZone(TIMEZONE));
return cal.getTime();
}
}

}

0 comments on commit ab527c7

Please sign in to comment.