Skip to main content

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.

Python module: from scalarlib import venue (alias: from scalarlib import brokerage)

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.
VenueAsset ClassModeStatusCapabilities
Alpaca PaperUS EquitiesPaperActiveTrade, read positions, order history
Alpaca LiveUS EquitiesLiveComing soonTrade, read positions, order history
Public.comUS EquitiesLiveComing soonTrade, read positions, order history
WebullUS EquitiesLiveComing soonTrade, read positions, order history
PolymarketPrediction MarketsLiveActiveTrade, read positions, order history
Jupiter DEXTokenized Assets (Solana)LiveActiveTrade, read positions, order history
RobinhoodUS EquitiesLiveRead-onlyView portfolio and holdings
Interactive BrokersUS EquitiesLiveRead-onlyView portfolio and holdings
FidelityUS EquitiesLiveRead-onlyView portfolio and holdings

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.
GroupCurrencyVenues
US EquitiesUSDAlpaca Paper, Alpaca Live, Public.com, Webull, Robinhood, Interactive Brokers, Fidelity
Prediction MarketsUSDC.ePolymarket
Tokenized AssetsUSDCJupiter DEX (Solana)

Connecting a Venue

  • Alpaca: OAuth flow — click “Connect” on the Portfolio page, authorize with your Alpaca account, and you are linked immediately.
  • Polymarket: Wallet-based — Scalar Field provisions a managed wallet on Polygon. Fund it with USDC to start trading. No external wallet connection required.
  • 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.
  • Read-only venues (Robinhood, Interactive Brokers, Fidelity): Linked via Plaid for portfolio viewing. No trade execution.

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).

venue.account()

Returns a snapshot of all connected venues with balances, positions, and metadata.
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

ParameterTypeRequiredDescription
accountstrNoFilter 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):
FieldTypeDescription
namestringVenue name (e.g. "Alpaca Paper")
typestring"brokerage"
cashfloatAvailable cash balance (USD)
buying_powerfloatTotal buying power
portfolio_valuefloatTotal account value
positionslistOpen positions (see position fields below)
Exchange accounts (Polymarket):
FieldTypeDescription
namestring"Polymarket"
typestring"exchange"
positionslistOpen prediction market positions with token_id, title, outcome, qty, avg_price, price, market_value, unrealized_pnl
Wallet accounts (Jupiter DEX / Solana):
FieldTypeDescription
namestring"wallet_sol"
typestring"wallet"
chainstring"solana"
cashfloatUSDC balance
portfolio_valuefloatTotal value of all holdings
positionslistTokenized equity positions with symbol (e.g. "T:AAPLX"), qty, avg_price, price, market_value, unrealized_pnl
Position fields (common across venue types):
FieldTypeDescription
symbolstringTicker symbol (equities) or token identifier
qtyfloatNumber of shares/tokens held
avg_pricefloatAverage entry price
pricefloatCurrent market price
market_valuefloatCurrent position value
cost_basisfloatTotal cost of the position
unrealized_pnlfloatUnrealized profit/loss

venue.positions()

Returns a flat list of all positions across all venues, each tagged with its venue name.
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

ParameterTypeRequiredDescription
accountstrNoFilter 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.
from scalarlib import venue

# All balances
all_bal = venue.balances()

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

Parameters

ParameterTypeRequiredDescription
accountstrNoFilter by venue name.
assetstrNoFilter by asset symbol (e.g. "USD", "USDC", "POL"). "USDC" also matches "USDC.E".

Return Schema

Returns a list of balance dicts:
FieldTypeDescription
venuestringVenue name
assetstringAsset symbol (e.g. "USD", "USDC")
amountfloatBalance amount
usd_valuefloatUSD equivalent
Exchange accounts (Polymarket) are skipped — they hold positions, not fungible balances. Polymarket funds live in the wallet_pol wallet.

venue.history()

Returns unified financial history across all venues — trades, transfers, dividends, and fees — sorted newest first.
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 symbol
jupiter = venue.history(symbol="T:AAPLX", account="wallet_sol")

Parameters

ParameterTypeRequiredDescription
symbolstrNoFilter by symbol (ticker, token ID, or tokenized asset symbol).
startstrNoStart date ("YYYY-MM-DD", New York time).
endstrNoEnd date (same format).
limitintNoMaximum number of records to return.
offsetintNoPagination offset.
accountstrNoFilter by venue name.
categorystrNo"trade" (buys/sells only), "transfer" (wallet transfers only), or None (all categories).

Return Schema

Returns a list of history dicts:
FieldTypeDescription
venuestringVenue name
categorystring"trade", "transfer", "dividend", or "fee"
sidestring"buy", "sell", "send", or "receive"
symbolstringTicker or token symbol (null for transfers)
qtyfloatQuantity traded (null for transfers)
pricefloatExecution price (null for transfers)
amountfloatTransfer amount in asset units (null for trades)
feesfloatFees charged on this transaction
tx_hashstringBlockchain transaction hash (on-chain venues only)
statusstringTransaction status (e.g. "SUCCESS", "confirmed")
tsstringTimestamp 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.
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
resp = venue.trade("buy", "T:AAPLX", 5, account="wallet_sol")
resp = venue.trade("sell", "T:AAPLX", 2.5, account="wallet_sol", slippage_bps=100)

# Trade any Solana token by mint address
from scalarlib import searchJupiterTokens
tokens = searchJupiterTokens("bonk")
mint = tokens.iloc[0]["mint_address"]
resp = venue.trade("buy", f"T:{mint}", 1000000, account="wallet_sol")

Parameters

ParameterTypeRequiredDescription
actionstrYes"buy" or "sell"
symbolstrYesTicker for equities (e.g. "AAPL"), outcome token ID for Polymarket, or "T:<symbol>" / "T:<mint_address>" for Jupiter.
qtyfloatYesNumber of shares/tokens to buy or sell. Fractional quantities are supported on all venues.
accountstrNoVenue name (e.g. "Alpaca Paper", "Polymarket", "wallet_sol"). Auto-selected when only one writable venue exists.
slippage_bpsintNoSlippage tolerance in basis points. Default: 50 bps (0.5%) for Jupiter, 500 bps (5%) for Polymarket. Ignored for Alpaca.

Return Schema

FieldTypeDescription
statusstring"FILLED", "PARTIALLY_FILLED", "PENDING", "REJECTED", or "FAILED"
symbolstringThe traded symbol
actionstring"buy" or "sell"
qtyfloatRequested quantity
filled_qtyfloatActual quantity filled (may differ due to slippage)
avg_pricefloatAverage fill price
broker_order_idstringBroker/venue order identifier
fee_bpsint or nullPlatform fee rate in basis points (null when 0)
fee_amountfloat or nullPlatform fee amount (null when 0)
reasonstring or nullRejection/failure reason
tsstringExecution timestamp in New York time
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.

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).Treatanypositionwithabs(marketvalue)<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.
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"T:{mint}", 1000000, account="wallet_sol")

Parameters

ParameterTypeRequiredDescription
querystrYesSearch string (token name, symbol, or mint address).
limitintNoMaximum results (default 20).

Return Schema

Returns a pandas DataFrame:
ColumnTypeDescription
mint_addressstringSolana mint address — use with venue.trade() as "T:<mint_address>"
symbolstringToken symbol (e.g. "BONK", "JUP")
namestringToken name
decimalsintToken decimal places
pricefloatCurrent USD price
mcapfloatMarket capitalization
volume_24hfloat24-hour trading volume
liquidityfloatAvailable liquidity
holder_countintNumber of token holders