Skip to content

Commit

Permalink
Add pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
evangriffiths committed Feb 8, 2024
1 parent 614f4b3 commit db0013c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
2 changes: 1 addition & 1 deletion prediction_market_agent/data_models/market_data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class ManifoldMarket(BaseModel):
creatorUsername: str
isResolved: bool
lastBetTime: datetime
lastCommentTime:t.Optional[datetime]
lastCommentTime: t.Optional[datetime] = None # Not always present
lastUpdatedTime: datetime
mechanism: str
outcomeType: str
Expand Down
34 changes: 23 additions & 11 deletions prediction_market_agent/deploy/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,42 @@ def deploy(
market_type: MarketType,
deployment_type: DeploymentType,
api_keys: APIKeys,
timeout: int,
place_bet: bool,
) -> None:
if deployment_type == DeploymentType.GOOGLE_CLOUD:
# Deploy to Google Cloud Functions, and use Google Cloud Scheduler to run the function
raise NotImplementedError("TODO not currently possible programatically")
raise NotImplementedError(
"TODO not currently possible via DeployableAgent class"
)
elif deployment_type == DeploymentType.LOCAL:
start_time = time.time()
while True:
self.run(market_type, api_keys)
self.run(
market_type=market_type, api_keys=api_keys, place_bet=place_bet
)
time.sleep(sleep_time)
if time.time() - start_time > timeout:
break

def run(self, market_type: MarketType, api_keys: APIKeys) -> None:
def run(
self, market_type: MarketType, api_keys: APIKeys, place_bet: bool = True
) -> None:
available_markets = [
x.to_agent_market() for x in get_binary_markets(market_type)
]
markets = self.pick_markets(available_markets)
for market in markets:
result = self.answer_binary_market(market)
print(f"Placing bet on {market} with result {result}")
place_bet(
market=market.original_market,
amount=get_tiny_bet(market_type),
outcome=result,
keys=api_keys,
omen_auto_deposit=True,
)
if place_bet:
print(f"Placing bet on {market} with result {result}")
place_bet(
market=market.original_market,
amount=get_tiny_bet(market_type),
outcome=result,
keys=api_keys,
omen_auto_deposit=True,
)

@classmethod
def get_gcloud_fname(cls, market_type: MarketType) -> str:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import random

from prediction_market_agent.data_models.market_data_models import AgentMarket
from prediction_market_agent.deploy.deploy import DeployableAgent, DeploymentType
from prediction_market_agent.markets.all_markets import MarketType
from prediction_market_agent.utils import get_keys


def test_local_deployment():
class DeployableCoinFlipAgent(DeployableAgent):
def pick_markets(self, markets: list[AgentMarket]) -> list[AgentMarket]:
if len(markets) > 1:
return random.sample(markets, 1)
return markets

def answer_binary_market(self, market: AgentMarket) -> bool:
return random.choice([True, False])

agent = DeployableCoinFlipAgent()
agent.deploy(
sleep_time=0.001,
market_type=MarketType.MANIFOLD,
deployment_type=DeploymentType.LOCAL,
api_keys=get_keys(),
timeout=0.01,
place_bet=False,
)

0 comments on commit db0013c

Please sign in to comment.