@Test public void activeOrders_success() throws Exception { when(mockAuthApi.makeRequest(eq(ACTIVE_ORDERS), anyMapOf(String.class, String.class))) .thenReturn(JSON_PARSER.parse("{\n" + "\t\"success\":1,\n" + "\t\"return\":{\n" + "\t\t\"343154\":{\n" + "\t\t\t\"pair\":\"btc_usd\",\n" + "\t\t\t\"type\":\"sell\",\n" + "\t\t\t\"amount\":1.00000000,\n" + "\t\t\t\"rate\":3.00000000,\n" + "\t\t\t\"timestamp_created\":1342448420,\n" + "\t\t\t\"status\":0\n" + "\t\t}\n" + "\t}\n" + "}").getAsJsonObject()); CallResult<List<ActiveOrder>> callResult = testable.getActiveOrders(); assertTrue(callResult.isSuccess()); assertNull(callResult.getError()); List<ActiveOrder> activeOrders = callResult.getPayload(); assertNotNull(activeOrders); assertEquals(1, activeOrders.size()); ActiveOrder activeOrder = activeOrders.get(0); assertEquals(343154, activeOrder.getId()); assertEquals("BTC/USD", activeOrder.getPair()); assertEquals("sell", activeOrder.getType()); assertEquals(new BigDecimal("1"), activeOrder.getAmount()); assertEquals(new BigDecimal("3"), activeOrder.getRate()); assertEquals(1342448420, activeOrder.getCreatedAt()); assertEquals(0, activeOrder.getStatus()); }
@NonNull @WorkerThread public CallResult<List<ActiveOrder>> getActiveOrders() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.ACTIVE_ORDERS, null); CallResult<List<ActiveOrder>> 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<ActiveOrder> activeOrders = new ArrayList<>(); Set<String> orderIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : orderIds) { long orderId = Long.parseLong(item); activeOrders.add(ActiveOrder.create(orderId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = activeOrders; return result; }
Api { @NonNull @WorkerThread public CallResult<List<ActiveOrder>> getActiveOrders() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.ACTIVE_ORDERS, null); CallResult<List<ActiveOrder>> 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<ActiveOrder> activeOrders = new ArrayList<>(); Set<String> orderIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : orderIds) { long orderId = Long.parseLong(item); activeOrders.add(ActiveOrder.create(orderId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = activeOrders; return result; } }
Api { @NonNull @WorkerThread public CallResult<List<ActiveOrder>> getActiveOrders() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.ACTIVE_ORDERS, null); CallResult<List<ActiveOrder>> 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<ActiveOrder> activeOrders = new ArrayList<>(); Set<String> orderIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : orderIds) { long orderId = Long.parseLong(item); activeOrders.add(ActiveOrder.create(orderId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = activeOrders; 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<ActiveOrder>> getActiveOrders() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.ACTIVE_ORDERS, null); CallResult<List<ActiveOrder>> 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<ActiveOrder> activeOrders = new ArrayList<>(); Set<String> orderIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : orderIds) { long orderId = Long.parseLong(item); activeOrders.add(ActiveOrder.create(orderId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = activeOrders; 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<ActiveOrder>> getActiveOrders() { JsonObject response = authApi.makeRequest(AuthApi.TradeMethod.ACTIVE_ORDERS, null); CallResult<List<ActiveOrder>> 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<ActiveOrder> activeOrders = new ArrayList<>(); Set<String> orderIds = response.getAsJsonObject(RETURN_KEY).keySet(); for (String item : orderIds) { long orderId = Long.parseLong(item); activeOrders.add(ActiveOrder.create(orderId, response.getAsJsonObject(RETURN_KEY).getAsJsonObject(item))); } result.payload = activeOrders; 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);  }