|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.marketcetera.strategy.AbstractRunningStrategy
public abstract class AbstractRunningStrategy
Base class for running strategies.
| Constructor Summary | |
|---|---|
AbstractRunningStrategy()
|
|
| Method Summary | |
|---|---|
protected void |
cancelAllDataRequests()
Cancels all data requests from this strategy. |
protected int |
cancelAllOrders()
Submits cancel requests for all OrderSingle open orders owned by the strategy's owner. |
protected void |
cancelDataFlow(DataFlowID inDataFlowID)
Cancels a data flow identified by the supplied data flow ID. |
protected void |
cancelDataRequest(int inRequestID)
Cancels the given data request. |
protected OrderCancel |
cancelOrder(OrderID inOrderID,
boolean inSendOrder)
Submits a request to cancel the OrderSingle with the given OrderID. |
protected OrderReplace |
cancelReplace(OrderID inOrderID,
OrderSingle inNewOrder,
boolean inSendOrder)
Submits a cancel-replace order for the given OrderID with
the given Order. |
protected DataFlowID |
createDataFlow(boolean inAppendDataSink,
DataRequest... inRequests)
Initiates a data flow request. |
protected void |
debug(String inMessage)
Emits the given debug message to the strategy log output. |
protected void |
error(String inMessage)
Emits the given error message to the strategy log output. |
protected Map<PositionKey<Future>,BigDecimal> |
getAllFuturePositionsAsOf(Date inDate)
Gets all open Future positions at the given point in time. |
protected Map<PositionKey<Option>,BigDecimal> |
getAllOptionPositionsAsOf(Date inDate)
Gets all open Option positions at the given point in time. |
protected Map<PositionKey<Equity>,BigDecimal> |
getAllPositionsAsOf(Date inDate)
Gets all open Equity positions at the given point in time. |
protected BrokerStatus[] |
getBrokers()
Returns the list of brokers known to the system. |
protected Deque<ReportBase> |
getExecutionReports(OrderID inOrderID)
Gets the ReportBase values representing the order history of the given OrderID. |
protected BigDecimal |
getFuturePositionAsOf(Date inDate,
String inUnderlyingSymbol,
FutureExpirationMonth inExpirationMonth,
int inExpirationYear)
Gets the position in the given Future at the given point in time. |
protected Set<OrderID> |
getOpenOrderIDs()
Returns the list of OrderID values for open orders created in this
session in the order they were submitted. |
protected Collection<ExecutionReport> |
getOpenOrders()
Gets the collection of open orders represented by the most recent ExecutionReport. |
protected BigDecimal |
getOptionPositionAsOf(Date inDate,
String inOptionRoot,
String inExpiry,
BigDecimal inStrikePrice,
OptionType inType)
Gets the position in the given Option at the given point in time. |
protected Map<PositionKey<Option>,BigDecimal> |
getOptionPositionsAsOf(Date inDate,
String... inOptionRoots)
Gets open positions for the options specified by the given option roots at the given point in time. |
protected Collection<String> |
getOptionRoots(String inUnderlying)
Gets the set of of known option roots for the given underlying symbol. |
protected OrderStatus |
getOrderStatus(OrderID inOrderID)
Gets the OrderStatus for the given OrderID. |
protected String |
getParameter(String inName)
Gets the parameter associated with the given name. |
protected BigDecimal |
getPositionAsOf(Date inDate,
String inSymbol)
Gets the position in the given Equity at the given point in time. |
protected static String |
getProperty(String inKey)
Gets the value associated with the given key. |
protected Date |
getReportHistoryOriginDate()
Gets the report history origin date to use for the order history. |
protected Set<OrderID> |
getSubmittedOrderIDs()
Returns the list of open order IDs created during this session in the order they were submitted. |
protected String |
getUnderlying(String inOptionRoot)
Gets the underlying symbol for the given option root, if available. |
protected ModuleURN |
getURN()
Gets the ModuleURN of this strategy. |
protected Properties |
getUserData()
Gets the user data associated with the current user. |
protected void |
info(String inMessage)
Emits the given info message to the strategy log output. |
protected void |
initializeReportHistoryManager()
Initializes the report history manager. |
protected void |
requestCallbackAfter(long inDelay,
Object inData)
Requests a callback after a specified delay in milliseconds. |
protected void |
requestCallbackAt(Date inDate,
Object inData)
Requests a callback at a specific point in time. |
protected void |
requestCallbackEvery(long inDelay,
long inPeriod,
Object inData)
Requests a callback periodically after a specified period in milliseconds. |
protected int |
requestCEPData(String[] inStatements,
String inSource)
Creates a complex event processor query. |
protected int |
requestMarketData(MarketDataRequest inRequest)
Requests market data. |
protected int |
requestMarketData(String inRequest)
Requests market data. |
protected int |
requestProcessedMarketData(MarketDataRequest inRequest,
String[] inStatements,
String inCepSource)
Requests market data processed by the given complex event processor. |
protected int |
requestProcessedMarketData(String inRequest,
String[] inStatements,
String inCepSource)
Requests market data processed by the given complex event processor from the given source. |
protected boolean |
send(Object inData)
Sends an order to order subscribers. |
protected void |
sendEvent(Event inEvent)
Sends the given event to the appropriate subscribers. |
protected void |
sendEventToCEP(Event inEvent,
String inProvider)
Sends the given event to the CEP module indicated by the provider. |
protected void |
sendMessage(Message inMessage,
BrokerID inBroker)
Sends a FIX message. |
protected void |
sendNotification(Notification inNotification)
Sends the given notification to the appropriate subscribers. |
protected static void |
setProperty(String inKey,
String inValue)
Sets the given key to the given value. |
protected void |
setUserData(Properties inUserData)
Sets the user data associated with the current user. |
protected void |
suggestTrade(OrderSingle inOrder,
BigDecimal inScore,
String inIdentifier)
Suggests a trade. |
String |
toString()
|
protected void |
warn(String inMessage)
Emits the given warn message to the strategy log output. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.marketcetera.strategy.RunningStrategy |
|---|
onAsk, onBid, onCallback, onCancelReject, onDividend, onExecutionReport, onMarketstat, onOther, onStart, onStop, onTrade |
| Constructor Detail |
|---|
public AbstractRunningStrategy()
| Method Detail |
|---|
public final String toString()
toString in class Objectprotected final Set<OrderID> getSubmittedOrderIDs()
Returns all order IDs regardless of their state.
Set<OrderID> valueprotected final Set<OrderID> getOpenOrderIDs()
OrderID values for open orders created in this
session in the order they were submitted.
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 cancelReplace(OrderID, OrderSingle, boolean),
the ID of the OrderReplace value sent to the broker is returned, not the
OrderSingle value used to create the OrderReplace.
Set<OrderID> valueprotected final Collection<ExecutionReport> getOpenOrders()
ExecutionReport.
Collection<ExecutionReport> valueprotected final OrderStatus getOrderStatus(OrderID inOrderID)
OrderStatus for the given OrderID.
The given OrderID may be any part of the order chain. For example, if an order is replaced,
either the original OrderID or the current OrderID will return the same value,
although only the current OrderID is open.
inOrderID - an OrderID value or null if the given order cannot be found
OrderStatus value
protected static void setProperty(String inKey,
String inValue)
All running strategies have access to this properties store.
inKey - a String valueinValue - a String valueprotected static String getProperty(String inKey)
All running strategies have access to this properties store.
inKey - a String valueprotected Date getReportHistoryOriginDate()
Strategies may override this method to return a date. For performance reasons, it is best to use the most recent date possible. The default is to return the first second of the current day.
All strategies in the same strategy agent share the same order history manager. The report history origin date can be set only by the first strategy to run.
Date valueprotected final String getParameter(String inName)
inName - a String value containing the key of a parameter key/value value
String value or null if no parameter is associated with the given nameprotected final int requestMarketData(MarketDataRequest inRequest)
inRequest - a MarketDataRequest value containing the request to execute
int value containing the handle of the request or 0 if the request failedprotected final int requestMarketData(String inRequest)
inRequest - a String value containing the representation of a MarketDataRequest to execute
int value containing the handle of the request or 0 if the request failed
protected final int requestProcessedMarketData(MarketDataRequest inRequest,
String[] inStatements,
String inCepSource)
inRequest - a MarketDataRequest value containing the request to executeinStatements - a String[] value containing the statements to pass to the
complex event processor. The meaning of the statements varies according to the actual
event processor that handles them.inCepSource - a String value containing the name of the complex event processor
to which to send the query request
int value containing the handle of the request or 0 if the request failed
protected final int requestProcessedMarketData(String inRequest,
String[] inStatements,
String inCepSource)
inRequest - a String value containing the representation of a MarketDataRequest to executeinStatements - a String[] value containing the statements to pass to the
complex event processor. The meaning of the statements varies according to the actual
event processor that handles them.inCepSource - a String value containing the name of the complex event processor
to which to send the query request
int value containing the handle of the request or 0 if the request failedprotected final void cancelDataRequest(int inRequestID)
inRequestID - an int value containing the identifier of the data request to cancelprotected final void cancelAllDataRequests()
protected final int requestCEPData(String[] inStatements,
String inSource)
inStatements - a String[] value containing the statements to pass to the
complex event processor. The meaning of the statements varies according to the actual
event processor that handles them.inSource - a String value containing the name of the complex event processor
to which to send the query request
int value containing the identifier of this request or 0 if the request
failedprotected final Deque<ReportBase> getExecutionReports(OrderID inOrderID)
ReportBase values representing the order history of the given OrderID.
The ReportBase objects returned by this call represent the history of the order represented
by the given OrderID. if there is no order history for the given OrderID, this operation
will return an empty collection.
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.
The collection returned by this operation will be updated as the underlying report history changes. The collection itself may not be modified.
The contents of the returned collection are limited by the value returned by getReportHistoryOriginDate(). The
default value is all reports. No reports with a sending time before the origin date will be returned.
inOrderID - an OrderID value corresponding to an existing order, either open or closed
Deque<ReportBase> value containing the ReportBase objects
protected final void suggestTrade(OrderSingle inOrder,
BigDecimal inScore,
String inIdentifier)
inOrder - an OrderSingle value containing the trade to suggestinScore - a BigDecimal value containing the score of this suggestion. this value is determined by the user
but is recommended to fit in the interval [0..1]inIdentifier - a String value containing a user-specified string to identify the suggestionprotected boolean send(Object inData)
OrderSingle objects passed to this method will be added to the list of submitted orders
but other object types will not. In order to track, for example, OrderReplace and OrderCancel
objects, they must have first been created via cancelReplace(OrderID, OrderSingle, boolean) and
cancelOrder(OrderID, boolean) respectively.
inData - an Object value
boolean value indicating whether the object was successfully transmitted or not
protected final OrderCancel cancelOrder(OrderID inOrderID,
boolean inSendOrder)
OrderSingle with the given OrderID.
The order must currently be open or this operation will fail. Note that the strategy's concept of
open orders is based on its report history origin date as specified.
inOrderID - an OrderID value containing the ID of the open order to cancelinSendOrder - a boolean value indicating whether the OrderCancel should be submitted or just returned to the caller
If false, it is the caller's responsibility to submit the OrderCancel with send(Object).
OrderCancel value containing the cancel order or null if the OrderCancel could not be constructedprotected final int cancelAllOrders()
OrderSingle open orders owned by the strategy's owner.
This method will make a best-effort attempt to cancel all orders. If an attempt to cancel one order fails, that order will be skipped and the others will still be attempted in their turn.
int value containing the number of orders for which cancels were submitted
protected final OrderReplace cancelReplace(OrderID inOrderID,
OrderSingle inNewOrder,
boolean inSendOrder)
OrderID with
the given Order.
The order must be open or this call will have no effect.
If inSendOrder is false, it is the caller's responsibility
to submit the OrderReplace.
inOrderID - an OrderID value containing the order to cancelinNewOrder - an OrderSingle value containing the order with which to replace the existing orderinSendOrder - a boolean value indicating whether the OrderReplace should be submitted or just returned to the caller. If false,
it is the caller's responsibility to submit the OrderReplace with send(Object).
OrderReplace value containing the new order or null if the old order could not be canceled and the new one could not be sent
protected final void sendMessage(Message inMessage,
BrokerID inBroker)
inMessage - a Message valueinBroker - a BrokerID value
protected final void sendEventToCEP(Event inEvent,
String inProvider)
The corresponding CEP module must already exist or the message will not be sent.
inEvent - an Event value containing the event to be sentinProvider - a String value containing the name of a CEP providerprotected final void sendEvent(Event inEvent)
inEvent - an Event valueprotected final void sendNotification(Notification inNotification)
inNotification - a Notification value
protected final void requestCallbackAfter(long inDelay,
Object inData)
The callback will be executed as close to the specified millisecond
as possible. There is no guarantee that the timing will be exact. If
more than one callback is requested by the same RunningStrategy
for the same millisecond, the requests will be processed serially in
FIFO order. This implies that a long-running callback request may
delay other callbacks from the same RunningStrategy unless the
caller takes steps to mitigate the bottleneck.
inDelay - a long value indicating how many milliseconds
to wait before executing the callback. A value <= 0 will be interpreted
as a request for an immediate callback.inData - an Object value to deliver along with the callback,
may be null
protected final void requestCallbackEvery(long inDelay,
long inPeriod,
Object inData)
The callback will be executed as close to the specified millisecond
as possible. There is no guarantee that the timing will be exact. If
more than one callback is requested by the same RunningStrategy
for the same millisecond, the requests will be processed serially in
FIFO order. This implies that a long-running callback request may
delay other callbacks from the same RunningStrategy unless the
caller takes steps to mitigate the bottleneck.
inDelay - a long value indicating how many milliseconds
to wait before executing the first callback. A value <= 0 will be interpreted
as a request for an immediate callback.inPeriod - a long value indicating how many milliseconds
to wait before executing the second callback, and thereafter repeatedly
The value must be > 0.inData - an Object value to deliver along with the callback,
may be null
protected final void requestCallbackAt(Date inDate,
Object inData)
The callback will be executed as close to the specified millisecond
as possible. There is no guarantee that the timing will be exact. If
more than one callback is requested by the same RunningStrategy
for the same millisecond, the requests will be processed serially in
FIFO order. This implies that a long-running callback request may
delay other callbacks from the same RunningStrategy unless the
caller takes steps to mitigate the bottleneck.
inDate - a Date value at which to execute the callback. A date
value earlier than the present will be interpreted as a request for an
immediate callback.inData - an Object value to deliver with the callback or nullprotected final BrokerStatus[] getBrokers()
These values can be used to create and send orders with sendMessage(Message, BrokerID)
or send(Object).
BrokerStatus[] value
protected final BigDecimal getPositionAsOf(Date inDate,
String inSymbol)
Equity at the given point in time.
Note that this method will not retrieve Option positions. To retrieve
Option positions, use getOptionPositionAsOf(Date, String, String, BigDecimal, OptionType).
inDate - a Date value indicating the point in time for which to searchinSymbol - a String value containing the Equity symbol
BigDecimal value or null if no position could be foundprotected final Map<PositionKey<Equity>,BigDecimal> getAllPositionsAsOf(Date inDate)
Equity positions at the given point in time.
inDate - a Date value indicating the point in time for which to search
Map<PositionKey<Equity>,BigDecimal> value
protected final BigDecimal getFuturePositionAsOf(Date inDate,
String inUnderlyingSymbol,
FutureExpirationMonth inExpirationMonth,
int inExpirationYear)
Future at the given point in time.
Note that this method will not retrieve Option or Equity positions. To retrieve
Option positions, use getOptionPositionAsOf(Date, String, String, BigDecimal, OptionType).
To retrieve
Equity positions, use getPositionAsOf(Date, String).
inDate - a Date value indicating the point in time for which to searchinUnderlyingSymbol - a String value containing the underlying Future symbolinExpirationMonth - a FutureExpirationMonth valueinExpirationYear - an int value
BigDecimal value or null if no position could be foundprotected final Map<PositionKey<Future>,BigDecimal> getAllFuturePositionsAsOf(Date inDate)
Future positions at the given point in time.
inDate - a Date value indicating the point in time for which to search
Map<PositionKey<Equity>,BigDecimal> value
protected final BigDecimal getOptionPositionAsOf(Date inDate,
String inOptionRoot,
String inExpiry,
BigDecimal inStrikePrice,
OptionType inType)
Option at the given point in time.
inDate - a Date value indicating the point in time for which to searchinOptionRoot - a String valueinExpiry - a String valueinStrikePrice - a BigDecimal valueinType - an OptionType value
BigDecimal value or null if no position could be foundprotected final Map<PositionKey<Option>,BigDecimal> getAllOptionPositionsAsOf(Date inDate)
Option positions at the given point in time.
inDate - a Date value indicating the point in time for which to search
Map<PositionKey<Option>,BigDecimal> value
protected final Map<PositionKey<Option>,BigDecimal> getOptionPositionsAsOf(Date inDate,
String... inOptionRoots)
inDate - a Date value indicating the point in time for which to searchinOptionRoots - a String[] value containing the specific option roots for which to search
Map<PositionKey<Option>,BigDecimal> valueprotected final String getUnderlying(String inOptionRoot)
inOptionRoot - a String value containing an option root
String value containing the symbol for the underlying instrument or null if
no underlying instrument could be foundprotected final Collection<String> getOptionRoots(String inUnderlying)
inUnderlying - a String value containing the symbol of an underlying instrument
Collection<String> value sorted lexicographically by option root or null
if no option roots could be found
protected final DataFlowID createDataFlow(boolean inAppendDataSink,
DataRequest... inRequests)
See DataFlowSupport.createDataFlow(DataRequest[], boolean).
inAppendDataSink - a boolean value indicating if the sink module should be appended to the
data pipeline, if it's not already requested as the last module and the last module is capable of emitting data.inRequests - a DataRequest... value containing the ordered list of requests. Each instance
identifies a stage of the data pipeline. The data from the first stage is piped to the next.
DataFlowID value containing a unique ID identifying the data flow. The ID can be used to cancel
the data flow request and get more details on it. Returns null if the request could not be created.protected final void cancelDataFlow(DataFlowID inDataFlowID)
See DataFlowSupport.cancel(DataFlowID).
inDataFlowID - a DataFlowID value containing the request handle that was returned from
a prior call to createDataFlow(boolean, DataRequest[])protected final ModuleURN getURN()
ModuleURN of this strategy.
ModuleURN valueprotected final Properties getUserData()
Properties valueprotected final void setUserData(Properties inUserData)
inUserData - a Properties valueprotected void debug(String inMessage)
inMessage - a String valueprotected void info(String inMessage)
inMessage - a String valueprotected void warn(String inMessage)
inMessage - a String valueprotected void error(String inMessage)
inMessage - a String valueprotected final void initializeReportHistoryManager()
This can be a very expensive call depending on the value returned
by getReportHistoryOriginDate() and the number of execution reports
in the database.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||