Class AbstractStrategy

java.lang.Object
com.wualabs.qtsurfer.engine.core.AbstractNameable
com.wualabs.qtsurfer.engine.strategy.AbstractStrategy
All Implemented Interfaces:
Nameable, Named, Strategy
Direct Known Subclasses:
AbstractSubscriptionStrategy

public abstract class AbstractStrategy extends AbstractNameable implements Strategy
Base strategy class
  • Field Details

  • Constructor Details

    • AbstractStrategy

      public AbstractStrategy()
  • Method Details

    • configure

      public void configure(TypeSafeConfig config)
      Specified by:
      configure in interface Strategy
    • init

      public void init(@NonNull @NonNull com.wualabs.qtsurfer.engine.exchange.ExchangeSupport exchangeSupport)
      Specified by:
      init in interface Strategy
    • reset

      public void reset(@NonNull @NonNull Instrument instrument)
      Specified by:
      reset in interface Strategy
    • getYields

      public io.reactivex.rxjava3.core.Observable<StrategyYield> getYields()
      Specified by:
      getYields in interface Strategy
    • getSignals

      public io.reactivex.rxjava3.core.Observable<StrategySignal> getSignals()
      Specified by:
      getSignals in interface Strategy
    • getExecutionMode

      public ExecutionMode getExecutionMode(Instrument instrument)
      Specified by:
      getExecutionMode in interface Strategy
    • getExecutionCallback

      public ExecutionCallback getExecutionCallback()
      Specified by:
      getExecutionCallback in interface Strategy
    • setEnabled

      public void setEnabled(boolean enabled)
      Specified by:
      setEnabled in interface Strategy
    • getNotices

      public List<Notice> getNotices()
      This strategy's own diagnostics, in the order the conditions were first raised. Subclasses that own further sources of notices override this and union them in — AbstractSubscriptionStrategy adds its per-instrument indicator groups.

      Synchronized on the map because synchronizedMap does not cover iteration, and copying the values is an iteration — see strategyNotices.

      Specified by:
      getNotices in interface Strategy
      Returns:
      the notices raised so far, empty if none (the default for strategies without indicators)
    • raiseNotice

      protected void raiseNotice(@NonNull @NonNull Notice notice)
      Records a diagnostic about this strategy, keeping the first occurrence of each Notice.key(): a condition seen again is the same problem, not a new one, and the first sighting is the informative one. What "the same" means is the notice's own business — a strategy-wide one keys on its code, a property one on (code, property).
      Parameters:
      notice - the notice to record
    • clearNotice

      protected void clearNotice(@NonNull @NonNull Object key)
      Drops a recorded notice, for conditions that genuinely clear (a resubscribe undoing a dead source). Do not use it to hide a condition that merely stopped repeating.
      Parameters:
      key - the Notice.key() to clear — the code itself for strategy-wide notices
    • setProperty

      public void setProperty(@NonNull @NonNull String key, @NonNull @NonNull Object value)
      Specified by:
      setProperty in interface Strategy
    • applyProperty

      public void applyProperty(@NonNull @NonNull String key, @NonNull @NonNull Object value)
      Description copied from interface: Strategy
      Applies a runtime property value, routing reflected properties through their typed setter so the strategy's underlying field actually changes — not just the property map (as Strategy.setProperty(String, Object) does). This is the injection seam the batch/sweep runner uses to apply a parameter vector before a run. The default falls back to Strategy.setProperty(String, Object) (map-only) for implementations without a reflected-property registry.
      Specified by:
      applyProperty in interface Strategy
      Parameters:
      key - the registered property name() (NOT the field name)
      value - the value to inject; converted to the property's declared type when reflecting
    • hasProperty

      public boolean hasProperty(@NonNull @NonNull String key)
      Specified by:
      hasProperty in interface Strategy
    • getProperty

      public <T> T getProperty(@NonNull @NonNull String key)
      Specified by:
      getProperty in interface Strategy
    • getPropertyInfo

      public Optional<PropertyInfo> getPropertyInfo(@NonNull @NonNull String propertyInfoId)
      Specified by:
      getPropertyInfo in interface Strategy
    • getPropertyInfos

      public Set<PropertyInfo> getPropertyInfos()
      Specified by:
      getPropertyInfos in interface Strategy
    • setExecutionMode

      public void setExecutionMode(@NonNull @NonNull ExecutionMode executionMode)
    • setMultiEntryEnabled

      public void setMultiEntryEnabled(boolean multiEntryEnabled)
      Backward-compatible setter: maps the legacy multiEntryEnabled config property to ExecutionMode.LONG_MULTI or ExecutionMode.LONG.
    • setExecutionCallback

      public void setExecutionCallback(ExecutionCallback executionCallback)
    • setCurrencyFilter

      public void setCurrencyFilter(@NonNull @NonNull StrategyCurrencyFilter currencyFilter)
    • setPercentGain

      public void setPercentGain(double percent)
      Sets the minimum percent gain threshold and precomputes the multiplier used to evaluate whether a trade meets the gain requirement.
      Parameters:
      percent - the minimum gain percentage (0-100)
    • getPercentGain

      public double getPercentGain()
    • setMinGain

      public void setMinGain(double minGain)
    • getMinGain

      public double getMinGain()
    • setWhitelistedCurrencies

      public void setWhitelistedCurrencies(List<String> currencyCodes)
      Reflection bridge for the property system.
    • setBlacklistedCurrencies

      public void setBlacklistedCurrencies(List<String> currencyCodes)
      Reflection bridge for the property system.
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getEngineVersion

      protected final String getEngineVersion()
      The engine version this strategy is running on (e.g. "0.99.55"), or "unknown" if it cannot be determined — sugar for EngineVersion.get(), so a strategy can log or emit it without an import.

      Worth recording from a strategy that is stored and re-run later: engine APIs change between versions, and a stored strategy that stops compiling is only diagnosable if the engine it was written against is known.

      Returns:
      the running engine version
    • getEngineVersionMajor

      protected final int getEngineVersionMajor()
      The major component of getEngineVersion() — the 0 of "0.99.55".
      Returns:
      the major component, or EngineVersion.UNKNOWN_COMPONENT (-1) if the version cannot be parsed — negative so a gate such as getEngineVersionMajor() >= 1 fails closed rather than matching by accident
    • getEngineVersionMinor

      protected final int getEngineVersionMinor()
      The minor component of getEngineVersion() — the 99 of "0.99.55".
      Returns:
      the minor component, or EngineVersion.UNKNOWN_COMPONENT (-1) if the version cannot be parsed
    • getMinPercentGainMultiplier

      protected BigDecimal getMinPercentGainMultiplier()
    • acceptCurrency

      protected final boolean acceptCurrency(@NonNull @NonNull Asset asset)
    • emitYield

      public void emitYield(@NonNull @NonNull StrategyYield yield)
    • emitSignal

      public void emitSignal(@NonNull @NonNull StrategySignal signal)
    • registerPropertyInfo

      protected PropertyInfo registerPropertyInfo(String name, String description, Class type)
    • registerPropertyInfo

      protected PropertyInfo registerPropertyInfo(String name, String description, Class type, String beanProperty)
    • registerPropertyInfo

      protected PropertyInfo registerPropertyInfo(String name, String description, Class type, String beanProperty, boolean reflected)
    • registerPropertyInfo

      protected PropertyInfo registerPropertyInfo(@NonNull @NonNull PropertyInfo propertyInfo)
    • toString

      protected void toString(com.google.common.base.MoreObjects.ToStringHelper ts)
    • getInputCurrency

      public Asset getInputCurrency()
      Specified by:
      getInputCurrency in interface Strategy
    • getOutputCurrency

      public Asset getOutputCurrency()
      Specified by:
      getOutputCurrency in interface Strategy
    • getStats

      public StrategyStats getStats()
      Specified by:
      getStats in interface Strategy
    • getInstruments

      public HashSet<Instrument> getInstruments()
      Specified by:
      getInstruments in interface Strategy
    • getId

      public String getId()
      Specified by:
      getId in interface Strategy
    • getExchangeName

      public String getExchangeName()
    • isEnabled

      public boolean isEnabled()
      Specified by:
      isEnabled in interface Strategy
    • getCurrencyFilter

      @NonNull public @NonNull StrategyCurrencyFilter getCurrencyFilter()
    • getExecutionConfig

      public ExecutionConfig getExecutionConfig()
      Description copied from interface: Strategy
      How the execution layer runs this strategy: backtest simulation settings, risk guards and entry sizing. Set by whoever drives the run — the backtest runner, or a deployment's configuration — and read by the execution pipelines.

      A strategy implementation has no reason to consult this: it decides when to trade, and this decides what the execution layer does with the resulting signals. It is here so that the configuration and sweep channels can reach it by the property names they already use.

      Specified by:
      getExecutionConfig in interface Strategy
      Returns:
      this strategy's execution configuration, never null