Skip to content

Commit

Permalink
minor cleanup of logging
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCookieLab committed Feb 7, 2018
1 parent d6aab45 commit dd53c33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public PoloniexTicker returnTicker(String currencyPair)
public List<String> returnAllMarkets()
{
long start = System.currentTimeMillis();
List<String> allMarkets = new ArrayList<String>();
List<String> allMarkets = new ArrayList<>();
try
{
String tickerData = publicClient.returnTicker();
Expand Down
19 changes: 14 additions & 5 deletions src/main/java/com/cf/data/map/poloniex/PoloniexDataMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.stream.Collectors;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
*
Expand All @@ -39,7 +40,9 @@
public class PoloniexDataMapper {

private final Gson gson;
private static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneOffset.UTC);

private final static Logger LOGGER = LogManager.getLogger();
private final static DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneOffset.UTC);
private final static String EMPTY_RESULTS = "[]";
private final static String INVALID_CHART_DATA_DATE_RANGE_RESULT = "[{\"date\":0,\"high\":0,\"low\":0,\"open\":0,\"close\":0,\"volume\":0,\"quoteVolume\":0,\"weightedAverage\":0}]";
private final static String INVALID_CHART_DATA_CURRENCY_PAIR_RESULT = "{\"error\":\"Invalid currency pair.\"}";
Expand All @@ -66,21 +69,27 @@ public List<PoloniexChartData> mapChartData(String chartDataResult) {
PoloniexChartData[] chartDataResults = gson.fromJson(chartDataResult, PoloniexChartData[].class);
results = Arrays.asList(chartDataResults);
} catch (JsonSyntaxException | DateTimeParseException ex) {
LogManager.getLogger().error("Exception mapping chart data {} - {}", chartDataResult, ex.getMessage());
LOGGER.error("Exception mapping chart data {} - {}", chartDataResult, ex.getMessage());
results = Collections.EMPTY_LIST;
}
return results;

}

public PoloniexFeeInfo mapFeeInfo(String feeInfoResult) {
PoloniexFeeInfo feeInfo = gson.fromJson(feeInfoResult, new TypeToken<PoloniexFeeInfo>() {
}.getType());
PoloniexFeeInfo feeInfo = null;

try {
feeInfo = gson.fromJson(feeInfoResult, new TypeToken<PoloniexFeeInfo>() {
}.getType());
} catch (Exception ex) {
LOGGER.error("Exception mapping fee info {} - {}", feeInfoResult, ex.getMessage());
}
return feeInfo;
}

public PoloniexActiveLoanTypes mapActiveLoans(String activeLoansResult) {

PoloniexActiveLoanTypes activeLoanTypes = gson.fromJson(activeLoansResult, PoloniexActiveLoanTypes.class);

return activeLoanTypes;
Expand All @@ -90,7 +99,7 @@ public Map<String, PoloniexTicker> mapTicker(String tickerData) {
return gson.fromJson(tickerData, new TypeToken<Map<String, PoloniexTicker>>() {
}.getType());
}

public PoloniexTicker mapTickerForCurrency(String currencyType, String tickerData) {
return mapTicker(tickerData).get(currencyType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ public void run(String propertiesFileName)
{
LOG.warn("Did not find value for " + POLONIEX_API_SECRET_PROP_NAME + " in " + propertiesFileName + ". Trading API commands will fail");
}

PoloniexExchangeService service = new PoloniexExchangeService(tradingAPIKey, tradingAPISecret);
Long yesterdayEpochSecond = ZonedDateTime.now(ZoneOffset.UTC).minusDays(1).toEpochSecond();
List<PoloniexChartData> btcDailyChartData = service.returnChartData(PoloniexExchangeService.USDT_BTC_CURRENCY_PAIR, PoloniexExchangeService.DAILY_TIME_PERIOD, yesterdayEpochSecond);
LOG.info(btcDailyChartData);
LOG.info(service.returnTicker());
}

private Properties loadProperties(String propertiesFileName)
Expand Down

0 comments on commit dd53c33

Please sign in to comment.