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

org.knowm.xchange.bitmex.dto.trade.BitmexOrderFlags Maven / Gradle / Ivy

There is a newer version: 5.2.0
Show newest version
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 java.io.IOException;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.knowm.xchange.dto.Order.IOrderFlags;

public enum BitmexOrderFlags implements IOrderFlags {
  FCIB, // prefer fee in base currency
  FCIQ, // prefer fee in quote currency
  NOMPP, // no market price protection
  POST, // for market maker orders
  VIQC; // volume in quote currency

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

  static {
    for (BitmexOrderFlags orderFlag : values()) fromString.put(orderFlag.toString(), orderFlag);
  }

  public static BitmexOrderFlags fromString(String orderTypeString) {

    return fromString.get(orderTypeString.toLowerCase());
  }

  @Override
  public String toString() {

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

  static class BitmexOrderFlagsDeserializer extends JsonDeserializer> {

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

      ObjectCodec oc = jsonParser.getCodec();
      JsonNode node = oc.readTree(jsonParser);
      String orderFlagsString = node.textValue();
      Set orderFlags = EnumSet.noneOf(BitmexOrderFlags.class);
      if (!orderFlagsString.isEmpty()) {
        for (String orderFlag : orderFlagsString.split(",")) orderFlags.add(fromString(orderFlag));
      }
      return orderFlags;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy