signal

package
v0.29.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package signal provides a client for the Longbridge strategy-signal OpenAPI: strategy signals and the catalyst (fact) events behind them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnomalyDetection

type AnomalyDetection struct {
	AnomalyResult     string
	SignificanceLevel string
	TestMethod        string
	Thresholds        AnomalyThresholds
}

AnomalyDetection is the outcome of the anomaly test behind a factor. Fields are empty for factors that did not run one.

type AnomalyThresholds

type AnomalyThresholds struct {
	Low    string
	Medium string
	High   string
}

AnomalyThresholds are the thresholds an anomaly test was scored against.

type FactDataSource

type FactDataSource struct {
	SourceName string
	SourceType FactType
	URL        string
	Icon       string
}

FactDataSource is where a fact came from.

type FactDirection

type FactDirection string

FactDirection is the side a fact or factor points to.

const (
	FactDirectionUnknown FactDirection = "" // wire empty string
	FactDirectionLong    FactDirection = "long"
	FactDirectionShort   FactDirection = "short"
	FactDirectionNeutral FactDirection = "neutral"
)

type FactFactor

type FactFactor struct {
	// Name is the factor name, e.g. rsi_14.
	Name string
	// FactorGroups are the groups the factor belongs to, e.g. MOMENTUM.
	FactorGroups []string
	// LongShortDirection is the side the factor points to.
	LongShortDirection FactDirection
	// TriggerCondition is the condition that fired the factor.
	TriggerCondition string
	// AnomalyDetection is the anomaly test behind the factor.
	AnomalyDetection AnomalyDetection
}

FactFactor is one factor that contributed to a fact.

type FactNlInfo

type FactNlInfo struct {
	// Title is the headline.
	Title string
	// SubTitle is the sub-headline.
	SubTitle string
	// Summary is what happened, as a JSON array of {tag, value} entries carried in
	// a string. Use SummaryTags to read it.
	Summary string
	// InvestAnal is what it may mean for an investor, in the same JSON-in-a-string
	// shape as Summary. Use InvestAnalTags to read it.
	InvestAnal string
	// EliExplain is a plain-language walk-through of the fact, in the same
	// JSON-in-a-string shape as Summary. Use EliExplainTags to read it.
	EliExplain string
}

FactNlInfo is the natural-language rendering of a fact, in the caller's language.

func (FactNlInfo) EliExplainTags

func (n FactNlInfo) EliExplainTags() []NlTag

EliExplainTags parses EliExplain into its {tag, value} entries. Returns an empty list when the field is empty or not the expected JSON.

func (FactNlInfo) InvestAnalTags

func (n FactNlInfo) InvestAnalTags() []NlTag

InvestAnalTags parses InvestAnal into its {tag, value} entries. Returns an empty list when the field is empty or not the expected JSON.

func (FactNlInfo) SummaryTags

func (n FactNlInfo) SummaryTags() []NlTag

SummaryTags parses Summary into its {tag, value} entries. Returns an empty list when the field is empty or not the expected JSON — the raw string stays available.

type FactSymbol

type FactSymbol struct {
	Symbol       string
	SecurityName string
}

FactSymbol is a security a fact is about.

type FactType

type FactType string

FactType is the kind of a fact, and of the source that produced it.

const (
	FactTypeUnknown     FactType = "Unknown"
	FactTypeNews        FactType = "News"
	FactTypeFundamental FactType = "Fundamental"
	FactTypeTechnical   FactType = "Technical"
)

type NlTag

type NlTag struct {
	// Tag is what the entry is about, e.g. RSI.
	Tag string `json:"tag"`
	// Value is the prose.
	Value string `json:"value"`
}

NlTag is one {tag, value} entry from a natural-language field.

type Outlook

type Outlook string

Outlook is the direction a strategy expects the security to take.

const (
	OutlookUnknown       Outlook = "Unknown"
	OutlookStrongBullish Outlook = "Strong bullish" // outlook_enum 1
	OutlookBullish       Outlook = "Bullish"        // outlook_enum 2
	OutlookNeutral       Outlook = "Neutral"        // outlook_enum 3
	OutlookBearish       Outlook = "Bearish"        // outlook_enum 4
	OutlookStrongBearish Outlook = "Strong bearish" // outlook_enum 5
)

type SecurityFact

type SecurityFact struct {
	// FactID is the fact ID, e.g. technical_rsi_14_short_1783674041337603409.
	FactID string
	// FactType is what kind of fact this is.
	FactType FactType
	// Direction is the side the fact points to.
	Direction FactDirection
	// OccurTime is when the fact occurred.
	OccurTime time.Time
	// SymbolsInfo are the securities the fact is about.
	SymbolsInfo []FactSymbol
	// Factors are the factors that contributed to the fact.
	Factors []FactFactor
	// DataSource is where the fact came from.
	DataSource []FactDataSource
	// NlInfo is the natural-language rendering of the fact.
	NlInfo FactNlInfo
}

SecurityFact is a fact (catalyst) event: something that happened to a security, with the factors, sources and prose behind it. Facts are what strategies react to — a signal names the fact that triggered it in Signal.KeyFactID.

type SecurityFactsOptions

type SecurityFactsOptions struct {
	// Symbol is the security to query, e.g. AAPL.US or 700.HK. Required.
	Symbol string
	// BeginTime is the start of the query window (zero = earliest available).
	BeginTime time.Time
	// EndTime is the end of the query window (zero = latest available).
	EndTime time.Time
	// Limit is the maximum number of facts to return; when more facts fall inside
	// the window, only the latest Limit are returned (nil = server default of 100).
	Limit *int32
}

SecurityFactsOptions filters SignalContext.SecurityFacts.

func (*SecurityFactsOptions) Values

func (o *SecurityFactsOptions) Values() url.Values

Values renders the options into a query string.

type Signal

type Signal struct {
	// ID is the signal ID, e.g. sign_992_1a00c9425c3_48ab. Pass it to
	// SignalContext.Signal for the full record.
	ID string
	// Symbol is the security symbol, e.g. 992.HK.
	Symbol string
	// CompanyName is the company name.
	CompanyName string
	// Market is the market the security trades in, e.g. HK.
	Market string
	// Title is the signal headline.
	Title string
	// Summary is a natural-language summary of the signal, in Markdown.
	Summary string
	// StrategyID is the strategy ID that produced the signal.
	StrategyID string
	// StrategyName is the strategy name that produced the signal.
	StrategyName string
	// RecommendBy is who recommended the signal; empty for strategy-generated signals.
	RecommendBy string
	// Expression is the strategy expression, e.g. 992.HK:GROWTH:long.
	Expression string
	// KeyFactID is the ID of the fact that triggered the signal.
	KeyFactID string
	// KeyCatalyst is the display label of the catalyst that triggered the signal,
	// e.g. "Q1 Revenue Surge". Filtering with SignalsOptions.CatalystName matches
	// the underlying factor name instead.
	KeyCatalyst string
	// AnalysisPrice is the price the analysis was based on.
	AnalysisPrice float64
	// ConservativePrice is the conservative-scenario target price.
	ConservativePrice float64
	// BenchmarkPrice is the benchmark-scenario target price.
	BenchmarkPrice float64
	// OptimisticPrice is the optimistic-scenario target price.
	OptimisticPrice float64
	// Outlook is the outlook the strategy takes on the security.
	Outlook Outlook
	// OutlookDesc is the localized rendering of Outlook in the caller's language.
	OutlookDesc string
	// Status is where the signal is in its lifecycle.
	Status SignalStatus
	// JsonData is the full analysis behind the signal, as a verbatim JSON document
	// (strategy-specific shape).
	JsonData string
	// CreatedAt is the creation time.
	CreatedAt time.Time
	// UpdatedAt is the last update time.
	UpdatedAt time.Time
}

Signal is a strategy's take on a security, triggered by a catalyst.

type SignalContext

type SignalContext struct {
	// contains filtered or unexported fields
}

SignalContext is a client for the Longbridge strategy-signal OpenAPI.

Example:

conf, err := config.NewFromEnv()
sctx, err := signal.NewFromCfg(conf)
resp, err := sctx.Signals(ctx, &signal.SignalsOptions{SymbolName: "AAPL.US"})

func NewFromCfg

func NewFromCfg(cfg *config.Config) (*SignalContext, error)

NewFromCfg creates a SignalContext from a *config.Config.

func NewFromEnv

func NewFromEnv() (*SignalContext, error)

NewFromEnv returns a SignalContext configured from environment variables.

func (*SignalContext) SecurityFacts

func (c *SignalContext) SecurityFacts(ctx context.Context, opts *SecurityFactsOptions) ([]*SecurityFact, error)

SecurityFacts lists the fact (catalyst) events for one security — anomaly detections, factor readings, data sources and natural-language summaries.

Facts are what strategies react to: a signal names the fact that triggered it in Signal.KeyFactID.

Path: GET /v1/facts/security_facts

func (*SignalContext) Signal

func (c *SignalContext) Signal(ctx context.Context, signalID string) (*Signal, error)

Signal gets one signal by ID, including the full analysis in Signal.JsonData.

Path: GET /v1/signals/{signal_id}

func (*SignalContext) Signals

func (c *SignalContext) Signals(ctx context.Context, opts *SignalsOptions) (*SignalsResponse, error)

Signals queries signals, filtered by symbol, strategy, catalyst and time range.

Path: GET /v1/signals

type SignalStatus

type SignalStatus int32

SignalStatus is where a signal is in its lifecycle.

const (
	// SignalStatusUnknown is a status this SDK does not know yet.
	SignalStatusUnknown SignalStatus = -1
	// SignalStatusPending is generated, not yet published.
	SignalStatusPending SignalStatus = 0
	// SignalStatusActive is published and current — the only status the API serves today.
	SignalStatusActive SignalStatus = 1
	// SignalStatusDeleted is deleted.
	SignalStatusDeleted SignalStatus = 2
	// SignalStatusAiFailed means the strategy analysis failed to generate.
	SignalStatusAiFailed SignalStatus = 3
	// SignalStatusFilteredByManual means a human reviewer filtered it out.
	SignalStatusFilteredByManual SignalStatus = 4
	// SignalStatusAiSubmitFailed means the strategy analysis failed to submit.
	SignalStatusAiSubmitFailed SignalStatus = 5
)

type SignalsOptions

type SignalsOptions struct {
	// SymbolName filters by security symbol, e.g. AAPL.US or 700.HK.
	SymbolName string
	// StrategyID filters by strategy id, e.g. buffett-value. Preferred over the
	// deprecated StrategyName; takes precedence when both are provided.
	StrategyID string
	// StrategyName filters by strategy name. Deprecated in favour of StrategyID.
	StrategyName string
	// CatalystName filters by the name of the factor that triggered the signal,
	// e.g. EARNINGS_RELEASED or macd_12_26_9 — the triggering fact's factor name,
	// not the display label in Signal.KeyCatalyst.
	CatalystName string
	// CatalystType filters by the catalyst type, e.g. News, Fundamental, Technical.
	CatalystType string
	// StartTime only returns signals created at or after this time (zero = no bound).
	StartTime time.Time
	// EndTime only returns signals created at or before this time (zero = no bound).
	EndTime time.Time
	// Limit is the maximum number of results to return (nil = server default of 20).
	Limit *int32
	// Offset is the number of results to skip for pagination (nil = 0).
	Offset *int32
}

SignalsOptions filters SignalContext.Signals. Every field is a filter; leaving one at its zero value removes that filter.

func (*SignalsOptions) Values

func (o *SignalsOptions) Values() url.Values

Values renders the options into a query string.

type SignalsResponse

type SignalsResponse struct {
	// Signals are the signals on this page.
	Signals []*Signal
	// Total is the total number of signals matching the filters, for paging with
	// SignalsOptions.Offset.
	Total int32
}

SignalsResponse is a page of signals returned by SignalContext.Signals.

Directories

Path Synopsis
Package jsontypes holds raw JSON-deserialization structs for the signal package.
Package jsontypes holds raw JSON-deserialization structs for the signal package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL