Skill站外收录 @skilllib/skill-2117939930272411256
indicator-stream
实现高性能实时指标计算,支持链式调用与报价转换,采用增量更新确保 O(1) 时间复杂度,通过状态回滚机制精确处理历史数据变更,并结合标准化测试验证结果一致性。
软件开发 AI 技能
Skills.MD
# StreamHub indicator development
## Provider selection
| Provider Base | Input | Output | Use Case |
| ------------- | ----- | ------ | -------- |
| `ChainHub<IReusable, TResult>` | Single value | IReusable | Chainable indicators |
| `ChainHub<IQuote, TResult>` | OHLCV | IReusable | Quote-driven, chainable output |
| `QuoteProvider<IQuote, TResult>` | OHLCV | IQuote | Quote-to-quote transformation |
| `StreamHub<TProviderResult, TResult>` | Any hub result | Any result | Compound hubs (internal hub dependency) |
## Performance requirements
**Target**: StreamHub ≤ 1.5x slower than Series
### Anti-pattern 1: O(n²) recalculation (FORBIDDEN)
```csharp
// WRONG - Rebuilds entire history on each tick
for (int k = 0; k <= i; k++) { subset.Add(cache[k]); }
var result = subset.ToIndicator();
```
### Correct: O(1) incremental update
```csharp
// CORRECT - Maintain state, update incrementally
_avgGain = ((_avgGain * (period - 1)) + gain) / period;
```
### Anti-pattern 2: O(n) window scans
Use `RollingWindowMax/Min` utilities instead of linear scans for max/min operations.
## RollbackState pattern
Override when maintaining stateful fields:
```csharp
protected override void RollbackState(DateTime timestamp)
{
int targetIndex = ProviderCache.IndexGte(timestamp);
_window.Clear();
if (targetIndex <= 0) return;
int restoreIndex = targetIndex - 1; // Rebuild up to but NOT including timestamp
int startIdx = Math.Max(0, restoreIndex + 1 - LookbackPeriods);
for (int p = startIdx; p <= restoreIndex; p++)
_window.Add(ProviderCache[p].Value);
}
```
**Critical**: Replay up to `targetIndex - 1` (exclusive of rollback timestamp). The quote at the rollback timestamp will be recalculated when it arrives via normal processing.
## Testing requirements
1. Inherit from `StreamHubTestBase`
2. Implement exactly ONE observer interface:
- `ITestChainObserver` (most common)
- `ITestQuoteObserver` (quote-only providers)
3. Implement at most ONE provider interface: `ITestChainProvider`
4. Comprehensive rollback validation (required):
- Prefill warmup window before subscribing
- Stream in-order including duplicates
- Insert a late historical quote → verify recalculation
- Remove a historical quote → verify recalculation
- Compare results to Series with strict ordering
## Required implementation
- [ ] Source code: `src/**/{IndicatorName}.StreamHub.cs` file exists
- [ ] Uses appropriate provider base (`ChainHub` or `QuoteProvider`)
- [ ] Validates parameters in constructor; calls `Reinitialize()` as needed
- [ ] Implements O(1) state updates; avoids O(n²) recalculation
- [ ] Overrides `RollbackState()` when maintaining stateful fields
- [ ] Overrides `ToString()` with concise hub name
- [ ] Unit testing: `tests/indicators/**/{IndicatorName}.StreamHub.Tests.cs` exists
- [ ] Inherits `StreamHubTestBase` with correct test interfaces
- [ ] Comprehensive rollback validation present
- [ ] Verifies Series parity
## Examples
- Chain: `src/e-k/Ema/Ema.StreamHub.cs`
- Complex state: `src/a-d/Adx/Adx.StreamHub.cs`
- Rolling window: `src/a-d/Chandelier/Chandelier.StreamHub.cs`
- Compound hub: `src/s-z/StochRsi/StochRsi.StreamHub.cs`, `src/e-k/Gator/Gator.StreamHub.cs`
See `references/` for detailed patterns:
- `provider-selection.md` - Choosing the right provider base
- `rollback-patterns.md` - RollbackState implementation examples
- `performance-patterns.md` - O(1) optimization techniques
- `compound-hubs.md` - Internal hub dependencies and construction patterns
---
Last updated: January 19, 2026
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「indicator-stream」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次