fix: suppress take-profit when active buy signal has high confidence
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build-1 Pipeline was successful
ci/woodpecker/push/build-2 Pipeline was successful
ci/woodpecker/push/build-3 Pipeline was successful
ci/woodpecker/push/finalize Pipeline was successful
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
Build and Push / beta-gate (push) Has been cancelled
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build-1 Pipeline was successful
ci/woodpecker/push/build-2 Pipeline was successful
ci/woodpecker/push/build-3 Pipeline was successful
ci/woodpecker/push/finalize Pipeline was successful
Build and Push / lint-and-test (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Has been cancelled
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Has been cancelled
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Has been cancelled
Build and Push / build-dashboard (push) Has been cancelled
Build and Push / build-superset (push) Has been cancelled
Build and Push / integration-test (push) Has been cancelled
Build and Push / beta-gate (push) Has been cancelled
Profit-taking was selling positions that still had strong bullish signals (0.93 confidence buy recommendations), then the engine would immediately rebuy at a worse price. Now checks for recent high-confidence buy recommendations (>=0.80) before executing a take-profit sell. If the signal says keep holding, the take-profit is suppressed. Stop-losses still fire unconditionally.
This commit is contained in:
@@ -946,6 +946,27 @@ class TradingEngine:
|
|||||||
if pos_match is None:
|
if pos_match is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Suppress take-profit when a strong buy signal is active
|
||||||
|
if trigger.trigger_type == "take_profit" and self.pool is not None:
|
||||||
|
try:
|
||||||
|
active_buy = await self.pool.fetchrow(
|
||||||
|
"SELECT confidence FROM recommendations "
|
||||||
|
"WHERE ticker = $1 AND action = 'buy' "
|
||||||
|
"AND mode IN ('paper_eligible', 'live_eligible') "
|
||||||
|
"AND generated_at > NOW() - INTERVAL '2 hours' "
|
||||||
|
"ORDER BY confidence DESC LIMIT 1",
|
||||||
|
trigger.ticker,
|
||||||
|
)
|
||||||
|
if active_buy and float(active_buy["confidence"]) >= 0.80:
|
||||||
|
logger.info(
|
||||||
|
"Suppressing take-profit for %s — active buy signal (confidence=%.3f)",
|
||||||
|
trigger.ticker,
|
||||||
|
float(active_buy["confidence"]),
|
||||||
|
)
|
||||||
|
continue
|
||||||
|
except Exception:
|
||||||
|
pass # On error, proceed with the take-profit
|
||||||
|
|
||||||
await self._submit_sell_order(
|
await self._submit_sell_order(
|
||||||
trigger.ticker,
|
trigger.ticker,
|
||||||
pos_match.quantity,
|
pos_match.quantity,
|
||||||
|
|||||||
Reference in New Issue
Block a user