Prerequisites
Before you begin, you’ll need:- A Kalshi account with API access configured
- Python with the
requests
andcryptography
libraries installed - Your authentication functions set up (see our authentication guide)
This guide assumes you have the authentication code from our authentication guide, including the
get()
function for making authenticated requests.Step 1: Find an Open Market
First, let’s find an open market to trade on.Step 2: Place a Buy Order
Now let’s place an order to buy 1 YES contract for 1 cent (limit order). We’ll use aclient_order_id
to deduplicate orders - this allows you to identify duplicate orders before receiving the server-generated order_id
in the response.
Complete Example Script
Here’s a complete script that creates your first order:Important Notes
Client Order ID
Theclient_order_id
field is crucial for order deduplication:
- Generate a unique ID (like UUID4) for each order before submission
- If network issues occur, you can resubmit with the same
client_order_id
- The API will reject duplicate submissions, preventing accidental double orders
- Store this ID locally to track orders before receiving the server’s
order_id
Error Handling
Common errors and how to handle them:401 Unauthorized
: Check your API keys and signature generation400 Bad Request
: Verify your order parameters (price must be 1-99 cents)409 Conflict
: Order with thisclient_order_id
already exists429 Too Many Requests
: You’ve hit the rate limit - slow down your requests
Next Steps
Now that you’ve created your first order, you can:- Check order status using the
/portfolio/orders/{order_id}
endpoint - List all your orders with
/portfolio/orders
- Amend your order price or quantity using PUT
/portfolio/orders/{order_id}
- Cancel orders using DELETE
/portfolio/orders/{order_id}
- Implement WebSocket connections for real-time updates
- Build automated trading strategies