Class InstrumentMapRTIndicator

java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.helpers.group.InstrumentMapRTIndicator
All Implemented Interfaces:
Backtestable, ClockAware, Resettable, RTIndicator
Direct Known Subclasses:
InstrumentMapFundingRateSourceRTIndicator, InstrumentMapKlineSourceRTIndicator, InstrumentMapTickerSourceRTIndicator

public abstract class InstrumentMapRTIndicator extends AbstractRTIndicator implements ClockAware, Backtestable
A map of RTIndicators for an instrument
  • Field Details

  • Constructor Details

    • InstrumentMapRTIndicator

      public InstrumentMapRTIndicator(@NonNull @NonNull Instrument instrument)
  • Method Details

    • add

      public InstrumentMapRTIndicator add(String name, RTIndicator indicator)
    • getCacheContext

      public final String getCacheContext(RTIndicator indicator)
      Identity of the value stream a memoized indicator is registered against (goal indicator-bank-coverage P5b) — what makes two otherwise identical indicators produce different series.

      A RichRTIndicator is fed the whole snapshot via updateFrom, never through cacheSelector()'s field — chg% and vwap both driving a snapshot- consuming TickerRTIndicator would otherwise be keyed apart by a selector neither of them reads, splitting one series into two for no difference in what either actually computes. A scalar indicator has no such isolation: two groups reading different fields of the same stream can and do produce different numbers, so the selector stays load-bearing for it.

      Parameters:
      indicator - the indicator about to be registered, deciding which identity it needs
      Returns:
      the stream identity, stable for the lifetime of this map for a given indicator shape
    • cacheSelector

      protected abstract String cacheSelector()
      Which field of the incoming data this map extracts for scalar indicators, as a stable string.

      Abstract rather than defaulted on purpose: a subclass that reads a different field and forgot to say so would share memoized series between streams that never produced the same numbers, and a compile error is a far better way to find that out than a wrong leaderboard.

      Returns:
      the selector name, never null
    • getValue

      public double getValue(String name)
    • getReadOnlyExisting

      public RTIndicator getReadOnlyExisting(String name)
    • getReadOnly

      public Optional<RTIndicator> getReadOnly(String name)
      Returns a read-only wrapper of the named indicator, creating and caching it on first access. Read-only wrappers prevent accidental mutation of shared indicators when they are referenced by multiple derived indicators. The cache is invalidated when indicators are added or removed.
      Parameters:
      name - the indicator name, or null
      Returns:
      an Optional containing the read-only wrapper, or empty if not found
    • getExisting

      public RTIndicator getExisting(String name)
    • get

      public Optional<RTIndicator> get(String name)
    • getRaw

      public RTIndicator getRaw(String name)
    • remove

      public RTIndicator remove(String name)
    • size

      public int size()
    • clear

      public void clear()
    • namedIndicators

      protected Collection<Map.Entry<String, RTIndicator>> namedIndicators()
      Every registered indicator paired with the name it was registered under, hidden ones included. This is the dispatch view: a subclass propagating market data needs the name to report anything about an individual indicator, which indicators() alone cannot give it.
      Returns:
      the name→indicator entries, in registration order
    • getNotices

      public List<IndicatorNotice> getNotices()
      Wiring diagnostics raised about this group — see IndicatorNotice for why these are data rather than log lines. Empty for a correctly wired group.
      Returns:
      the notices in the order they were first raised, never null
    • raiseNotice

      protected boolean raiseNotice(@NonNull @NonNull IndicatorNotice notice)
      Records a notice, keeping only the first occurrence per (code, indicator) pair.

      De-duplication is the whole point: the conditions worth reporting are detected inside the per-tick dispatch loop, so a naive implementation would raise the same notice on every tick of every instrument for the lifetime of the run. The first occurrence is kept rather than the last because they are identical by construction, and keeping the first means the list order matches the order problems were discovered.

      Parameters:
      notice - the diagnostic to record
      Returns:
      true if this was the first time that notice was raised
    • forEachPublicable

      public void forEachPublicable(BiConsumer<String, RTIndicator> action)
      Iterates over the public indicators — those not marked hidden — invoking the given action. Internal indicators (the _gain/_loss/_win entries the gain()/loss()/window() factories register, the auto-created Bollinger behind bollingerBandwidth, …) are skipped so their values are not emitted. The skip reads visibility metadata, not the "_" name prefix, which the registration path has already translated into that metadata.
      Parameters:
      action - consumer receiving the indicator name and instance
    • setClockSupplier

      public void setClockSupplier(Supplier<Clock> clockSupplier)
      Specified by:
      setClockSupplier in interface ClockAware
    • reset

      public void reset()
      Resets every child indicator in place, mirroring setClockSupplier(Supplier). The instrument map itself is kept (use clear() to drop instruments); only the children's rolling state is zeroed, so the base reset() contract — return to a pre-first-tick state — holds for containers too. The read-only wrappers stay valid: they delegate live to the children they wrap.
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class AbstractRTIndicator
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractRTIndicator
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class AbstractRTIndicator
    • toString

      protected com.google.common.base.MoreObjects.ToStringHelper toString(com.google.common.base.MoreObjects.ToStringHelper ts)
      Overrides:
      toString in class AbstractRTIndicator
    • indicators

      protected Collection<RTIndicator> indicators()
    • getInstrument

      public Instrument getInstrument()