Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Jun 17, 2024
1 parent 414f09a commit ae126bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,10 @@ enum class OrderStatus(val rawValue: String) {
canceling("BEST_EFFORT_CANCELED"),
filled("FILLED"),
`open`("OPEN"),
pending("PENDING"),
pending("PENDING"), // indexer returns order as BEST_EFFORT_OPENED, or BEST_EFFORT_CANCELED when order is IOC
untriggered("UNTRIGGERED"),
partiallyFilled("PARTIALLY_FILLED"),
partiallyCanceled("PARTIALLY_CANCELED");
partiallyFilled("PARTIALLY_FILLED"), // indexer returns order as OPEN but order is partially filled
partiallyCanceled("PARTIALLY_CANCELED"); // indexer returns order as CANCELED but order is partially filled

companion object {
operator fun invoke(rawValue: String): OrderStatus? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,11 @@ internal class OrderProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
parser.asDouble(payload["orderFlags"])?.let { orderFlags ->
// if order is short-term order and indexer returns best effort canceled and has no partial fill
// treat as a pending order until it's partially filled or finalized
val isShortTermOrder = orderFlags.equals(Numeric.double.ZERO)
val isBestEffortCanceled = modified["status"] == "BEST_EFFORT_CANCELED"
val cancelReason = parser.asString(modified["cancelReason"])
val isUserCanceled = cancelReason == "USER_CANCELED" || cancelReason == "ORDER_REMOVAL_REASON_USER_CANCELED"
if (orderFlags.equals(Numeric.double.ZERO) && isBestEffortCanceled && !isUserCanceled) {
if (isShortTermOrder && isBestEffortCanceled && !isUserCanceled) {
modified.safeSet("status", "PENDING")
}
}
Expand Down Expand Up @@ -319,7 +320,7 @@ internal class OrderProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
return Pair(existing, false)
}

private fun isStatusFinalized(status: Any?): Boolean {
private fun isStatusFinalized(status: String?): Boolean {
// once an order is filled, canceled, or canceled with partial fill
// there is no need to update status again
return when (status) {
Expand All @@ -333,7 +334,7 @@ internal class OrderProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
): Map<String, Any> {
val modified = existing.mutable()
// show order status as canceling if frontend initiated cancel
if (!isStatusFinalized(modified["status"])) {
if (!isStatusFinalized(parser.asString(modified["status"]))) {
modified["status"] = "BEST_EFFORT_CANCELED"
}

Expand Down

0 comments on commit ae126bd

Please sign in to comment.