Skip to content

Commit

Permalink
Remove apis from args
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii committed Feb 9, 2024
1 parent d9c559b commit cdf1bfd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
3 changes: 1 addition & 2 deletions examples/cloud_deployment/gcp/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from prediction_market_agent_tooling.markets.data_models import AgentMarket
from prediction_market_agent_tooling.deploy.agent import DeployableAgent
from prediction_market_agent_tooling.markets.markets import MarketType
from prediction_market_agent_tooling.config import APIKeys


class DeployableCoinFlipAgent(DeployableAgent):
Expand All @@ -20,5 +19,5 @@ def answer_binary_market(self, market: AgentMarket) -> bool:

@functions_framework.http
def main(request: Request) -> str:
DeployableCoinFlipAgent().run(market_type=MarketType.MANIFOLD, api_keys=APIKeys())
DeployableCoinFlipAgent().run(market_type=MarketType.MANIFOLD)
return "Success"
10 changes: 2 additions & 8 deletions prediction_market_agent_tooling/deploy/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def deploy(
self,
market_type: MarketType,
deployment_type: DeploymentType,
api_keys: APIKeys,
sleep_time: float,
timeout: float,
place_bet: bool,
Expand All @@ -50,16 +49,12 @@ def deploy(
elif deployment_type == DeploymentType.LOCAL:
start_time = time.time()
while True:
self.run(
market_type=market_type, api_keys=api_keys, _place_bet=place_bet
)
self.run(market_type=market_type, _place_bet=place_bet)
time.sleep(sleep_time)
if time.time() - start_time > timeout:
break

def run(
self, market_type: MarketType, api_keys: APIKeys, _place_bet: bool = True
) -> None:
def run(self, market_type: MarketType, _place_bet: bool = True) -> None:
available_markets = [
x.to_agent_market() for x in get_binary_markets(market_type)
]
Expand All @@ -72,7 +67,6 @@ def run(
market=market.original_market,
amount=get_tiny_bet(market_type),
outcome=result,
keys=api_keys,
omen_auto_deposit=True,
)

Expand Down
5 changes: 3 additions & 2 deletions prediction_market_agent_tooling/markets/manifold.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import typing as t
from prediction_market_agent_tooling.gtypes import Mana
from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.markets.data_models import (
ManifoldMarket,
)
Expand Down Expand Up @@ -43,7 +44,7 @@ def pick_binary_market() -> ManifoldMarket:
return get_manifold_binary_markets(1)[0]


def place_bet(amount: Mana, market_id: str, outcome: bool, api_key: str) -> None:
def place_bet(amount: Mana, market_id: str, outcome: bool) -> None:
outcome_str = "YES" if outcome else "NO"
url = "https://api.manifold.markets/v0/bet"
params = {
Expand All @@ -53,7 +54,7 @@ def place_bet(amount: Mana, market_id: str, outcome: bool, api_key: str) -> None
}

headers = {
"Authorization": f"Key {api_key}",
"Authorization": f"Key {APIKeys().manifold_api_key}",
"Content-Type": "application/json",
}
response = requests.post(url, json=params, headers=headers)
Expand Down
12 changes: 4 additions & 8 deletions prediction_market_agent_tooling/markets/markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,19 @@ def get_bet_amount(amount: Decimal, market_type: MarketType) -> BetAmount:
@t.overload
def get_binary_markets(
market_type: t.Literal[MarketType.MANIFOLD],
) -> list[manifold.ManifoldMarket]:
...
) -> list[manifold.ManifoldMarket]: ...


@t.overload
def get_binary_markets(
market_type: t.Literal[MarketType.OMEN],
) -> list[omen.OmenMarket]:
...
) -> list[omen.OmenMarket]: ...


@t.overload
def get_binary_markets(
market_type: MarketType,
) -> t.Union[list[manifold.ManifoldMarket], list[omen.OmenMarket]]:
...
) -> t.Union[list[manifold.ManifoldMarket], list[omen.OmenMarket]]: ...


def get_binary_markets(
Expand All @@ -65,10 +62,10 @@ def get_binary_markets(
def place_bet(
market: t.Union[omen.OmenMarket, manifold.ManifoldMarket],
outcome: bool,
keys: APIKeys,
omen_auto_deposit: bool,
amount: BetAmount,
) -> None:
keys = APIKeys()
if isinstance(market, manifold.ManifoldMarket):
if amount.currency != Currency.Mana:
raise ValueError(f"Manifold bets are made in Mana. Got {amount.currency}.")
Expand All @@ -77,7 +74,6 @@ def place_bet(
amount=check_not_none(amount_mana),
market_id=market.id,
outcome=outcome,
api_key=check_not_none(keys.manifold_api_key),
)
elif isinstance(market, omen.OmenMarket):
if amount.currency != Currency.xDai:
Expand Down
2 changes: 0 additions & 2 deletions tests/deploy/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
DeploymentType,
)
from prediction_market_agent_tooling.markets.markets import MarketType
from prediction_market_agent_tooling.config import APIKeys


def test_local_deployment() -> None:
Expand All @@ -24,7 +23,6 @@ def answer_binary_market(self, market: AgentMarket) -> bool:
sleep_time=0.001,
market_type=MarketType.MANIFOLD,
deployment_type=DeploymentType.LOCAL,
api_keys=APIKeys(),
timeout=0.01,
place_bet=False,
)
3 changes: 1 addition & 2 deletions tests/markets/test_manifold.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from tests.utils import RUN_PAID_TESTS
from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.markets import manifold
from prediction_market_agent_tooling.gtypes import mana_type

Expand All @@ -9,4 +8,4 @@
def test_manifold() -> None:
market = manifold.pick_binary_market()
print("Placing bet on market:", market.question)
manifold.place_bet(mana_type(0.01), market.id, True, APIKeys().manifold_api_key)
manifold.place_bet(mana_type(0.01), market.id, True)

0 comments on commit cdf1bfd

Please sign in to comment.