S
StockBud Docs

StockBud.io Trading Schema

Schema for trading operations and order management in StockBud.io

📈 StockBud.io Trading Schema

Version: 1.0.0

Schema for trading operations and order management in StockBud.io

Overview

This schema defines 4 data structures:


Definitions

Order

Trading order structure

Properties

PropertyTypeRequiredDescription
order_idstringUnique order identifier
client_order_idstringClient-generated order identifier
symbolstringStock symbol
quantitynumberOrder quantity
sideenum: 'buy', 'sell'Order side
order_typeenum: 'market', 'limit', 'stop', 'stop_limit', 'trailing_stop'Order type
statusenum: 'new', 'partially_filled', 'filled', 'done_for_day', 'canceled', 'expired', 'replaced', 'pending_cancel', 'pending_replace', 'pending_review', 'accepted', 'pending_new', 'accepted_for_bidding', 'stopped', 'rejected', 'suspended', 'calculated'Order status
time_in_forceenum: 'day', 'gtc', 'opg', 'cls', 'ioc', 'fok'Time in force
limit_pricenumberLimit price (for limit orders)
stop_pricenumberStop price (for stop orders)
trail_percentnumberTrail percentage (for trailing stop orders)
trail_pricenumberTrail price (for trailing stop orders)
filled_quantitynumberQuantity filled
average_fill_pricenumberAverage fill price
extended_hoursbooleanExtended hours trading enabled
order_classenum: 'simple', 'bracket', 'oco', 'oto'Advanced order class
legsArray<Record<string, unknown>>Order legs for multi-leg orders (bracket, OCO, OTO)
submitted_atstringOrder submission timestamp
updated_atstringLast order update timestamp
filled_atstringOrder fill timestamp
canceled_atstringOrder cancellation timestamp
expired_atstringOrder expiration timestamp
commissionnumberCommission charged for the order
hwmnumberHigh water mark (for trailing stops)

TypeScript

interface Order {
  /** Unique order identifier */
  order_id: string;
  /** Client-generated order identifier */
  client_order_id?: string;
  /** Stock symbol */
  symbol: string;
  /** Order quantity */
  quantity: number;
  /** Order side */
  side: "buy" | "sell";
  /** Order type */
  order_type: "market" | "limit" | "stop" | "stop_limit" | "trailing_stop";
  /** Order status */
  status: "new" | "partially_filled" | "filled" | "done_for_day" | "canceled" | "expired" | "replaced" | "pending_cancel" | "pending_replace" | "pending_review" | "accepted" | "pending_new" | "accepted_for_bidding" | "stopped" | "rejected" | "suspended" | "calculated";
  /** Time in force */
  time_in_force?: "day" | "gtc" | "opg" | "cls" | "ioc" | "fok";
  /** Limit price (for limit orders) */
  limit_price?: number;
  /** Stop price (for stop orders) */
  stop_price?: number;
  /** Trail percentage (for trailing stop orders) */
  trail_percent?: number;
  /** Trail price (for trailing stop orders) */
  trail_price?: number;
  /** Quantity filled */
  filled_quantity?: number;
  /** Average fill price */
  average_fill_price?: number;
  /** Extended hours trading enabled */
  extended_hours?: boolean;
  /** Advanced order class */
  order_class?: "simple" | "bracket" | "oco" | "oto";
  /** Order legs for multi-leg orders (bracket, OCO, OTO) */
  legs?: Record<string, unknown>[];
  /** Order submission timestamp */
  submitted_at?: string;
  /** Last order update timestamp */
  updated_at?: string;
  /** Order fill timestamp */
  filled_at?: string;
  /** Order cancellation timestamp */
  canceled_at?: string;
  /** Order expiration timestamp */
  expired_at?: string;
  /** Commission charged for the order */
  commission?: number;
  /** High water mark (for trailing stops) */
  hwm?: number;
}

Trade

Executed trade record

Properties

PropertyTypeRequiredDescription
trade_idstringUnique trade identifier
order_idstringAssociated order identifier
symbolstringStock symbol
quantitynumberTrade quantity
pricenumberTrade price
sideenum: 'buy', 'sell'Trade side
timestampstringTrade execution timestamp
commissionnumberCommission paid
feesnumberAdditional fees
net_amountnumberNet amount (price * quantity - commission - fees)

TypeScript

interface Trade {
  /** Unique trade identifier */
  trade_id: string;
  /** Associated order identifier */
  order_id: string;
  /** Stock symbol */
  symbol: string;
  /** Trade quantity */
  quantity: number;
  /** Trade price */
  price: number;
  /** Trade side */
  side: "buy" | "sell";
  /** Trade execution timestamp */
  timestamp: string;
  /** Commission paid */
  commission?: number;
  /** Additional fees */
  fees?: number;
  /** Net amount (price * quantity - commission - fees) */
  net_amount?: number;
}

TradingSignal

AI-generated trading signal

Properties

PropertyTypeRequiredDescription
signal_idstringUnique signal identifier
symbolstringStock symbol
signal_typeenum: 'momentum', 'mean_reversion', 'value', 'growth', 'quality', 'sentiment', 'technical', 'fundamental', 'statistical_arbitrage'Type of trading signal
directionenum: 'long', 'short', 'flat', 'hold'Signal direction
strengthnumberSignal strength (-1 to 1)
confidencenumberSignal confidence (0 to 1)
target_pricenumberTarget price for the signal
stop_lossnumberSuggested stop loss price
take_profitnumberSuggested take profit price
position_sizenumberSuggested position size as percentage of portfolio
time_horizonenum: 'intraday', 'short_term', 'medium_term', 'long_term'Expected signal duration
rationalestringExplanation of the signal
indicatorsobjectTechnical indicators supporting the signal
timestampstringSignal generation timestamp
expires_atstringSignal expiration timestamp
strategy_namestringName of strategy that generated the signal

TypeScript

interface TradingSignal {
  /** Unique signal identifier */
  signal_id?: string;
  /** Stock symbol */
  symbol: string;
  /** Type of trading signal */
  signal_type: "momentum" | "mean_reversion" | "value" | "growth" | "quality" | "sentiment" | "technical" | "fundamental" | "statistical_arbitrage";
  /** Signal direction */
  direction: "long" | "short" | "flat" | "hold";
  /** Signal strength (-1 to 1) */
  strength: number;
  /** Signal confidence (0 to 1) */
  confidence: number;
  /** Target price for the signal */
  target_price?: number;
  /** Suggested stop loss price */
  stop_loss?: number;
  /** Suggested take profit price */
  take_profit?: number;
  /** Suggested position size as percentage of portfolio */
  position_size?: number;
  /** Expected signal duration */
  time_horizon?: "intraday" | "short_term" | "medium_term" | "long_term";
  /** Explanation of the signal */
  rationale?: string;
  /** Technical indicators supporting the signal */
  indicators?: Record<string, unknown>;
  /** Signal generation timestamp */
  timestamp: string;
  /** Signal expiration timestamp */
  expires_at?: string;
  /** Name of strategy that generated the signal */
  strategy_name?: string;
}

TradingStrategy

Trading strategy configuration

Properties

PropertyTypeRequiredDescription
namestringStrategy name
strategy_typeenum: 'momentum', 'mean_reversion', 'pairs_trading', 'market_making', 'trend_following', 'swing_trading', 'day_trading', 'scalping', 'arbitrage', 'multi_factor'Type of trading strategy
descriptionstringStrategy description
parametersobjectStrategy-specific parameters
universeArray<string>Trading universe (symbols)
risk_parametersobject
schedulestringCron-style schedule for strategy execution
enabledbooleanWhether the strategy is enabled
created_atstringStrategy creation timestamp
updated_atstringLast update timestamp

TypeScript

interface TradingStrategy {
  /** Strategy name */
  name: string;
  /** Type of trading strategy */
  strategy_type: "momentum" | "mean_reversion" | "pairs_trading" | "market_making" | "trend_following" | "swing_trading" | "day_trading" | "scalping" | "arbitrage" | "multi_factor";
  /** Strategy description */
  description?: string;
  /** Strategy-specific parameters */
  parameters: Record<string, unknown>;
  /** Trading universe (symbols) */
  universe?: string[];
  risk_parameters?: Record<string, unknown>;
  /** Cron-style schedule for strategy execution */
  schedule?: string;
  /** Whether the strategy is enabled */
  enabled?: boolean;
  /** Strategy creation timestamp */
  created_at?: string;
  /** Last update timestamp */
  updated_at?: string;
}

Usage Example

import type { Order, Trade, TradingSignal, TradingStrategy } from '@stockbud/schemas';
 
// Create a new Order
const example: Order = {
  order_id: "example-value",
  symbol: "example-value",
  quantity: 0,
  side: "example-value",
  order_type: "example-value",
};

Full JSON Schema

Click to expand raw JSON Schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "StockBud.io Trading Schema",
  "description": "Schema for trading operations and order management in StockBud.io",
  "version": "1.0.0",
  "type": "object",
  "definitions": {
    "Order": {
      "type": "object",
      "description": "Trading order structure",
      "required": [
        "order_id",
        "symbol",
        "quantity",
        "side",
        "order_type",
        "status"
      ],
      "properties": {
        "order_id": {
          "type": "string",
          "description": "Unique order identifier"
        },
        "client_order_id": {
          "type": "string",
          "description": "Client-generated order identifier"
        },
        "symbol": {
          "type": "string",
          "pattern": "^[A-Z]{1,5}$",
          "description": "Stock symbol"
        },
        "quantity": {
          "type": "number",
          "minimum": 0,
          "description": "Order quantity"
        },
        "side": {
          "type": "string",
          "enum": [
            "buy",
            "sell"
          ],
          "description": "Order side"
        },
        "order_type": {
          "type": "string",
          "enum": [
            "market",
            "limit",
            "stop",
            "stop_limit",
            "trailing_stop"
          ],
          "description": "Order type"
        },
        "status": {
          "type": "string",
          "enum": [
            "new",
            "partially_filled",
            "filled",
            "done_for_day",
            "canceled",
            "expired",
            "replaced",
            "pending_cancel",
            "pending_replace",
            "pending_review",
            "accepted",
            "pending_new",
            "accepted_for_bidding",
            "stopped",
            "rejected",
            "suspended",
            "calculated"
          ],
          "description": "Order status"
        },
        "time_in_force": {
          "type": "string",
          "enum": [
            "day",
            "gtc",
            "opg",
            "cls",
            "ioc",
            "fok"
          ],
          "default": "day",
          "description": "Time in force"
        },
        "limit_price": {
          "type": "number",
          "minimum": 0,
          "description": "Limit price (for limit orders)"
        },
        "stop_price": {
          "type": "number",
          "minimum": 0,
          "description": "Stop price (for stop orders)"
        },
        "trail_percent": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Trail percentage (for trailing stop orders)"
        },
        "trail_price": {
          "type": "number",
          "minimum": 0,
          "description": "Trail price (for trailing stop orders)"
        },
        "filled_quantity": {
          "type": "number",
          "minimum": 0,
          "default": 0,
          "description": "Quantity filled"
        },
        "average_fill_price": {
          "type": "number",
          "minimum": 0,
          "description": "Average fill price"
        },
        "extended_hours": {
          "type": "boolean",
          "default": false,
          "description": "Extended hours trading enabled"
        },
        "order_class": {
          "type": "string",
          "enum": [
            "simple",
            "bracket",
            "oco",
            "oto"
          ],
          "default": "simple",
          "description": "Advanced order class"
        },
        "legs": {
          "type": "array",
          "description": "Order legs for multi-leg orders (bracket, OCO, OTO)",
          "items": {
            "type": "object",
            "properties": {
              "leg_type": {
                "type": "string",
                "enum": [
                  "entry",
                  "take_profit",
                  "stop_loss"
                ],
                "description": "Order leg type"
              },
              "order_type": {
                "type": "string",
                "enum": [
                  "market",
                  "limit",
                  "stop",
                  "stop_limit"
                ],
                "description": "Leg order type"
              },
              "limit_price": {
                "type": "number",
                "minimum": 0,
                "description": "Leg limit price"
              },
              "stop_price": {
                "type": "number",
                "minimum": 0,
                "description": "Leg stop price"
              }
            }
          }
        },
        "submitted_at": {
          "type": "string",
          "format": "date-time",
          "description": "Order submission timestamp"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time",
          "description": "Last order update timestamp"
        },
        "filled_at": {
          "type": "string",
          "format": "date-time",
          "description": "Order fill timestamp"
        },
        "canceled_at": {
          "type": "string",
          "format": "date-time",
          "description": "Order cancellation timestamp"
        },
        "expired_at": {
          "type": "string",
          "format": "date-time",
          "description": "Order expiration timestamp"
        },
        "commission": {
          "type": "number",
          "minimum": 0,
          "description": "Commission charged for the order"
        },
        "hwm": {
          "type": "number",
          "description": "High water mark (for trailing stops)"
        }
      }
    },
    "Trade": {
      "type": "object",
      "description": "Executed trade record",
      "required": [
        "trade_id",
        "order_id",
        "symbol",
        "quantity",
        "price",
        "side",
        "timestamp"
      ],
      "properties": {
        "trade_id": {
          "type": "string",
          "description": "Unique trade identifier"
        },
        "order_id": {
          "type": "string",
          "description": "Associated order identifier"
        },
        "symbol": {
          "type": "string",
          "pattern": "^[A-Z]{1,5}$",
          "description": "Stock symbol"
        },
        "quantity": {
          "type": "number",
          "minimum": 0,
          "description": "Trade quantity"
        },
        "price": {
          "type": "number",
          "minimum": 0,
          "description": "Trade price"
        },
        "side": {
          "type": "string",
          "enum": [
            "buy",
            "sell"
          ],
          "description": "Trade side"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "Trade execution timestamp"
        },
        "commission": {
          "type": "number",
          "minimum": 0,
          "description": "Commission paid"
        },
        "fees": {
          "type": "number",
          "minimum": 0,
          "description": "Additional fees"
        },
        "net_amount": {
          "type": "number",
          "description": "Net amount (price * quantity - commission - fees)"
        }
      }
    },
    "TradingSignal": {
      "type": "object",
      "description": "AI-generated trading signal",
      "required": [
        "symbol",
        "signal_type",
        "direction",
        "strength",
        "confidence",
        "timestamp"
      ],
      "properties": {
        "signal_id": {
          "type": "string",
          "description": "Unique signal identifier"
        },
        "symbol": {
          "type": "string",
          "pattern": "^[A-Z]{1,5}$",
          "description": "Stock symbol"
        },
        "signal_type": {
          "type": "string",
          "enum": [
            "momentum",
            "mean_reversion",
            "value",
            "growth",
            "quality",
            "sentiment",
            "technical",
            "fundamental",
            "statistical_arbitrage"
          ],
          "description": "Type of trading signal"
        },
        "direction": {
          "type": "string",
          "enum": [
            "long",
            "short",
            "flat",
            "hold"
          ],
          "description": "Signal direction"
        },
        "strength": {
          "type": "number",
          "minimum": -1,
          "maximum": 1,
          "description": "Signal strength (-1 to 1)"
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Signal confidence (0 to 1)"
        },
        "target_price": {
          "type": "number",
          "minimum": 0,
          "description": "Target price for the signal"
        },
        "stop_loss": {
          "type": "number",
          "minimum": 0,
          "description": "Suggested stop loss price"
        },
        "take_profit": {
          "type": "number",
          "minimum": 0,
          "description": "Suggested take profit price"
        },
        "position_size": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Suggested position size as percentage of portfolio"
        },
        "time_horizon": {
          "type": "string",
          "enum": [
            "intraday",
            "short_term",
            "medium_term",
            "long_term"
          ],
          "description": "Expected signal duration"
        },
        "rationale": {
          "type": "string",
          "description": "Explanation of the signal"
        },
        "indicators": {
          "type": "object",
          "description": "Technical indicators supporting the signal"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "Signal generation timestamp"
        },
        "expires_at": {
          "type": "string",
          "format": "date-time",
          "description": "Signal expiration timestamp"
        },
        "strategy_name": {
          "type": "string",
          "description": "Name of strategy that generated the signal"
        }
      }
    },
    "TradingStrategy": {
      "type": "object",
      "description": "Trading strategy configuration",
      "required": [
        "name",
        "strategy_type",
        "parameters"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "Strategy name"
        },
        "strategy_type": {
          "type": "string",
          "enum": [
            "momentum",
            "mean_reversion",
            "pairs_trading",
            "market_making",
            "trend_following",
            "swing_trading",
            "day_trading",
            "scalping",
            "arbitrage",
            "multi_factor"
          ],
          "description": "Type of trading strategy"
        },
        "description": {
          "type": "string",
          "description": "Strategy description"
        },
        "parameters": {
          "type": "object",
          "description": "Strategy-specific parameters"
        },
        "universe": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Trading universe (symbols)"
        },
        "risk_parameters": {
          "type": "object",
          "properties": {
            "max_position_size": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Maximum position size as percentage of portfolio"
            },
            "stop_loss_pct": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Stop loss percentage"
            },
            "take_profit_pct": {
              "type": "number",
              "minimum": 0,
              "description": "Take profit percentage"
            },
            "max_drawdown": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Maximum acceptable drawdown"
            }
          }
        },
        "schedule": {
          "type": "string",
          "description": "Cron-style schedule for strategy execution"
        },
        "enabled": {
          "type": "boolean",
          "default": true,
          "description": "Whether the strategy is enabled"
        },
        "created_at": {
          "type": "string",
          "format": "date-time",
          "description": "Strategy creation timestamp"
        },
        "updated_at": {
          "type": "string",
          "format": "date-time",
          "description": "Last update timestamp"
        }
      }
    }
  },
  "properties": {
    "orders": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Order"
      }
    },
    "trades": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Trade"
      }
    },
    "signals": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/TradingSignal"
      }
    },
    "strategies": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/TradingStrategy"
      }
    }
  }
}

On this page