# Alpaca

> Read Alpaca trading account activity and manage orders, positions and watchlists.

App · 20 actions. Web page: https://docs.lodol.com/docs/integrations/alpaca

## Actions

### Cancel an order

Cancel an order.

**Inputs**

- Order ID (`order_id`, text, required): order id

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {}
}
```

### Create a watchlist

Create a watchlist.

**Inputs**

- Name (`name`, text, required): The watchlist name.
- Symbols (`symbols`, list): List of asset symbols to include in the watchlist.

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "account_id": "example",
    "assets": [
      {
        "attributes": [
          {}
        ],
        "borrow_status": "example",
        "class": "example",
        "cusip": "example",
        "exchange": "example",
        "fractionable": true,
        "id": "example",
        "maintenance_margin_requirement": 1,
        "margin_requirement_long": "example",
        "margin_requirement_short": "example",
        "marginable": true,
        "min_order_size": "example",
        "min_trade_increment": "example",
        "name": "example",
        "price_increment": "example",
        "shortable": true,
        "status": "example",
        "symbol": "example",
        "tradable": true
      }
    ],
    "created_at": "example",
    "id": "example",
    "name": "example",
    "updated_at": "example"
  }
}
```

### Delete a watchlist

Delete a watchlist.

**Inputs**

- Watchlist (`watchlist_id`, text, required): watchlist id

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {}
}
```

### Get a watchlist

Get a watchlist.

**Inputs**

- Watchlist (`watchlist_id`, text, required): watchlist id

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "assets": [
      {
        "id": "example",
        "name": "example",
        "status": "example",
        "symbol": "example",
        "tradable": true
      }
    ],
    "created_at": "example",
    "id": "example",
    "name": "example",
    "updated_at": "example"
  }
}
```

### Get account portfolio history

Get account portfolio history.

**Inputs**

- Period (`period`, text): The total duration of history being requested defined as `number` + `unit`.
- Timeframe (`timeframe`, text): The resolution of time window. 1Min, 5Min, 15Min, 1H, or 1D. If omitted, 1Min for less than 7 days period,. One of: `1D`, `1H`, `15Min`, `5Min`, `1Min`.
- Start (`start`, text): The first timestamp of the timeseries.
- End (`end`, text): The last timestamp of the timeseries.
- Extended hours (`extended_hours`, text): **deprecated**: Users are strongly advised to **rely on the `intraday_reporting` query parameter** for better control

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "base_value": 1,
    "base_value_asof": "example",
    "cashflow": {},
    "equity": [
      1
    ],
    "profit_loss": [
      1
    ],
    "profit_loss_pct": [
      1
    ],
    "timeframe": "example",
    "timestamp": [
      1
    ]
  }
}
```

### Get an asset

Get an asset.

**Inputs**

- Symbol or asset ID (`symbol_or_asset_id`, text, required): symbol or assetId. CUSIP is also accepted for US equities.

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "attributes": [
      "example"
    ],
    "borrow_status": "example",
    "class": "example",
    "cusip": "example",
    "exchange": "example",
    "fractionable": true,
    "id": "example",
    "maintenance_margin_requirement": 1,
    "margin_requirement_long": "example",
    "margin_requirement_short": "example",
    "marginable": true,
    "min_order_size": "example",
    "min_trade_increment": "example",
    "name": "example",
    "price_increment": "example",
    "shortable": true,
    "status": "example",
    "symbol": "example",
    "tradable": true
  }
}
```

### Get an open position

Get an open position.

**Inputs**

- Symbol or asset ID (`symbol_or_asset_id`, text, required): symbol or assetId

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "asset_class": "example",
    "asset_id": "example",
    "asset_marginable": true,
    "avg_entry_price": "example",
    "avg_entry_swap_rate": "example",
    "change_today": "example",
    "cost_basis": "example",
    "current_price": "example",
    "exchange": "example",
    "lastday_price": "example",
    "market_value": "example",
    "prev_swap_rate": "example",
    "qty": "example",
    "qty_available": "example",
    "side": "example",
    "swap_rate": "example",
    "symbol": "example",
    "unrealized_intraday_pl": "example",
    "unrealized_intraday_plpc": "example",
    "unrealized_pl": "example",
    "unrealized_plpc": "example",
    "usd": {
      "avg_entry_price": "example",
      "change_today": "example",
      "cost_basis": "example",
      "current_price": "example",
      "lastday_price": "example",
      "market_value": "example",
      "unrealized_intraday_pl": "example",
      "unrealized_intraday_plpc": "example",
      "unrealized_pl": "example",
      "unrealized_plpc": "example"
    }
  }
}
```

### Get an order

Get an order.

**Inputs**

- Order ID (`order_id`, text, required): order id

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "client_order_id": "example",
    "created_at": "example",
    "filled_qty": "example",
    "id": "example",
    "status": "example",
    "symbol": "example",
    "updated_at": "example"
  }
}
```

### Get an order by client ID

Get an order by client ID.

**Inputs**

- Client order ID (`client_order_id`, text, required): The client-assigned order ID.

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "client_order_id": "example",
    "created_at": "example",
    "filled_qty": "example",
    "id": "example",
    "status": "example",
    "symbol": "example",
    "updated_at": "example"
  }
}
```

### Get the trading account

Get the trading account.

**Inputs**: None.

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "account_blocked": true,
    "account_number": "example",
    "accrued_fees": "example",
    "balance_asof": "example",
    "buying_power": "example",
    "cash": "example",
    "created_at": "example",
    "crypto_status": "example",
    "currency": "example",
    "equity": "example",
    "id": "example",
    "initial_margin": "example",
    "intraday_adjustments": "example",
    "last_equity": "example",
    "last_maintenance_margin": "example",
    "long_market_value": "example",
    "maintenance_margin": "example",
    "multiplier": "example",
    "non_marginable_buying_power": "example",
    "options_approved_level": 1,
    "options_buying_power": "example",
    "options_trading_level": 1,
    "pending_reg_taf_fees": "example",
    "pending_transfer_in": "example",
    "pending_transfer_out": "example",
    "portfolio_value": "example",
    "regt_buying_power": "example",
    "short_market_value": "example",
    "shorting_enabled": true,
    "sma": "example",
    "status": "example",
    "trade_suspended_by_user": true,
    "trading_blocked": true,
    "transfers_blocked": true
  }
}
```

### Get the US market clock

Get the US market clock.

**Inputs**: None.

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "is_open": true,
    "next_close": "example",
    "next_open": "example",
    "timestamp": "example"
  }
}
```

### Get trading account settings

Get trading account settings.

**Inputs**: None.

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "disable_overnight_trading": true,
    "fractional_trading": true,
    "max_margin_multiplier": "example",
    "max_options_trading_level": 1,
    "no_shorting": true,
    "ptp_no_exception_entry": true,
    "suspend_trade": true,
    "trade_confirm_email": "example"
  }
}
```

### List account activities

List account activities.

**Inputs**

- Activity types (`activity_types`, list): A comma-separated list of activity types used to filter the results. One or more of: `ACATC`, `ACATS`, `ALLOC`, `CFEE`, `CGD`, `CIL`, `CSD`, `CSR`, `CSW`, `DIV`, and 49 more.
- Date (`date`, date and time): Filter activities by their creation date (created_at), not the activity's settlement date. For non-trade activities such as fees, the creation date is typically the day after the trade date (in UTC). Both formats YYYY-MM-DD and YYYY-MM-DDTHH:MM:SSZ are supported.
- Until (`until`, date and time): Get activities created before this date. Both formats YYYY-MM-DD and YYYY-MM-DDTHH:MM:SSZ are supported.
- After (`after`, date and time): Get activities created after this date. Both formats YYYY-MM-DD and YYYY-MM-DDTHH:MM:SSZ are supported.
- Direction (`direction`, text): The chronological order of response based on the activity datetime. One of: `asc`, `desc`.
- Page size (`page_size`, number): The maximum number of entries to return in the response. From 1 to 100.
- Page token (`page_token`, text): Token used for pagination. Provide the ID of the last activity from the last page to retrieve the next set of results.

**Outputs**

- `data` (list): The response from Alpaca.

**Example output**

```json
{
  "data": [
    {
      "activity_type": "example",
      "date": "example",
      "id": "example",
      "order_id": "example",
      "price": "example",
      "qty": "example",
      "symbol": "example",
      "transaction_time": "example"
    }
  ]
}
```

### List open positions

List open positions.

**Inputs**: None.

**Outputs**

- `data` (list): The response from Alpaca.

**Example output**

```json
{
  "data": [
    {
      "asset_class": "example",
      "asset_id": "example",
      "asset_marginable": true,
      "avg_entry_price": "example",
      "avg_entry_swap_rate": "example",
      "change_today": "example",
      "cost_basis": "example",
      "current_price": "example",
      "exchange": "example",
      "lastday_price": "example",
      "market_value": "example",
      "prev_swap_rate": "example",
      "qty": "example",
      "qty_available": "example",
      "side": "example",
      "swap_rate": "example",
      "symbol": "example",
      "unrealized_intraday_pl": "example",
      "unrealized_intraday_plpc": "example",
      "unrealized_pl": "example",
      "unrealized_plpc": "example",
      "usd": {
        "avg_entry_price": "example",
        "change_today": "example",
        "cost_basis": "example",
        "current_price": "example",
        "lastday_price": "example",
        "market_value": "example",
        "unrealized_intraday_pl": "example",
        "unrealized_intraday_plpc": "example",
        "unrealized_pl": "example",
        "unrealized_plpc": "example"
      }
    }
  ]
}
```

### List orders

List orders.

**Inputs**

- Status (`status`, text): Order status to be queried. open, closed or all. Defaults to open. One of: `open`, `closed`, `all`.
- Limit (`limit`, number): The maximum number of orders in response. Defaults to 50 and max is 500.
- After (`after`, text): The response will include only ones submitted after this timestamp (exclusive.)
- Until (`until`, text): The response will include only ones submitted until this timestamp (exclusive.)
- Direction (`direction`, text): The chronological order of response based on the submission time. asc or desc. Defaults to desc. One of: `asc`, `desc`.
- Symbols (`symbols`, list): A comma-separated list of symbols to filter by (ex. "AAPL,TSLA,MSFT"). A currency pair is required for crypto orders (ex. "BTCUSD,BCHUSD,LTCUSD,ETCUSD").
- Side (`side`, text): Filters down to orders that have a matching side field set.
- After order ID (`after_order_id`, text): Return orders submitted after the order with this ID (exclusive).

**Outputs**

- `data` (list): The response from Alpaca.

**Example output**

```json
{
  "data": [
    {
      "client_order_id": "example",
      "created_at": "example",
      "filled_qty": "example",
      "id": "example",
      "status": "example",
      "symbol": "example",
      "updated_at": "example"
    }
  ]
}
```

### List tradable assets

List tradable assets.

**Inputs**

- Status (`status`, text): e.g. "active". By default, all statuses are included.
- Asset class (`asset_class`, text): Defaults to us_equity.
- Exchange (`exchange`, text): Optional comma-separated exchanges to filter `us_equity` and `us_index` assets by: AMEX, ARCA, BATS, NYSE, NASDAQ, NYSEARCA, OTC, TXSE, or INDEX. `INDEX` requires `asset_class=us_index`.

**Outputs**

- `data` (list): The response from Alpaca.

**Example output**

```json
{
  "data": [
    {
      "id": "example",
      "name": "example",
      "status": "example",
      "symbol": "example",
      "tradable": true
    }
  ]
}
```

### List US market days

List US market days.

**Inputs**

- Start (`start`, date): The first date to retrieve data for (inclusive).
- End (`end`, date): The last date to retrieve data for (inclusive).
- Date type (`date_type`, text): Indicates what start and end mean. Default: TRADING. If TRADING is specified, returns a calendar whose trading date matches start, end. If SETTLEMENT is specified, returns the calendar whose settlement date matches start and end. One of: `TRADING`, `SETTLEMENT`.

**Outputs**

- `data` (list): The response from Alpaca.

**Example output**

```json
{
  "data": [
    {
      "close": "example",
      "date": "example",
      "open": "example",
      "session_close": "example",
      "session_open": "example",
      "settlement_date": "example"
    }
  ]
}
```

### List watchlists

List watchlists.

**Inputs**: None.

**Outputs**

- `data` (list): The response from Alpaca.

**Example output**

```json
{
  "data": [
    {
      "account_id": "example",
      "created_at": "example",
      "id": "example",
      "name": "example",
      "updated_at": "example"
    }
  ]
}
```

### Submit an order

Submit an order.

**Inputs**

- Client order ID (`client_order_id`, text): A unique identifier for the order. Automatically generated if not sent. (<= 128 characters)
- Extended hours (`extended_hours`, true/false): (default) false. If true, order will be eligible for execution in the pre-market, after-hours, and overnight sessions. Only works with type `limit` and time_in_force set to either `day` or `gtc`
- Limit price (`limit_price`, text): Required if type is `limit` or `stop_limit`.
- Notional (`notional`, text): dollar amount to trade. Cannot work with `qty`. Can only work for market order types and day for time in force.
- Qty (`qty`, text): number of shares to trade. Can be fractionable for only market and day order types. Required for `mleg` order class, represents the number of units to trade of this strategy.
- Side (`side`, text, required): Represents which side this order was on: One of: `buy`, `sell`.
- Stop price (`stop_price`, text): required if type is `stop` or `stop_limit`
- Symbol (`symbol`, text, required): symbol, asset ID, or currency pair to identify the asset to trade, required for all order classes except for `mleg`.
- Time in force (`time_in_force`, text, required): The Time-In-Force values supported by Alpaca vary based on the order's security type. Here is a breakdown of the supported TIFs for each specific security type: One of: `day`, `gtc`, `opg`, `cls`, `ioc`, `fok`.
- Type (`type`, text, required): The order types supported by Alpaca vary based on the order's security type. The following provides a comprehensive breakdown of the supported order types for each category: One of: `market`, `limit`, `stop`, `stop_limit` (Stop limit).

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "asset_class": "example",
    "asset_id": "example",
    "canceled_at": "example",
    "client_order_id": "example",
    "created_at": "example",
    "expired_at": "example",
    "expires_at": "example",
    "extended_hours": true,
    "failed_at": "example",
    "filled_at": "example",
    "filled_avg_price": "example",
    "filled_qty": "example",
    "group_id": "example",
    "group_role": "example",
    "hwm": "example",
    "id": "example",
    "legs": [
      {
        "asset_class": "example",
        "asset_id": "example",
        "canceled_at": "example",
        "client_order_id": "example",
        "created_at": "example",
        "expired_at": "example",
        "extended_hours": true,
        "failed_at": "example",
        "filled_at": "example",
        "filled_avg_price": "example",
        "filled_qty": "example",
        "group_id": "example",
        "group_role": "example",
        "hwm": "example",
        "id": "example",
        "legs": [
          {}
        ],
        "limit_price": "example",
        "notional": "example",
        "order_class": "example",
        "order_type": "example",
        "position_intent": "example",
        "qty": "example",
        "replaced_at": "example",
        "replaced_by": "example",
        "replaces": "example",
        "side": "example",
        "status": "example",
        "stop_price": "example",
        "submitted_at": "example",
        "symbol": "example",
        "time_in_force": "example",
        "trail_percent": "example",
        "trail_price": "example",
        "type": "example",
        "updated_at": "example"
      }
    ],
    "limit_price": "example",
    "notional": "example",
    "order_class": "example",
    "order_type": "example",
    "position_intent": "example",
    "qty": "example",
    "ratio_qty": "example",
    "replaced_at": "example",
    "replaced_by": "example",
    "replaces": "example",
    "side": "example",
    "status": "example",
    "stop_price": "example",
    "submitted_at": "example",
    "symbol": "example",
    "time_in_force": "example",
    "trail_percent": "example",
    "trail_price": "example",
    "type": "example",
    "updated_at": "example"
  }
}
```

### Update a watchlist

Update a watchlist.

**Inputs**

- Watchlist (`watchlist_id`, text, required): watchlist id
- Name (`name`, text): New name for the watchlist.
- Symbols (`symbols`, list): List of asset symbols to include in the watchlist. The existing assets will be replaced with the new list.

**Outputs**

- `data` (object): The response from Alpaca.

**Example output**

```json
{
  "data": {
    "account_id": "example",
    "assets": [
      {
        "attributes": [
          {}
        ],
        "borrow_status": "example",
        "class": "example",
        "cusip": "example",
        "exchange": "example",
        "fractionable": true,
        "id": "example",
        "maintenance_margin_requirement": 1,
        "margin_requirement_long": "example",
        "margin_requirement_short": "example",
        "marginable": true,
        "min_order_size": "example",
        "min_trade_increment": "example",
        "name": "example",
        "price_increment": "example",
        "shortable": true,
        "status": "example",
        "symbol": "example",
        "tradable": true
      }
    ],
    "created_at": "example",
    "id": "example",
    "name": "example",
    "updated_at": "example"
  }
}
```
