From a297c6aceefa3a88cc8e093f8ee3e7bb2606f9cd Mon Sep 17 00:00:00 2001 From: Roy Jones Date: Mon, 15 Dec 2025 21:00:58 +0100 Subject: [PATCH 1/2] docs: add env.sample for kalshi starter Added env.sample file with an example set of environment variables for the starter code. --- env.sample | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 env.sample diff --git a/env.sample b/env.sample new file mode 100644 index 0000000..bfe0669 --- /dev/null +++ b/env.sample @@ -0,0 +1,8 @@ +# Example environment variables for kalshi-starter-code-python + +# API credentials for Kalshi +KALSHI_API_KEY=your_api_key_here +KALSHI_API_SECRET=your_api_secret_here + +# Environment: "demo" or "prod" +KALSHI_ENV=demo From 957f615921b22f7fd3d7e3f071d505c6f818ef05 Mon Sep 17 00:00:00 2001 From: Roy Jones Date: Mon, 22 Dec 2025 21:07:34 +0100 Subject: [PATCH 2/2] feat: add basic list markets example script Adds a small example script showing how to initialize the official SDK and print a few active markets. --- examples/list_markets_basic.py | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 examples/list_markets_basic.py diff --git a/examples/list_markets_basic.py b/examples/list_markets_basic.py new file mode 100644 index 0000000..1f1ac30 --- /dev/null +++ b/examples/list_markets_basic.py @@ -0,0 +1,50 @@ +""" +Basic example script for listing a few active Kalshi markets. + +Prerequisites: + - Install the official SDK: + pip install kalshi-python + - Set the following environment variables: + KALSHI_API_KEY_ID + KALSHI_PRIVATE_KEY_PATH + +Usage: + python examples/list_markets_basic.py +""" + +import os +from kalshi_python import Configuration, KalshiClient # type: ignore[import-not-found] + + +def build_client() -> KalshiClient: + api_key_id = os.environ.get("KALSHI_API_KEY_ID") + private_key_path = os.environ.get("KALSHI_PRIVATE_KEY_PATH") + + if not api_key_id or not private_key_path: + raise RuntimeError( + "Missing KALSHI_API_KEY_ID or KALSHI_PRIVATE_KEY_PATH environment variables" + ) + + with open(private_key_path, "r", encoding="utf-8") as f: + private_key_pem = f.read() + + config = Configuration( + host="https://api.elections.kalshi.com/trade-api/v2", + ) + config.api_key_id = api_key_id + config.private_key_pem = private_key_pem + + return KalshiClient(config) + + +def main() -> None: + client = build_client() + markets = client.markets_api.get_markets(limit=5) # type: ignore[attr-defined] + + print("First 5 markets:") + for market in markets.markets: # type: ignore[attr-defined] + print(f"- {market.ticker} | {market.title}") + + +if __name__ == "__main__": + main()