project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

AlphaEnsemble

What's the best part about trading on-chain? You can see eachother's trades. We build AI agentic traders which compete to see how open information affects trading strategies.

AlphaEnsemble

Created At

ETHOnline 2024

Project Description

AlphaEnsemble is an on-chain, AI-driven financial agent system designed to optimize portfolio management through agent-based competition in transparent, decentralized environments like blockchain. The project aims to study how the transparency inherent in on-chain trading affects decision-making. We provide a frontend UI that can display information about agents such as their profit over time, the prices of tradable assets, and the portfolio makeup of every agent.

The system deploys multiple agents, each equipped with customizable strategies and powered by on-chain LLMs (e.g., ChatGPT through Galadriel) to respond to real-time market conditions. Agents adjust their positions across various assets based on live price feeds and the behavior of competing agents, with the goal of maximizing their overall profits.

The current iteration uses high-frequency trading, with price updates multiple times per minute and position rebalancing 1-2 times per minute. However, many settings are fully customisable including the update frequency (prices and positions), the number of agents, the strategy each agent uses (i.e. add risk constraints, position limits), and the assets that can be traded.

Ultimately, we aim to explore how different configurations—such as the number of agents, their strategies, and the assets they trade—impact trading outcomes. This customizability allows for in-depth experimentation with various portfolio management techniques, making AlphaEnsemble a valuable tool for researchers and traders alike. The ultimate goal is to enhance decision-making frameworks for on-chain traders and to better understand the interactions between AI agents in decentralized markets.

How it's Made

The AlphaEnsemble system is designed around two core smart contracts: AlphaEnsemble.sol and Agent.sol. The AlphaEnsemble contract acts as the central manager, orchestrating agent deployment, updating price feeds, making LLM (Large Language Model) calls to generate trading strategies, and tracking key performance metrics such as Profit and Loss (PnL). It interacts with external oracles like Galadriel for LLM execution and has built-in compatibility with Chainlink price feeds. Though Chainlink isn’t available on the Galadriel network yet, the system includes support for Chainlink Keepers via the checkUpkeep and performUpkeep functions, preparing the system for future automated updates.

The Agent.sol contract defines the behavior of individual agents. Each agent operates independently, making real-time trading decisions based on live market data and interactions with other agents. Agents receive continuous price updates, calculate their PnL, and adjust positions accordingly. The system is designed for scalability, allowing multiple agents to be deployed, each with customizable trading strategies. By leveraging the Galadriel Oracle, agents interact with ChatGPT to generate dynamic trading strategies. Through the startAgentRun function, each agent queries the LLM, processes the response, and rebalances its portfolio based on the LLM’s recommendations.

For automation and real-time updates, AlphaEnsemble is designed to work seamlessly with Chainlink Keepers, even though they are not yet available on the Galadriel network. The built-in checkUpkeep and performUpkeep functions allow automated LLM rebalancing and price updates without user intervention once Chainlink support becomes available. Additionally, we included custom contracts like SepoliaOracle.sol and GaladrielReceiver.sol to bridge Sepolia Chainlink price feeds into Galadriel, simulating a Keeper system. Real-time market data is fetched from Binance using WebSocket feeds, and a custom script pushes this data to the contract. This ensures that agents make decisions based on up-to-the-minute information, critical for high-frequency trading.

One of the key technical challenges was parsing the LLM responses from ChatGPT. We developed a custom parser to extract asset positions from the LLM’s output. By designing precise and intelligent prompts, we ensured the responses adhered to a specific structure that could be directly processed by the smart contracts. This allowed the agents to rebalance their positions based on the LLM's recommendations in a reliable and automated fashion.

In addition to real-time data, PnL calculations are handled using an average cost basis for both long and short positions. This ensures that realized gains and losses are updated accurately whenever an agent closes or adjusts its position. By tracking separate cost bases for long and short trades, the system maintains accurate profit reporting, regardless of frequent position changes or market volatility.

Customization is a central feature of AlphaEnsemble. Users can control how often price updates occur and how frequently the LLM generates new strategies. This can be configured manually or automated via Chainlink Keepers once integrated. Additionally, users can choose from a variety of Binance-sourced assets, with the option to integrate other data sources. Each agent can be given a unique strategy, defining its risk profile, optimization goals, and trading frequency, providing maximum flexibility for experimentation.

The frontend of AlphaEnsemble is built using Next.js and integrates with the contracts via ethers.js. It serves as the real-time monitoring interface for agent activities, displaying PnL, market prices, and agent portfolios. The DynamicGraph component tracks historical PnL over time, while the PositionPieGraph provides a snapshot of each agent’s portfolio allocations. These visualizations are updated in real-time, leveraging blockchain events to keep the data current.

To ensure a responsive system, we implemented a polling mechanism that fetches blockchain events like AssetPricesUpdated, PositionsUpdated, and PnLUpdated at customizable intervals. These events are processed to update the frontend in real-time, reflecting the current state of the market and agent activities. We also optimized performance using memoization via React’s useMemo and useCallback hooks. This reduces unnecessary re-renders, ensuring the leaderboard and graphical components are only updated when new data is received, thereby minimizing the computational load on the frontend.

On the backend, we have several scripts to automate key processes. The deploy_agents.py script facilitates agent deployment, allowing users to easily set up agents with custom strategies. Meanwhile, the price_feed_binance.py script acts like a Chainlink Keeper, fetching real-time prices from Binance and updating the contract regularly. This ensures that the agents are always using the latest market data for their decision-making.

Overall, AlphaEnsemble’s high degree of customizability makes it a flexible platform for exploring different portfolio management strategies. Users can customize assets, strategies, and trading frequencies, allowing for scalable experimentation with different agent configurations and performance outcomes. The system's modularity and transparency make it a valuable tool for both researchers and traders interested in decentralized, AI-driven portfolio management in blockchain-based environments.

background image mobile

Join the mailing list

Get the latest news and updates