Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Autonomous-Finance/limit-order-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Limit Order Agent

AO License Status Teal

Autonomous trading agents for decentralized finance on AO

Execute limit orders, stop-losses, and DCA strategies without centralized intermediaries

Features β€’ Architecture β€’ Strategies β€’ Getting Started β€’ License


⚠️ ARCHIVED PROJECT

This project is archived and no longer maintained. It is provided as-is for educational and reference purposes. No support, updates, or bug fixes will be provided.

Originally developed by Autonomous Finance


🌟 Features

πŸ“ˆ Limit Orders

Execute trades at your target price or better. Supports partial fills across multiple swaps with eager execution.

πŸ›‘ Stop Orders

Protect your positions with stop-loss triggers. Choose between market or limit execution when thresholds are hit.

πŸ“Š Trailing Stops

Dynamic stop prices that follow favorable price movements, automatically locking in profits while limiting downside.

πŸ”„ DCA Strategies

Dollar-cost averaging with configurable intervals. Automatically distribute capital across time-based executions.

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        FACTORY PROCESS                          β”‚
β”‚  β€’ Spawns & tracks agents    β€’ Manages subscriptions            β”‚
β”‚  β€’ Stores configurations     β€’ Handles lifecycle events         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β–Ό             β–Ό             β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  AGENT 1  β”‚  β”‚  AGENT 2  β”‚  β”‚  AGENT N  β”‚
            β”‚  Limit    β”‚  β”‚  Stop     β”‚  β”‚  DCA      β”‚
            β”‚  Order    β”‚  β”‚  Order    β”‚  β”‚  Order    β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚             β”‚             β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚    AMM PRICE FEEDS      β”‚
                    β”‚   (Dexi Subscriptions)  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

How It Works

  1. Factory creates agent processes with specific trading configurations
  2. Agents subscribe to real-time AMM price updates
  3. When conditions are met, agents autonomously execute trades
  4. Upon completion, agents finalize and return funds to the owner

πŸ“‹ Strategy Components

Limit Order

A limit order fills your trade at a specific price or better:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Input: 100 TOKEN_A                          β”‚
β”‚  Min Output: 500 TOKEN_B                     β”‚
β”‚  ─────────────────────────────               β”‚
β”‚  βœ“ Partial fills supported                   β”‚
β”‚  βœ“ Eager execution on favorable prices       β”‚
β”‚  βœ“ Optional stop-loss attachment             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Stop Order

Triggers when price crosses your threshold:

Type Behavior
Stop-Market Immediate swap at current price
Stop-Limit Places limit order when triggered
Trailing Stop Dynamic threshold follows price

DCA Order

Automated periodic trading:

Day 1    Day 2    Day 3    Day 4    Day 5
  β”‚        β”‚        β”‚        β”‚        β”‚
  β–Ό        β–Ό        β–Ό        β–Ό        β–Ό
β”Œβ”€β”€β”€β”    β”Œβ”€β”€β”€β”    β”Œβ”€β”€β”€β”    β”Œβ”€β”€β”€β”    β”Œβ”€β”€β”€β”
β”‚$20β”‚    β”‚$20β”‚    β”‚$20β”‚    β”‚$20β”‚    β”‚$20β”‚  = $100 total
β””β”€β”€β”€β”˜    β””β”€β”€β”€β”˜    β””β”€β”€β”€β”˜    β””β”€β”€β”€β”˜    β””β”€β”€β”€β”˜

πŸ”„ Agent Lifecycle

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  CREATION   │────▢│   DEPOSIT   │────▢│ SUBSCRIPTIONβ”‚
β”‚             β”‚     β”‚             β”‚     β”‚             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                               β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    READY    │────▢│  SWAPPING   │────▢│  FINALIZED  β”‚
β”‚  Monitoring β”‚     β”‚  Executing  β”‚     β”‚  Complete βœ“ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

States

State Description
AwaitingStrategyConfiguration Initial state after creation
AwaitingDeposit Waiting for user to fund the agent
AwaitingSubscription Waiting for price feed subscription
Ready 🟒 Active and monitoring for trade conditions
Swapping πŸ”„ Currently executing a swap
Complete βœ… Strategy successfully completed
Expired ⏰ Order expired before completion
Canceled ❌ User cancelled the order
EmergencyExited 🚨 Emergency withdrawal executed

πŸš€ Getting Started

Prerequisites

  • Lua 5.4.6
  • LuaRocks (package manager)
  • Teal 0.15.3 (typed Lua)
  • Cyan 0.3.1 (Teal build tool)
  • amalg (Lua bundler)
  • Node.js 18+ (for tooling)

Installation

# Clone the repository
git clone https://github.com/Autonomous-Finance/limit-order-agent.git
cd limit-order-agent

# Install Node dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

Build Output

The build process produces:

  • build/agent.lua - Bundled agent process code
  • build/factory.lua - Bundled factory process code (includes agent source)

πŸ“ Project Structure

limit-order-agent/
β”œβ”€β”€ πŸ“‚ src/
β”‚   β”œβ”€β”€ πŸ“‚ agent/              # Agent process implementation
β”‚   β”‚   β”œβ”€β”€ agent.tl           # Main agent module
β”‚   β”‚   β”œβ”€β”€ swaps.tl           # Swap execution logic
β”‚   β”‚   └── πŸ“‚ strategies/     # Strategy implementations
β”‚   β”‚       β”œβ”€β”€ limit-order.tl
β”‚   β”‚       β”œβ”€β”€ stop-order.tl
β”‚   β”‚       β”œβ”€β”€ dca-order.tl
β”‚   β”‚       └── πŸ“‚ primitives/ # Composable building blocks
β”‚   β”œβ”€β”€ πŸ“‚ factory/            # Factory process implementation
β”‚   β”‚   β”œβ”€β”€ factory.tl         # Main factory module
β”‚   β”‚   β”œβ”€β”€ queries.tl         # Database queries
β”‚   β”‚   └── sqlschema.tl       # SQLite schema
β”‚   β”œβ”€β”€ πŸ“‚ utils/              # Shared utilities
β”‚   └── πŸ“‚ typedefs/           # Type definitions
β”œβ”€β”€ πŸ“‚ test/                   # Unit tests
β”‚   β”œβ”€β”€ πŸ“‚ mocked-env/         # Mock AO environment
β”‚   └── unit_test_*.lua        # Test suites
β”œβ”€β”€ πŸ“‚ scripts/                # Build & test scripts
└── πŸ“‚ packages/               # External packages

βš™οΈ Configuration

Agents are configured through process tags when spawned:

Tag Description Required
Amm AMM process ID for trading βœ…
Token-From Input token process ID βœ…
Token-To Output token process ID βœ…
Input Amount of input token βœ…
Expires-At Expiration timestamp βœ…
Order-Owner Owner wallet address βœ…

Strategy-Specific Tags

Limit Order
Tag Description
Min-Output Minimum acceptable output amount
Stop-Price (Optional) Stop-loss trigger price
Stop Order
Tag Description
Stop-Price Price threshold to trigger execution
Is-Stop-Limit true for limit execution, false for market
Is-Trailing true for trailing stop functionality
Trailing-Difference Basis points for trailing distance
DCA Order
Tag Description
Run-Time Total duration for DCA execution
Tick-Interval (Optional) Custom interval between swaps

πŸ› οΈ Tech Stack

Technology Purpose
Teal Typed Lua for safer code
AO Decentralized compute on Arweave
Cyan Teal project build tool
Busted Lua testing framework
SQLite Embedded database for factory

⚠️ Disclaimer

This software is provided "as is" without warranty of any kind. Use at your own risk. The authors are not responsible for any financial losses incurred through the use of this software.

This is experimental DeFi software. Always:

  • Test with small amounts first
  • Understand the risks of AMM trading
  • Review the code before deploying with real assets

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE.md file for details.


Originally developed with ❀️ by Autonomous Finance

Building the future of autonomous finance on Arweave

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors