public final class OrderBookModel extends Object
Order
event class and
arranges incoming orders into a lists of buyOrders
and
sellOrders
that are, in turn, arranged by price, so that
the first element of the list (at index 0) is at the top of the corresponding side of the book.
dxFeed API comes with a set of samples.DXFeed
feed = ...; OrderBookModel model = newOrderBookModel
(); model.setFilter
(OrderBookModelFilter
.ALL
); model.setSymbol
("AAPL"); model.getBuyOrders
().addListener
(newObservableListModelListener
<Order
>() { public void modelChanged(Change
<? extends Order> change) { for (Order order : change.getSource
()) System.out.println(order); System.out.println(); } }); model.attach
(feed);
DXFeedMarketDepth
sample is a very simple UI application
that shows how to use this model, concentrating your
effort on data representation logic, while delegating all the data-handling logic to this model.
AbstractIndexedEventModel
class documentation for details and constrains on
the usage of this class.
Installed ObservableListModelListener
instances are invoked from a separate thread via the executor.
Default executor for all models is configured with DXEndpoint.executor
method. Each model can individually override its executor with setExecutor
method. The corresponding
modelChanged
notification is guaranteed to never be concurrent, even though it may happen from different
threads if executor is multi-threaded.
Custom executor can be used by backend applications that do not need to immediately update this model on
arrival of new events, but want to update the model at a later time, for example, from inside of a servlet request.
This approach is explained with code samples in
Threads and locks
section of DXFeedSubscription
class documentation.
Constructor and Description |
---|
OrderBookModel()
Creates new model.
|
Modifier and Type | Method and Description |
---|---|
void |
attach(DXFeed feed)
Attaches model to the specified feed.
|
void |
clear()
Clears subscription symbol and, subsequently, all events in this model.
|
void |
detach(DXFeed feed)
Detaches model from the specified feed.
|
ObservableListModel<Order> |
getBuyOrders()
Returns the view of bid side (buy orders) of the order book.
|
Executor |
getExecutor()
Returns executor for processing event notifications on this model.
|
OrderBookModelFilter |
getFilter()
Returns filter for the model.
|
int |
getLotSize()
Returns lot size.
|
ObservableListModel<Order> |
getSellOrders()
Returns the view of offer side (sell orders) of the order book.
|
String |
getSymbol()
Returns order book symbol, or
null for empty subscription. |
void |
setExecutor(Executor executor)
Changes executor for processing event notifications on this model.
|
void |
setFilter(OrderBookModelFilter filter)
Sets the specified filter to the model.
|
void |
setLotSize(int lotSize)
Sets the lot size.
|
void |
setSymbol(String symbol)
Sets symbol for the order book to subscribe for.
|
public OrderBookModel()
OrderBookModelFilter.ALL
.
Use setSymbol(java.lang.String)
to specify subscription symbol and
attach(com.dxfeed.api.DXFeed)
method to specify feed to start receiving events.public void attach(DXFeed feed)
feed
- feed to attach to.public void detach(DXFeed feed)
feed
- feed to detach from.public Executor getExecutor()
null
if default executor of the attached DXFeed
is used.public void setExecutor(Executor executor)
executor
- executor for processing event notifications on this model,
or null
if default executor of the attached DXFeed
is used.public void clear()
setSymbol
(null)
.public OrderBookModelFilter getFilter()
OrderBookModelFilter
public void setFilter(OrderBookModelFilter filter)
filter
- model filterpublic String getSymbol()
null
for empty subscription.public void setSymbol(String symbol)
symbol
- order book symbol, use null
to unsubscribe.public int getLotSize()
Scope.COMPOSITE
,
Scope.REGIONAL
, and Scope.AGGREGATE
orders.public void setLotSize(int lotSize)
lotSize
- lot size multipliergetLotSize()
public ObservableListModel<Order> getBuyOrders()
public ObservableListModel<Order> getSellOrders()
Copyright © 2015 Devexperts. All Rights Reserved.