From 3aaf37202bdc6e1ee426c9f5f04e7f252372f467 Mon Sep 17 00:00:00 2001 From: Seth Ladygo Date: Fri, 13 Jul 2018 17:10:46 -0700 Subject: [PATCH] add OHLCValueEvent --- src/main/java/EsperProcessor.java | 2 + src/main/java/ats/plugin/OHLCValueEvent.java | 42 ++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/main/java/ats/plugin/OHLCValueEvent.java diff --git a/src/main/java/EsperProcessor.java b/src/main/java/EsperProcessor.java index 23da4d3..bf0807c 100644 --- a/src/main/java/EsperProcessor.java +++ b/src/main/java/EsperProcessor.java @@ -1,6 +1,7 @@ import ats.plugin.OHLCPlugInViewFactory; import ats.plugin.OHLCUpdateListener; import ats.plugin.OHLCEvent; +import ats.plugin.OHLCValueEvent; import com.espertech.esper.client.Configuration; import com.espertech.esper.client.EPServiceProvider; import com.espertech.esper.client.EPServiceProviderManager; @@ -34,6 +35,7 @@ public class EsperProcessor implements TickProcessor { config.addEventType(LongEntryEvent.class); //config.addVariable("FOO", int.class, 12); config.addEventType(OHLCEvent.class); + config.addEventType(OHLCValueEvent.class); config.addPlugInView("ATS", "OHLC", OHLCPlugInViewFactory.class.getName()); diff --git a/src/main/java/ats/plugin/OHLCValueEvent.java b/src/main/java/ats/plugin/OHLCValueEvent.java new file mode 100644 index 0000000..ed12b74 --- /dev/null +++ b/src/main/java/ats/plugin/OHLCValueEvent.java @@ -0,0 +1,42 @@ +package ats.plugin; + +import org.joda.time.DateTime; + +/** + * OHLCValueEvent stores one bar of OHLC info. + */ +public class OHLCValueEvent extends OHLCEvent { + private double value; + + + public OHLCValueEvent() { + this(null, 0, 0, 0, 0, 0); + } + + public OHLCValueEvent(DateTime time, + double open, double high, + double low, double close, + double value) + { + super(time, open, high, low, close); + this.value = value; + } + + public static OHLCValueEvent make(DateTime time, + double open, double high, + double low, double close, + double value) + { + return new OHLCValueEvent(time, open, high, low, close, value); + } + + public Double getValue() { return value; } + + /** + * Return a human readable representation of this event. + */ + public String toString() { + return String.format("OHLCValueEvent[%s, open=%.3f, high=%.3f, low=%.3f, close=%.3f, value=%.3f]", + getTime(), getOpen(), getHigh(), getLow(), getClose(), value); + } +}