@Override public void run() { try { while(isRunning) { // process any updates that exist add(updateReports.take()); } } catch (InterruptedException ignored) {} } },
/** * Initializes the report history manager. * * <p>This can be a very expensive call depending on the value returned * by {@link #getReportHistoryOriginDate()} and the number of execution reports * in the database. */ protected final void initializeReportHistoryManager() { synchronized(AbstractRunningStrategy.class) { Date origin = getReportHistoryOriginDate(); Messages.USING_ORDER_HISTORY_ORIGIN.info(AbstractRunningStrategy.class, origin); try { if(orderHistoryManager != null) { orderHistoryManager.stop(); } orderHistoryManager = new LiveOrderHistoryManager(origin); orderHistoryManager.start(); } catch (ClientInitException e) { throw new RuntimeException(e); } } } /**
@Override public synchronized void stop() { SLF4JLoggerProxy.debug(LiveOrderHistoryManager.class, "LiveOrderHistoryManager stopping"); //$NON-NLS-1$ if(!isRunning) { return; } if(reportProcessor != null) { reportProcessor.interrupt(); try { reportProcessor.join(); } catch (InterruptedException ignored) {} reportProcessor = null; } clear(); isRunning = false; } /**
@Override public synchronized void stop() { getClient().removeReportListener(this); super.stop(); } }
@Override public synchronized void start() { getClient().addReportListener(this); super.start(); } /* (non-Javadoc)
/** * Gets the collection of open orders represented by the most recent <code>ExecutionReport</code>. * * @return a <code>Collection<ExecutionReport></code> value */ protected final Collection<ExecutionReport> getOpenOrders() { return orderHistoryManager.getOpenOrders().values(); } /**
/** * Gets the <code>ReportBase</code> values representing the order history of the given <code>OrderID</code>. * * <p>The <code>ReportBase</code> objects returned by this call represent the history of the order represented * by the given <code>OrderID</code>. if there is no order history for the given <code>OrderID</code>, this operation * will return an empty collection. * * <p>The values returned by this operation are sorted from newest to oldest: the order's current status is represented * by the first element in the collection. * * <p>The collection returned by this operation will be updated as the underlying report history changes. The collection itself * may not be modified. * * <p>The contents of the returned collection are limited by the value returned by {@link #getReportHistoryOriginDate()}. The * default value is all reports. No reports with a sending time before the origin date will be returned. * * @param inOrderID an <code>OrderID</code> value corresponding to an existing order, either open or closed * @return a <code>Deque<ReportBase></code> value containing the <code>ReportBase</code> objects */ protected final Deque<ReportBase> getExecutionReports(OrderID inOrderID) { if (inOrderID == null) { return EMPTY_REPORTS; } return orderHistoryManager.getReportHistoryFor(inOrderID); } /**
/** * Gets the <code>OrderStatus</code> for the given <code>OrderID</code>. * * <p>The given <code>OrderID</code> may be any part of the order chain. For example, if an order is replaced, * either the original <code>OrderID</code> or the current <code>OrderID</code> will return the same value, * although only the current <code>OrderID</code> is open. * * @param inOrderID an <code>OrderID</code> value or <code>null</code> if the given order cannot be found * @return an <code>OrderStatus</code> value */ protected final OrderStatus getOrderStatus(OrderID inOrderID) { ReportBase latestReport = orderHistoryManager.getLatestReportFor(inOrderID); if(latestReport == null) { return null; } return latestReport.getOrderStatus(); } /**
/** * Returns the list of <code>OrderID</code> values for open orders created in this * session in the order they were submitted. * * <p>Returns IDs of open orders only. Orders that were canceled, replaced, filled, or * otherwise are no longer open will not be returned. For orders submitted * via {@link AbstractRunningStrategy#cancelReplace(OrderID, OrderSingle, boolean)}, * the ID of the {@link OrderReplace} value sent to the broker is returned, not the * {@link OrderSingle} value used to create the <code>OrderReplace</code>. * * @return a <code>Set<OrderID></code> value */ protected final Set<OrderID> getOpenOrderIDs() { return orderHistoryManager.getOpenOrders().keySet(); } /**
@Override public void receiveExecutionReport(ExecutionReport inReport) { SLF4JLoggerProxy.debug(LiveOrderHistoryManager.class, "Received {}", //$NON-NLS-1$ inReport); if(inReport != null) { super.add(inReport); } } /* (non-Javadoc)
strategy); Set<OrderID> openOrdersCopy = new HashSet<OrderID>(orderHistoryManager.getOpenOrders().keySet()); SLF4JLoggerProxy.debug(AbstractRunningStrategy.class, "Found {} open orders to cancel",
@Override public void receiveCancelReject(OrderCancelReject inReport) { SLF4JLoggerProxy.debug(LiveOrderHistoryManager.class, "Received {}", //$NON-NLS-1$ inReport); if(inReport != null) { super.add(inReport); } } /* (non-Javadoc)
return null; ExecutionReport report = orderHistoryManager.getOpenOrders().get(inOrderID); if(report == null) { StrategyModule.log(LogEventBuilder.warn().withMessage(INVALID_ORDERID,
/** * Provides a non-overridable route for {@link OrderCancelReject} data to * allow this object to process the data before handing it to the strategy. * * @param inCancelReject an <code>OrderCanceleject</code> value */ final void onCancelRejectRedirected(OrderCancelReject inCancelReject) { // record the order cancel reject orderHistoryManager.add(inCancelReject); // now notify the strategy onCancelReject(inCancelReject); } /**
return null; ExecutionReport executionReport = orderHistoryManager.getOpenOrders().get(inOrderID); if(executionReport == null) { StrategyModule.log(LogEventBuilder.warn().withMessage(INVALID_ORDERID,
/** * Provides a non-overridable route for {@link ExecutionReport} data to * allow this object to process the data before handing it to the strategy. * * @param inExecutionReport an <code>ExecutionReport</code> value */ final void onExecutionReportRedirected(ExecutionReport inExecutionReport) { // record the execution report orderHistoryManager.add(inExecutionReport); // now notify the strategy onExecutionReport(inExecutionReport); } /**