add trading managers
This commit is contained in:
@ -12,6 +12,7 @@ import com.espertech.esper.client.time.CurrentTimeEvent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ats.orders.MarketOrderRequest;
|
||||
import ats.plugin.OHLCEvent;
|
||||
import ats.plugin.OHLCPlugInViewFactory;
|
||||
import ats.plugin.OHLCValueEvent;
|
||||
@ -20,9 +21,11 @@ import ats.plugin.OHLCValueEvent;
|
||||
public class EsperProcessor implements TickProcessor {
|
||||
final Logger log = LoggerFactory.getLogger(EsperProcessor.class);
|
||||
EPServiceProvider engine;
|
||||
TradingManager trader;
|
||||
|
||||
|
||||
public EsperProcessor(String epl) {
|
||||
public EsperProcessor(String epl, TradingManager trader) {
|
||||
this.trader = trader;
|
||||
Configuration config = new Configuration();
|
||||
|
||||
// disable esper's internal clock. we use tick data for our
|
||||
@ -39,8 +42,6 @@ public class EsperProcessor implements TickProcessor {
|
||||
|
||||
engine = EPServiceProviderManager.getDefaultProvider(config);
|
||||
|
||||
//engine.getEPRuntime().setVariableValue("FOO", 12d);
|
||||
|
||||
addStatements(epl);
|
||||
|
||||
// addLogStatement("TickEvent");
|
||||
@ -50,7 +51,13 @@ public class EsperProcessor implements TickProcessor {
|
||||
// respond to long entry events
|
||||
addStatement("select * from LongEntryDistinct",
|
||||
(newData, oldData) -> {
|
||||
log.debug("Long entry triggered: {} at {}",
|
||||
String instrument = (String)newData[0].get("instrument");
|
||||
Integer units = (Integer)newData[0].get("units");
|
||||
trader.placeOrder(new MarketOrderRequest(instrument, units));
|
||||
|
||||
log.debug("Long entry triggered: {} of {} at price {} at time {}",
|
||||
units,
|
||||
instrument,
|
||||
newData[0].get("current"),
|
||||
newData[0].get("time"));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user