Quant.Infra.Net

Data Acquisition, Statistical Analysis, Broker Integration, Portfolio Analytics & Notifications — One NuGet Package

数据获取、统计分析、券商集成、组合分析、通知推送 —— 一个 NuGet 包全部搞定

View on GitHub 在 GitHub 上查看

Why Use This Library?

Building quantitative trading systems requires connecting to multiple data sources, brokers, and notification channels — each with their own API quirks. Instead of writing separate integrations for every platform, Quant.Infra.Net gives you a single unified C# API.

Pain PointSolution
Data APIs return inconsistent formats — you write converters for every providerUnified ITraditionalFinanceSourceDataService and ICryptoSourceDataService with standardized OHLCV models
Binance needs API keys + rate limiting; Schwab needs OAuth; IB needs TWS/Gateway IPCSingle IBrokerService abstraction — swap brokers by changing configuration, not code
Every broker uses different order models and status enumsCross-broker unified order model with state machine for fill tracking
Portfolio metrics require stitching together position data from multiple brokersBuilt-in CAGR, Sharpe ratio, Calmar ratio, Max Drawdown — just call the method
Strategy alerts scattered across Slack, email, DingTalk, WeChat...One notification service with pluggable channels — send everywhere from one line of code

Architecture Overview

ModuleResponsibilityKey Interfaces
SourceDataMulti-source market data ingestionYahoo Finance (via yfinance/pythonnet), Binance klines, Alpaca equity, CSV/MySQL/MongoDB
BrokerUnified broker execution layerBinance Futures (Testnet/Paper/Live), Alpaca US Equity, Charles Schwab, Interactive Brokers via InterReact
AnalysisQuantitative/statistical toolingADF test, OLS regression, Z-Score, Shapiro-Wilk, pair-trading spread
PortfolioPosition tracking and performanceCAGR, Sharpe, Calmar, Max Drawdown, equity curve charting (ScottPlot)
NotificationStrategy alert dispatchDingTalk bot, WeChat Work webhook, bulk email
SharedCross-cutting utilitiesIntervalTrigger, RollingWindow<T>, resolution helpers

Quick Start

1. Install via NuGet

# Add the library (v1.5.1) dotnet add package Quant.Infra.Net --version 1.5.1 # Required for Python-based data sources (Yahoo Finance via yfinance) dotnet add package pythonnet # Recommended for dependency injection dotnet add package Microsoft.Extensions.DependencyInjection

2. Use in Code

using Quant.Infra.Net.SourceData.Service; using Quant.Infra.Net.Analysis.Service; using Quant.Infra.Net.Broker.Service; using Microsoft.Extensions.DependencyInjection; // Register services via DI var services = new ServiceCollection(); services.AddQuantInfraNet(); // --- Fetch OHLCV data --- var dataService = services.BuildServiceProvider() .GetService<ITraditionalFinanceService>(); var bars = await dataService.GetOhlcvListAsync("AAPL", DateTime.Now.AddDays(-30), DateTime.Now); // --- Statistical analysis (pair trading) --- var analysis = services.BuildServiceProvider() .GetService<IAnalysisService>(); var correlation = await analysis.CalculateCorrelationAsync(aaplPrices, msftPrices); // --- Place orders across broker platforms --- var broker = services.BuildServiceProvider() .GetService<IBrokerService>(); var result = await broker.PlaceOrderAsync(new OrderRequest { Symbol="AAPL", Side=Side.Buy, Quantity=10 });

3. Configuration

// appsettings.json { "BinanceApi": { "ApiKey": "your-api-key", "SecretKey": "your-secret-key", "Environment": "testnet" // testnet | paper | live } }

Version History

VersionDateHighlights
1.5.12026-08-12Code_Standards.md compliance — bilingual XML docs on all public members, parameter validation audit
1.5.02026-05-28Interactive Brokers (InterReact) full integration; Charles Schwab broker service; MIT license; enhanced unit tests
1.4.02024-05-16Updated broker API integrations, comprehensive documentation
1.3.02024-04-05Enhanced notification services with email templates
1.0.02024-01-15Initial release — data, analysis, execution, notifications

Detailed Documentation

View complete module documentation, API reference, and code examples:

📖 Read the Full Documentation

Testing Notes

⚠️ Cryptocurrency Exchange Region Notice: Cryptocurrency exchange regulations vary by country/region. For example, Binance API may not be accessible from the Mainland,China or the US but works in Singapore. This repository only provides technical solutions—comply with local laws and take full responsibility for your actions.
Run other test modules with: dotnet test --filter "FullyQualifiedName!~Binance"

为什么要用这个库?

构建量化交易系统需要连接多个数据源、券商和通知渠道,每个平台的 API 都有不同的细节。Quant.Infra.Net 让你不再为每个平台重复编写集成代码,而是提供一个统一的 C# API。

痛点解决方案
数据 API 返回格式不一致,每个提供商都要写转换器统一的 ITraditionalFinanceSourceDataServiceICryptoSourceDataService,标准化的 OHLCV 数据模型
Binance 需要 API Key + 限流;Schwab 需要 OAuth;IB 需要 TWS/Gateway IPC单一 IBrokerService 抽象接口 —— 改配置换券商,不改代码
每个券商使用不同的订单模型和状态枚举跨券商统一订单模型,状态机追踪成交
组合指标需要拼接多个券商的持仓数据内置 CAGR、夏普比率、卡尔玛比率、最大回撤 —— 调用一个方法即可
策略信号分散在 Slack、邮件、钉钉、企业微信……单一通知服务,插件式通道 —— 一行代码发送到所有渠道

架构概览

模块职责关键接口
SourceData多源市场数据接入Yahoo Finance (通过 yfinance/pythonnet)、Binance K 线、Alpaca 美股、CSV/MySQL/MongoDB
Broker统一券商执行层Binance Futures (测试网/模拟盘/实盘)、Alpaca 美股、Charles Schwab、Interactive Brokers (通过 InterReact)
Analysis量化统计工具ADF 平稳性检验、OLS 回归、Z-Score、Shapiro-Wilk 正态性检验、配对交易价差计算
Portfolio持仓跟踪和绩效分析CAGR、夏普比率、卡尔玛比率、最大回撤、权益曲线图表 (ScottPlot)
Notification策略通知推送钉钉机器人、企业微信 Webhook、批量邮件
Shared横切工具类IntervalTriggerRollingWindow<T>、分辨率转换辅助方法

快速开始

1. 通过 NuGet 安装

# 添加库 (v1.5.1) dotnet add package Quant.Infra.Net --version 1.5.1 # 使用基于 Python 的数据源(Yahoo Finance / yfinance)需要 dotnet add package pythonnet # 推荐使用依赖注入 dotnet add package Microsoft.Extensions.DependencyInjection

2. 代码中使用

using Quant.Infra.Net.SourceData.Service; using Quant.Infra.Net.Analysis.Service; using Quant.Infra.Net.Broker.Service; using Microsoft.Extensions.DependencyInjection; // 注册服务 var services = new ServiceCollection(); services.AddQuantInfraNet(); // --- 获取 OHLCV 数据 --- var dataService = services.BuildServiceProvider() .GetService<ITraditionalFinanceService>(); var bars = await dataService.GetOhlcvListAsync("AAPL", DateTime.Now.AddDays(-30), DateTime.Now); // --- 统计分析(配对交易)--- var analysis = services.BuildServiceProvider() .GetService<IAnalysisService>(); var correlation = await analysis.CalculateCorrelationAsync(aaplPrices, msftPrices); // --- 跨券商平台下单 --- var broker = services.BuildServiceProvider() .GetService<IBrokerService>(); var result = await broker.PlaceOrderAsync(new OrderRequest { Symbol="AAPL", Side=Side.Buy, Quantity=10 });

3. 配置

// appsettings.json { "BinanceApi": { "ApiKey": "your-api-key", "SecretKey": "your-secret-key", "Environment": "testnet" // testnet | paper | live } }

版本历史

版本日期主要变更
1.5.12026-08-12Code_Standards.md 合规 —— 所有公共成员添加双语 XML 文档,参数校验审计
1.5.02026-05-28Interactive Brokers (InterReact) 完整集成;Charles Schwab 券商服务;MIT 许可证;增强单元测试
1.4.02024-05-16更新券商 API 集成,完善文档
1.3.02024-04-05增强通知服务(邮件模板)
1.0.02024-01-15初始版本 —— 数据、分析、执行、通知

测试说明

⚠️ Crypto 交易所地区合规说明:不同国家和地区对 Crypto 交易所监管要求不同。例如中国大陆、美国 IP 不能访问 Binance API,但新加坡可以。请遵守当地法律法规,本 Repo 仅提供技术方案,您为自己的行为负有全部责任。
运行其他测试模块:dotnet test --filter "FullyQualifiedName!~Binance"

详细文档

查看完整的模块说明、API 参考和使用示例:

📖 查看完整文档