Skip to content

Commit

Permalink
MATP-1125 Add Cancel All Open Orders to Open Order View
Browse files Browse the repository at this point in the history
  • Loading branch information
colinduplantis committed Apr 1, 2023
1 parent 4702abb commit a043f86
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;

Expand Down Expand Up @@ -80,6 +81,7 @@ protected void onStart()
tradeClientService = serviceManager.getService(TradeClientService.class);
initializeTradeMessageListener();
mainLayout = new VBox();
aboveTableLayout = new FlowPane();
reportsTableView = new TableView<>();
reportsTableView.setPlaceholder(getPlaceholder());
TableViewSelectionModel<FixClazz> selectionModel = reportsTableView.getSelectionModel();
Expand All @@ -103,7 +105,8 @@ public void changed(ObservableValue<? extends Number> inObservable,
reportsTableView.prefWidthProperty().bind(getParentWindow().widthProperty());
reportsTableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
mainLayout.prefHeightProperty().bind(getParentWindow().heightProperty());
mainLayout.getChildren().addAll(reportsTableView,
mainLayout.getChildren().addAll(aboveTableLayout,
reportsTableView,
pagination);
currentPage = 0;
pageSize = 10;
Expand Down Expand Up @@ -165,6 +168,37 @@ public void receiveTradeMessage(TradeMessage inTradeMessage)
};
tradeClientService.addTradeMessageListener(tradeMessageListener);
}
/**
* Cancel the order from the given report.
*
* @param inReport a <code>FixClazz</code> value
*/
protected void cancelOrder(FixClazz inReport)
{
ExecutionReport executionReport = tradeClientService.getLatestExecutionReportForOrderChain(inReport.getOrderId());
if(executionReport == null) {
uiMessageService.post(new NotificationEvent("Cancel Order",
"Unable to cancel " + inReport.getOrderId() + ": no execution report",
AlertType.ERROR));
return;
}
OrderCancel orderCancel = Factory.getInstance().createOrderCancel(executionReport);
SLF4JLoggerProxy.info(this,
"{} sending {}",
SessionUser.getCurrent().getUsername(),
orderCancel);
SendOrderResponse response = tradeClientService.send(orderCancel);
if(response.getFailed()) {
uiMessageService.post(new NotificationEvent("Cancel Order",
"Unable to submit cancel: " + response.getOrderId() + " " + response.getMessage(),
AlertType.ERROR));
return;
} else {
uiMessageService.post(new NotificationEvent("Cancel Order",
"Cancel order " + response.getOrderId() + " submitted",
AlertType.INFORMATION));
}
}
/**
* Initialize the context menu for the FIX table.
*
Expand All @@ -176,29 +210,7 @@ protected void initializeContextMenu(TableView<FixClazz> inTableView)
cancelOrderMenuItem = new MenuItem("Cancel Order");
cancelOrderMenuItem.setOnAction(event -> {
FixClazz report = inTableView.getSelectionModel().getSelectedItem();
ExecutionReport executionReport = tradeClientService.getLatestExecutionReportForOrderChain(report.getOrderId());
if(executionReport == null) {
uiMessageService.post(new NotificationEvent("Cancel Order",
"Unable to cancel " + report.getOrderId() + ": no execution report",
AlertType.ERROR));
return;
}
OrderCancel orderCancel = Factory.getInstance().createOrderCancel(executionReport);
SLF4JLoggerProxy.info(this,
"{} sending {}",
SessionUser.getCurrent().getUsername(),
orderCancel);
SendOrderResponse response = tradeClientService.send(orderCancel);
if(response.getFailed()) {
uiMessageService.post(new NotificationEvent("Cancel Order",
"Unable to submit cancel: " + response.getOrderId() + " " + response.getMessage(),
AlertType.ERROR));
return;
} else {
uiMessageService.post(new NotificationEvent("Cancel Order",
"Cancel order " + response.getOrderId() + " submitted",
AlertType.INFORMATION));
}
cancelOrder(report);
});
replaceOrderMenuItem = new MenuItem("Replace Order");
replaceOrderMenuItem.setOnAction(event -> {
Expand Down Expand Up @@ -293,6 +305,17 @@ protected void enableContextMenuItems(FixClazz inNewValue)
cancelOrderMenuItem.setDisable(!orderStatus.isCancellable());
replaceOrderMenuItem.setDisable(!orderStatus.isCancellable());
}
/**
* Get the layout for above-the-table controls.
*
* <p>Subclasses can add controls to this layout as desired.</p>
*
* @return a <code>FlowPane</code> value
*/
protected FlowPane getAboveTableLayout()
{
return aboveTableLayout;
}
/**
* Render the given column as a Date cell.
*
Expand Down Expand Up @@ -804,4 +827,8 @@ protected AbstractFixMessageView(Region inParentWindow,
* listens for trade messages
*/
private TradeMessageListener tradeMessageListener;
/**
* optional layout used for above-the-table
*/
private FlowPane aboveTableLayout;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import org.marketcetera.persist.PageRequest;
import org.marketcetera.trade.OrderID;
import org.marketcetera.trade.OrderSummary;
import org.marketcetera.ui.PhotonServices;
import org.marketcetera.ui.events.NewWindowEvent;
import org.marketcetera.ui.trade.view.AbstractFixMessageView;
import org.marketcetera.ui.view.ContentView;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Region;


Expand Down Expand Up @@ -59,6 +65,22 @@ public OpenOrderView(Region inParentWindow,
inEvent,
inViewProperties);
}
/* (non-Javadoc)
* @see org.marketcetera.ui.trade.view.AbstractFixMessageView#onStart()
*/
@Override
protected void onStart()
{
super.onStart();
cancelOpenOrdersButton = new Button();
cancelOpenOrdersButton.setTooltip(new Tooltip("Cancel all open orders"));
cancelOpenOrdersButton.setGraphic(new ImageView(PhotonServices.getIcon("images/erase.png")));
cancelOpenOrdersButton.setPadding(new Insets(0,20,0,20));
cancelOpenOrdersButton.setOnAction(event -> cancelOpenOrders());
getAboveTableLayout().setAlignment(Pos.BASELINE_RIGHT);
getAboveTableLayout().getChildren().add(cancelOpenOrdersButton);
getAboveTableLayout().prefWidthProperty().bind(getMainLayout().widthProperty());
}
/* (non-Javadoc)
* @see org.marketcetera.ui.trade.view.AbstractFixMessageView#getClientReports(org.marketcetera.persist.PageRequest)
*/
Expand Down Expand Up @@ -95,6 +117,19 @@ protected void initializeColumns(TableView<DisplayOrderSummary> inTableView)
inTableView.getColumns().add(2,
rootOrderIdColumn);
}
/**
* Cancel all open orders displayed in the FIX table.
*/
private void cancelOpenOrders()
{
for(DisplayOrderSummary orderSummary : reportsTableView.getItems()) {
cancelOrder(orderSummary);
}
}
/**
* cancel open orders button
*/
private Button cancelOpenOrdersButton;
/**
* root order id table column
*/
Expand Down
Binary file added photon/src/main/resources/images/erase.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a043f86

Please sign in to comment.