@Test public void getTransactionsHistory_success() throws Exception { when(mockAuthApi.makeRequest(eq(TRANSACTIONS_HISTORY), anyMapOf(String.class, String.class))) .thenReturn(JSON_PARSER.parse("{\n" + "\t\"success\":1,\n" + "\t\"return\":{\n" + "\t\t\"1081672\":{\n" + "\t\t\t\"type\":1,\n" + "\t\t\t\"amount\":1.00000000,\n" + "\t\t\t\"currency\":\"BTC\",\n" + "\t\t\t\"desc\":\"BTC Payment\",\n" + "\t\t\t\"status\":2,\n" + "\t\t\t\"timestamp\":1342448420\n" + "\t\t}\n" + "\t}\n" + "}").getAsJsonObject()); CallResult<List<Transaction>> callResult = testable.getTransactionsHistory( Collections.<String, String>emptyMap()); assertTrue(callResult.isSuccess()); assertNull(callResult.getError()); List<Transaction> transactions = callResult.getPayload(); assertNotNull(transactions); assertEquals(1, transactions.size()); Transaction transaction = transactions.get(0); assertEquals(1081672, transaction.getId()); assertEquals(1, transaction.getType()); assertEquals(1342448420, transaction.getTimestamp()); assertEquals(2, transaction.getStatus()); assertEquals("BTC", transaction.getCurrency()); assertEquals("BTC Payment", transaction.getDescription()); assertEquals(new BigDecimal("1"), transaction.getAmount()); }
@NonNull @WorkerThread public CallResult<List<Transaction>> getTransactionsHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRANSACTIONS_HISTORY, parameters); CallResult<List<Transaction>> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; List<Transaction> transactions = new ArrayList<>(); Set<String> transactionIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : transactionIds) { long transactionId = Long.parseLong(item); transactions.add(Transaction.create(transactionId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = transactions; return result; }
Api { @NonNull @WorkerThread public CallResult<List<Transaction>> getTransactionsHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRANSACTIONS_HISTORY, parameters); CallResult<List<Transaction>> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; List<Transaction> transactions = new ArrayList<>(); Set<String> transactionIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : transactionIds) { long transactionId = Long.parseLong(item); transactions.add(Transaction.create(transactionId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = transactions; return result; } }
Api { @NonNull @WorkerThread public CallResult<List<Transaction>> getTransactionsHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRANSACTIONS_HISTORY, parameters); CallResult<List<Transaction>> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; List<Transaction> transactions = new ArrayList<>(); Set<String> transactionIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : transactionIds) { long transactionId = Long.parseLong(item); transactions.add(Transaction.create(transactionId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = transactions; return result; } Api(@NonNull Context appContext, @NonNull String hostUrl,
               @Nullable String apiKey, @Nullable String apiSecret); @VisibleForTesting  Api(@NonNull Context appContext, @NonNull String hostUrl,
        @NonNull GuestApi guestApi, @NonNull AuthApi authApi); }
Api { @NonNull @WorkerThread public CallResult<List<Transaction>> getTransactionsHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRANSACTIONS_HISTORY, parameters); CallResult<List<Transaction>> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; List<Transaction> transactions = new ArrayList<>(); Set<String> transactionIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : transactionIds) { long transactionId = Long.parseLong(item); transactions.add(Transaction.create(transactionId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = transactions; return result; } Api(@NonNull Context appContext, @NonNull String hostUrl,
               @Nullable String apiKey, @Nullable String apiSecret); @VisibleForTesting  Api(@NonNull Context appContext, @NonNull String hostUrl,
        @NonNull GuestApi guestApi, @NonNull AuthApi authApi); void setCredentials(@NonNull String apiKey, @NonNull String apiSecret); void setHostUrl(@NonNull String hostUrl); @WorkerThread @NonNull CallResult<ExchangeInfo> getExchangeInfo(); @WorkerThread @NonNull CallResult<List<Ticker>> getPairInfo(@NonNull Set<String> pairs); @NonNull @WorkerThread CallResult<Depth> depth(@NonNull String pair); @NonNull @WorkerThread CallResult<AccountInfo> getAccountInfo(); @NonNull @WorkerThread CallResult<List<Transaction>> getTransactionsHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<TradeHistoryEntry>> getTradeHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<ActiveOrder>> getActiveOrders(); @NonNull @WorkerThread CallResult<TradeResponse> trade(@NonNull String pair, @TradeType @NonNull String type,
                                           @NonNull String rate, @NonNull String amount); @NonNull @WorkerThread CallResult<CancelOrderResponse> cancelOrder(long orderId); @NonNull @WorkerThread CallResult<WithdrawResponse> withdraw(@NonNull String coinName,
                                                 double amount, @NonNull String address); }
Api { @NonNull @WorkerThread public CallResult<List<Transaction>> getTransactionsHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRANSACTIONS_HISTORY, parameters); CallResult<List<Transaction>> result = new CallResult<>(); if (response == null || (response.has(SUCCESS_KEY) && response.get(SUCCESS_KEY).getAsInt() == 0)) { result.isSuccess = false; result.error = response == null ? generalErrorText : response.get(ERROR_KEY).getAsString(); return result; } result.isSuccess = true; List<Transaction> transactions = new ArrayList<>(); Set<String> transactionIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : transactionIds) { long transactionId = Long.parseLong(item); transactions.add(Transaction.create(transactionId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = transactions; return result; } Api(@NonNull Context appContext, @NonNull String hostUrl,
               @Nullable String apiKey, @Nullable String apiSecret); @VisibleForTesting  Api(@NonNull Context appContext, @NonNull String hostUrl,
        @NonNull GuestApi guestApi, @NonNull AuthApi authApi); void setCredentials(@NonNull String apiKey, @NonNull String apiSecret); void setHostUrl(@NonNull String hostUrl); @WorkerThread @NonNull CallResult<ExchangeInfo> getExchangeInfo(); @WorkerThread @NonNull CallResult<List<Ticker>> getPairInfo(@NonNull Set<String> pairs); @NonNull @WorkerThread CallResult<Depth> depth(@NonNull String pair); @NonNull @WorkerThread CallResult<AccountInfo> getAccountInfo(); @NonNull @WorkerThread CallResult<List<Transaction>> getTransactionsHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<TradeHistoryEntry>> getTradeHistory(
            @NonNull Map<String, String> parameters); @NonNull @WorkerThread CallResult<List<ActiveOrder>> getActiveOrders(); @NonNull @WorkerThread CallResult<TradeResponse> trade(@NonNull String pair, @TradeType @NonNull String type,
                                           @NonNull String rate, @NonNull String amount); @NonNull @WorkerThread CallResult<CancelOrderResponse> cancelOrder(long orderId); @NonNull @WorkerThread CallResult<WithdrawResponse> withdraw(@NonNull String coinName,
                                                 double amount, @NonNull String address);  }