Building my own trading platform, three rebuilds in
Building my own trading platform, three rebuilds in
构建我自己的交易平台:三次重构后的心得
I traded forex and crypto manually for years and lost money doing it. Looking back, my strategies were rarely the main problem. I entered trades on emotion and kept no real journal of why I did anything, so I couldn’t tell whether a bad week meant bad luck or a strategy that had stopped working. Like a lot of traders, I’d go on tilt, taking worse trades to win back the last loss. 我曾手动交易外汇和加密货币多年,并因此亏损。回过头来看,我的策略本身很少是主要问题。我往往凭情绪进行交易,也没有记录下任何操作背后的逻辑,因此我无法判断糟糕的一周是因为运气不好,还是策略已经失效。像许多交易者一样,我会陷入“上头”状态,为了挽回损失而进行更糟糕的交易。
Atlas is my attempt to fix that. I’ve rebuilt it three times to get to this version, and I’m still early. It’s a trading environment that runs on my own machine and takes an idea from a written strategy to backtests, then to paper trading, and eventually to live trading. I want the system to make the decisions I used to make badly, and I want it to prove the strategy has an edge before I let it anywhere near real money. Atlas 是我为解决这些问题所做的尝试。为了达到现在的版本,我已经重构了三次,而且目前还处于早期阶段。这是一个在我本地机器上运行的交易环境,它能将一个书面策略转化为回测,接着进行模拟交易,最终实现实盘交易。我希望这个系统能替我做出我过去做得糟糕的决策,并且在让它接触真实资金之前,先证明该策略确实具备优势。
Right now Atlas does historical research. It stores price history from an OANDA practice account as fixed evidence: 15-minute candles for my current strategy’s decisions and 1-minute bid and ask candles for simulating fills. Once stored, that data can’t change, so a backtest always points to the exact data it ran on. Strategies work the same way. If I change a single setting, Atlas saves a new version instead of editing the old one, which means I can’t accidentally compare results against logic that no longer exists. 目前,Atlas 主要进行历史研究。它将来自 OANDA 模拟账户的价格历史记录存储为固定证据:用于当前策略决策的 15 分钟 K 线,以及用于模拟成交的 1 分钟买入/卖出 K 线。一旦存储,这些数据就无法更改,因此回测总是指向它所运行的确切数据。策略的运作方式也一样。如果我更改了任何设置,Atlas 会保存一个新版本而不是修改旧版本,这意味着我不会意外地将结果与不再存在的逻辑进行比较。
The same version on the same data gives the same result every time, and any trade can be traced from the strategy’s decision to the simulated fill. Every position is sized by one central risk rule. The first market I tested was EUR/USD. Current research runs on GBP/JPY, which forced me to handle converting profit and loss back into a USD account properly. It also forced me to stop treating EUR/USD as the only market. My AI coding agent had hard-coded it all over the place, so now each new market gets added and tested on its own. 同一个版本在相同数据下每次都会得出相同的结果,并且任何一笔交易都可以从策略决策追溯到模拟成交。每个仓位都由一个核心风险规则来确定规模。我测试的第一个市场是欧元/美元(EUR/USD)。目前的研究运行在英镑/日元(GBP/JPY)上,这迫使我必须妥善处理盈亏转换回美元账户的问题。这也迫使我不再将欧元/美元视为唯一的市场。我的 AI 编程代理之前到处硬编码了该货币对,所以现在每个新市场都会被单独添加并进行测试。
Paper trading is close. The code exists, has been tested against a simulated broker, and as of this week can save a run and start it from the command line. It hasn’t placed a real practice order yet. The first runs will use an OANDA practice account. A lot of the work went into what happens when something is unclear. An order request doesn’t count as a position until the broker’s own records confirm the fill, and if the outcome of an outcome is uncertain, Atlas stops taking new entries until it’s resolved. 模拟交易已近在咫尺。代码已经存在,并已针对模拟经纪商进行了测试,截至本周,它已经可以保存运行状态并从命令行启动。它尚未下达真正的模拟订单。首次运行将使用 OANDA 模拟账户。大量工作投入到了处理“不确定情况”的逻辑上。订单请求在经纪商记录确认成交之前不会被计为仓位;如果订单结果不确定,Atlas 会停止新的入场,直到问题解决。
When the market closes, even for an unscheduled pause, any setup the strategy was waiting on gets discarded, and entries stay blocked for 30 minutes after the market reopens. Stale prices or a disagreement between Atlas and the broker halt the run instead of letting it guess. The part I care about most is that nothing trades by default. Starting Atlas doesn’t authorize trading, and neither does loading credentials. Loading the practice credentials, placing the first order, activating paper trading, and restarting a run each need my approval, every time. 当市场关闭时,即使是计划外的暂停,策略正在等待的任何设置都会被丢弃,并且在市场重新开放后的 30 分钟内禁止入场。陈旧的价格或 Atlas 与经纪商之间的分歧会导致运行停止,而不是让它进行猜测。我最关心的一点是,默认情况下不会进行任何交易。启动 Atlas 并不授权交易,加载凭据也不行。加载模拟凭据、下达第一个订单、激活模拟交易以及重启运行,每一次都需要我的批准。
The code that talks to the broker also refuses to connect to the live server at all. It would have been easy to let “the app is running” imply “the app can trade.” I kept those as separate steps on purpose, even though it makes day-to-day use a little annoying. I build most of my software with AI coding agents now, and Atlas is where I’ve learned the most about what that takes. A trading system is a demanding test. If an agent gets the risk logic mostly right, or quietly changes how something behaves between two commits, I end up with a system that isn’t safe to run with real orders. 与经纪商通信的代码也完全拒绝连接到实盘服务器。让“应用运行”等同于“应用可以交易”很容易,但我特意将这些步骤分离开来,尽管这让日常使用变得有点麻烦。我现在大部分软件都是用 AI 编程代理构建的,而 Atlas 是我学习到这一过程所需条件最多的地方。交易系统是一个严苛的测试。如果代理在风险逻辑上做得不够准确,或者在两次提交之间悄悄改变了行为方式,我最终得到的系统将无法安全地执行真实订单。
Most of the discipline in Atlas exists for that reason. Fixed data, frozen strategy versions, and explicit approvals make it harder for me or an agent to ship a subtle mistake without noticing. Atlas isn’t deployed anywhere, and no real money has touched it. It isn’t ready for that yet. Live trading doesn’t exist, and I don’t plan to build it until paper trading has run long enough to show how Atlas behaves in real market conditions. I expect real money to surface problems that paper trading can’t, and I’m looking forward to finding out what they are. I’ll write about the first real paper order when it happens. Atlas 中的大部分纪律正是出于这个原因。固定的数据、冻结的策略版本和明确的批准流程,使得我和 AI 代理更难在不经意间引入细微的错误。Atlas 目前没有部署在任何地方,也没有涉及任何真实资金。它还没准备好。实盘交易尚不存在,在模拟交易运行足够长的时间以展示 Atlas 在真实市场条件下的表现之前,我不打算构建实盘功能。我预计真实资金会暴露出模拟交易无法发现的问题,我很期待找出这些问题。当第一笔真正的模拟订单产生时,我会写文章记录下来。
Originally published at victorike.me. I write about building Atlas, the times the AI agents get it wrong, and the economic news that moves the markets I trade. I use AI to help write these posts, the same way I use it to build Atlas. It’s a tool. The stories are real, and the edits, the decisions, and the final version are mine. Atlas is a tool. Nothing here is financial advice. I am not a registered financial or investment adviser. 最初发布于 victorike.me。我撰写关于构建 Atlas 的过程、AI 代理出错的时刻,以及影响我所交易市场的经济新闻。我使用 AI 来辅助撰写这些文章,就像我用它来构建 Atlas 一样。它只是一个工具。故事是真实的,而编辑、决策和最终版本都出自于我。Atlas 是一个工具。本文内容不构成任何财务建议。我不是注册财务或投资顾问。