bytex README

项目的 README,来自 github.com/BYTEX-TRADE/bytex。合并为一个 markdown 文件:README.md。

BYTEX: technology in motion, advantage in result

CI Latest release License: Apache-2.0 .NET 10

BYTEX

An event-driven algorithmic trading engine for .NET — one strategy, from backtest to live.

BYTEX is an open-source trading platform written in C#. It lets you write a trading strategy once and run it unchanged against historical data, against live market data with simulated execution, and against real exchange accounts. The engine is deterministic, asset-class agnostic, and built around a small set of composable components that are the same in every environment.

Status: pre-release. APIs may change between minor versions until 1.0; what counts as an API and how the promise is held are in docs/versioning.md. Backtesting, sandbox and live trading run the same strategy code on the same engine, with the pre-trade limits and the halt a live node needs. The venue adapters are beta until they complete verification against live venues.

Every commit runs more than 3,400 tests on Linux, Windows and macOS, and none of them is skipped: a defect is found by a test that states the right answer, and the fix is what makes that test pass. What each release fixed is in the changelog; what is still open is an issue.

Why BYTEX

Capabilities

Area What is included
Strategy SDK RuntimeModule and Strategy base classes with lifecycle, data, order, and position handlers; typed configuration; order factory; cache and portfolio access; clock and timers; indicators
Orders market, limit, stop-market, stop-limit, market-if-touched, limit-if-touched, trailing stops, market-to-limit; GTC / IOC / FOK / GTD / DAY; post-only, reduce-only, iceberg display quantity; OCO / OTO / OUO contingencies; bracket orders; stop and if-touched orders triggered in the engine for venues that have none, released as market or limit under the same id; execution algorithms that work one order as many, with TWAP included
Backtesting simulated venues with a per-instrument matching engine, fills bounded by the size on offer, fill and slippage models, fee models by rate, notional or contract, funding on perpetuals, liquidation of margin accounts, cash and margin accounts; bar, quote, and trade data; Parquet data catalog; performance reports; batch runs over instrument lists, period lists and parameter grids, compared in one table
Live trading trading node with live clock, exchange adapters, reconciliation at start-up and, if asked, while it runs, sandbox execution (live data, simulated fills), optional Redis state persistence; a local control channel for status, a view of what the node holds, cancel, flatten, halt, release and limits
Risk pre-trade validation of precision, size, notional, rate limits; cash balance and margin checks; a loss limit that counts what open positions are down as well as what was realised, watches it between fills and stops the node when it is reached; exposure limits; caps on open positions and working orders; trading state control and a halt that leaves the node running
Strategy documents a strategy as data: a typed node graph (data, indicators, levels, conditions, actions, risk, flow, events) with a node catalog whose every parameter choice carries its own name, unit and sentence, a three-layer validator and a deterministic runtime; sizing carries a ceiling, so a risk-based rule cannot stake the account; an order can be worked in pieces by an execution algorithm the document names; the same document backtests, paper trades and trades live
Adapters Binance (spot, USDⓈ-M futures, COIN-M futures), Bitget (spot, USDT- and USDC-margined perpetuals), Bybit (spot, linear perpetuals, inverse contracts, options), Gate (spot, USDT perpetuals, USDT delivery futures), Hyperliquid (perpetuals), Kraken (spot, futures), KuCoin (spot, futures), OKX (spot, perpetual swaps, dated futures); Databento and Tardis historical data; adapter SDK for new venues
Tooling bytex CLI for backtests, live nodes, catalog management, strategy documents (validate, catalog, schema, examples), API key verification, and a control channel for a running node; Docker image; notebook support

Roadmap

Release Milestone Highlights
0.1 ✅ Foundation tradingRuntime · backtesting · live and sandbox trading · Binance · Bybit · test suite
0.2 ✅ Strategy Documents strategies as data · node catalog · validator · runtime · example documents · node control channel
0.3 ✅ Risk loss and exposure limits · position and order caps · margin checks · kill switch · limits from configuration, control channel or command line
0.4 ✅ Execution order emulation · execution algorithms (TWAP) · continuous reconciliation · batch runs and parameter sweeps · a loss limit watched between fills that stops the node · every parameter choice saying what it means
0.5 ✅ Realism fills bounded by the size on offer · funding payments on perpetuals · liquidation of margin accounts · per-contract fees · reference backtests run on every commit
0.6 ✅ Depth order-book-level matching · own-order book · a paper venue matched against its venue's live book · margin held for working orders · leverage stated by the strategy
0.7 ✅ Venues OKX · Kraken · Bitget · Gate · Hyperliquid · KuCoin Futures · a broker id on every order an adapter sends
0.8 ✅ Resumption and large data a killed node comes back the same · timers that keep their phase · backtests over data larger than memory · what the catalog holds, and putting it right · CSV files an exchange actually hands out
0.9 ✅ Markets and state Databento · full Redis state and the bus on Redis streams · cloud storage for the catalog · strategies added and stopped while a node runs · margin models · position snapshots and figures of your own · a wider indicator set · information-driven bars · node types a plugin brings · a run as one page · documents evaluated on ticks · the recordings checked against the venues once per release
0.10 ✅ State, strictness and book depth a node's state in PostgreSQL · one key layout shared by every backing store, and a conformance suite each answers · the last bar of a window checked against the venues · five things the engine accepted while quietly doing something else · a backtest fed a real order book, from a vendor that gives the first day of every month away · depth stored in bounded files, because an instrument-day is 4.3 GiB · order books that compare equal when their levels are equal
1.0 Stable verification against live venues · the API freeze taking effect

A milestone marked ✅ is delivered; the changelog says what each one carried. 0.8 and 0.9 shipped together as 0.9.0, because everything in both was finished before either was cut. The rest have no dates: a release ships when it is ready and the order may change, and fixes do not wait for a milestone - they ship continuously as patch releases. The same list lives in docs/roadmap.md.

Quick start

Build from source (the packages are attached to every release, and installation shows how to use them; they are not on nuget.org yet):

git clone https://github.com/BYTEX-TRADE/bytex
cd bytex
dotnet build
dotnet run --project examples/Bytex.Examples -- backtest-ema-cross
public sealed record EmaCrossConfig : StrategyConfig
{
    public required MarketKey MarketKey { get; init; }
    public required CandleSeries CandleSeries { get; init; }
    public int FastPeriod { get; init; } = 10;
    public int SlowPeriod { get; init; } = 20;
    public decimal TradeSize { get; init; } = 1m;
}

public sealed class EmaCross : Strategy<EmaCrossConfig>
{
    private readonly ExponentialMovingAverage _fast;
    private readonly ExponentialMovingAverage _slow;

    public EmaCross(EmaCrossConfig config) : base(config)
    {
        _fast = new ExponentialMovingAverage(config.FastPeriod);
        _slow = new ExponentialMovingAverage(config.SlowPeriod);
    }

    protected override void OnStart()
    {
        RegisterIndicatorForBars(Config.CandleSeries, _fast);
        RegisterIndicatorForBars(Config.CandleSeries, _slow);
        SubscribeBars(Config.CandleSeries);
    }

    protected override void OnBar(Bar bar)
    {
        if (!_fast.IsInitialized || !_slow.IsInitialized)
        {
            return;
        }

        var instrument = Cache.Instrument(Config.MarketKey)!;
        var quantity = instrument.MakeQuantity(Config.TradeSize);

        if (_fast.Value > _slow.Value && Portfolio.IsFlat(Config.MarketKey))
        {
            SubmitOrder(OrderFactory.Market(Config.MarketKey, OrderSide.Buy, quantity));
        }
        else if (_fast.Value < _slow.Value && Portfolio.IsNetLong(Config.MarketKey))
        {
            CloseAllPositions(Config.MarketKey);
        }
    }
}

The same class runs in a BacktestEngine, in a sandbox, or in a live TradingNode. Full walkthroughs are in docs/getting-started.

Command line

The bytex tool runs backtests and trading nodes from JSON configuration (installable with dotnet tool install --global Bytex.Cli once the packages are on nuget.org; from source, use dotnet run --project src/Bytex.Cli --):

bytex catalog fetch-instruments --path ./catalog --venue BINANCE --quote USDT
bytex catalog import-csv --path ./catalog --file btcusdt-1m.csv --kind bars --instrument bx-market:v2/BINANCE/BTCUSDT --candle-series bx-candle:v2/BINANCE/BTCUSDT/minute/1/last/provider
bytex --plugins ./plugins backtest --config examples/configs/backtest-ema-cross.json
bytex --plugins ./plugins run --config examples/configs/sandbox-binance-ema-cross.json

A strategy written as a document needs no C# at all:

bytex documents examples --out ./documents
bytex documents validate --document ./documents/ema-cross.json --catalog ./catalog
bytex --plugins ./plugins backtest --config examples/configs/backtest-document.json

Strategies are referenced by type name in JSON and loaded from plugin assemblies, so one CLI runs any strategy. See docs/getting-started/cli.md.

Repository layout

src/Bytex.Core               domain model, messaging, clock, cache, portfolio, engines, Strategy SDK, adapter SDK, plugins
src/Bytex.Indicators         technical indicators
src/Bytex.Documents          strategy documents: a strategy as data, and the runtime that trades one
src/Bytex.Data               Parquet data catalog, CSV loaders
src/Bytex.Backtest           simulated venues, backtest engine and node, reports
src/Bytex.Live               trading node, tradingRuntime loop, network infrastructure, sandbox execution
src/Bytex.Adapters.*         Binance, Bitget, Bybit, Databento, Gate, Hyperliquid, Kraken, KuCoin, OKX, Tardis
src/Bytex.Persistence.Redis  Redis state persistence
src/Bytex.Persistence.S3     the data catalog on S3-compatible object storage
src/Bytex.Cli                the bytex command-line tool
examples/                    example strategies, configurations and the notebook
tests/                       unit and integration tests, eight projects
docs/                        getting started, concepts, integrations, design notes, requirements, roadmap

Building from source

Requires the .NET 10 SDK.

dotnet build
dotnet run --project examples/Bytex.Examples -- backtest-ema-cross

Contributing

Contributions are welcome. Please read CONTRIBUTING.md first. Security issues should be reported as described in SECURITY.md.

License

BYTEX is licensed under the Apache License, Version 2.0. Third-party components are listed in THIRD-PARTY-NOTICES.md.

Disclaimer

BYTEX is software for building trading systems. It is not investment advice, and it does not guarantee any trading outcome. Trading financial instruments involves risk of loss. You are solely responsible for any strategy you run and any account you connect.

bytex (BYTEX-TRADE/bytex)

正在搜索数据库…

这是什么?BYTEX 是一个用 C# 编写的开源事件驱动算法交易引擎,面向 .NET。你只需编写一次交易策略,同一份代码无需修改即可在回测、沙盒模拟和对接真实交易所账户的实盘交易中运行。
它是框架还是库?它是一个框架:你使用 BYTEX 的 Strategy/Actor 基类把策略写成一个 C# 类,由引擎的单线程内核驱动整个事件生命周期——没有单独的脚本层或语言绑定。
怎么让它跑起来?目前你需要从源码构建并直接引用各项目,因为 Bytex.Cli 的 NuGet 包尚未发布;之后你的策略类无需修改即可运行在 BacktestEngine、沙盒或实盘 TradingNode 中。
除了 .NET,构建它还需要什么?从源码构建需要 .NET 10 SDK;只有当你想为实盘交易节点启用可选的状态持久化时才需要 Redis。
它现在能直接用于实盘交易吗?还不能完全——BYTEX 处于预发布阶段,1.0 之前 API 仍可能变动,Binance/Bybit 交易所适配器在完成对真实交易所的验证之前标记为 beta。回测和沙盒交易(真实行情数据加模拟成交)已经完全可用。
可以在哪些交易所交易?BYTEX 自带 Binance(现货和 USDS-M 合约)和 Bybit(现货和线性永续合约)适配器,外加一个用于历史数据的 Tardis 适配器;可以通过适配器 SDK 接入新的交易所,而无需改动引擎。
BYTEX 为什么避免用浮点数表示资金?价格、数量和余额都以显式精度的定点小数存储,而不是浮点数,这样可以避免舍入误差漂移,并保证回测结果可精确复现。
沙盒模式具体是做什么的?沙盒模式让你的策略运行在实时行情数据上,但执行的是模拟成交而非真实订单,因此你可以在实时条件下测试,而不会危及真实的交易所账户。
bytex CLI 能做什么?bytex CLI 通过 JSON 配置文件运行回测和实盘交易节点,按类型名从插件程序集中加载策略,因此一个 CLI 二进制就能运行任意策略;它还负责管理 Parquet 数据目录。
大小
1.9 MB
星标
886
时长
3个月
提交 · 90 天