Skip to content

Commit

Permalink
#169 - Use parameterised log statements
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Nov 13, 2024
1 parent 4b45b96 commit d924af4
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@ public static ExchangeConfigImpl buildConfig(ExchangeConfig exchangeConfig) {
exchangeApiNetworkConfig.setNonFatalErrorCodes(nonFatalErrorCodes);
} else {
log.info(
"No (optional) NetworkConfiguration NonFatalErrorCodes have been set for Exchange Adapter: {}",
exchangeConfig.getAdapter());
"No (optional) NetworkConfiguration NonFatalErrorCodes have been set for Exchange "
+ "Adapter: "
+ exchangeConfig.getAdapter());
}

final List<String> nonFatalErrorMessages = networkConfig.getNonFatalErrorMessages();
if (nonFatalErrorMessages != null && !nonFatalErrorMessages.isEmpty()) {
exchangeApiNetworkConfig.setNonFatalErrorMessages(nonFatalErrorMessages);
} else {
log.info(
"No (optional) NetworkConfiguration NonFatalErrorMessages have been set for Exchange Adapter: {}",
exchangeConfig.getAdapter());
"No (optional) NetworkConfiguration NonFatalErrorMessages have been set for "
+ "Exchange Adapter: "
+ exchangeConfig.getAdapter());
}

exchangeApiConfig.setNetworkConfig(exchangeApiNetworkConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ abstract class AbstractExchangeAdapter {
* @throws ExchangeNetworkException if a network error occurred trying to connect to the exchange.
* This exception allows for recovery from temporary network issues.
* @throws TradingApiException if the API call failed for any reason other than a network error.
* This means something really bad as happened.
* This means something awful has happened.
*/
ExchangeHttpResponse sendNetworkRequest(
URL url, String httpMethod, String postData, Map<String, String> requestHeaders)
Expand All @@ -125,7 +125,7 @@ ExchangeHttpResponse sendNetworkRequest(
final StringBuilder exchangeResponse = new StringBuilder();

try {
log.debug("Using following URL for API call: " + url);
log.debug("Using following URL for API call: {}", url);

exchangeConnection = (HttpURLConnection) url.openConnection();
exchangeConnection.setUseCaches(false);
Expand All @@ -140,7 +140,7 @@ ExchangeHttpResponse sendNetworkRequest(
exchangeConnection.setReadTimeout(timeoutInMillis);

if (httpMethod.equalsIgnoreCase("POST") && postData != null) {
log.debug("Doing POST with request body: " + postData);
log.debug("Doing POST with request body: {}", postData);
try (final OutputStreamWriter outputPostStream =
new OutputStreamWriter(exchangeConnection.getOutputStream(), StandardCharsets.UTF_8)) {
outputPostStream.write(postData);
Expand Down Expand Up @@ -236,19 +236,19 @@ void setNetworkConfig(ExchangeConfig exchangeConfig) {
log.error(errorMsg);
throw new IllegalArgumentException(errorMsg);
}
log.info(CONNECTION_TIMEOUT_PROPERTY_NAME + ": " + connectionTimeout);
log.info(CONNECTION_TIMEOUT_PROPERTY_NAME + ": {}", connectionTimeout);

final List<Integer> nonFatalErrorCodesFromConfig = networkConfig.getNonFatalErrorCodes();
if (nonFatalErrorCodesFromConfig != null) {
nonFatalNetworkErrorCodes.addAll(nonFatalErrorCodesFromConfig);
}
log.info(NON_FATAL_ERROR_CODES_PROPERTY_NAME + ": " + nonFatalNetworkErrorCodes);
log.info(NON_FATAL_ERROR_CODES_PROPERTY_NAME + ": {}", nonFatalNetworkErrorCodes);

final List<String> nonFatalErrorMessagesFromConfig = networkConfig.getNonFatalErrorMessages();
if (nonFatalErrorMessagesFromConfig != null) {
nonFatalNetworkErrorMessages.addAll(nonFatalErrorMessagesFromConfig);
}
log.info(NON_FATAL_ERROR_MESSAGES_PROPERTY_NAME + ": " + nonFatalNetworkErrorMessages);
log.info(NON_FATAL_ERROR_MESSAGES_PROPERTY_NAME + ": {}", nonFatalNetworkErrorMessages);
}

/**
Expand Down Expand Up @@ -309,7 +309,7 @@ String getAuthenticationConfigItem(AuthenticationConfig authenticationConfig, St
*/
String getOtherConfigItem(OtherConfig otherConfig, String itemName) {
final String itemValue = otherConfig.getItem(itemName);
log.debug(itemName + ": " + itemValue);
log.debug("{}: {}", itemName, itemValue);
return assertItemExists(itemName, itemValue);
}

Expand Down Expand Up @@ -370,7 +370,7 @@ private void setRequestHeaders(
if (requestHeaders != null) {
for (final Map.Entry<String, String> requestHeader : requestHeaders.entrySet()) {
exchangeConnection.setRequestProperty(requestHeader.getKey(), requestHeader.getValue());
log.debug("Setting following request header: " + requestHeader);
log.debug("Setting following request header: {}", requestHeader);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public BitfinexExchangeAdapter() {

@Override
public void init(ExchangeConfig config) {
log.info("About to initialise Bitfinex ExchangeConfig: " + config);
log.info("About to initialise Bitfinex ExchangeConfig: {}", config);
setAuthenticationConfig(config);
setNetworkConfig(config);

Expand All @@ -163,7 +163,7 @@ public MarketOrderBook getMarketOrders(String marketId)
throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("book/" + marketId);
log.debug("Market Orders response: " + response);
log.debug("Market Orders response: {}", response);

final BitfinexOrderBook orderBook =
gson.fromJson(response.getPayload(), BitfinexOrderBook.class);
Expand Down Expand Up @@ -206,7 +206,7 @@ public List<OpenOrder> getYourOpenOrders(String marketId)
throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange("orders", null);
log.debug("Open Orders response: " + response);
log.debug("Open Orders response: {}", response);

final BitfinexOpenOrders bitfinexOpenOrders =
gson.fromJson(response.getPayload(), BitfinexOpenOrders.class);
Expand Down Expand Up @@ -308,7 +308,7 @@ public String createOrder(
// params.put("is_hidden", "false");

final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange("order/new", params);
log.debug("Create Order response: " + response);
log.debug("Create Order response: {}", response);

final BitfinexNewOrderResponse createOrderResponse =
gson.fromJson(response.getPayload(), BitfinexNewOrderResponse.class);
Expand Down Expand Up @@ -342,7 +342,7 @@ public boolean cancelOrder(String orderId, String marketIdNotNeeded)

final ExchangeHttpResponse response =
sendAuthenticatedRequestToExchange("order/cancel", params);
log.debug("Cancel Order response: " + response);
log.debug("Cancel Order response: {}", response);

// Exchange returns order id and other details if successful, a 400 HTTP Status if the order
// id was not recognised.
Expand Down Expand Up @@ -370,7 +370,7 @@ public BigDecimal getLatestMarketPrice(String marketId)
throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("pubticker/" + marketId);
log.debug("Latest Market Price response: " + response);
log.debug("Latest Market Price response: {}", response);

final BitfinexTicker ticker = gson.fromJson(response.getPayload(), BitfinexTicker.class);
return ticker.lastPrice;
Expand All @@ -388,7 +388,7 @@ public BigDecimal getLatestMarketPrice(String marketId)
public BalanceInfo getBalanceInfo() throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange("balances", null);
log.debug("Balance Info response: " + response);
log.debug("Balance Info response: {}", response);

final BitfinexBalances allAccountBalances =
gson.fromJson(response.getPayload(), BitfinexBalances.class);
Expand Down Expand Up @@ -430,7 +430,7 @@ public BigDecimal getPercentageOfBuyOrderTakenForExchangeFee(String marketId)
try {
final ExchangeHttpResponse response =
sendAuthenticatedRequestToExchange("account_infos", null);
log.debug("Buy Fee response: " + response);
log.debug("Buy Fee response: {}", response);

// Nightmare to adapt! Just take the top-level taker fees.
final BitfinexAccountInfos bitfinexAccountInfos =
Expand All @@ -455,7 +455,7 @@ public BigDecimal getPercentageOfSellOrderTakenForExchangeFee(String marketId)
try {
final ExchangeHttpResponse response =
sendAuthenticatedRequestToExchange("account_infos", null);
log.debug("Sell Fee response: " + response);
log.debug("Sell Fee response: {}", response);

// Nightmare to adapt! Just take the top-level taker fees.
final BitfinexAccountInfos bitfinexAccountInfos =
Expand Down Expand Up @@ -483,7 +483,7 @@ public String getImplName() {
public Ticker getTicker(String marketId) throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("pubticker/" + marketId);
log.debug("Latest Market Price response: " + response);
log.debug("Latest Market Price response: {}", response);

final BitfinexTicker ticker = gson.fromJson(response.getPayload(), BitfinexTicker.class);
return new TickerImpl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public BitstampExchangeAdapter() {

@Override
public void init(ExchangeConfig config) {
log.info("About to initialise Bitstamp ExchangeConfig: " + config);
log.info("About to initialise Bitstamp ExchangeConfig: {}", config);
setAuthenticationConfig(config);
setNetworkConfig(config);

Expand All @@ -158,7 +158,7 @@ public MarketOrderBook getMarketOrders(String marketId)
throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("order_book/" + marketId);
log.debug("Market Orders response: " + response);
log.debug("Market Orders response: {}", response);

final BitstampOrderBook bitstampOrderBook =
gson.fromJson(response.getPayload(), BitstampOrderBook.class);
Expand Down Expand Up @@ -204,7 +204,7 @@ public List<OpenOrder> getYourOpenOrders(String marketId)
try {
final ExchangeHttpResponse response =
sendAuthenticatedRequestToExchange("open_orders/" + marketId, null);
log.debug("Open Orders response: " + response);
log.debug("Open Orders response: {}", response);

final BitstampOrderResponse[] myOpenOrders =
gson.fromJson(response.getPayload(), BitstampOrderResponse[].class);
Expand Down Expand Up @@ -279,7 +279,7 @@ public String createOrder(
throw new IllegalArgumentException(errorMsg);
}

log.debug("Create Order response: " + response);
log.debug("Create Order response: {}", response);

final BitstampOrderResponse createOrderResponse =
gson.fromJson(response.getPayload(), BitstampOrderResponse.class);
Expand Down Expand Up @@ -313,7 +313,7 @@ public boolean cancelOrder(String orderId, String marketIdNotNeeded)

final ExchangeHttpResponse response =
sendAuthenticatedRequestToExchange("cancel_order", params);
log.debug("Cancel Order response: " + response);
log.debug("Cancel Order response: {}", response);

final BitstampCancelOrderResponse cancelOrderResponse =
gson.fromJson(response.getPayload(), BitstampCancelOrderResponse.class);
Expand All @@ -339,7 +339,7 @@ public BigDecimal getLatestMarketPrice(String marketId)
throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("ticker/" + marketId);
log.debug("Latest Market Price response: " + response);
log.debug("Latest Market Price response: {}", response);

final BitstampTicker bitstampTicker =
gson.fromJson(response.getPayload(), BitstampTicker.class);
Expand All @@ -358,7 +358,7 @@ public BigDecimal getLatestMarketPrice(String marketId)
public BalanceInfo getBalanceInfo() throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange(BALANCE, null);
log.debug("Balance Info response: " + response);
log.debug("Balance Info response: {}", response);

final BitstampBalance balances = gson.fromJson(response.getPayload(), BitstampBalance.class);

Expand Down Expand Up @@ -392,7 +392,7 @@ public BigDecimal getPercentageOfBuyOrderTakenForExchangeFee(String marketId)
throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange(BALANCE, null);
log.debug("Buy Fee response: " + response);
log.debug("Buy Fee response: {}", response);

final BitstampBalance balances = gson.fromJson(response.getPayload(), BitstampBalance.class);

Expand Down Expand Up @@ -430,7 +430,7 @@ public BigDecimal getPercentageOfSellOrderTakenForExchangeFee(String marketId)
throws TradingApiException, ExchangeNetworkException {
try {
final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange(BALANCE, null);
log.debug("Sell Fee response: " + response);
log.debug("Sell Fee response: {}", response);

final BitstampBalance balances = gson.fromJson(response.getPayload(), BitstampBalance.class);

Expand Down Expand Up @@ -473,7 +473,7 @@ public Ticker getTicker(String marketId) throws TradingApiException, ExchangeNet

try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("ticker/" + marketId);
log.debug("Ticker response: " + response);
log.debug("Ticker response: {}", response);

final BitstampTicker bitstampTicker =
gson.fromJson(response.getPayload(), BitstampTicker.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public GeminiExchangeAdapter() {

@Override
public void init(ExchangeConfig config) {
log.info("About to initialise Gemini ExchangeConfig: " + config);
log.info("About to initialise Gemini ExchangeConfig: {}", config);
setAuthenticationConfig(config);
setNetworkConfig(config);
setOtherConfig(config);
Expand Down Expand Up @@ -238,7 +238,7 @@ public String createOrder(

final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange("order/new", params);

log.debug("Create Order response: " + response);
log.debug("Create Order response: {}", response);

final GeminiOpenOrder createOrderResponse =
gson.fromJson(response.getPayload(), GeminiOpenOrder.class);
Expand Down Expand Up @@ -270,7 +270,7 @@ public boolean cancelOrder(String orderId, String marketIdNotNeeded)
final ExchangeHttpResponse response =
sendAuthenticatedRequestToExchange("order/cancel", params);

log.debug("Cancel Order response: " + response);
log.debug("Cancel Order response: {}", response);

// Exchange returns order id and other details if successful, a 400 HTTP Status if the order
// id was not recognised.
Expand Down Expand Up @@ -299,7 +299,7 @@ public List<OpenOrder> getYourOpenOrders(String marketId)
try {
final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange("orders", null);

log.debug("Open Orders response: " + response);
log.debug("Open Orders response: {}", response);

final GeminiOpenOrders geminiOpenOrders =
gson.fromJson(response.getPayload(), GeminiOpenOrders.class);
Expand Down Expand Up @@ -357,7 +357,7 @@ public MarketOrderBook getMarketOrders(String marketId)
try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("book/" + marketId);

log.debug("Market Orders response: " + response);
log.debug("Market Orders response: {}", response);

final GeminiOrderBook orderBook = gson.fromJson(response.getPayload(), GeminiOrderBook.class);

Expand Down Expand Up @@ -400,7 +400,7 @@ public BigDecimal getLatestMarketPrice(String marketId)
try {
final ExchangeHttpResponse response = sendPublicRequestToExchange("pubticker/" + marketId);

log.debug("Latest Market Price response: " + response);
log.debug("Latest Market Price response: {}", response);

final GeminiTicker ticker = gson.fromJson(response.getPayload(), GeminiTicker.class);
return ticker.last;
Expand All @@ -419,7 +419,7 @@ public BalanceInfo getBalanceInfo() throws TradingApiException, ExchangeNetworkE
try {
final ExchangeHttpResponse response = sendAuthenticatedRequestToExchange("balances", null);

log.debug("Balance Info response: " + response);
log.debug("Balance Info response: {}", response);

final GeminiBalances allAccountBalances =
gson.fromJson(response.getPayload(), GeminiBalances.class);
Expand Down Expand Up @@ -490,6 +490,7 @@ private static class GeminiMarketOrder {

BigDecimal price;
BigDecimal amount;

// ignore the timestamp attribute as per the API spec

@Override
Expand Down Expand Up @@ -799,12 +800,12 @@ private void setOtherConfig(ExchangeConfig exchangeConfig) {
final String buyFeeInConfig = getOtherConfigItem(otherConfig, BUY_FEE_PROPERTY_NAME);
buyFeePercentage =
new BigDecimal(buyFeeInConfig).divide(new BigDecimal("100"), 8, RoundingMode.HALF_UP);
log.info("Buy fee % in BigDecimal format: " + buyFeePercentage);
log.info("Buy fee % in BigDecimal format: {}", buyFeePercentage);

final String sellFeeInConfig = getOtherConfigItem(otherConfig, SELL_FEE_PROPERTY_NAME);
sellFeePercentage =
new BigDecimal(sellFeeInConfig).divide(new BigDecimal("100"), 8, RoundingMode.HALF_UP);
log.info("Sell fee % in BigDecimal format: " + sellFeePercentage);
log.info("Sell fee % in BigDecimal format: {}", sellFeePercentage);
}

// --------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit d924af4

Please sign in to comment.