All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.contek.invoker.bybit.api.rest.user.PostOrderCancel Maven / Gradle / Ivy

package io.contek.invoker.bybit.api.rest.user;

import com.google.common.collect.ImmutableList;
import io.contek.invoker.bybit.api.ApiFactory;
import io.contek.invoker.bybit.api.common._OrderRef;
import io.contek.invoker.bybit.api.rest.common.ResponseWrapper;
import io.contek.invoker.commons.actor.IActor;
import io.contek.invoker.commons.actor.ratelimit.TypedPermitRequest;
import io.contek.invoker.commons.rest.RestContext;
import io.contek.invoker.commons.rest.RestMethod;
import io.contek.invoker.commons.rest.RestParams;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import static io.contek.invoker.bybit.api.rest.user.PostOrderCancel.Response;
import static io.contek.invoker.commons.rest.RestMethod.POST;
import static java.util.Objects.requireNonNull;

@NotThreadSafe
public final class PostOrderCancel extends UserRestRequest {

  private String category;
  private String symbol;
  private String orderId;
  private String orderLinkId;
  private String orderFilter;

  PostOrderCancel(IActor actor, RestContext context) {
    super(actor, context);
  }

  public PostOrderCancel setCategory(String category) {
    this.category = category;
    return this;
  }

  public PostOrderCancel setSymbol(String symbol) {
    this.symbol = symbol;
    return this;
  }

  public PostOrderCancel setOrderId(@Nullable String orderId) {
    this.orderId = orderId;
    return this;
  }

  public PostOrderCancel setOrderLinkId(@Nullable String orderLinkId) {
    this.orderLinkId = orderLinkId;
    return this;
  }

  public PostOrderCancel setOrderFilter(@Nullable String orderFilter) {
    this.orderFilter = orderFilter;
    return this;
  }

  @Override
  protected RestMethod getMethod() {
    return POST;
  }

  @Override
  protected String getEndpointPath() {
    return "/v5/order/cancel";
  }

  @Override
  protected RestParams getParams() {
    RestParams.Builder builder = RestParams.newBuilder();

    requireNonNull(category);
    builder.add("category", category);

    requireNonNull(symbol);
    builder.add("symbol", symbol);

    if (orderId == null && orderLinkId == null) {
      throw new IllegalArgumentException();
    }
    if (orderId != null) {
      builder.add("orderId", orderId);
    }
    if (orderLinkId != null) {
      builder.add("orderLinkId", orderLinkId);
    }
    if (orderFilter != null) {
      builder.add("orderFilter", orderFilter);
    }

    return builder.build();
  }

  @Override
  protected ImmutableList getRequiredQuotas() {
    return ApiFactory.RateLimits.ONE_REST_PRIVATE_ORDER_CREATE_REQUEST;
  }

  @Override
  protected Class getResponseType() {
    return Response.class;
  }

  @NotThreadSafe
  public static final class Response extends ResponseWrapper {}

  @NotThreadSafe
  public static final class Result extends _OrderRef {}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy