Go With The Flow: How aPriori’s Order Flow Segmentation Unlocks Better Trading (and How You Can Help)
Build your OF profile. JUICY GETS FILLED LIKE A PRIORITY.
Last month, we introduced Swapr, our DEX aggregator featuring an AI-powered order flow segmentation engine, and discussed its integral role within aPriori’s technology stack. Building on that, this article explains how aPriori’s AI model powers Swapr's order flow segmentation and how the broader community can contribute to its training and refinement.
What is Order Flow Segmentation?
Order flow segmentation is the process of categorizing trading activities based on their characteristics and intent. It distinguishes between different types of trades, particularly separating organic (non-toxic) trades from potentially harmful (toxic) activities such as arbitrage or front-running. At aPriori, effective segmentation allows us to optimize execution quality, protect liquidity providers, and enhance overall market fairness.
Why Now?
Blockchain ecosystems each have unique strengths and trade-offs. Solana, known for its high throughput and active trading culture, generates extensive transaction data and profitable order flow. However, many of its smart contracts are closed-source, limiting the depth of actionable insights that can be drawn from on-chain data. Conversely, Ethereum and other EVM-compatible chains offer exceptional transparency due to their open-source nature but face performance constraints and typically less aggressive trading activity.
At aPriori, we've been leveraging historical data from existing EVM blockchains to train our models. While results have been promising, we're especially excited about Monad. Monad combines the best of both worlds: the high performance and vibrant trading ecosystem akin to Solana, coupled with the transparency and developer-friendly environment characteristic of Ethereum and other EVM-compatible chains. This unique blend creates an ideal foundation for our advanced order flow segmentation techniques.
How We're Collecting and Utilizing Data
To provide robust data for training our advanced AI models, we're launching a unique data collection campaign that maps user wallets, forming valuable wallet clusters. These clusters become critical inputs into our Order Flow Knowledge Graph, sharpening our engine's detection capabilities.
Here's how it works:
Wallet Collection: Users sign in with their primary EVM wallet and link additional wallets they own.
Supported Chains: Ethereum Mainnet, BNB, and Monad Testnet.
Socials: Users can optionally give more insight in their data contribution by linking more wallets or social media accounts (Twitter, Discord), verifying their aPriori role and Monad roles, following our account (@apr_labs), or sharing their progress online. We'll also have daily check-ins for data refresh and inclusion.
Personal Dashboard: Each user gets a personalized dashboard displaying their data contribution, including total wallets linked, lifetime transactions, daily check-ins and social progress. Users can also share these summaries publicly.
Why Wallet Clustering Matters
Integrating wallet tagging, social affiliations, and multi-wallet aggregations allows us to build sophisticated collaborative filtering features. These features help our model better understand group behaviors by:
Calculating transaction similarities between addresses.
Detecting synchronized trading actions, such as simultaneous position openings or closings.
Generating metrics like collaborative address density scores and group profit-and-loss correlations.
These insights significantly enhance our AI’s capacity to recognize complex arbitrage patterns and toxic trading activities.
How Our AI Detects Toxic Trades
The core goal of our AI model is to determine the likelihood that a specific trade is toxic—defined simply as profitable across different time horizons. To achieve this, our model is trained on detailed transaction data:
Transaction Information: Timestamp, address, route, direction (buy/sell), asset amounts, gas costs, and fees.
Trader History: Number of trades by the initiating address and wallet balance.
Market Movements: Markout prices at intervals of 1 to 5 seconds, 5 minutes, 1 hour, and 24 hours post-trade.
Profit and Loss Metrics: Original and net profits calculated across multiple intervals.
These feature vectors flow into our production model ensemble, which assigns every incoming swap a 0-to-1 toxicity score—the higher the score, the more likely the trade is informed or adversarial.
Sample Scenario
Consider a trader buying ETH using USDC. Our AI evaluates:
The transaction’s initial cost, gas fees, and total expenses.
The trader's historical trading activity and current wallet balance.
The asset's price movement within defined timeframes after the trade.
The resulting profitability to determine potential toxicity.
Ensembling Traditional and Advanced AI Approaches
Our segmentation engine is the result of a comprehensive survey of modeling techniques, ranging from traditional tree-based classifiers to modern sequence-aware neural networks. Early iterations relied on models like XGBoost and LightGBM, which offered speed, interpretability, and solid performance on static transaction features.
To incorporate higher dimensional time-series data, we expanded the architecture portfolio to include RNNs and Transformer-based models. These sequence-aware approaches are well suited for capturing time-dependent signals—such as evolving trade patterns, price trajectories, and behavioral correlations across wallet clusters.
Rather than relying on a single architecture, we ensemble multiple models—each trained on different feature regimes and temporal horizons—to combine the strengths of fast path inference with deep behavioral understanding. This hybrid approach allows us to dynamically segment flow with greater robustness and precision.
By continuously refining these models through our innovative data collection and training processes, aPriori ensures Swapr delivers superior trading performance and fairness to DeFi participants.
Ready to Contribute?
Creating your Order Flow profile doesn’t just improve your execution—it strengthens the entire aPriori ecosystem. Help us train smarter models, build better markets, and make onchain trading fairer for everyone.
You are a Priority. Time to get treated like one.
Nice
nice