Skip to content

Commit

Permalink
[mercadobitcoin] Bug fix: adding missing left padding.
Browse files Browse the repository at this point in the history
  • Loading branch information
felipelalli committed Dec 11, 2014
1 parent c7d2465 commit 8974126
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ target/
javadoc/
bin/
log/
xchange-mercadobitcoin/classes/
xchange-mercadobitcoin/src/main/java/META-INF/

# Misc.
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
import java.util.Map;

/**
* IMPORTANT NOTE: the sleep of 1 sec between each call is necessary
* due to a API limitation (at least until Dec 2014) because the "tonce"
* of API is calculated based on Unix time, which is second-based.
*
* <p>
* Example showing the following:
* </p>
Expand All @@ -48,17 +44,13 @@ private static void generic(PollingTradeService tradeService) throws IOException

printOpenOrders(tradeService);

Thread.sleep(1000);

// place a limit buy order
LimitOrder limitOrder = new LimitOrder((Order.OrderType.ASK), new BigDecimal("0.01"), CurrencyPair.BTC_BRL, "", null, new BigDecimal("9000.00"));
String limitOrderReturnValue = tradeService.placeLimitOrder(limitOrder);
System.out.println("Limit Order return value: " + limitOrderReturnValue);

printOpenOrders(tradeService);

Thread.sleep(1000);

// Cancel the added order
boolean cancelResult = tradeService.cancelOrder(limitOrderReturnValue);
System.out.println("Canceling returned " + cancelResult);
Expand All @@ -68,7 +60,6 @@ private static void generic(PollingTradeService tradeService) throws IOException

private static void printOpenOrders(PollingTradeService tradeService) throws IOException, InterruptedException {

Thread.sleep(1000);
OpenOrders openOrders = tradeService.getOpenOrders();
System.out.println("Open Orders: " + openOrders.toString());
}
Expand All @@ -77,16 +68,12 @@ private static void raw(MercadoBitcoinTradeServiceRaw tradeService) throws IOExc

printRawOpenOrders(tradeService);

Thread.sleep(1000);

// place a limit buy order
MercadoBitcoinBaseTradeApiResult<MercadoBitcoinPlaceLimitOrderResult> order = tradeService.mercadoBitcoinPlaceLimitOrder("ltc_brl", "buy", new BigDecimal("0.01"), new BigDecimal("1"));
System.out.println("MercadoBitcoinBaseTradeApiResult<MercadoBitcoinPlaceLimitOrderResult> return value: " + order);

printRawOpenOrders(tradeService);

Thread.sleep(1000);

// Cancel the added order
MercadoBitcoinBaseTradeApiResult<MercadoBitcoinCancelOrderResult> cancelResult = tradeService.mercadoBitcoinCancelOrder("ltc_brl", order.getTheReturn().keySet().iterator().next());
System.out.println("Canceling returned " + cancelResult);
Expand All @@ -96,8 +83,6 @@ private static void raw(MercadoBitcoinTradeServiceRaw tradeService) throws IOExc

private static void printRawOpenOrders(MercadoBitcoinTradeServiceRaw tradeService) throws IOException, InterruptedException {

Thread.sleep(1000);

MercadoBitcoinBaseTradeApiResult<MercadoBitcoinUserOrders> openOrdersResult = tradeService.getMercadoBitcoinUserOrders("btc_brl", null, "active", null, null, null, null);

MercadoBitcoinUserOrders openOrders = openOrdersResult.getTheReturn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

/**
* Various adapters for converting from Mercado Bitcoin DTOs to XChange DTOs
*
* @author Felipe Micaroni Lalli
*/
public final class MercadoBitcoinAdapters {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ public String digestParams(RestInvocation restInvocation) {

hmac512.update(message.getBytes());

return String.format("%x", new BigInteger(1, hmac512.doFinal())).toLowerCase();
return String.format("%0128x", new BigInteger(1, hmac512.doFinal())).toLowerCase();
}
}

0 comments on commit 8974126

Please sign in to comment.