Skip to content

Commit

Permalink
Enable resilience as part of the default specification
Browse files Browse the repository at this point in the history
  • Loading branch information
gmax0 committed Jun 14, 2021
1 parent b093d9f commit 5b3a9a1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
@Path("/api/v5")
@Produces(APPLICATION_JSON)
public interface Okex {
String instrumentsPath = "/public/instruments";
String instrumentsPath = "/public/instruments"; // Stated as 20 req/2 sec

// To avoid 429s, actual req/second may need to be lowered!
Map<String, List<Integer>> publicPathRateLimits =
new HashMap<String, List<Integer>>() {
{
put(instrumentsPath, Arrays.asList(20, 2)); // e.g. 20 requests per 2 seconds
put(instrumentsPath, Arrays.asList(8, 1));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@
@Path("/api/v5")
@Produces(MediaType.APPLICATION_JSON)
public interface OkexAuthenticated extends Okex {
String balancePath = "/account/balance";
String currenciesPath = "/asset/currencies";
String pendingOrdersPath = "/trade/orders-pending";
String placeOrderPath = "/trade/order";
String placeBatchOrderPath = "/trade/batch-orders";
String cancelOrderPath = "/trade/cancel-order";
String cancelBatchOrderPath = "trade/cancel-batch-orders";
String amendOrderPath = "trade/amend-order";
String amendBatchOrderPath = "trade/amend-batch-orders";
String balancePath = "/account/balance"; // Stated as 10 req/2 sec
String currenciesPath = "/asset/currencies"; // Stated as 6 req/sec
String pendingOrdersPath = "/trade/orders-pending"; // Stated as 20 req/2 sec
String placeOrderPath = "/trade/order"; // Stated as 60 req/2 sec
String placeBatchOrderPath = "/trade/batch-orders"; // Stated as 300 req/2 sec
String cancelOrderPath = "/trade/cancel-order"; // Stated as 60 req/2 sec
String cancelBatchOrderPath = "trade/cancel-batch-orders"; // Stated as 300 req/2 sec
String amendOrderPath = "trade/amend-order"; // Stated as 60 req/2 sec
String amendBatchOrderPath = "trade/amend-batch-orders"; // Stated as 300 req/2 sec

// To avoid 429s, actual req/second may need to be lowered!
Map<String, List<Integer>> privatePathRateLimits =
new HashMap<String, List<Integer>>() {
{
put(balancePath, Arrays.asList(6, 1));
put(balancePath, Arrays.asList(5, 1));
put(currenciesPath, Arrays.asList(6, 1));
put(pendingOrdersPath, Arrays.asList(20, 2));
put(placeOrderPath, Arrays.asList(60, 2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public ExchangeSpecification getDefaultExchangeSpecification() {
exchangeSpecification.setExchangeName("Okex");
exchangeSpecification.setExchangeDescription("Okex Exchange");

ExchangeSpecification.ResilienceSpecification resilienceSpec = new ExchangeSpecification.ResilienceSpecification();
resilienceSpec.setRetryEnabled(true);
resilienceSpec.setRateLimiterEnabled(true);
exchangeSpecification.setResilience(resilienceSpec);

exchangeSpecification.setExchangeSpecificParametersItem(Parameters.PARAM_USE_AWS, false);
exchangeSpecification.setExchangeSpecificParametersItem(
Parameters.PARAM_AWS_SSL_URI, "https://aws.okex.com");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@

@Slf4j
public class OkexExchangeIntegrationTest {
//Enter your authentication details here to run private endpoint tests
private static final String API_KEY = "";
private static final String SECRET_KEY = "";
private static final String PASSPHRASE = "";

@Test
public void testCreateExchangeShouldApplyDefaultSpecification() throws Exception {
ExchangeSpecification spec =
ExchangeFactory.INSTANCE
.createExchange(OkexExchange.class)
.getDefaultExchangeSpecification();
ExchangeSpecification spec = new OkexExchange().getDefaultExchangeSpecification();
final Exchange exchange = ExchangeFactory.INSTANCE.createExchange(spec);

assertThat(exchange.getExchangeSpecification().getSslUri()).isEqualTo("https://www.okex.com");
assertThat(exchange.getExchangeSpecification().getHost()).isEqualTo("okex.com");
assertThat(exchange.getExchangeSpecification().getResilience().isRateLimiterEnabled()).isEqualTo(true);
assertThat(exchange.getExchangeSpecification().getResilience().isRetryEnabled()).isEqualTo(true);
}

@Test
Expand Down

0 comments on commit 5b3a9a1

Please sign in to comment.