5.1 Using capture as a Library

Goal: call the detection logic from your own Python code, get structured opportunities back, not printed text.

  1. 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 to capture_engine.py.

  2. 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 opportunities
  1. Use it from another module:

Moral: expose a pure function / method that returns a list of structured opportunities. Stop printing inside the core logic; only your UI layer prints

Last updated