5.1 Using capture as a Library
Goal: call the detection logic from your own Python code, get structured opportunities back, not printed text.
Put the repo in your project:
Option A: add it as a git submodule / subtree.
Option B: copy the relevant engine file(s) (e.g.
spreadnet.py) into your own repo and rename tocapture_engine.py.
Refactor the core into a class or function (if not already):
You want something like:
# capture_engine.py
class CaptureEngine:
def __init__(self, min_profit_threshold=0.1, sleep_seconds=2):
self.min_profit_threshold = min_profit_threshold
self.sleep_seconds = sleep_seconds
# init dex configs, http session, etc.
async def tick(self) -> list[dict]:
"""
One full detection cycle:
- fetch quotes
- normalize
- calculate spreads/profit
- filter
Returns: list of opportunity dicts.
"""
# your existing logic split into steps
opportunities = [] # fill from pipeline
return opportunitiesUse it from another module:
import asyncio
from capture_engine import CaptureEngine
async def run_engine():
engine = CaptureEngine(min_profit_threshold=0.2, sleep_seconds=2)
while True:
opps = await engine.tick()
for opp in opps:
handle_opportunity(opp) # your own logic
await asyncio.sleep(engine.sleep_seconds)
def handle_opportunity(opp: dict):
# Example structure you want:
# {
# "pair": "SOL/USDC",
# "buy_venue": "jupiter",
# "buy_price": 99.8,
# "sell_venue": "raydium",
# "sell_price": 100.2,
# "spread_pct": 0.4,
# "profit_pct": 0.3,
# "profit_bps": 30,
# "timestamp": 1710000000
# }
print(opp)
if __name__ == "__main__":
asyncio.run(run_engine())Moral: expose a pure function / method that returns a list of structured opportunities. Stop printing inside the core logic; only your UI layer prints
Previous5. Developer Integration (How to Use Capture Engine as a Component)Next5.2 Building Your Own API Layer
Last updated

