# Quickstart

> Install stx-python, add an API key, and make your first calls.

Source: https://docs.stxapp.io/sdks/python/quickstart/

From nothing to reading markets, placing an order and streaming your account.

:::note
Build against a **demo** exchange. Demo balances are not real money; production is.
:::

## Prerequisites

- Python 3.9 or newer (`python3 --version`)
- An API key for the exchange you are building against: a key ID and an Ed25519 private key. [Environments](/environments/) lists the exchanges and where to get a key.

## Walkthrough

  
#### Install the SDK

    ```bash
    pip install stx-python
    ```
  

  
#### Save your key

    Save the private key as a file, for example `~/.stx/demo.pem`, then create `~/.stx/credentials` with a `[default]` profile. Set `region` and `env` to the exchange the key belongs to; the values are on [Environments](/sdks/python/environments/).

    ```ini
    [default]
    region   = us
    env      = demo
    key_id   = your-key-id
    key_file = ~/.stx/demo.pem
    ```

    Environment variables and keyword arguments work too; see [Authentication](/sdks/python/authentication/).
  

  
#### Make your first call

    ```python hello_stx.py
    from stx import STX

    with STX() as client:
        me = client.me()
        print("user", me.user_id, "account", me.account_id, "scope", me.scope)
    ```

    `scope` is `read_only` or `read_write`; placing orders needs `read_write`.
  

  
#### Read some markets

    ```python markets.py
    from stx import STX

    with STX() as client:
        page = client.markets(status="open", limit=5)
        for m in page:
            bid = m.bids[0].price if m.bids else "-"
            offer = m.offers[0].price if m.offers else "-"
            print(f"{m.symbol:<50} bid {bid:>8} offer {offer:>8} pays {m.max_price}")
        print("next cursor:", page.cursor)
    ```

    Prices are dollar strings (`"0.4200"`). A winning contract pays the market's `max_price`.
  

  
#### Place and cancel an order

    ```python order.py
    from stx import STX

    with STX() as client:
        market = next(
            m
            for m in client.iter_markets(
                status="open", trading=True, sort_by="event_start", sort_direction="desc"
            )
            if m.event_status == "scheduled"
        )
        order = client.place_order(market.market_id, "buy", "limit", price="0.01", quantity="1")
        print("placed", order.id, order.status, order.price, order.quantity)
        print("cancel", client.cancel_order(order.id).status)
    ```

    A 1-cent buy for one contract, cancelled straight away.
  

  
#### Stream your orders

    ```python stream.py
    import asyncio

    from stx import AsyncSTX

    async def main():
        async with AsyncSTX() as client:
            async with client.websocket() as ws:
                orders = await ws.orders()
                snapshot = await orders.wait_snapshot()
                print("open orders:", len(snapshot["all_orders"]["orders"]))

    asyncio.run(main())
    ```
  

## Next

- [Trading](/sdks/python/trading/): batch orders, cancel many or all, expiration, cancel-on-disconnect
- [WebSockets](/sdks/python/websockets/): every channel
- [Errors & retries](/sdks/python/errors-and-retries/)
