Fix WebSocket connection header parameter in KalshiWebSocketClient#11
Open
harrodyuan wants to merge 2 commits into
Open
Fix WebSocket connection header parameter in KalshiWebSocketClient#11harrodyuan wants to merge 2 commits into
harrodyuan wants to merge 2 commits into
Conversation
|
mine works with the old version "additional_headers" and not "extra_headers"; as the requirement file now has a fixed version |
…analysis, trading_workflow
There was a problem hiding this comment.
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.pyto support environment selection via env var, add event caching, and demo event searching. - Updated WebSocket connection call signature in
clients.pyand added sample.envtemplate + 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 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 on lines
+79
to
+81
| url = "/trade-api/v2/events" | ||
| if cursor: | ||
| url += f"&cursor={cursor}" |
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 on lines
+146
to
+149
| print(f"\n🔍 Analyzing {len(markets)} markets for opportunities...") | ||
|
|
||
| # Analyze each market | ||
| for i, market in enumerate(markets, 1): |
| # Analyze each market | ||
| for i, market in enumerate(markets, 1): | ||
| if i % 100 == 0: # Progress indicator | ||
| print(f" � Processed {i}/{len(markets)} markets...") |
| # 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.") |
| # ...existing code... | ||
|
|
||
| # Get all orders (pending, open, etc.) | ||
| orders = client.get("/trade-api/v2/portfolio/orders?cursor=EhIKEAnPLuins0i5pLfKfpANAL8aDAiN6d7BBhConqPRAw") |
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 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 |
| """ | ||
|
|
||
| import os | ||
| import json |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.