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

io.contek.invoker.bybitinverse.api.rest.user.PostPositionLeverageSave Maven / Gradle / Ivy

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

import com.google.common.collect.ImmutableList;
import io.contek.invoker.bybitinverse.api.ApiFactory;
import io.contek.invoker.bybitinverse.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.commons.rest.RestMethod.POST;
import static java.util.Objects.requireNonNull;

@NotThreadSafe
public final class PostPositionLeverageSave
    extends UserRestRequest {

  private String symbol;
  private Double leverage;
  private Boolean leverage_only;

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

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

  public PostPositionLeverageSave setLeverage(Double leverage) {
    this.leverage = leverage;
    return this;
  }

  public PostPositionLeverageSave setLeverageOnly(@Nullable Boolean leverage_only) {
    this.leverage_only = leverage_only;
    return this;
  }

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

  @Override
  protected String getEndpointPath() {
    return "/v2/private/position/leverage/save";
  }

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

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

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

    if (leverage_only != null) {
      builder.add("leverage_only", leverage_only);
    }

    return builder.build();
  }

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

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

  @NotThreadSafe
  public static final class Response extends ResponseWrapper {}
}