Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,35 @@ or

### REST
```python
from predmarket import KalshiRest, PolymarketRest
from predmarket import UnifiedClient, KalshiRest, PolymarketRest
from httpx import AsyncClient
import asyncio

async def main()
async def main():
async with AsyncClient() as client:

# Initialize fetchers. Each with exact same public-facing API.
# Initialize fetchers for each platform
kalshi = KalshiRest(client)
polymarket = PolymarketRest(client)

# Fetch available Questions (e.g. "When will Elon Musk get to Mars?", known as events in native API)
kalshi_questions = await kalshi.fetch_questions()
polymarket_questions = await polymarket.fetch_questions(limit=10, asc=True) # Polymarket-specific query params
# Initialize the unified client
unified_client = UnifiedClient(kalshi, polymarket)

# Fetch available Questions (e.g. "When will Elon Musk get to Mars?")
questions = await unified_client.fetch_questions()
for question in questions:
print(f"- {question.title} ({question.platform})")

# Fetch available Contracts (e.g. "Will Elon Musk get to Mars before 2026?")
contracts = await unified_client.fetch_contracts()
for contract in contracts:
print(f"- {contract.id} ({contract.platform})")

# Fetch available Contracts (e.g. "Will Elon Musk get to Mars before 2026?", these are individual "solutions" for a given question , Markets in native APIs)
kalshi_contracts = await kalshi.fetch_contracts()
polymarket_contracts = await polymarket.fetch_contracts() # Polymarket-specific query params
if __name__ == "__main__":
asyncio.run(main())
```
### WS
```python
from predmarket import PolymarktWS # Kalshi is NOT currently supported, but will be very solutions
from predmarket import PolymarketWS # Kalshi is NOT currently supported, but will be very solutions

async def main():
async with PolymarketWS.connect() as socket:
Expand Down
4 changes: 4 additions & 0 deletions api.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INFO: Started server process [17125]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
35 changes: 35 additions & 0 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from fastapi import FastAPI
from predmarket.client import UnifiedClient
from predmarket.kalshi.rest import KalshiRest
from predmarket.polymarket.rest import PolymarketRest
import httpx
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

# Configure CORS
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows all origins
allow_credentials=True,
allow_methods=["*"], # Allows all methods
allow_headers=["*"], # Allows all headers
)

@app.get("/questions")
async def get_questions():
async with httpx.AsyncClient() as client:
kalshi = KalshiRest(client)
polymarket = PolymarketRest(client)
unified_client = UnifiedClient(kalshi, polymarket)
questions = await unified_client.fetch_questions()
return questions

@app.get("/contracts")
async def get_contracts():
async with httpx.AsyncClient() as client:
kalshi = KalshiRest(client)
polymarket = PolymarketRest(client)
unified_client = UnifiedClient(kalshi, polymarket)
contracts = await unified_client.fetch_contracts()
return contracts
9 changes: 9 additions & 0 deletions dashboard.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

> dashboard@0.0.0 dev
> vite


VITE v7.2.2 ready in 312 ms

➜ Local: http://localhost:5173/
➜ Network: use --host to expose
24 changes: 24 additions & 0 deletions dashboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
8 changes: 8 additions & 0 deletions dashboard/.vite/deps/_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"hash": "e78552b8",
"configHash": "3cd48f58",
"lockfileHash": "9814d410",
"browserHash": "0247092a",
"optimized": {},
"chunks": {}
}
3 changes: 3 additions & 0 deletions dashboard/.vite/deps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
16 changes: 16 additions & 0 deletions dashboard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# React + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## React Compiler

The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).

## Expanding the ESLint configuration

If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
29 changes: 29 additions & 0 deletions dashboard/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{js,jsx}'],
extends: [
js.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
rules: {
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
},
},
])
13 changes: 13 additions & 0 deletions dashboard/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>dashboard</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
Loading