Skip to content

Commit

Permalink
Merge pull request #2801 from SaschaZ/add_missing_order_parameters
Browse files Browse the repository at this point in the history
[Bitmex] Add missing order parameters
  • Loading branch information
timmolter committed Sep 18, 2018
2 parents 91b2706 + 70b438c commit 4ab85c1
Show file tree
Hide file tree
Showing 18 changed files with 1,788 additions and 876 deletions.
1,072 changes: 641 additions & 431 deletions xchange-bitmex/src/main/java/org/knowm/xchange/bitmex/Bitmex.java

Large diffs are not rendered by default.

Expand Up @@ -24,6 +24,10 @@ public BitmexException(@JsonProperty("error") Error error) {
this.error = error;
}

public String getErrorName() {
return error.name;
}

@Override
public String getMessage() {
return error.message == null ? error.name : error.message;
Expand Down
Expand Up @@ -27,7 +27,7 @@ public class BitmexPrivateOrder extends AbstractHttpResponseAware {
private final BigDecimal stopPx;
private final BigDecimal pegOffsetValue;
private final String pegPriceType;
private final String ordType;
private final String orderType;
private final String timeInForce;
private final String execInst;
private final String contingencyType;
Expand Down Expand Up @@ -67,7 +67,7 @@ public BitmexPrivateOrder(
@JsonProperty("stopPx") BigDecimal stopPx,
@JsonProperty("pegOffsetValue") BigDecimal pegOffsetValue,
@JsonProperty("pegPriceType") String pegPriceType,
@JsonProperty("ordType") String ordType,
@JsonProperty("orderType") String orderType,
@JsonProperty("timeInForce") String timeInForce,
@JsonProperty("execInst") String execInst,
@JsonProperty("contingencyType") String contingencyType,
Expand Down Expand Up @@ -102,7 +102,7 @@ public BitmexPrivateOrder(
this.stopPx = stopPx;
this.pegOffsetValue = pegOffsetValue;
this.pegPriceType = pegPriceType;
this.ordType = ordType;
this.orderType = orderType;
this.timeInForce = timeInForce;
this.execInst = execInst;
this.contingencyType = contingencyType;
Expand Down Expand Up @@ -192,8 +192,8 @@ public String getPegPriceType() {
return pegPriceType;
}

public String getOrdType() {
return ordType;
public String getOrderType() {
return orderType;
}

public String getTimeInForce() {
Expand Down Expand Up @@ -303,8 +303,8 @@ public String toString() {
+ ", pegPriceType='"
+ pegPriceType
+ '\''
+ ", ordType='"
+ ordType
+ ", orderType='"
+ orderType
+ '\''
+ ", timeInForce='"
+ timeInForce
Expand Down
@@ -0,0 +1,19 @@
package org.knowm.xchange.bitmex.dto.trade;

@SuppressWarnings("unused")
public enum BitmexContingencyType {
OCO("OneCancelsTheOther"),
OTO("OneTriggersTheOther"),
OUOA("OneUpdatesTheOtherAbsolute"),
OUOP("OneUpdatesTheOtherProportional");

private String apiParameter;

BitmexContingencyType(String apiParameter) {
this.apiParameter = apiParameter;
}

public String toApiParameter() {
return apiParameter;
}
}
@@ -0,0 +1,108 @@
package org.knowm.xchange.bitmex.dto.trade;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("unused")
public enum BitmexExecutionInstruction {
PARTICIPATE_DO_NOT_INITIATE("ParticipateDoNotInitiate"),
ALL_OR_NONE("AllOrNone"),
MARK_PRICE("MarkPrice"),
INDEX_PRICE("IndexPrice"),
LAST_PRICE("LastPrice"),
CLOSE("Close"),
REDUCE_ONLY("ReduceOnly"),
FIXED("Fixed");

private String apiParameter;

BitmexExecutionInstruction(String apiParameter) {
this.apiParameter = apiParameter;
}

@Override
public String toString() {
return apiParameter;
}

public static class Builder {

private boolean postOnly;
private boolean allOrNone;
private boolean markPrice;
private boolean indexPrice;
private boolean lastPrice;
private boolean close;
private boolean reduceOnly;
private boolean fixed;

public List<BitmexExecutionInstruction> build() {
final ArrayList<BitmexExecutionInstruction> instructions = new ArrayList<>();
if (postOnly) {
instructions.add(PARTICIPATE_DO_NOT_INITIATE);
}
if (allOrNone) {
instructions.add(ALL_OR_NONE);
}
if (markPrice) {
instructions.add(MARK_PRICE);
}
if (indexPrice) {
instructions.add(INDEX_PRICE);
}
if (lastPrice) {
instructions.add(LAST_PRICE);
}
if (close) {
instructions.add(CLOSE);
}
if (reduceOnly) {
instructions.add(REDUCE_ONLY);
}
if (fixed) {
instructions.add(FIXED);
}
return instructions;
}

public Builder setPostOnly(boolean postOnly) {
this.postOnly = postOnly;
return this;
}

public Builder setAllOrNone(boolean allOrNone) {
this.allOrNone = allOrNone;
return this;
}

public Builder setMarkPrice(boolean markPrice) {
this.markPrice = markPrice;
return this;
}

public Builder setIndexPrice(boolean indexPrice) {
this.indexPrice = indexPrice;
return this;
}

public Builder setLastPrice(boolean lastPrice) {
this.lastPrice = lastPrice;
return this;
}

public Builder setClose(boolean close) {
this.close = close;
return this;
}

public Builder setReduceOnly(boolean reduceOnly) {
this.reduceOnly = reduceOnly;
return this;
}

public Builder setFixed(boolean fixed) {
this.fixed = fixed;
return this;
}
}
}
Expand Up @@ -7,7 +7,7 @@ public class BitmexOrderDescription {

private final String assetPair;
private final BitmexSide type;
private final BitmexOrderType orderType;
private final BitmexOrderTypeDescription orderType;
private final BigDecimal price;
private final BigDecimal secondaryPrice;
private final String leverage;
Expand All @@ -31,7 +31,7 @@ public class BitmexOrderDescription {
public BitmexOrderDescription(
@JsonProperty("pair") String assetPair,
@JsonProperty("type") BitmexSide type,
@JsonProperty("ordertype") BitmexOrderType orderType,
@JsonProperty("ordertype") BitmexOrderTypeDescription orderType,
@JsonProperty("price") BigDecimal price,
@JsonProperty("price2") BigDecimal secondaryPrice,
@JsonProperty("leverage") String leverage,
Expand Down Expand Up @@ -60,7 +60,7 @@ public BitmexSide getType() {
return type;
}

public BitmexOrderType getOrderType() {
public BitmexOrderTypeDescription getOrderType() {

return orderType;
}
Expand Down
@@ -1,67 +1,23 @@
package org.knowm.xchange.bitmex.dto.trade;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.knowm.xchange.bitmex.dto.trade.BitmexOrderType.BitmexOrderTypeDeserializer;

@JsonDeserialize(using = BitmexOrderTypeDeserializer.class)
@SuppressWarnings("unused")
public enum BitmexOrderType {
MARKET,
LIMIT,
STOP_LOSS,
TAKE_PROFIT,
STOP_LOSS_PROFIT,
STOP_LOSS_PROFIT_LIMIT,
STOP_LOSS_LIMIT,
TAKE_PROFIT_LIMIT,
TRAILING_STOP,
TRAILING_STOP_LIMIT,
STOP_LOSS_AND_LIMIT,
SETTLE_POSITION;

private static final Map<String, BitmexOrderType> fromString = new HashMap<>();

static {
for (BitmexOrderType orderType : values()) fromString.put(orderType.toString(), orderType);

fromString.put("l", LIMIT);
fromString.put("m", MARKET);
LIMIT("Limit"),
STOP("Stop"),
MARKET("Market"),
STOP_LIMIT("StopLimit"),
PEGGED("Pegged"),
MARKET_IF_TOUCHED("MarketIfTouched"),
LIMIT_IF_TOUCHED("MarketIfTouched"),
MARKET_WITH_LEFT_OVER_AS_LIMIT("MarketWithLeftOverAsLimit");

private String apiParameter;

BitmexOrderType(String apiParameter) {
this.apiParameter = apiParameter;
}

public static BitmexOrderType fromString(String orderTypeString) {

return fromString.get(orderTypeString.replace('-', '_').toLowerCase());
}

@Override
public String toString() {

return super.toString().toLowerCase();
}

public String toApiFormat() {

return name().toLowerCase().replace('_', '-');
}

static class BitmexOrderTypeDeserializer extends JsonDeserializer<BitmexOrderType> {

@Override
public BitmexOrderType deserialize(JsonParser jsonParser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {

ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
String orderTypeString = node.textValue();
return fromString(orderTypeString);
}
public String toApiParameter() {
return apiParameter;
}
}
@@ -0,0 +1,69 @@
package org.knowm.xchange.bitmex.dto.trade;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.knowm.xchange.bitmex.dto.trade.BitmexOrderTypeDescription.BitmexOrderTypeDeserializer;

@JsonDeserialize(using = BitmexOrderTypeDeserializer.class)
public enum BitmexOrderTypeDescription {
MARKET,
LIMIT,
STOP_LOSS,
TAKE_PROFIT,
STOP_LOSS_PROFIT,
STOP_LOSS_PROFIT_LIMIT,
STOP_LOSS_LIMIT,
TAKE_PROFIT_LIMIT,
TRAILING_STOP,
TRAILING_STOP_LIMIT,
STOP_LOSS_AND_LIMIT,
SETTLE_POSITION;

private static final Map<String, BitmexOrderTypeDescription> fromString = new HashMap<>();

static {
for (BitmexOrderTypeDescription orderType : values())
fromString.put(orderType.toString(), orderType);

fromString.put("l", LIMIT);
fromString.put("m", MARKET);
}

public static BitmexOrderTypeDescription fromString(String orderTypeString) {

return fromString.get(orderTypeString.replace('-', '_').toLowerCase());
}

@Override
public String toString() {

return super.toString().toLowerCase();
}

public String toApiFormat() {

return name().toLowerCase().replace('_', '-');
}

static class BitmexOrderTypeDeserializer extends JsonDeserializer<BitmexOrderTypeDescription> {

@Override
public BitmexOrderTypeDescription deserialize(
JsonParser jsonParser, DeserializationContext ctxt)
throws IOException, JsonProcessingException {

ObjectCodec oc = jsonParser.getCodec();
JsonNode node = oc.readTree(jsonParser);
String orderTypeString = node.textValue();
return fromString(orderTypeString);
}
}
}
@@ -0,0 +1,20 @@
package org.knowm.xchange.bitmex.dto.trade;

@SuppressWarnings("unused")
public enum BitmexPegPriceType {
LAST_PEG("LastPeg"),
MID_PRICE_PEG("MidPricePeg"),
MARGET_PEG("MarketPeg"),
PRIMARY_PEG("PrimaryPeg"),
TRAILING_STOP_PEG("TrailingStopPeg");

private String apiParameter;

BitmexPegPriceType(String apiParameter) {
this.apiParameter = apiParameter;
}

public String toApiParameter() {
return apiParameter;
}
}

0 comments on commit 4ab85c1

Please sign in to comment.