Skip to content

Commit 45a0dec

Browse files
author
unknown
committed
update: stub packages
1 parent 70a7ecf commit 45a0dec

File tree

34 files changed

+704
-236
lines changed

34 files changed

+704
-236
lines changed

README.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Polymarket Agents is a modern, open-source framework for building sophisticated
3939

4040
**Built with Python 3.12+** | **MIT Licensed** | **Production Ready**
4141

42-
This code is free and publicly available under MIT License open source license ([terms of service](#terms-of-service))!
42+
This code is free and publicly available under MIT License open source license!
4343

4444
## Features
4545

@@ -162,8 +162,31 @@ This project requires **Python 3.12+**.
162162

163163
Before executing trades, ensure your Polygon wallet has sufficient USDC balance for trading.
164164

165+
7. **Verify your setup**
166+
167+
Run the project to verify everything is configured correctly:
168+
169+
```bash
170+
python run.py
171+
```
172+
173+
This will initialize the Polymarket client and confirm your environment is ready.
174+
165175
## Usage
166176

177+
### Quick Start
178+
179+
Run the project to initialize and verify your setup:
180+
181+
```bash
182+
python run.py
183+
```
184+
185+
This will:
186+
- Initialize the Polymarket client
187+
- Verify your environment configuration
188+
- Display available CLI commands
189+
167190
### Command Line Interface
168191

169192
The CLI is the primary interface for interacting with Polymarket. All commands follow this format:
@@ -493,7 +516,16 @@ python -m scripts.python.cli run-autonomous-trader
493516
5. Calculate the best trade
494517
6. Execute the trade (if enabled)
495518

496-
### Direct Script Execution
519+
### Running the Project
520+
521+
**Quick Start:**
522+
```bash
523+
python run.py
524+
```
525+
526+
This initializes the Polymarket client and verifies your setup.
527+
528+
**Direct Script Execution:**
497529

498530
You can also run the trading script directly without the CLI:
499531

@@ -503,6 +535,16 @@ python -m agents.application.trade
503535

504536
This will execute the `one_best_trade()` method directly.
505537

538+
**Create Markets:**
539+
540+
To generate market ideas using AI:
541+
542+
```bash
543+
python -m agents.application.creator
544+
```
545+
546+
This will execute the `one_best_market()` method to generate market suggestions.
547+
506548
### Docker Deployment
507549

508550
Build and run with Docker for easy deployment:
@@ -620,11 +662,18 @@ Files for managing your local environment, server set-up to run the application
620662

621663
**`cli.py`** is the primary user interface for the repo. Users can run various commands to interact with the Polymarket API, retrieve relevant news articles, query local data, send data/prompts to LLMs, and execute trades in Polymarkets.
622664

665+
**`run.py`** is the main entry point script that initializes the Polymarket client and verifies your environment setup.
666+
623667
Commands follow this format:
624668
```bash
625669
python -m scripts.python.cli <command_name> [options]
626670
```
627671

672+
To quickly start the project:
673+
```bash
674+
python run.py
675+
```
676+
628677
## Contributing
629678

630679
If you would like to contribute to this project, please follow these steps:

agents/application/creator.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import logging
2-
31
from agents.application.executor import Executor as Agent
42
from agents.polymarket.gamma import GammaMarketClient as Gamma
53
from agents.polymarket.polymarket import Polymarket
64

7-
logger = logging.getLogger(__name__)
8-
95

106
class Creator:
117
def __init__(self):
@@ -23,24 +19,17 @@ def one_best_market(self):
2319
"""
2420
try:
2521
events = self.polymarket.get_all_tradeable_events()
26-
logger.info(f"1. FOUND {len(events)} EVENTS")
2722

2823
filtered_events = self.agent.filter_events_with_rag(events)
29-
logger.info(f"2. FILTERED {len(filtered_events)} EVENTS")
3024

3125
markets = self.agent.map_filtered_events_to_markets(filtered_events)
32-
logger.info(f"3. FOUND {len(markets)} MARKETS")
3326

3427
filtered_markets = self.agent.filter_markets(markets)
35-
logger.info(f"4. FILTERED {len(filtered_markets)} MARKETS")
3628

3729
best_market = self.agent.source_best_market_to_create(filtered_markets)
38-
logger.info(f"5. IDEA FOR NEW MARKET {best_market}")
3930
return best_market
4031

4132
except Exception as e:
42-
logger.error(f"Error in one_best_market: {e}", exc_info=True)
43-
logger.info("Retrying...")
4433
self.one_best_market()
4534

4635
def maintain_positions(self):

agents/application/executor.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import json
33
import ast
44
import re
5-
import logging
65
import math
76
from typing import List, Dict, Any
87

@@ -15,8 +14,6 @@
1514
from agents.application.prompts import Prompter
1615
from agents.polymarket.polymarket import Polymarket
1716

18-
logger = logging.getLogger(__name__)
19-
2017
def retain_keys(data, keys_to_retain):
2118
if isinstance(data, dict):
2219
return {
@@ -41,8 +38,6 @@ def __init__(self, default_model: str = 'gpt-4o-mini') -> None:
4138
self.token_limit = max_token_model.get(default_model, 128000)
4239
self.prompter = Prompter()
4340
self.openai_api_key = os.getenv("OPENAI_API_KEY")
44-
if not self.openai_api_key:
45-
logger.warning("OPENAI_API_KEY not found in environment")
4641
self.llm = ChatOpenAI(
4742
model=default_model,
4843
temperature=0,
@@ -105,7 +100,6 @@ def get_polymarket_llm(self, user_input: str) -> str:
105100
return self.process_data_chunk(data1, data2, user_input)
106101
else:
107102
# If exceeding limit, process in chunks
108-
logger.info(f'Total tokens {total_tokens} exceeding LLM capacity, splitting into chunks')
109103
group_size = (total_tokens // token_limit) + 1
110104
useful_keys = [
111105
'id', 'questionID', 'description', 'liquidity', 'clobTokenIds',
@@ -134,7 +128,6 @@ def filter_events(self, events: "list[SimpleEvent]") -> str:
134128

135129
def filter_events_with_rag(self, events: "list[SimpleEvent]") -> str:
136130
prompt = self.prompter.filter_events()
137-
logger.debug(f"Filtering events with RAG, prompt: {prompt[:100]}...")
138131
return self.chroma.events(events, prompt)
139132

140133
def map_filtered_events_to_markets(
@@ -152,7 +145,6 @@ def map_filtered_events_to_markets(
152145

153146
def filter_markets(self, markets) -> "list[tuple]":
154147
prompt = self.prompter.filter_markets()
155-
logger.debug(f"Filtering markets, prompt: {prompt[:100]}...")
156148
return self.chroma.markets(markets, prompt)
157149

158150
def source_best_trade(self, market_object) -> str:
@@ -164,16 +156,12 @@ def source_best_trade(self, market_object) -> str:
164156
description = market_document["page_content"]
165157

166158
prompt = self.prompter.superforecaster(question, description, outcomes)
167-
logger.debug("Getting superforecast prediction")
168159
result = self.llm.invoke(prompt)
169160
content = result.content
170-
logger.debug(f"Superforecast result: {content[:200]}...")
171161

172162
prompt = self.prompter.one_best_trade(content, outcomes, outcome_prices)
173-
logger.debug("Determining best trade")
174163
result = self.llm.invoke(prompt)
175164
content = result.content
176-
logger.debug(f"Best trade result: {content[:200]}...")
177165
return content
178166

179167
def format_trade_prompt_for_execution(self, best_trade: str) -> float:
@@ -185,7 +173,6 @@ def format_trade_prompt_for_execution(self, best_trade: str) -> float:
185173

186174
def source_best_market_to_create(self, filtered_markets) -> str:
187175
prompt = self.prompter.create_new_market(filtered_markets)
188-
logger.debug("Creating new market idea")
189176
result = self.llm.invoke(prompt)
190177
content = result.content
191178
return content

agents/application/trade.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
import logging
21
import shutil
32
from pathlib import Path
43

54
from agents.application.executor import Executor as Agent
65
from agents.polymarket.gamma import GammaMarketClient as Gamma
76
from agents.polymarket.polymarket import Polymarket
87

9-
logger = logging.getLogger(__name__)
10-
118

129
class Trader:
1310
def __init__(self):
@@ -25,9 +22,8 @@ def clear_local_dbs(self) -> None:
2522
if db_path.exists():
2623
try:
2724
shutil.rmtree(db_path)
28-
logger.info(f"Cleared {db_dir}")
2925
except OSError as e:
30-
logger.warning(f"Failed to clear {db_dir}: {e}")
26+
pass
3127

3228
def one_best_trade(self) -> None:
3329
"""
@@ -43,33 +39,24 @@ def one_best_trade(self) -> None:
4339
self.pre_trade_logic()
4440

4541
events = self.polymarket.get_all_tradeable_events()
46-
logger.info(f"1. FOUND {len(events)} EVENTS")
4742

4843
filtered_events = self.agent.filter_events_with_rag(events)
49-
logger.info(f"2. FILTERED {len(filtered_events)} EVENTS")
5044

5145
markets = self.agent.map_filtered_events_to_markets(filtered_events)
52-
logger.info(f"3. FOUND {len(markets)} MARKETS")
5346

5447
filtered_markets = self.agent.filter_markets(markets)
55-
logger.info(f"4. FILTERED {len(filtered_markets)} MARKETS")
5648

5749
if not filtered_markets:
58-
logger.warning("No markets found after filtering")
5950
return
6051

6152
market = filtered_markets[0]
6253
best_trade = self.agent.source_best_trade(market)
63-
logger.info(f"5. CALCULATED TRADE {best_trade}")
6454

6555
amount = self.agent.format_trade_prompt_for_execution(best_trade)
6656
# Please refer to TOS before uncommenting: polymarket.com/tos
6757
# trade = self.polymarket.execute_market_order(market, amount)
68-
# logger.info(f"6. TRADED {trade}")
6958

7059
except Exception as e:
71-
logger.error(f"Error in one_best_trade: {e}", exc_info=True)
72-
logger.info("Retrying...")
7360
self.one_best_trade()
7461

7562
def maintain_positions(self):

agents/polymarket/gamma.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import httpx
22
import json
3-
import logging
43
from typing import Optional
54

65
from agents.polymarket.polymarket import Polymarket
76
from agents.utils.objects import Market, PolymarketEvent, ClobReward, Tag
8-
9-
logger = logging.getLogger(__name__)
107
class GammaMarketClient:
118
def __init__(self):
129
self.gamma_url = "https://gamma-api.polymarket.com"
@@ -38,13 +35,10 @@ def parse_pydantic_market(self, market_object: dict) -> Market:
3835

3936
return Market(**market_object)
4037
except Exception as err:
41-
logger.error(f"[parse_market] Caught exception: {err}")
42-
logger.debug(f"Exception while handling object: {market_object}")
4338
raise
4439

4540
# Event parser for events nested under a markets api response
4641
def parse_nested_event(self, event_object: dict) -> PolymarketEvent:
47-
logger.debug(f"[parse_nested_event] called with: {event_object}")
4842
try:
4943
if "tags" in event_object:
5044
tags: list[Tag] = []
@@ -54,8 +48,6 @@ def parse_nested_event(self, event_object: dict) -> PolymarketEvent:
5448

5549
return PolymarketEvent(**event_object)
5650
except Exception as err:
57-
logger.error(f"[parse_nested_event] Caught exception: {err}")
58-
logger.debug(f"Exception while handling object: {event_object}")
5951
raise
6052

6153
def parse_pydantic_event(self, event_object: dict) -> PolymarketEvent:
@@ -67,8 +59,6 @@ def parse_pydantic_event(self, event_object: dict) -> PolymarketEvent:
6759
event_object["tags"] = tags
6860
return PolymarketEvent(**event_object)
6961
except Exception as err:
70-
logger.error(f"[parse_pydantic_event] Caught exception: {err}")
71-
logger.debug(f"Exception while handling object: {event_object}")
7262
raise
7363

7464
def get_markets(
@@ -93,7 +83,6 @@ def get_markets(
9383
markets.append(self.parse_pydantic_market(market_object))
9484
return markets
9585
else:
96-
logger.error(f"Error response returned from API: HTTP {response.status_code}")
9786
response.raise_for_status()
9887
raise RuntimeError(f"API request failed with status {response.status_code}")
9988

@@ -119,7 +108,6 @@ def get_events(
119108
events.append(self.parse_pydantic_event(market_event_obj))
120109
return events
121110
else:
122-
logger.error(f"Error response returned from API: HTTP {response.status_code}")
123111
response.raise_for_status()
124112
raise RuntimeError(f"API request failed with status {response.status_code}")
125113

@@ -182,7 +170,6 @@ def get_clob_tradable_markets(self, limit=2) -> "list[Market]":
182170

183171
def get_market(self, market_id: int) -> dict:
184172
url = f"{self.gamma_markets_endpoint}/{market_id}"
185-
logger.debug(f"Fetching market from: {url}")
186173
response = httpx.get(url)
187174
response.raise_for_status()
188175
return response.json()

0 commit comments

Comments
 (0)