Skip to main content

Direction

Represents the direction of a trade or order. BUY = Going long (buying to open, or buying to close a short) SELL = Going short (selling to open, or selling to close a long)

Direction.java
package com.bookmap.ordermanagement.model;

/**
* Represents the direction of a trade or order.
*
* BUY = Going long (buying to open, or buying to close a short)
* SELL = Going short (selling to open, or selling to close a long)
*/
public enum Direction {

BUY("BUY", true),
SELL("SELL", false);

private final String label;
private final boolean isBuy;

Direction(String label, boolean isBuy) {
this.label = label;
this.isBuy = isBuy;
}

/**
* Returns true if this is a BUY direction.
*/
public boolean isBuy() {
return isBuy;
}

/**
* Returns the opposite direction.
*/
public Direction opposite() {
return this == BUY ? SELL : BUY;
}

/**
* Convert from boolean (Bookmap convention).
*/
public static Direction fromBoolean(boolean isBuy) {
return isBuy ? BUY : SELL;
}

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