Ali H. Askar retweeted
ETH Zürich's "Mathematical Foundations for Finance"
PDF: metaphor.ethz.ch/x/2021/hs/4…
如何更快取得 @HyperliquidX 的盤口數據?
在 Hyperliquid 進行跨所套利時,發現部分成交滑點偏高,p90 達 2–8 bp
經查,主因為下單當下所持盤口數據已過時,價格已先行變動,所見仍為數百毫秒前的狀態。伺服器部署於東京,物理距離已盡量縮短,惟官方公共 WebSocket 推送之盤口仍偏慢。以全天生產數據統計:
中位數 236 ms
p90 346 ms
約 2% 之幀超過 1 秒才抵達
後續採用 @Quicknode 的 gRPC 盤口推送
p50:236 ms → 176 ms
p90:346 ms → 211 ms
超過 1 秒之幀:2.05% → 0.02%
費用方面,Build 方案每月 49 美元,包含 8,000 萬 credits。僅訂閱最佳買賣報價、約 20 個幣種,已完全足夠
若追求更快,可自行成為 Hyperliquid validator,直接自鏈上取得數據,惟每月伺服器成本約 1,000 美元
真正的機會來自結構差異——跨所、跨 DEX、資金費率與定價規則之間的不一致。先找出結構,機會方才存在;速度僅是使既有機會執行得更為乾淨
以每月 49 美元換取約 60 ms 的改善,性價比可接受;更高成本則待結構機會更為明確後再行考慮。因此,QuickNode 對我而言是實用工具,而非 alpha 本身。先尋找結構,再談論速度
(但是我仍然尋找當中....)
Ali H. Askar retweeted
Ex-Tower Research HFT trader Annanay Kapila (@annanay) on why prop firms can make 100% a year and hedge funds can't:
"Proprietary trading firms tend to have only their own partners' money. So they tend to be less well capitalized. So they need to achieve a good return on capital."
"They tend to run strategies that you can't necessarily put a lot of money behind, but you can make a lot of return from them. So returns on proprietary trading firms can be upwards of 50%, even 100% a year."
"You'd struggle to find a hedge fund achieving those kinds of returns. But the point with a hedge fund is they take in a lot of capital. Even if they achieve a modest return on that capital, they still make a lot of money."
"Hedge funds ultimately are dealing with clients' money. They have to act within risk constraints that their clients put on them. There needs to be a sales process to get the capital in, and a process for how to return the capital."
"With proprietary trading firms, none of those considerations really apply, because ultimately you're trading with your own money."
"Greed makes markets."
Annanay Kapila (@annanay) spent years as an HFT quant at Flow Traders and Tower Research before founding QFEX (@QFEX), a perpetual futures exchange for equities, commodities & FX. Cambridge Maths.
At his last job, the desk traded $10B+ of volume a day, run almost entirely by algorithms.
In this lecture, he builds market making from first principles:
- The map of systematic trading: prop money vs. other people's money, HFT vs. mid-frequency, and why every strategy lives in one quadrant
- Why prop firms can return 50-100% a year while hedge funds can't: HFT never leaves you holding a big position
- The order book from scratch: bids, offers, limit orders, and why the first order on a price level gets the trade
- No free lunch: how arbitrageurs force every order book to reveal a fair price without anyone trying to
- The entire strategy in one line: bid below fair value, offer above it, collect the difference forever
- Market making is "time-spreading risk," warehousing positions between a seller who shows up now and a buyer who shows up later
- Adverse selection: you're most likely to get filled precisely when your price is most wrong
- Why market makers are completely self-serving, and why that's exactly what makes markets work
- The competitive race that compresses spreads: greed among market makers means lower costs for everyone else
- Thick books vs. thin books, and the vicious loop that keeps illiquid markets illiquid
Highlights:
(00:45) The systematic trading map: capital vs speed
(01:45) Prop firms vs hedge funds: return-on-capital economics
(06:29) A message from Onyx
(07:55) Where market making sits: high-Sharpe prop HFT
(08:55) Fungibility and why exchanges exist
(11:00) How a central limit order book actually works
(17:40) No free lunch: arbitrage-free pricing in the book
(19:55) Theo: reading fair value from the mid
(22:45) Who really posts the book (not retail)
(24:35) Market making as warehousing risk across time
(27:20) Edge: quoting around your fair value
(29:45) Queue priority and the adverse selection problem
(33:05) How competition compresses the bid-offer spread
(37:40) Thick vs thin books: liquidity begets liquidity
(43:55) Scaling to $10B a day on algorithms
good stuff. i used a similar tactic in 01 to be the first one on the books whenever they got out of (usually unplanned) maintainance.
hammer the API to be the first one in the books, and pick off anyone who forgot or couldnt to cancel their orders.
gud monies
exchanges deploy too, downtime exist.
use that as an edge.
01/ for example
recently lighter added a shutdown notice before closing:
{"close_in_ms":12943,"type":"shutdown"}
then closes with code 1012 "server shutting down". they say within 30s
02/ ok then what ?
all sockets got the notice within 13ms of each other. close_in_ms ranged from ~5.3s to ~13.8s, different per socket.
every close landed between 10ms before and 4ms after the deadline. data kept flowing until the close
think about it. everyone has the same constraints, if you're the first to reconnect, you're basically alone for a few seconds.
won't matter in most cases, sure, but during high volatility times this can be a money printer.
03/ works for market data too
you can open the new socket while the old one is still draining, so there's no blind window at all.
basically you always have to treat venue maintenance as a normal state of your system, not an exception.
04/ edge lies in the p99
when designing hft systems, always think about the worst case, the last quantile, that's where shit ton of money can be printed (or lost)
every api/dependency you have can go down, be ready for this
Ali H. Askar retweeted
After almost 10 years of work corporateownershipdata.com now makes available all publicly available ownership records of 7,156 publicly traded firms, not just the S&P 500, including dual-class shares.
Ali H. Askar retweeted
one thing every hft developer should have:
a repeatable blueprint of scenarii that you can run on any exchange API to understand its behavior.
01/ list all possible operations
think about all the possible edge cases there can be, try sending each operation 3x then 10x, then invert the order of operations.
try everything so you can draw as much conclusions as possible on how their ordering/matching engine works.
02/ pipeline it
make this easily repeatable, so you can easily run it through any new exchange API you find.
every time you find an edge case on any exchange, add it to your blueprint and test it everywhere.
many details are hidden out there waiting for you to be found.
03/ run it after every update
exchanges update their logic pretty often, don't assume things will always be the way they are.
use this as an edge, the faster you catch an internal logic change, the longer you can take advantage of it.
a few more good HFT tricks for you to try out
again. not rocket science. just there to nudge you in the right direction.
01/ multiple feeds
subscribe to multiple feeds, from different places, with different IPs, multiple times.
and deduplicate the output.
you never know why one feed or the other can be faster in different conditions.
benchmarking when the market is calm has nothing to do with high vol times.
even the worst median can be the best p99.
yes ultimately you want a private fiber w/ @Avelacom_Corp but until then just compound the feeds you have and make the best usage of em. can already get you pretty far.
02/ always a/b test
keep a low risk engine running on the side that serves as a reference for your optimizations.
first, well you can still catch some liquidations but more importantly bugs early on and actually see your improvements.
more volume, more activity = more messages going through your system, you need to be able to spot where is the bottleneck at all times.
03/ stale data is worse than no data
you have to know your data feeds, their edge cases, especially when pricing fair value using multiple sources and layers.
each layer should have its own thresholds and protections, an oracle feed you're using for a basis or a weekend mid price should not be treated equally.
Ali H. Askar retweeted
勇闯Perp价差套利第一周,供大家参考:
延迟:(我的服务器在 AWS 东京)
@arcus_xyz:挂单 43ms,改价 28ms,撤单 52ms,挂单成交到收到推送 10ms 左右
@Lighter_xyz :357ms,其中 300ms 是 Standard 档固定的吃单延迟,网络往返只有 33ms
@entropyIO:540ms 撮合,780ms 收到回执
540ms 里网络只占很小一部分,东京到交易所的往返通常只有几十毫秒。剩下的大部分应该是 Hyperliquid 链上出块、撮合的等待时间
每组 2个号,本金 = 两边账户合计
A 组|Entropy × Lighter RH
运行 4.8 天|本金 $205|交易量 $12,035|平均 OI $404
盈利 +$6.01
B 组|Arcus × Lighter RH(保守)
运行 7 天|本金 $282|交易量 $20,269|平均 OI $699
盈利 +$2.69|积分 1.26
C 组|Arcus × Lighter RH(均衡)
运行 4.8 天|本金 $411|交易量 $47,463|平均 OI $1,361
盈利 +$4.27|积分 1.94
D 组|Arcus × Lighter RH(激进)
运行 2 天|本金 $200|交易量 $31,593|平均 OI $819
盈利 +$1.94|积分 0.87
Arcus × Lighter(B + C + D)合计:本金 $893,交易量 $99,325,盈利 +$8.90,Arcus积分 4.07,Lighter给的积分总共不到0.3😂😂
Arcus积分跟什么有关:
OI x 持仓时间、交易量
大约每 1 万刀交易量 0.17 分,每 1000 刀 OI 持仓一天 0.18 分,三组的误差都在 4% 以内。
也就是说,持仓 1000 刀 OI 一整天,差不多相当于刷 1 万刀交易量。
各品种表现:(我只选择了流动性还不错的RWA品种,Crypto只做了ZEC)
CRCL 赚得最多,SPCX 滑点最大、SPY滑点最小,只有ZEC是亏得。
Ali H. Askar retweeted
高频基建大致可以分成这几层,从底层硬件一直到上层运维
1. 硬件与网络
机房选址和托管:服务器放在离交易所撮合引擎最近的地方(比如 AWS 东京)
服务器配置:CPU 绑核、关超线程、大页内存、网卡选型
网络:内核旁路(kernel bypass)、多网卡分离行情和下单、专线
2. 时钟与延迟测量
时钟同步(NTP、PTP)
全链路打点:从收到行情到发出订单,每一段花了多少时间
延迟分布统计:看的是 p50、p99,而不是平均值
3. 行情层
连接管理:WS 订阅、断线重连、心跳
解析与归一化:不同交易所格式统一成内部格式
本地订单簿重建:快照加增量、序号断档检测和补数据
数据质量:乱序、重复、丢包、延迟异常的识别
4. 交易接口层(连接层)
交易所适配:每家 API 的差异抽象成统一接口
限频管理:按 API Key 或按 IP 的令牌桶
下单通道:WS 下单、批量下单、撤改单
5. 订单管理(OMS)
订单状态机
成交回报处理与持仓计算
状态对账:本地和交易所的订单、持仓核对
6. 策略引擎
事件驱动框架:行情、成交、定时器事件的调度
低延迟设计:无锁队列、预分配内存、避免 GC
策略和基础设施的接口解耦
7. 风控
事前风控:下单前的仓位、金额、价格偏离检查
实时风控:回撤、库存、敞口监控
熔断与 kill switch:行情异常、延迟超标、交易所故障时停止报价并撤单
8. 数据与研究
行情和成交的全量落盘存储
回放系统:用历史 tick 数据重放
回测与仿真:撮合、队列位置、延迟模型
9. 监控与运维
监控面板:延迟、成交率、PnL、系统资源
告警:分级告警,谁接、多久响应
日志、部署、灰度发布、故障恢复
10. 资金与账户
多交易所、多账户资金调度
费率档位和做市协议管理
Ali H. Askar retweeted
🐘 Introducing Postgres Internals in 3D.
🌟 pgrun.dev/pi
Stop reading boring diagrams. Start exploring PostgreSQL.
An interactive 3D map to understand how Postgres actually works.
100% free. Built for developers.
xitter.cf/alxshp/status/21100494…
Introducing PGSync 🐘
Real-time PostgreSQL replication. FREE. OSS
Built in Rust. 🦀
Postgres 16 / 17 / 18.
No extensions. No triggers. No complex setup.
→ snapshot
→ replicate
→ stream changes
→ track WAL
→ recover from crashes
→ resume automatically
→ keep databases in sync
~15 MB RAM during streaming.
Built for developers. Built for AI agents.
Open source.
xitter.cf/alxshp/status/21078790…
Ali H. Askar retweeted
Before you ship a vibe-coded site, make Opus 5.5 audit it like a performance team.
Send 4 subagents across these 20 checks:
*Images + fonts*
• Convert images to WebP/AVIF and size them correctly
• Use next/image for large assets
• Lazy-load below-the-fold media
• Prioritize the main above-the-fold image
• Use framework-native font loading
• Keep fonts limited
• Remove unused third-party scripts
• Delay analytics/chat widgets until after load
*Frontend*
• Run a bundle analyzer
• Replace full-library imports with only what you use
• Dynamically import heavy charts, editors and maps
• Fetch homepage data on the server
• Stream AI responses
• Use skeletons while loading
*Database + APIs*
• Add indexes for filtered/sorted columns and RLS fields
• Use (select auth.uid()) in RLS policies
• Kill N+1 queries
• Paginate long lists
• Cache shared API responses, never user-specific ones
• Move emails, image processing and reports to background jobs
*Servers + network*
• Keep functions near the database region
• Use static pages or ISR where possible
• Parallelize independent API calls
• Test on low-end Android + slow 4G
Then paste this:
“Send one subagent per group to check it without editing anything, and note which file each issue is in and which page it affects. Run the database subagent at high effort. Before changing anything, run a production build or preview, then run Lighthouse three times in mobile mode on the homepage and the two or three slowest pages and note the median. Then fix everything yourself from their lists, measure again the same way, and give me the before-and-after numbers. Don’t remove features to gain speed. Ask me before removing dependencies, changing the deploy region, or changing the database.”
Ali H. Askar retweeted
time to talk about pricing in HFT
01/ micro price or mid price?
well none, you need a proper filter.
mid price and micro price can easily be manipulated, especially during weekends or illiquid markets.
what you want, is to filter out the noise from the signal.
1. don't overreact to price movements, wait for confirmations.
2. anchor on the deepest side of the book.
3. the tighter, the closer to the actual mid
02/ kalman filter
there is a very good description of it in the book "Algorithmic Trading: Winning Strategies and Their Rationale"
not for lead-lag arb or tight quoting.
good if you have one fast but noisy source and one slower more reliable source.
be careful to align on origin timestamps.
rewind, correct, replay.
03/ future contracts rolling
xitter.cf/AriPingle/status/20422…
outdated alfa, but if you look around closely it's still a good example on how you can print with better pricing models.
look at the oracles used by each market, there are lots of innefficiencies or MMs mispricing out there.
Yesterday, Hyperliquid oil perp was paying -300% annualized funding. Onchain infrastructure is telling us something about how commodity markets will work going forward
@tradexyz perps use CME front month as the oracle. Front month ~$95, back month ~$87. Oracle rolls over 5 business days, stepping down ~$1.70 per shift
The "obvious" trade is to short the perp, hedge on CME, collect the roll. We open-sourced a model to price it w/ a link at end of the 🧵
Ali H. Askar retweeted
Introducing Anatomy
Describe a machine in one line. Claude brings it to life.
- Interactive isometric wireframes you can rotate, inspect and explore
- WebGL shaders for fire, water, plasma and more
- Real 3D motion, with individual parts that rotate and move
Install it as an agent skill. Fully open source.
Ali H. Askar retweeted
I need help from my street quants.
When I create features, I plot quantiles of the feature value vs forward returns, I often get this kind of results: linear positive relation in the middle, and reversion at the tails of the feature.
I added an example, of feature= 10 days returns / 10 days std. the three lines are just the same feature but on 3 terciles of the universe by ADV.
In the end, I want to use a linear model so it won’t pickup this behavior.
1. I could use a non-linear model (will probably overfit)
2. I could apply a transform to the feature such that larger values of the features gets lower.
3. I could ignore this issue
Still not figured out what the best solution is, any advice ?
最初通过加密交易所而非传统交易所接触程序化交易的交易员无疑是幸运的。
在IB,你需要为几乎所有实时数据支付费用,股票、大宗、债券等等,各种不同交易所的标的都要收一遍,L1和L2还要拆开来收。少则两三美元一个月,多则一两百刀一个月。如果不交,只能看到延时15分钟的数据。即使交了数据订阅费,你也只能同时订阅3个标的的L2,每3个L2标的实时数据需要一个月30刀。周六数据服务器维护时段你是调不了历史数据的。你的手机端和服务器端都需要维护各自的账号才能不产生登录冲突。所有交易标的的交易权限都要手动开通,有的还要答各种题目。出入金存在相当程度的时延而且基本只能从同名账户出入。
我要是AI Agent我一定会从加密交易所开始我的交易之旅,毕竟我连传统交易所的KYC都过不去。而据我所知AI会在接下来10年内接管一切。
This is a must read for all aspiring traders/PMs
Contrary to clever punditry, risk is both quantitative and qualitative in nature. The physics of money works under a stable regime but the seismic monetary resets, where the big money is, occur by the whims of the human condition
Ali H. Askar retweeted
This is all you need for your next System Design interview.
Bookmark these 👇
github.com/liquidslr/system-…
pagefy.io/system-design/syst…
Ali H. Askar retweeted
Don’t underestimate how much value you can get from a free blog. I came across a blog by Sergi (the #1 trader on Darwinex) explaining how he evaluates whether a filter actually improves a trading strategy.
I used his framework to build a model that systematically evaluates the effectiveness of filters applied to any trading strategy. I’m pretty confident this will become one of the core pillars of my development process going forward.
I combined his framework with another concept I learned from Timothy Masters (Monte Carlo Permutation Tests) to develop the full model.
There are so many gems like this on Sergi’s website. You just have to dig.
Here’s the blog post:
sersansistemas.com/filtros-t…
Ali H. Askar retweeted
Daha önce parasını yaklaşık 10 bin katına çıkaran Qullamaggie ile ilgili bir paylaşımım olmuştu.
Manuelci arkadaşlardan inek öğrenci modunda detaylı araştırmak isteyen olursa pozisyon büyüklüğü risk ve poz kapatma tarzı ile ilgili oldukça detaylı bir makale var alıntıda.
Kabaca özetlersek: her bir tradede çok az miktarı riske atıyor ve poz kapatırken kuralcı davranışlardan daha çok sezgisel hareket ediyor.
Detaylar makalede.
Ali H. Askar retweeted
在量化交易的微结构分析中,委托簿的形状反映了市场的供需弹性,深厚平坦的委托簿价格不易被推动,浅薄陡峭的委托簿则价格敏感。本文想谈谈如何计算订单簿的斜率与深度指标,从委托簿的分布结构中提取短线价格压力的讯号
什么是订单簿斜率
订单簿斜率衡量的是:当价格偏离最佳报价时,累积委托量增加的速度。斜率愈大,代表委托量集中在最佳报价附近,价格稍微偏离就会遇到大量流动性;斜率愈小,代表委托量分散在各个价位,价格偏离时需要吃掉的委托量相对较少
以买方为例,假设 Best Bid 的价格为 P_0,对应的累积委托量为 Q_0,通常就是该价位的委托量。在价格 P_0 - ΔP 处,累积委托量为 Q(ΔP),即从 P_0 到 P_0 - ΔP 之间所有买单的总和。则买方委托簿在深度 ΔP 处的斜率定义为:
Slope_bid(ΔP) = Q(ΔP) / ΔP
类似地,卖方委托簿在深度 ΔP 处的斜率为:
Slope_ask(ΔP) = Q(ΔP) / ΔP
其中 Q(ΔP) 是从 Best Ask 到 Best Ask + ΔP 之间所有卖单的总和
在实务中,价格是离散的,例如以 tick 为单位,因此斜率通常以每 tick 的累积委托量来衡量。例如,若从 Best Bid 往下数五个 tick,累积委托量为 500 张,则斜率为 100 张/tick。
什么是订单簿深度
订单簿深度衡量的是:在距离最佳报价某个特定价格范围内,总共有多少委托量。深度指标比斜率更直观,它直接告诉你在当前价格的上下 X% 范围内,有多少流动性可用
深度指标的定义为:
Depth(ΔP) = Q(ΔP)
其中 Q(ΔP) 是在价格范围 [P_best - ΔP, P_best] 内的累积买方委托量,或在 [P_best, P_best + ΔP] 内的累积卖方委托量。ΔP 的选择通常以百分比表示,例如 0.1%、0.5% 或 1%
深度指标与斜率指标之间的关系是:深度 = 斜率 × ΔP。两者从不同角度描述同一件事,斜率描述的是增加一单位价格偏离所带来的委托量增加,深度描述的是在特定价格偏离范围内的总委托量
订单簿失衡指标
除了斜率与深度之外,另一个重要的微结构指标是订单簿失衡。它衡量的是买方与卖方委托量的相对强弱
最简单的失衡指标是买卖深度比:
Imbalance = (Depth_bid - Depth_ask) / (Depth_bid + Depth_ask)
这个指标介于 -1 与 1 之间。正值代表买方深度大于卖方深度,市场有较强的买方支撑;负值代表卖方深度大于买方深度,市场有较强的卖方压力
更精细的失衡指标会考虑不同价位的权重。例如,靠近最佳报价的委托量给予较高的权重,远离最佳报价的委托量给予较低的权重。这是因为靠近最佳报价的委托更有可能在短期内被执行,对价格的影响更直接
如何从斜率与深度提取交易讯号
第一种是流动性压力讯号。当买方深度显著大于卖方深度时,Imbalance > 0,代表市场有较强的买方支撑,短期价格可能偏向上涨。反之,若卖方深度显著大于买方深度,短期价格可能偏向下跌。这种讯号的时间尺度通常很短,从数秒到数分钟
第二种是流动性枯竭讯号。当委托簿的深度急剧下降时,代表流动性提供者正在撤出市场。这种情况通常发生在重大资讯即将公布之前,或市场波动率突然上升之时。流动性枯竭本身不预测价格方向,但它预示着价格波动即将放大。交易者可以据此调整部位规模或扩大停损范围
第三种是斜率变化讯号。当委托簿的斜率突然变陡时,代表流动性正在向最佳报价集中。这可能意味着市场参与者对当前价格有较强的共识,价格短期内不易被推动。当斜率突然变平时,代表流动性正在从最佳报价向外扩散,市场的供需弹性增加,价格可能更容易被推动
第四种是委托簿形状不对称讯号。除了单纯的深度失衡之外,委托簿的形状本身也蕴含资讯。例如,若买方委托簿在最佳报价附近很厚、但往外迅速变薄,而卖方委托簿在最佳报价附近很薄、但往外迅速变厚,这种不对称的形状可能预示着价格即将向上突破,因为买方在近端有强力支撑,而卖方在近端的阻力较弱


































