Skip to content

Conditional/stop orders invisible to getOrders — broker state blind spot #90

@atxinsky

Description

@atxinsky

Summary

When using Binance Futures, conditional orders (stop-loss, take-profit) placed via the platform are not returned by getOrders (which maps to ccxt's fetchOpenOrders). This creates a critical blind spot where the system believes no stop-loss is in place when one actually exists.

Impact (observed in Demo)

  1. False "naked position" alerts — Alice repeatedly warned about zero stop-loss protection (15+ times) when stops were actually active on Binance, causing unnecessary panic
  2. Duplicate order placement — Since verification logic can't see existing conditional orders, it re-submits stops, resulting in 3x duplicate stop-losses and 3x duplicate limit orders that had to be manually cleaned up
  3. Phantom order tracking — Brain state records orders it thinks it placed, but can't verify against broker reality, leading to hallucinated order IDs (e.g. cab7db76)

Root Cause

Binance separates:

  • Regular ordersGET /fapi/v1/openOrders (what ccxt's fetchOpenOrders hits)
  • Conditional orders (stop-market, take-profit-market) → GET /fapi/v1/openOrders with type=STOP_MARKET or via GET /fapi/v1/conditionalOrders

The current CcxtBroker implementation only calls the standard path and misses conditional/stop orders entirely.

Suggested Fix

In CcxtBroker.ts, the order query methods should:

  1. Fetch both regular and conditional orders (ccxt's fetchOpenOrders with params: { type: 'STOP_MARKET' } or equivalent)
  2. Merge results before returning to the caller
  3. Consider a unified getAllActiveOrders() method that covers all order types

Environment

  • OpenAlice v0.9.0-beta.7 → beta.8
  • Broker: Binance Futures (USDT-M) via ccxt
  • Demo trading on ETHUSDT

Related

This blind spot also contributes to the duplicate order problem — without visibility into existing conditional orders, there's no way to implement idempotency checks before placing new ones.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions