Skip to content
broker-order-limitations logo

Broker Order Limitations (Alpaca)

broker-order-limitations

Alpaca broker limitations: crypto shorts blocked (broker doesn't support), stock shorts allowed. Trigger when: (1) shorting gate blocks wrong assets, (2) SELL signals blocked, (3) order type confusion.

SKILL.md

Full skill instructions

Broker Order Limitations (Alpaca)

Experiment Overview

ItemDetails
Date2024-12-26
GoalDocument broker-specific order limitations
Environmentscripts/​live_trader.py, Alpaca Trading API
StatusReference

Context

Alpaca broker has specific limitations on order types. The most important one for this trading system:

Crypto shorting is NOT supported by Alpaca. Stock shorting IS allowed.

This distinction is critical because:

  1. Model generates SELL signals for both crypto and equities
  2. SELL signal on crypto = blocked by broker limitation
  3. SELL signal on equities = allowed (short selling)

Verified Implementation

Crypto Short Gate (Correct)

# In live_trader.py (~line 1335)
# Only block shorts for crypto, not equities
if desired_side == -1 and asset_type == AssetType.CRYPTO and state.side <= 0:
    # Trying to go short on crypto when not already long
    gate_statuses[symbol] = GateStatus(
        final_status='BLOCKED',
        blocking_gate='crypto_short',
        crypto_short_gate=False,  # Failed
    )
    continue

Key Logic Points

# desired_side == -1: Model wants to SELL
# asset_type == AssetType.CRYPTO: Asset is cryptocurrency
# state.side <= 0: Not currently holding a long position

# All three conditions must be true to block:
# 1. SELL signal (-1)
# 2. Is crypto (not equity)
# 3. Would be opening a short (not closing a long)

What IS Allowed

Asset TypeBuy (Long)Sell to CloseSell to Short
EquityYesYesYes
CryptoYesYesNO

Gate Status in Dashboard

When crypto short is blocked:

gate_status = {
    'final_status': 'BLOCKED',
    'blocking_gate': 'crypto_short',
    'crypto_short_gate': False,
    # ... other gates may be True
}

Failed Attempts (Critical)

AttemptWhy it FailedLesson Learned
Block all SELL signals for cryptoPrevented closing profitable longsOnly block new shorts
Block all shorts (crypto + equity)Equity shorts are valid strategyCheck asset type
No short gate at allOrders rejected by brokerPre-filter before submission
Check desired_side < 0Could catch rounding errorsUse == -1 exactly

Alpaca Order Types Reference

Supported Order Types

Order TypeEquitiesCrypto
Market BuyYesYes
Market SellYesYes (close only)
Limit BuyYesYes
Limit SellYesYes (close only)
Stop LossYesYes
Take ProfitYesYes
Short SellYesNO
FractionalYes (0.001)Yes (varies)

Crypto-Specific Limitations

  1. No shorting: Cannot borrow and sell crypto
  2. 24/​7 trading: No market hours restrictions
  3. Symbol format: Ends with USD (e.g., BTCUSD, ETHUSD)
  4. Fractional minimum: Varies by crypto (check API)

Equity-Specific Features

  1. Short selling: Allowed with margin account
  2. Market hours: 9:30 AM - 4:00 PM ET (regular)
  3. Extended hours: 4:00 AM - 8:00 PM ET (with flag)
  4. Pattern day trader: Rules apply if >3 day trades in 5 days

Key Insights

Detecting Asset Type

# Simple heuristic used in live_trader.py
def is_crypto(symbol: str) -> bool:
    return symbol.endswith('USD')

# Or use Alpaca's asset class
from alpaca.trading.enums import AssetClass
asset = api.get_asset(symbol)
is_crypto = asset.asset_class == AssetClass.CRYPTO

Why Not Block at Model Level?

The model is trained on both crypto and equity data. It learns:

  • When to go long (BUY = +1)
  • When to go short (SELL = -1)
  • When to stay out (HOLD = 0)

Blocking shorts in the model would:

  • Reduce training efficiency
  • Create inconsistent behavior
  • Miss valid equity short signals

Better approach: Let model predict freely, filter at execution gate.

Capital Shift Interaction

When equity markets close, capital shifts to crypto. During this time:

  • More crypto signals generated
  • All crypto SELL signals blocked
  • Only crypto BUY signals executed
  • Effective strategy: crypto long-only overnight

Files Modified

scripts/​live_trader.py:
  - Line 1335: Crypto short gate check
  - Uses AssetType enum for asset classification
  - Gate status stored in gate_statuses dict

References

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View