Skip to content

fix(ton-trading-bot): surface per-DEX errors in get_arbitrage_opportunities#108

Merged
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-102-99338d5796a5
Apr 5, 2026
Merged

fix(ton-trading-bot): surface per-DEX errors in get_arbitrage_opportunities#108
xlabtg merged 3 commits intoxlabtg:mainfrom
konard:issue-102-99338d5796a5

Conversation

@konard
Copy link
Copy Markdown

@konard konard commented Apr 5, 2026

Problem

ton_trading_get_arbitrage_opportunities consistently fails with the generic error "Could not fetch DEX quotes" (fixes #102).

The root cause was two-fold:

  1. The function called sdk.ton.dex.quote() (aggregated) but that method's failure was silently caught and turned into a null — the actual error was only logged as a warning, invisible to the caller.
  2. dexFees listed tonco and swapcoffee as expected DEX keys, but the SDK only exposes quoteSTONfi and quoteDeDust — so those entries could never be populated.

Fix

  • Switch from the aggregated sdk.ton.dex.quote() to individual sdk.ton.dex.quoteSTONfi() / sdk.ton.dex.quoteDeDust() calls run in parallel.
  • Each failure is logged with its specific error and the affected asset pair (e.g. StonFi quote failed for TON→USDT: Router contract not found).
  • When all DEXes fail, the error response now includes per-DEX detail: Could not fetch DEX quotes — stonfi: …; dedust: ….
  • When only one DEX fails, the function continues with the partial result (one quote is still enough to surface partial data — arbitrage just isn't possible with fewer than 2 quotes, which is already handled downstream).
  • Remove tonco / swapcoffee from dexFees — the SDK does not expose quote methods for those DEXes.

How to reproduce

// Before fix — always fails silently:
sdk.ton.dex.quote = async () => { throw new Error("Router contract not found") }
// result: { success: false, error: "Could not fetch DEX quotes" }  ← no detail

// After fix — actual error is surfaced:
// result: { success: false, error: "Could not fetch DEX quotes — stonfi: Router contract not found; dedust: …" }

Tests added

Test What it verifies
error message includes the actual DEX error, not just a generic message The response includes per-DEX failure details, not just the old generic string
succeeds with partial quotes when only one DEX fails Function returns success: true with an empty opportunities list rather than failing completely when one DEX is unavailable

All 106 tests pass locally (node --test plugins/ton-trading-bot/tests/index.test.js).

🤖 Generated with Claude Code

konard and others added 2 commits April 5, 2026 19:20
Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: xlabtg#102
…nities

Previously, sdk.ton.dex.quote() failures were silently swallowed and
returned a generic "Could not fetch DEX quotes" message with no indication
of which DEX failed or why.

Switch to individual quoteSTONfi / quoteDeDust calls run in parallel so:
- Each DEX failure is logged with its specific error message and the
  affected asset pair (e.g. "StonFi quote failed for TON→USDT: …")
- When all DEXes fail, the error response includes per-DEX details
  ("Could not fetch DEX quotes — stonfi: …; dedust: …")
- When only one DEX fails, the function continues and returns partial
  results instead of aborting entirely
- Remove unsupported tonco/swapcoffee keys from dexFees (the SDK
  only exposes quoteSTONfi and quoteDeDust)

Tests added:
- error message includes actual DEX error, not the generic message
- succeeds with partial quotes when only one DEX fails

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] Bug: ton_trading_get_arbitrage_opportunities fails with "Could not fetch DEX quotes" fix(ton-trading-bot): surface per-DEX errors in get_arbitrage_opportunities Apr 5, 2026
@konard konard marked this pull request as ready for review April 5, 2026 19:26
@konard
Copy link
Copy Markdown
Author

konard commented Apr 5, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $1.007688
  • Calculated by Anthropic: $1.007688 USD
  • Difference: $0.000000 (0.00%)

📊 Context and tokens usage:

Claude Sonnet 4.6:

  • Max context window: 58.0K / 1M input tokens (6%)
  • Max output tokens: 11.2K / 64K output tokens (17%)

Total input tokens: 52.2K + 1.6M cached
Total output tokens: 11.2K output
Cost: $0.835487

Claude Haiku 4.5:

  • Context window: 821.5K / 200K tokens (411%)
  • Max output tokens: 8.0K / 64K output tokens (12%)

Total input tokens: 43.6K + 777.9K cached
Total output tokens: 8.0K output
Cost: $0.172201

🤖 Models used:

  • Tool: Anthropic Claude Code
  • Requested: sonnet
  • Main model: Claude Sonnet 4.6 (claude-sonnet-4-6)
  • Additional models:
    • Claude Haiku 4.5 (claude-haiku-4-5-20251001)

📎 Log file uploaded as Gist (1327KB)


Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard
Copy link
Copy Markdown
Author

konard commented Apr 5, 2026

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

@xlabtg xlabtg merged commit f82b534 into xlabtg:main Apr 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: ton_trading_get_arbitrage_opportunities fails with "Could not fetch DEX quotes"

2 participants