> ## Documentation Index
> Fetch the complete documentation index at: https://scalarfield.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Supported Brokerages

> Connect to brokerages, prediction markets, and decentralized exchanges through Scalar Field. Trade US equities, prediction markets on Polymarket, crypto perps on Hyperliquid, and Solana tokens via Jupiter — via chat or automated strategy agents.

<Info>**Python module:** `from scalarlib import venue` (alias: `from scalarlib import brokerage`)</Info>

# Venue Registry

Scalar Field connects to multiple trading venues organized by asset class. You can view portfolios, place trades, and run automated strategies on any active venue.

| Venue                                            | Asset Class                            | Mode  | Status      | Capabilities                                                                |
| ------------------------------------------------ | -------------------------------------- | ----- | ----------- | --------------------------------------------------------------------------- |
| [Alpaca Paper](/docs/trading/venues/alpaca)           | US Equities & Options                  | Paper | Active      | Trade, read positions, order history                                        |
| [Alpaca Live](/docs/trading/venues/alpaca)            | US Equities & Options                  | Live  | Active      | Trade, read positions, order history                                        |
| [Public.com](/docs/trading/venues/public)             | US Equities & Options                  | Live  | Active      | Trade, read positions, order history                                        |
| [Robinhood](/docs/trading/venues/robinhood)           | US Equities & ETFs                     | Live  | Active      | Trade, read positions, order history                                        |
| [Polymarket](/docs/trading/venues/polymarket)         | Prediction Markets                     | Live  | Active      | Trade, read positions, order history                                        |
| [Polymarket Paper](/docs/trading/venues/polymarket)   | Prediction Markets                     | Paper | Active      | Simulated fills against the live order book                                 |
| [Jupiter DEX](/docs/trading/venues/jupiter)           | Solana Tokens (incl. tokenized stocks) | Live  | Active      | Trade, read positions, order history                                        |
| [Hyperliquid](/docs/trading/venues/hyperliquid)       | Crypto Perps & Spot                    | Live  | Active      | Trade (long/short, leverage), read positions, fills                         |
| [Hyperliquid Paper](/docs/trading/venues/hyperliquid) | Crypto Perps & Spot                    | Paper | Active      | Simulated fills against the live order book (long/short, leverage, funding) |
| Webull                                           | US Equities                            | Live  | Coming soon | Trade, read positions, order history                                        |

Each active venue has a dedicated page covering connection, order semantics, and available data functions: [Hyperliquid](/docs/trading/venues/hyperliquid), [Polymarket](/docs/trading/venues/polymarket), [Jupiter DEX](/docs/trading/venues/jupiter), [Robinhood](/docs/trading/venues/robinhood), [Alpaca](/docs/trading/venues/alpaca), and [Public.com](/docs/trading/venues/public).

# Enterprise Plan Connections

Read-only portfolio connections to **Interactive Brokers** and **Fidelity** are available on the [Enterprise plan](/docs/usage/pricing). They are linked via Plaid from the Portfolio page — the same place other venues are connected — and provide portfolio and holdings viewing only, with no trade execution.

# Asset-Class Groups

Venues are organized into **compatibility groups** by the instruments they trade. Strategies are compatible with any venue in the same group — for example, a US equities strategy can run on Alpaca Paper today and migrate to Alpaca Live, Public.com, or Webull when those venues launch.

| Group                                              | Currency | Venues                                                   |
| -------------------------------------------------- | -------- | -------------------------------------------------------- |
| US Equities                                        | USD      | Alpaca Paper, Alpaca Live, Public.com, Webull, Robinhood |
| Prediction Markets                                 | USDC.e   | Polymarket, Polymarket Paper                             |
| Solana Tokens via Jupiter (incl. tokenized stocks) | USDC     | Jupiter DEX (Solana)                                     |
| Crypto Perps & Spot                                | USDC     | Hyperliquid, Hyperliquid Paper                           |

# Connecting a Venue

* **Alpaca**: OAuth flow — click "Connect" on the Portfolio page, authorize with your Alpaca account, and you are linked immediately.
* **Public.com**: Click "Connect" on the Portfolio page and authorize with your Public.com account.
* **Polymarket**: Wallet-based — Scalar Field provisions a managed wallet on Polygon. Fund it with USDC to start trading. No external wallet connection required. Polymarket Paper needs no setup — it is auto-provisioned with virtual USDC on first use.
* **Jupiter DEX**: Wallet-based — Scalar Field provisions a managed Solana wallet. Fund it with USDC to trade tokenized equities (xStocks) and any verified Solana token.
* **Hyperliquid**: Wallet-based — fund your Arbitrum wallet with USDC and bridge it to Hyperliquid from the Portfolio page. Hyperliquid Paper needs no setup — it is auto-provisioned with virtual USDC on first use.
* **Robinhood**: OAuth flow — click "Connect" on the Portfolio page and authorize with your Robinhood account. Trading is limited to equities and ETFs (no options or crypto orders).

# Venue Functions Reference

The `venue` module provides functions for account data, positions, balances, trade history, and order placement. These functions are available in chat code execution. For automated strategy agents, use the `strategy` module instead (see [Strategies](/docs/trading/strategies)).

## `venue.account()`

Returns a snapshot of all connected venues with balances, positions, and metadata.

```python theme={null}
from scalarlib import venue

# All connected venues
data = venue.account()
for acct in data["accounts"]:
    print(acct["name"], acct.get("portfolio_value"))

# Single venue
data = venue.account(account="Alpaca Paper")
alpaca = data["accounts"][0]
print(alpaca["cash"], alpaca["buying_power"])
```

### Parameters

| Parameter | Type | Required | Description                                                                                                  |
| --------- | ---- | -------- | ------------------------------------------------------------------------------------------------------------ |
| `account` | str  | No       | Filter by venue name (e.g. `"Alpaca Paper"`, `"Polymarket"`, `"WALLET_SOL"`). Returns all venues if omitted. |

### Return Schema

Returns `{"accounts": [...]}` where each account contains fields relevant to its type:

**Brokerage accounts** (Alpaca):

| Field             | Type   | Description                                |
| ----------------- | ------ | ------------------------------------------ |
| `name`            | string | Venue name (e.g. `"Alpaca Paper"`)         |
| `type`            | string | `"brokerage"`                              |
| `cash`            | float  | Available cash balance (USD)               |
| `buying_power`    | float  | Total buying power                         |
| `portfolio_value` | float  | Total account value                        |
| `positions`       | list   | Open positions (see position fields below) |

**Exchange accounts** (Polymarket):

| Field       | Type   | Description                                                                                                                         |
| ----------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------- |
| `name`      | string | `"Polymarket"`                                                                                                                      |
| `type`      | string | `"exchange"`                                                                                                                        |
| `positions` | list   | Open prediction market positions with `token_id`, `title`, `outcome`, `qty`, `avg_price`, `price`, `market_value`, `unrealized_pnl` |

**Wallet accounts** (Jupiter DEX / Solana):

| Field             | Type   | Description                                                                                                                                      |
| ----------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `name`            | string | `"WALLET_SOL"`                                                                                                                                   |
| `type`            | string | `"wallet"`                                                                                                                                       |
| `chain`           | string | `"solana"`                                                                                                                                       |
| `cash`            | float  | USDC balance                                                                                                                                     |
| `portfolio_value` | float  | Total value of all holdings                                                                                                                      |
| `positions`       | list   | Solana token positions with `symbol` (`J:`-prefixed mint, e.g. `"J:XsbEhLAt..."`), `qty`, `avg_price`, `price`, `market_value`, `unrealized_pnl` |

**Position fields** (common across venue types):

| Field            | Type   | Description                                  |
| ---------------- | ------ | -------------------------------------------- |
| `symbol`         | string | Ticker symbol (equities) or token identifier |
| `qty`            | float  | Number of shares/tokens held                 |
| `avg_price`      | float  | Average entry price                          |
| `price`          | float  | Current market price                         |
| `market_value`   | float  | Current position value                       |
| `cost_basis`     | float  | Total cost of the position                   |
| `unrealized_pnl` | float  | Unrealized profit/loss                       |

***

## `venue.positions()`

Returns a flat list of all positions across all venues, each tagged with its venue name.

```python theme={null}
from scalarlib import venue

# All positions across all venues
all_pos = venue.positions()
for p in all_pos:
    print(p["venue"], p["symbol"], p["qty"], p["unrealized_pnl"])

# Positions for a specific venue
poly_pos = venue.positions(account="Polymarket")
jupiter_pos = venue.positions(account="WALLET_SOL")
```

### Parameters

| Parameter | Type | Required | Description                                          |
| --------- | ---- | -------- | ---------------------------------------------------- |
| `account` | str  | No       | Filter by venue name. Returns all venues if omitted. |

### Return Schema

Returns a list of position dicts. Each position includes a `venue` field plus the standard position fields (`symbol`, `qty`, `avg_price`, `price`, `market_value`, `cost_basis`, `unrealized_pnl`). Polymarket positions additionally include `token_id`, `title`, `outcome`, and `slug`.

***

## `venue.balances()`

Returns cash and token balances across venues.

```python theme={null}
from scalarlib import venue

# All balances
all_bal = venue.balances()

# Filter by asset (USDC also matches USDC.E)
usdc = venue.balances(asset="USDC")
```

### Parameters

| Parameter | Type | Required | Description                                                                                 |
| --------- | ---- | -------- | ------------------------------------------------------------------------------------------- |
| `account` | str  | No       | Filter by venue name.                                                                       |
| `asset`   | str  | No       | Filter by asset symbol (e.g. `"USD"`, `"USDC"`, `"POL"`). `"USDC"` also matches `"USDC.E"`. |

### Return Schema

Returns a list of balance dicts:

| Field       | Type   | Description                           |
| ----------- | ------ | ------------------------------------- |
| `venue`     | string | Venue name                            |
| `asset`     | string | Asset symbol (e.g. `"USD"`, `"USDC"`) |
| `amount`    | float  | Balance amount                        |
| `usd_value` | float  | USD equivalent                        |

<Info>Exchange accounts (Polymarket) are skipped — they hold positions, not fungible balances. Polymarket funds live in the `WALLET_POL` wallet.</Info>

***

## `venue.history()`

Returns unified financial history across all venues — trades, transfers, dividends, and fees — sorted newest first.

```python theme={null}
from scalarlib import venue

# Recent activity
all_activity = venue.history(limit=50)

# Trades only on Alpaca
trades = venue.history(category="trade", account="Alpaca Paper")

# Wallet transfers
transfers = venue.history(category="transfer", account="WALLET_POL")

# Jupiter trades for a specific token
jupiter = venue.history(symbol="J:XsbEhLAtcf6HdfpFZ5xEMdqW8nfAvcsP5bdudRLJzJp", account="WALLET_SOL")
```

### Parameters

| Parameter  | Type | Required | Description                                                                                    |
| ---------- | ---- | -------- | ---------------------------------------------------------------------------------------------- |
| `symbol`   | str  | No       | Filter by symbol (ticker, Polymarket token ID, or Jupiter `J:` ticker).                        |
| `start`    | str  | No       | Start date (`"YYYY-MM-DD"`, New York time).                                                    |
| `end`      | str  | No       | End date (same format).                                                                        |
| `limit`    | int  | No       | Maximum number of records to return.                                                           |
| `offset`   | int  | No       | Pagination offset.                                                                             |
| `account`  | str  | No       | Filter by venue name.                                                                          |
| `category` | str  | No       | `"trade"` (buys/sells only), `"transfer"` (wallet transfers only), or `None` (all categories). |

### Return Schema

Returns a list of history dicts:

| Field      | Type   | Description                                          |
| ---------- | ------ | ---------------------------------------------------- |
| `venue`    | string | Venue name                                           |
| `category` | string | `"trade"`, `"transfer"`, `"dividend"`, or `"fee"`    |
| `side`     | string | `"buy"`, `"sell"`, `"send"`, or `"receive"`          |
| `symbol`   | string | Ticker or token symbol (null for transfers)          |
| `qty`      | float  | Quantity traded (null for transfers)                 |
| `price`    | float  | Execution price (null for transfers)                 |
| `amount`   | float  | Transfer amount in asset units (null for trades)     |
| `fees`     | float  | Fees charged on this transaction                     |
| `tx_hash`  | string | Blockchain transaction hash (on-chain venues only)   |
| `status`   | string | Transaction status (e.g. `"SUCCESS"`, `"confirmed"`) |
| `ts`       | string | Timestamp in New York time (`"YYYY-MM-DD HH:MM:SS"`) |

***

## `venue.trade()`

Places a buy or sell order on a connected venue. Direct execution — no approval workflow.

```python theme={null}
from scalarlib import venue

# Buy equities on Alpaca
resp = venue.trade("buy", "AAPL", 5)
resp = venue.trade("sell", "MSFT", 10, account="Alpaca Paper")

# Buy prediction market tokens on Polymarket
from scalarlib import screenPolymarkets
markets = screenPolymarkets(query="bitcoin", closed=False)
token_id = markets.iloc[0]["token_ids"][0]
resp = venue.trade("buy", token_id, 100, account="Polymarket")

# Buy tokenized equities on Jupiter DEX — resolve the J: ticker first
from scalarlib import searchJupiterTokens
aaplx = searchJupiterTokens("AAPL").iloc[0]["ticker"]   # 'J:<mint>'
resp = venue.trade("buy", aaplx, 5, account="WALLET_SOL")
resp = venue.trade("sell", aaplx, 2.5, account="WALLET_SOL", slippage_bps=100)

# Trade any Solana token by mint address
tokens = searchJupiterTokens("bonk")
ticker = tokens.iloc[0]["ticker"]
resp = venue.trade("buy", ticker, 1000000, account="WALLET_SOL")
```

### Parameters

| Parameter      | Type  | Required | Description                                                                                                                               |
| -------------- | ----- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| `action`       | str   | Yes      | `"buy"` or `"sell"`                                                                                                                       |
| `symbol`       | str   | Yes      | Ticker for equities (e.g. `"AAPL"`), outcome token ID for Polymarket, or `"J:<mint_address>"` for Jupiter (from `searchJupiterTokens()`). |
| `qty`          | float | Yes      | Number of shares/tokens to buy or sell. Fractional quantities are supported on all venues.                                                |
| `account`      | str   | No       | Venue name (e.g. `"Alpaca Paper"`, `"Polymarket"`, `"WALLET_SOL"`). Auto-selected when only one writable venue exists.                    |
| `slippage_bps` | int   | No       | Slippage tolerance in basis points. Default: 50 bps (0.5%) for Jupiter, 500 bps (5%) for Polymarket. Ignored for Alpaca.                  |

### Return Schema

| Field             | Type           | Description                                                                |
| ----------------- | -------------- | -------------------------------------------------------------------------- |
| `status`          | string         | `"FILLED"`, `"PARTIALLY_FILLED"`, `"PENDING"`, `"REJECTED"`, or `"FAILED"` |
| `symbol`          | string         | The traded symbol                                                          |
| `action`          | string         | `"buy"` or `"sell"`                                                        |
| `qty`             | float          | Requested quantity                                                         |
| `filled_qty`      | float          | Actual quantity filled (may differ due to slippage)                        |
| `avg_price`       | float          | Average fill price                                                         |
| `broker_order_id` | string         | Broker/venue order identifier                                              |
| `fee_bps`         | int or null    | Platform fee rate in basis points (null when 0)                            |
| `fee_amount`      | float or null  | Platform fee amount (null when 0)                                          |
| `reason`          | string or null | Rejection/failure reason                                                   |
| `ts`              | string         | Execution timestamp in New York time                                       |

<Info>**Alpaca** orders may return `"PENDING"` — the order is submitted but not yet filled. **Jupiter** and **Polymarket** orders are synchronous and always block until the fill completes.</Info>

### Important Notes

* **Fractional shares**: All venues support fractional orders. When computing quantity from a dollar budget, use `round(budget / price, 2)` — never `int()`, which floors to 0 when the budget is less than one share price.
* **Dust positions**: On Jupiter and Polymarket, selling an entire position may leave a tiny residual quantity due to rounding (e.g. 0.0001 tokens worth $0.02). Treat any position with `abs(market_value) < $0.10\` as effectively closed.
* **Settlement delay**: After a Jupiter or Polymarket trade, positions and balances may take a moment to reflect the fill due to on-chain settlement. Allow a brief delay before re-querying.

***

## `searchJupiterTokens()`

Search for verified tokens tradeable on Jupiter DEX by name, symbol, or mint address.

```python theme={null}
from scalarlib import searchJupiterTokens

tokens = searchJupiterTokens("bonk")
print(tokens[["symbol", "name", "mint_address", "price"]])

# Trade the first result
mint = tokens.iloc[0]["mint_address"]
resp = venue.trade("buy", f"J:{mint}", 1000000, account="WALLET_SOL")
```

### Parameters

| Parameter | Type | Required | Description                                          |
| --------- | ---- | -------- | ---------------------------------------------------- |
| `query`   | str  | Yes      | Search string (token name, symbol, or mint address). |
| `limit`   | int  | No       | Maximum results (default 20).                        |

### Return Schema

Returns a pandas DataFrame:

| Column         | Type   | Description                                                            |
| -------------- | ------ | ---------------------------------------------------------------------- |
| `mint_address` | string | Solana mint address — use with `venue.trade()` as `"J:<mint_address>"` |
| `symbol`       | string | Token symbol (e.g. `"BONK"`, `"JUP"`)                                  |
| `name`         | string | Token name                                                             |
| `decimals`     | int    | Token decimal places                                                   |
| `price`        | float  | Current USD price                                                      |
| `mcap`         | float  | Market capitalization                                                  |
| `volume_24h`   | float  | 24-hour trading volume                                                 |
| `liquidity`    | float  | Available liquidity                                                    |
| `holder_count` | int    | Number of token holders                                                |
