apexrunner-tools 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .pytest_cache/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 APEX Runner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,127 @@
1
+ Metadata-Version: 2.5
2
+ Name: apexrunner-tools
3
+ Version: 0.1.0
4
+ Summary: LangChain and CrewAI tools for APEX Runner pre-trade crypto signals (risk, execution timing, slippage), paid per call over x402 in USDC on Base.
5
+ Project-URL: Homepage, https://apexrunner.ai
6
+ Project-URL: Documentation, https://apexrunner.ai/signals/docs/
7
+ Project-URL: Repository, https://github.com/kynto2001-ctrl/apexrunner-tools
8
+ Project-URL: Issues, https://github.com/kynto2001-ctrl/apexrunner-tools/issues
9
+ Author-email: APEX Runner <267811382+kynto2001-ctrl@users.noreply.github.com>
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: agents,base,crewai,crypto,langchain,trading,usdc,x402
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Office/Business :: Financial :: Investment
19
+ Requires-Python: >=3.11
20
+ Requires-Dist: pydantic<3,>=2.6
21
+ Requires-Dist: x402[evm,httpx,requests]<3,>=2.8
22
+ Provides-Extra: crewai
23
+ Requires-Dist: crewai<2,>=1.0; extra == 'crewai'
24
+ Provides-Extra: dev
25
+ Requires-Dist: crewai<2,>=1.0; extra == 'dev'
26
+ Requires-Dist: langchain-core<2,>=1.0; extra == 'dev'
27
+ Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
28
+ Requires-Dist: pytest>=8; extra == 'dev'
29
+ Provides-Extra: langchain
30
+ Requires-Dist: langchain-core<2,>=1.0; extra == 'langchain'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # apexrunner-tools
34
+
35
+ Pre-trade crypto signals for **LangChain** and **CrewAI** agents. Each call is paid per use over [x402](https://x402.org) from the agent's own wallet: about $0.01 in USDC on Base mainnet. There is no API key, no account and no subscription.
36
+
37
+ | Tool | Input | Returns |
38
+ |---|---|---|
39
+ | `risk_assessment_bundle` | none | 4 signals in one call: liquidation cascade risk, nearest liquidation clusters, market heat, top-trader positioning |
40
+ | `execution_window_optimizer` | `coin` | 0–100 window score and a verdict: EXECUTE_NOW / GOOD_WINDOW / WAIT_15MIN / WAIT_SESSION, plus an order type |
41
+ | `slippage_forecast` | `coin`, `size_usd`, `side` | Expected slippage % and USD, and a recommendation: EXECUTE_NOW / EXECUTE / SPLIT_ORDER / USE_LIMIT |
42
+
43
+ Coins: BTC, ETH, SOL, AVAX, LINK, XRP.
44
+
45
+ ## Install
46
+
47
+ ```bash
48
+ pip install "apexrunner-tools[langchain]" # or [crewai]
49
+ ```
50
+
51
+ ## LangChain
52
+
53
+ ```python
54
+ import os
55
+ from langchain.agents import create_agent
56
+ from apexrunner_tools.langchain import get_apex_tools
57
+
58
+ tools = get_apex_tools(private_key=os.environ["AGENT_WALLET_KEY"]) # $1.00 budget by default
59
+ agent = create_agent("openai:gpt-4.1-mini", tools=tools)
60
+ ```
61
+
62
+ Each tool returns `content_and_artifact`. The model sees compact JSON. The `ToolMessage.artifact` holds the full data and the payment receipt (amount and transaction hash).
63
+
64
+ ## CrewAI
65
+
66
+ ```python
67
+ import os
68
+ from crewai import Agent
69
+ from apexrunner_tools.crewai import get_apex_tools
70
+
71
+ trader = Agent(
72
+ role="Execution trader",
73
+ goal="Place orders at the lowest total cost",
74
+ backstory="Checks risk, timing and slippage before every order.",
75
+ tools=get_apex_tools(private_key=os.environ["AGENT_WALLET_KEY"]),
76
+ )
77
+ ```
78
+
79
+ ## Without a framework
80
+
81
+ ```python
82
+ from apexrunner_tools import ApexClient
83
+
84
+ with ApexClient(private_key=os.environ["AGENT_WALLET_KEY"]) as apex:
85
+ r = apex.call("slippage_forecast", coin="ETH", size_usd=5000, side="sell")
86
+ print(r.data["recommendation"], r.amount_usdc, r.transaction)
87
+ print(apex.budget.spent_usdc, apex.budget.remaining_usdc)
88
+ ```
89
+
90
+ `acall()` is the async version.
91
+
92
+ ## Wallet
93
+
94
+ Supply exactly one of these:
95
+
96
+ - `private_key="0x…"`. It is turned into an `eth_account` signer, which holds the key only so it can sign. The key never appears in any attribute, `repr()` or a tool's serialised form.
97
+ - `account=LocalAccount`, from `eth_account`.
98
+ - `signer=...`, any object with an `address` and `sign_typed_data(...)`. Use this for KMS, HSM or hosted wallets.
99
+
100
+ The wallet needs **USDC on Base mainnet**, and no ETH. Payments are signed USDC authorizations (EIP-3009), and the facilitator pays the gas. One dollar covers about 100 calls.
101
+
102
+ ## Safeguards
103
+
104
+ | Safeguard | What it does |
105
+ |---|---|
106
+ | **Pinned payment terms** | Before anything is signed, every payment option is checked: it must be x402 v2 `exact` USDC on Base, payable to APEX Runner's pinned address. Anything else is refused and **nothing is signed** (`PaymentRefused`). This holds even if the server, DNS or a proxy is compromised. |
107
+ | **Per-call cap** | `max_payment_usdc`, default **$0.02** and never above $1.00. A higher price is refused before signing. |
108
+ | **Spend budget** | `budget_usdc`, default **$1.00** per client. It is checked at the moment of signing, every signature counts (including the SDK's automatic re-sign on recovery), and it is safe across threads. When the budget is spent, calls raise `BudgetExceeded` and nothing is signed. A signed payment counts as spent even if the call then fails: the budget never assumes a payment was not settled. |
109
+ | **Expiring cache** | Repeating an identical call while its data is still valid (the response's `valid_for_seconds` minus its age, at most 300 s) returns the cached result at no cost. Stale data is never cached. CrewAI's own cache has no expiry, so it is switched off for these tools. |
110
+
111
+ ## Errors
112
+
113
+ All errors subclass `ApexError`:
114
+
115
+ | Error | Meaning | Charged? |
116
+ |---|---|---|
117
+ | `PaymentRefused` | The payment request didn't match the pinned terms | No, nothing was signed |
118
+ | `BudgetExceeded` | The budget is spent | No, nothing was signed |
119
+ | `PaymentRejected` | A payment was signed but refused, usually too little USDC | No settlement |
120
+ | `ApexUnavailable` | The server returned a non-2xx status | x402 settles only on success |
121
+ | `ApexResponseError` | The server returned a 2xx with an unreadable body | Possibly; report it |
122
+
123
+ LangChain turns these into a tool message the model can read. CrewAI tools return `{"success": false, "error": ...}`.
124
+
125
+ ## License
126
+
127
+ MIT
@@ -0,0 +1,95 @@
1
+ # apexrunner-tools
2
+
3
+ Pre-trade crypto signals for **LangChain** and **CrewAI** agents. Each call is paid per use over [x402](https://x402.org) from the agent's own wallet: about $0.01 in USDC on Base mainnet. There is no API key, no account and no subscription.
4
+
5
+ | Tool | Input | Returns |
6
+ |---|---|---|
7
+ | `risk_assessment_bundle` | none | 4 signals in one call: liquidation cascade risk, nearest liquidation clusters, market heat, top-trader positioning |
8
+ | `execution_window_optimizer` | `coin` | 0–100 window score and a verdict: EXECUTE_NOW / GOOD_WINDOW / WAIT_15MIN / WAIT_SESSION, plus an order type |
9
+ | `slippage_forecast` | `coin`, `size_usd`, `side` | Expected slippage % and USD, and a recommendation: EXECUTE_NOW / EXECUTE / SPLIT_ORDER / USE_LIMIT |
10
+
11
+ Coins: BTC, ETH, SOL, AVAX, LINK, XRP.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install "apexrunner-tools[langchain]" # or [crewai]
17
+ ```
18
+
19
+ ## LangChain
20
+
21
+ ```python
22
+ import os
23
+ from langchain.agents import create_agent
24
+ from apexrunner_tools.langchain import get_apex_tools
25
+
26
+ tools = get_apex_tools(private_key=os.environ["AGENT_WALLET_KEY"]) # $1.00 budget by default
27
+ agent = create_agent("openai:gpt-4.1-mini", tools=tools)
28
+ ```
29
+
30
+ Each tool returns `content_and_artifact`. The model sees compact JSON. The `ToolMessage.artifact` holds the full data and the payment receipt (amount and transaction hash).
31
+
32
+ ## CrewAI
33
+
34
+ ```python
35
+ import os
36
+ from crewai import Agent
37
+ from apexrunner_tools.crewai import get_apex_tools
38
+
39
+ trader = Agent(
40
+ role="Execution trader",
41
+ goal="Place orders at the lowest total cost",
42
+ backstory="Checks risk, timing and slippage before every order.",
43
+ tools=get_apex_tools(private_key=os.environ["AGENT_WALLET_KEY"]),
44
+ )
45
+ ```
46
+
47
+ ## Without a framework
48
+
49
+ ```python
50
+ from apexrunner_tools import ApexClient
51
+
52
+ with ApexClient(private_key=os.environ["AGENT_WALLET_KEY"]) as apex:
53
+ r = apex.call("slippage_forecast", coin="ETH", size_usd=5000, side="sell")
54
+ print(r.data["recommendation"], r.amount_usdc, r.transaction)
55
+ print(apex.budget.spent_usdc, apex.budget.remaining_usdc)
56
+ ```
57
+
58
+ `acall()` is the async version.
59
+
60
+ ## Wallet
61
+
62
+ Supply exactly one of these:
63
+
64
+ - `private_key="0x…"`. It is turned into an `eth_account` signer, which holds the key only so it can sign. The key never appears in any attribute, `repr()` or a tool's serialised form.
65
+ - `account=LocalAccount`, from `eth_account`.
66
+ - `signer=...`, any object with an `address` and `sign_typed_data(...)`. Use this for KMS, HSM or hosted wallets.
67
+
68
+ The wallet needs **USDC on Base mainnet**, and no ETH. Payments are signed USDC authorizations (EIP-3009), and the facilitator pays the gas. One dollar covers about 100 calls.
69
+
70
+ ## Safeguards
71
+
72
+ | Safeguard | What it does |
73
+ |---|---|
74
+ | **Pinned payment terms** | Before anything is signed, every payment option is checked: it must be x402 v2 `exact` USDC on Base, payable to APEX Runner's pinned address. Anything else is refused and **nothing is signed** (`PaymentRefused`). This holds even if the server, DNS or a proxy is compromised. |
75
+ | **Per-call cap** | `max_payment_usdc`, default **$0.02** and never above $1.00. A higher price is refused before signing. |
76
+ | **Spend budget** | `budget_usdc`, default **$1.00** per client. It is checked at the moment of signing, every signature counts (including the SDK's automatic re-sign on recovery), and it is safe across threads. When the budget is spent, calls raise `BudgetExceeded` and nothing is signed. A signed payment counts as spent even if the call then fails: the budget never assumes a payment was not settled. |
77
+ | **Expiring cache** | Repeating an identical call while its data is still valid (the response's `valid_for_seconds` minus its age, at most 300 s) returns the cached result at no cost. Stale data is never cached. CrewAI's own cache has no expiry, so it is switched off for these tools. |
78
+
79
+ ## Errors
80
+
81
+ All errors subclass `ApexError`:
82
+
83
+ | Error | Meaning | Charged? |
84
+ |---|---|---|
85
+ | `PaymentRefused` | The payment request didn't match the pinned terms | No, nothing was signed |
86
+ | `BudgetExceeded` | The budget is spent | No, nothing was signed |
87
+ | `PaymentRejected` | A payment was signed but refused, usually too little USDC | No settlement |
88
+ | `ApexUnavailable` | The server returned a non-2xx status | x402 settles only on success |
89
+ | `ApexResponseError` | The server returned a 2xx with an unreadable body | Possibly; report it |
90
+
91
+ LangChain turns these into a tool message the model can read. CrewAI tools return `{"success": false, "error": ...}`.
92
+
93
+ ## License
94
+
95
+ MIT
@@ -0,0 +1,29 @@
1
+ """CrewAI crew with an execution trader that uses APEX Runner tools.
2
+
3
+ pip install "apexrunner-tools[crewai]"
4
+ AGENT_WALLET_KEY=0x... OPENAI_API_KEY=... python examples/crewai_crew.py
5
+
6
+ Spends real USDC on Base (about $0.007 per tool call), capped by budget_usdc.
7
+ """
8
+
9
+ import os
10
+
11
+ from crewai import Agent, Crew, Task
12
+
13
+ from apexrunner_tools import ApexClient
14
+ from apexrunner_tools.crewai import get_apex_tools
15
+
16
+ apex = ApexClient(private_key=os.environ["AGENT_WALLET_KEY"], budget_usdc=0.10)
17
+ trader = Agent(
18
+ role="Execution trader",
19
+ goal="Execute crypto orders at the lowest total cost and risk",
20
+ backstory="You never place an order without checking risk, timing and slippage first.",
21
+ tools=get_apex_tools(apex),
22
+ )
23
+ task = Task(
24
+ description="Decide how and when to sell $5,000 of ETH. Use the tools, then give a concrete plan.",
25
+ expected_output="A short execution plan: now or later, order type, and whether to split the order.",
26
+ agent=trader,
27
+ )
28
+ print(Crew(agents=[trader], tasks=[task]).kickoff())
29
+ print(f"APEX spend: ${apex.budget.spent_usdc:.3f} of ${apex.budget.limit_usdc:.2f}")
@@ -0,0 +1,24 @@
1
+ """LangChain agent that checks risk, timing and slippage before proposing a trade.
2
+
3
+ pip install "apexrunner-tools[langchain]" langchain langchain-openai
4
+ AGENT_WALLET_KEY=0x... OPENAI_API_KEY=... python examples/langchain_agent.py
5
+
6
+ Spends real USDC on Base (about $0.007 per tool call), capped by budget_usdc.
7
+ """
8
+
9
+ import os
10
+
11
+ from langchain.agents import create_agent
12
+
13
+ from apexrunner_tools import ApexClient
14
+ from apexrunner_tools.langchain import get_apex_tools
15
+
16
+ apex = ApexClient(private_key=os.environ["AGENT_WALLET_KEY"], budget_usdc=0.10)
17
+ agent = create_agent(
18
+ "openai:gpt-4.1-mini",
19
+ tools=get_apex_tools(apex),
20
+ system_prompt="Before recommending any crypto order, check market risk, the execution window and slippage.",
21
+ )
22
+ result = agent.invoke({"messages": [{"role": "user", "content": "Should I sell $5,000 of ETH right now?"}]})
23
+ print(result["messages"][-1].content)
24
+ print(f"APEX spend: ${apex.budget.spent_usdc:.3f} of ${apex.budget.limit_usdc:.2f}")
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "apexrunner-tools"
7
+ version = "0.1.0"
8
+ description = "LangChain and CrewAI tools for APEX Runner pre-trade crypto signals (risk, execution timing, slippage), paid per call over x402 in USDC on Base."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ requires-python = ">=3.11"
13
+ authors = [{ name = "APEX Runner", email = "267811382+kynto2001-ctrl@users.noreply.github.com" }]
14
+ keywords = ["x402", "langchain", "crewai", "crypto", "trading", "agents", "usdc", "base"]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Topic :: Office/Business :: Financial :: Investment",
21
+ "Intended Audience :: Developers",
22
+ ]
23
+ dependencies = [
24
+ # 2.8 is the floor the API was verified against (same names through 2.28).
25
+ "x402[evm,requests,httpx]>=2.8,<3",
26
+ "pydantic>=2.6,<3",
27
+ ]
28
+
29
+ [project.optional-dependencies]
30
+ langchain = ["langchain-core>=1.0,<2"]
31
+ crewai = ["crewai>=1.0,<2"]
32
+ dev = ["pytest>=8", "pytest-asyncio>=0.24", "langchain-core>=1.0,<2", "crewai>=1.0,<2"]
33
+
34
+ [project.urls]
35
+ Homepage = "https://apexrunner.ai"
36
+ Documentation = "https://apexrunner.ai/signals/docs/"
37
+ Repository = "https://github.com/kynto2001-ctrl/apexrunner-tools"
38
+ Issues = "https://github.com/kynto2001-ctrl/apexrunner-tools/issues"
39
+
40
+ [tool.hatch.build.targets.wheel]
41
+ packages = ["src/apexrunner_tools"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
45
+ asyncio_mode = "auto"
46
+ asyncio_default_fixture_loop_scope = "function"
47
+
48
+ [tool.hatch.build.targets.sdist]
49
+ # scripts/ holds APEX-internal ops tooling (live paid test, seed wallet address, key path).
50
+ exclude = ["scripts/", ".github/", ".venv/", "dist/"]
@@ -0,0 +1,31 @@
1
+ """APEX Runner pre-trade crypto signals for LangChain and CrewAI agents, paid per call over x402.
2
+
3
+ Framework adapters live in ``apexrunner_tools.langchain`` and ``apexrunner_tools.crewai``
4
+ so that importing the core never requires either framework.
5
+ """
6
+
7
+ from .client import ApexClient, ApexResult
8
+ from .constants import __version__
9
+ from .errors import (
10
+ ApexError,
11
+ ApexResponseError,
12
+ ApexUnavailable,
13
+ BudgetExceeded,
14
+ PaymentRefused,
15
+ PaymentRejected,
16
+ )
17
+ from .signals import SIGNALS, SignalSpec
18
+
19
+ __all__ = [
20
+ "ApexClient",
21
+ "ApexResult",
22
+ "ApexError",
23
+ "ApexResponseError",
24
+ "ApexUnavailable",
25
+ "BudgetExceeded",
26
+ "PaymentRefused",
27
+ "PaymentRejected",
28
+ "SIGNALS",
29
+ "SignalSpec",
30
+ "__version__",
31
+ ]