feat(ton-trading-bot): add ton_trading_check_stop_loss to query stop_loss_rules table#66
Merged
xlabtg merged 3 commits intoxlabtg:mainfrom Mar 27, 2026
Merged
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: xlabtg#58
…stop_loss_rules table The stop_loss_rules table was written to but never read, making the stop-loss feature non-functional. Add ton_trading_check_stop_loss (tool 19) that queries active rules and flags any triggered by the current market price, closing the loop between set_stop_loss and trade closure. - Query active stop-loss/take-profit rules from the database - Annotate each rule with stop_loss_hit / take_profit_hit flags - Separate triggered rules from safe ones for clear LLM guidance - Support optional trade_id filter to check a single position - Update manifest.json and file header to register the new tool - Update tool count assertion and add 6 targeted unit tests Fixes xlabtg#58 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This reverts commit fedc045.
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
🤖 Models used:
📎 Log file uploaded as Gist (1656KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
Author
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause
The
stop_loss_rulestable was written to byton_trading_set_stop_loss(tool 18) but never queried anywhere, so the stop-loss feature was entirely non-functional — rules were stored and silently ignored.Solution
Add a new atomic tool
ton_trading_check_stop_loss(tool 19) that reads thestop_loss_rulestable and checks whether the current market price has triggered any active rule:stop_loss_rules WHERE status = 'active'(optionally filtered bytrade_id)stop_loss_price = entry_price × (1 − stop_loss_percent / 100)andtake_profit_pricefor each rulestop_loss_hit/take_profit_hitboolean flagstriggered_rulesfromsafe_rulesso the LLM has unambiguous guidancenotedirecting the LLM to close affected trades viaton_trading_record_tradeThis follows the same read-and-annotate pattern used by
ton_trading_get_scheduled_trades(tool 23).Changes
plugins/ton-trading-bot/index.jston_trading_check_stop_losstool; renumber tools 19→21, 20→22, 21→23plugins/ton-trading-bot/manifest.jsonplugins/ton-trading-bot/tests/index.test.jsTests
All 182 tests pass (
npm test). Plugin validates with22 tool(s) validated(npm run validate).New tests cover:
current_price)data-bearingstop_lossaction flaggedtake_profitaction flaggedtrade_idfilter routes query correctlyFixes #58