Skip to content

Fix WebSocket connection header parameter in KalshiWebSocketClient#11

Open
harrodyuan wants to merge 2 commits into
Kalshi:mainfrom
harrodyuan:main
Open

Fix WebSocket connection header parameter in KalshiWebSocketClient#11
harrodyuan wants to merge 2 commits into
Kalshi:mainfrom
harrodyuan:main

Conversation

@harrodyuan
Copy link
Copy Markdown

Fixes a critical issue in KalshiWebSocketClient caused by an upstream change in the websockets package, which now requires the extra_headers parameter to be explicitly passed.

Without this fix, the WebSocket connection fails and the example code cannot run. This patch updates the connect call to restore compatibility.

Tested locally and confirmed working.

@rmojgani
Copy link
Copy Markdown

rmojgani commented Dec 26, 2025

mine works with the old version "additional_headers" and not "extra_headers"; as the requirement file now has a fixed version

Copilot AI review requested due to automatic review settings June 3, 2026 05:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds several helper scripts and docs to interact with the Kalshi API (fetch open events/markets, place orders) and expands main.py with caching + event search helpers.

Changes:

  • Added CLI scripts for scanning open markets/events and placing orders in production.
  • Updated main.py to support environment selection via env var, add event caching, and demo event searching.
  • Updated WebSocket connection call signature in clients.py and added sample .env template + guide.

Reviewed changes

Copilot reviewed 8 out of 26 changed files in this pull request and generated 17 comments.

Show a summary per file
File Description
trading_workflow/Comprehensive_Guide.md Adds an authorization-centric usage guide for the Kalshi API/client.
requirements.txt Removes pinned Python dependencies (currently leaving no install spec).
quick_open_markets.py Adds a production-only script to list/search open events.
place_order.py Adds an interactive production order-placement script with RFQ/quote logic and fallbacks.
open_events.json Adds a large JSON snapshot of open events.
main.py Adds caching helpers, open-event fetching, event helper demo, and env selection via env var.
fetch_open_markets_fixed.py Adds a more complete open-events → markets scanner and opportunity scoring.
fetch_open_markets.py Adds an open markets scanner (currently contains a runtime error).
env.example Adds an example env file for production credentials.
clients.py Updates WebSocket connect call to use extra_headers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread main.py
Comment on lines +12 to +15
# env = clearEnvironment.DEMO # toggle environment her
env = Environment.PROD if os.getenv('USE_DEMO_ENVIRONMENT', 'False').lower() == 'false' else Environment.DEMO

print(f"Using environment: {env.value}")
Comment thread main.py
Comment on lines +79 to +81
url = "/trade-api/v2/events"
if cursor:
url += f"&cursor={cursor}"
Comment thread fetch_open_markets.py
Comment on lines +137 to +141
# Get all open events first
events = get_open_events(client)

if not markets:
print("❌ No open markets found")
Comment thread fetch_open_markets.py
Comment on lines +146 to +149
print(f"\n🔍 Analyzing {len(markets)} markets for opportunities...")

# Analyze each market
for i, market in enumerate(markets, 1):
Comment thread fetch_open_markets.py
# Analyze each market
for i, market in enumerate(markets, 1):
if i % 100 == 0: # Progress indicator
print(f" � Processed {i}/{len(markets)} markets...")
Comment thread place_order.py
# If RFQ already exists, that means we already have an open RFQ!
if error['code'] == 'already_exists':
print(f"✅ RFQ already exists for this market - this means it was created successfully!")
print(f"� The RFQ creation probably succeeded on a previous attempt.")
Comment thread main.py
# ...existing code...

# Get all orders (pending, open, etc.)
orders = client.get("/trade-api/v2/portfolio/orders?cursor=EhIKEAnPLuins0i5pLfKfpANAL8aDAiN6d7BBhConqPRAw")
Comment thread open_events.json
Comment on lines +1 to +5
{
"KXNEWPOPE-70": "Who will the next Pope be?",
"KXWARMING-50": "Will the world pass 2 degrees Celsius over pre-industrial levels before 2050?",
"KXMARSVRAIL-50": "Will a human land on Mars before California starts high-speed rail?",
"KXERUPTSUPER-0": "Will a supervolcano erupt before 2050?",
Comment thread env.example
Comment on lines +6 to +9
PROD_KEYID=your_api_key_id_here

# The absolute path to your private key .pem file
PROD_KEYFILE=/path/to/your/private_key.pem
Comment thread quick_open_markets.py
"""

import os
import json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants