@Test public void getTradeHistory_success() throws Exception { when(mockAuthApi.makeRequest(eq(TRADE_HISTORY), anyMapOf(String.class, String.class))) .thenReturn(JSON_PARSER.parse("{\n" + "\t\"success\":1,\n" + "\t\"return\":{\n" + "\t\t\"166830\":{\n" + "\t\t\t\"pair\":\"btc_usd\",\n" + "\t\t\t\"type\":\"sell\",\n" + "\t\t\t\"amount\":1,\n" + "\t\t\t\"rate\":1,\n" + "\t\t\t\"order_id\":343148,\n" + "\t\t\t\"is_your_order\":1,\n" + "\t\t\t\"timestamp\":1342445793\n" + "\t\t}\n" + "\t}\n" + "}").getAsJsonObject()); CallResult<List<TradeHistoryEntry>> callResult = testable.getTradeHistory(Collections.<String, String>emptyMap()); assertTrue(callResult.isSuccess()); assertNull(callResult.getError()); List<TradeHistoryEntry> trades = callResult.getPayload(); assertNotNull(trades); assertEquals(1, trades.size()); TradeHistoryEntry trade = trades.get(0); assertEquals(166830, trade.getId()); assertEquals(343148, trade.getOrderId()); assertEquals(1342445793, trade.getTimestamp()); assertTrue(trade.isYourOrder()); assertEquals("BTC/USD", trade.getPair()); assertEquals("sell", trade.getType()); assertEquals(new BigDecimal("1"), trade.getRate()); assertEquals(new BigDecimal("1"), trade.getAmount()); }
@NonNull @WorkerThread public CallResult<List<TradeHistoryEntry>> getTradeHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRADE_HISTORY, parameters); CallResult<List<TradeHistoryEntry>> 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<TradeHistoryEntry> trades = new ArrayList<>(); Set<String> tradeIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : tradeIds) { long tradeId = Long.parseLong(item); trades.add(TradeHistoryEntry.create(tradeId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = trades; return result; }
Api { @NonNull @WorkerThread public CallResult<List<TradeHistoryEntry>> getTradeHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRADE_HISTORY, parameters); CallResult<List<TradeHistoryEntry>> 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<TradeHistoryEntry> trades = new ArrayList<>(); Set<String> tradeIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : tradeIds) { long tradeId = Long.parseLong(item); trades.add(TradeHistoryEntry.create(tradeId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = trades; return result; } }
Api { @NonNull @WorkerThread public CallResult<List<TradeHistoryEntry>> getTradeHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRADE_HISTORY, parameters); CallResult<List<TradeHistoryEntry>> 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<TradeHistoryEntry> trades = new ArrayList<>(); Set<String> tradeIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : tradeIds) { long tradeId = Long.parseLong(item); trades.add(TradeHistoryEntry.create(tradeId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = trades; 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<TradeHistoryEntry>> getTradeHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRADE_HISTORY, parameters); CallResult<List<TradeHistoryEntry>> 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<TradeHistoryEntry> trades = new ArrayList<>(); Set<String> tradeIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : tradeIds) { long tradeId = Long.parseLong(item); trades.add(TradeHistoryEntry.create(tradeId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = trades; 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<TradeHistoryEntry>> getTradeHistory( @NonNull Map<String, String> parameters) { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.TRADE_HISTORY, parameters); CallResult<List<TradeHistoryEntry>> 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<TradeHistoryEntry> trades = new ArrayList<>(); Set<String> tradeIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : tradeIds) { long tradeId = Long.parseLong(item); trades.add(TradeHistoryEntry.create(tradeId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = trades; 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);  }