Skip to content

Commit

Permalink
code restructure per kovatch
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnicita committed Aug 1, 2024
1 parent d94a48f commit 9a25723
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 67 deletions.
5 changes: 2 additions & 3 deletions lib/creator.py → application/creator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from polymarket.agents.ai.llm.executor import Executor as Agent
from polymarket.agents.api.polymarket import Polymarket
from polymarket.agents.data.newspaper import Newspaper
from application.executor import Executor as Agent
from connectors.polymarket import Polymarket


class Creator:
Expand Down
7 changes: 1 addition & 6 deletions jobs/scheduler.py → application/cron.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import datetime as dt
import time
from polymarket.agents.lib.trade import Trader

from polymarket.agents.lib.history import record_history
from polymarket.agents.lib.refresh import refresh_trades
from application.trade import Trader

from scheduler import Scheduler
from scheduler.trigger import Monday
Expand All @@ -25,8 +22,6 @@ def __init__(self):
super()
self.trader = Trader()
self.weekly(Monday(), self.trader.one_best_trade)
self.daily(dt.time(hour=12), refresh_trades)
self.hourly(dt.time(minute=30), record_history)


# TODO: add task objects for generalized schedule management infrastructure
6 changes: 3 additions & 3 deletions ai/llm/executor.py → application/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_openai import ChatOpenAI

from ai.llm import prompts
from api.gamma import GammaMarketClient
from polymarket.agents.ai.llm.prompts import Prompter
from application import prompts
from connectors.gamma import GammaMarketClient
from application.prompts import Prompter


class Executor:
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions lib/trade.py → application/trade.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from polymarket.agents.ai.llm.executor import Executor as Agent
from polymarket.agents.api.polymarket import Polymarket
from polymarket.agents.data.newspaper import Newspaper
from application.executor import Executor as Agent
from connectors.polymarket import Polymarket


class Trader:
def __init__(self):
self.polymarket = Polymarket()
self.newspaper = Newspaper()
self.agent = Agent()

def one_best_trade(self):
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion ai/rag/chroma.py → connectors/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
from langchain_community.document_loaders import JSONLoader
from api.gamma import GammaMarketClient

from connectors.gamma import GammaMarketClient


class PolymarketRAG:
Expand Down
10 changes: 5 additions & 5 deletions api/gamma.py → connectors/gamma.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import httpx
import json

from api.types import PolymarketEvent
from api.types import Market
from api.types import ClobReward
from api.types import Tag
from connectors.objects import PolymarketEvent
from connectors.objects import Market
from connectors.objects import ClobReward
from connectors.objects import Tag


class GammaMarketClient:
def __init__(self):
self.gamma_url = "https://gamma-api.polymarket.com"
self.gamma_url = "https://gamma-polymarket.com"
self.gamma_markets_endpoint = self.gamma_url + "/markets"
self.gamma_events_endpoint = self.gamma_url + "/events"

Expand Down
4 changes: 2 additions & 2 deletions data/news/newsapiorg/api.py → connectors/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from newsapi import NewsApiClient

from data.news.types import Article
from connectors.objects import Article


class API:
class News:
def __init__(self) -> None:
self.configs = {
"language": "en",
Expand Down
16 changes: 16 additions & 0 deletions api/types.py → connectors/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,19 @@ class SimpleEvent(BaseModel):
featured: bool
restricted: bool
markets: str


class Source(BaseModel):
id: Optional[str]
name: Optional[str]


class Article(BaseModel):
source: Optional[Source]
author: Optional[str]
title: Optional[str]
description: Optional[str]
url: Optional[str]
urlToImage: Optional[str]
publishedAt: Optional[str]
content: Optional[str]
11 changes: 5 additions & 6 deletions api/polymarket.py → connectors/polymarket.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
from py_clob_client.clob_types import OrderArgs
from py_clob_client.order_builder.constants import BUY

from api.polymarket.types import SimpleMarket
from api.polymarket.types import SimpleEvent
from connectors.objects import SimpleMarket, SimpleEvent

load_dotenv()


class Polymarket:
def __init__(self):
self.gamma_url = "https://gamma-api.polymarket.com"
self.gamma_url = "https://gamma-com"
self.gamma_markets_endpoint = self.gamma_url + "/markets"
self.gamma_events_endpoint = self.gamma_url + "/events"

Expand All @@ -45,8 +44,8 @@ def __init__(self):
self.exchange_address = "0x4bfb41d5b3570defd03c39a9a4d8de6bd8b8982e"
self.neg_risk_exchange_address = "0xC5d563A36AE78145C45a50134d48A1215220f80a"

self._init_api_keys()
self._init_approvals(True)
# self._init_api_keys()
# self._init_approvals(True)

def _init_api_keys(self):
self.client = ClobClient(
Expand Down Expand Up @@ -346,7 +345,7 @@ def test():


def gamma():
url = "https://gamma-api.polymarket.com"
url = "https://gamma-com"
markets_url = url + "/markets"
res = httpx.get(markets_url)
code = res.status_code
Expand Down
1 change: 1 addition & 0 deletions connectors/recorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# record the trades placed here
File renamed without changes.
18 changes: 0 additions & 18 deletions data/news/types.py

This file was deleted.

9 changes: 0 additions & 9 deletions data/newspaper.py

This file was deleted.

2 changes: 0 additions & 2 deletions lib/history.py

This file was deleted.

2 changes: 0 additions & 2 deletions lib/refresh.py

This file was deleted.

12 changes: 6 additions & 6 deletions scripts/python/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import typer
from devtools import pprint

from api.polymarket import Polymarket
from ai.llm import executor, prompts
from ai.rag.chroma import PolymarketRAG
from data.news.newsapiorg.api import API as NewsApiCaller
from jobs.scheduler import TradingAgent
from connectors.polymarket import Polymarket
from application import executor, prompts
from connectors.chroma import PolymarketRAG
from connectors.news import News
from application.cron import TradingAgent

app = typer.Typer()
polymarket = Polymarket()
newsapi_client = NewsApiCaller()
newsapi_client = News()
polymarket_rag = PolymarketRAG()


Expand Down

0 comments on commit 9a25723

Please sign in to comment.