bytex README

The project's README from github.com/BYTEX-TRADE/bytex. As one markdown file: README.md.

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, and the venue adapters are beta until they complete verification against live venues. Backtesting and sandbox trading are fully functional today.

Why BYTEX

Capabilities

Area What is included
Strategy SDK Actor 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
Backtesting simulated venues with a per-instrument matching engine, fill and slippage models, fee models, cash and margin accounts; bar, quote, and trade data; Parquet data catalog; performance reports
Live trading trading node with live clock, exchange adapters, startup reconciliation, sandbox execution (live data, simulated fills), optional Redis state persistence
Risk pre-trade validation of precision, size, notional, rate limits; trading state control
Adapters Binance (spot, USDⓈ-M futures), Bybit (spot, linear perpetuals); Tardis historical data; adapter SDK for new venues
Tooling bytex CLI for backtests, live nodes, and catalog management; Docker image; notebook support

See the roadmap for what is planned next.

Quick start

Build from source (NuGet packages are planned; until they are published, reference the projects directly):

git clone https://github.com/BYTEX-TRADE/bytex
cd bytex
dotnet build
dotnet run --project examples/Bytex.Examples -- backtest-ema-cross
public sealed class EmaCrossConfig : StrategyConfig
{
    public required InstrumentId InstrumentId { get; init; }
    public required BarType BarType { 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.BarType, _fast);
        RegisterIndicatorForBars(Config.BarType, _slow);
        SubscribeBars(Config.BarType);
    }

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

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

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

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 packages are published; 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 BTCUSDT.BINANCE --bar-type BTCUSDT.BINANCE-1-MINUTE-LAST-EXTERNAL
bytex --plugins ./plugins backtest --config examples/configs/backtest-ema-cross.json
bytex --plugins ./plugins run --config examples/configs/sandbox-binance-ema-cross.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.Data               Parquet data catalog, CSV loaders
src/Bytex.Backtest           simulated venues, backtest engine and node, reports
src/Bytex.Live               trading node, kernel loop, network infrastructure, sandbox execution
src/Bytex.Adapters.*         Binance, Bybit, Tardis
src/Bytex.Persistence.Redis  Redis state persistence
src/Bytex.Cli                the bytex command-line tool
examples/                    example strategies and configurations
tests/                       unit, integration, and performance tests
docs/                        getting started, concepts, integrations, design notes, 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)

Searching Database…

886 ·GitHub
这是什么?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 数据目录。
Size
1.9 MB
Stars
886
Age
1mo
Commits · 90 Days