Skip to content

About

Pascal prediction market exchange API client example in Python.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

Pascal Python Quickstart

This repository is a small, copyable Python quickstart for interacting with Pascal's public API.

It is not the Pascal Python SDK. The SDK will eventually provide a polished package, typed models, stable client APIs, and stronger abstractions. This quickstart should stay close to the wire format so integrators can see exactly how request signing, order placement, and cancellation work.

Public API reference: https://docs.pascal.trade/

Quickstart

Clone the repository and install dependencies:

git clone https://github.com/Pascal-Research-Inc/pascal-python-quickstart.git
cd pascal-python-quickstart
uv sync

Step 1: Hit the public API

Run a read-only market data example:

uv run python examples/01_market_context.py

Step 2: Choose Your Onboarding Path

Before placing orders, choose exactly one onboarding path:

  • Use docs/onboarding_web_app.md if you are connecting a wallet in the Pascal web app and generating a trading key there.
  • Use docs/onboarding_solana_key.md if you already have a Solana private key and want to register the deposit address and trading key from the command line.

Both paths end with the same .env shape:

PASCAL_OWNER_PUBLIC_KEY=<owner-wallet-public-key>
PASCAL_TRADING_PRIVATE_KEY=<authorized-trading-private-key>

Do not use your owner wallet private key as PASCAL_TRADING_PRIVATE_KEY. Order and cancel requests are signed by a separate trading key. The owner wallet key is only for owner-wallet actions such as registering a deposit address, registering trading keys, or withdrawing.

After either onboarding path, verify the configured signer:

uv run pytest tests/test_signing_vectors.py
uv run python examples/07_check_trading_key.py

If you are writing your own signing code, use the test signing vectors to verify its correctness.

Step 3: Place and Cancel an Order

Build a signed order request. By default this prints the JSON request without sending it.

uv run python examples/02_place_order.py

The example defaults to prod, selects the first available market if you do not pass --symbol, uses 123 as the default client_order_id, and builds a one-contract post-only bid. Use --help to see the fields you can override.

Send the order only when you are ready to place the order:

uv run python examples/02_place_order.py --send

Cancel the order by client_order_id:

uv run python examples/03_cancel_order.py --send

The cancel example uses 123 as the default client_order_id, matching the place example. You can also pass --client-order-id or --order-id explicitly.

Orders With Builder Codes

The same order example can attach a builder fee. Set BUILDER_PUBKEY to the builder account's wallet public key, not its trading key. The builder must be a registered Pascal account other than the trader's own account and must have at least $100 of free collateral when the order is placed.

export BUILDER_PUBKEY="YOUR_BUILDER_WALLET_PUBLIC_KEY"
uv run python examples/02_place_order.py \
  --symbol ME_SEN_2026.REP --side BID --price 0.500000 --size 100 \
  --builder-pubkey "$BUILDER_PUBKEY" --builder-fee-rate 0.010000

This prints a signed request without sending it. Add --send only when you are ready to place the order. If all 100 contracts fill at $0.50, the 1% builder rate pays the builder 100 * 0.50 * (1 - 0.50) * 0.01 = $0.25, in addition to any venue fees. Rates are decimal strings, not percentages: 0.010000 is 1%, and the maximum rate is 0.100000 (10%).

In Python, pass builder_pubkey and builder_fee_rate together to signed_place_order_request() (or place_order_message() for raw permit bytes). The request helper adds:

{
  "builder_info": {
    "builder_pubkey": "<builder-wallet-public-key>",
    "builder_fee_rate": "0.010000"
  }
}

Both fields are included in the signed permit, so do not append or change builder_info after signing. No separate builder approval signature is needed. Omit both arguments for orders without a builder. To stop paying a builder on future fills, cancel any open orders naming it and omit the builder on new orders. See the builder code rules.

Agent-Friendly CLI

The repo also includes a small discoverable CLI for agents and operators. From the project root, run the committed ./cli shim or the equivalent uv run cli project script.

./cli
./cli markets
./cli limit-order

Running ./cli lists commands. Running a read-only command such as ./cli positions executes it with .env defaults; use ./cli <command> --help to see that command's arguments and examples. Write commands remain dry-run by default, print the exact request JSON, and only post when --send is present. The CLI covers market lists, top of book, open orders, positions, deposit addresses, fills/transfers/position-resolution history, PnL, simple limit or market orders, and batch order placement from an unsigned JSON array. History-like commands print rows by default; pass --json for the full response.

./cli markets
./cli markets --limit 10
./cli book ME_SEN_2026.REP
./cli orders --symbol ME_SEN_2026.REP
./cli positions
./cli deposit-address
./cli history --limit 5
./cli history --kind fills --symbol ME_SEN_2026.REP --limit 25 --json
./cli pnl
./cli limit-order --symbol ME_SEN_2026.REP --side BID --price 0.450000 --size 1
./cli market-order --symbol ME_SEN_2026.REP --side BID --size 1
./cli batch-orders orders.json
./cli cancel-order --client-order-id 1783261000000 1783261000001

Batch order input is a JSON array of unsigned order specs. Omit client_order_id to generate timestamp-based ids:

[
  {"symbol": "ME_SEN_2026.REP", "side": "BID", "price": "0.450000", "size": 1},
  {"type": "MARKET", "symbol": "ME_SEN_2026.REP", "side": "ASK", "size": 1}
]

More

  • See examples/04_simple_market_maker.py for a looped market maker. It picks a market, fetches account state and the order book once per second, maintains three post-only bid and ask levels sized 1, 3, and 5 contracts, bounds exposure to +/-10 contracts by default, and cancels its open orders when interrupted with Ctrl+C.

  • See examples/05_register_deposit_address.py and examples/06_register_trading_key.py for the owner-wallet flow that registers a deposit address, waits for funding, then registers a trading key.

  • See examples/07_check_trading_key.py for a read-only check that derives the configured trading key's public key and confirms it is active for the configured owner.

  • See examples/08_trade_history_pagination.py for a read-only example that pages through historical trades using the correct cursor parameter.

Trade History Pagination

Historical endpoints return data.next_cursor in the response. To fetch the next older page, send that value back as before_cursor.

GET /api/v1/trades?symbols=ME_SEN_2026.REP&limit=5
# response data.next_cursor = 00000000000000737841:0000000000

GET /api/v1/trades?symbols=ME_SEN_2026.REP&limit=5&before_cursor=00000000000000737841:0000000000

Do not send cursor=<next_cursor>; next_cursor is the response field, while before_cursor is the query parameter for the next older page.

Run the Python example:

uv run python examples/08_trade_history_pagination.py --symbol ME_SEN_2026.REP --limit 5 --pages 3

FAQ

Troubleshooting unauthorized_signer

unauthorized_signer usually means the request's auth.signer is not an active trading key for the request's auth.owner in that environment. First verify that your local signing code still matches Pascal's public API examples:

uv run pytest tests/test_signing_vectors.py

Then confirm your configured private key derives to one of the owner's active trading keys:

uv run python examples/07_check_trading_key.py

If the derived signer is missing from the active trading-key list, use the private key that matches an active trading key, register the configured key with examples/06_register_trading_key.py, or confirm that --env and PASCAL_OWNER_PUBLIC_KEY refer to the same account.

Troubleshooting TRADING_KEY_NAME_ALREADY_USED

A TRADING_KEY_NAME_ALREADY_USED response means the label is already taken; it does not prove that the private key in .env matches that registered signer.

Developers

Run checks:

uv run ruff format --check .
uv run ruff check .
uv run basedpyright
uv run pytest

About

Pascal prediction market exchange API client example in Python.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages