Skip to content

Commit

Permalink
Merge pull request #60 from Polymarket/feat/markets-endpoints-pagination
Browse files Browse the repository at this point in the history
Pagination payload on /markets endpoint
  • Loading branch information
poly-rodr authored Jul 7, 2023
2 parents ec3e515 + 66fdd86 commit 0c2927e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
31 changes: 31 additions & 0 deletions examples/get_markets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

from py_clob_client.client import ClobClient
from py_clob_client.clob_types import ApiCreds
from dotenv import load_dotenv
from py_clob_client.constants import MUMBAI

load_dotenv()


def main():
host = "http://localhost:8080"
key = os.getenv("PK")
creds = ApiCreds(
api_key=os.getenv("CLOB_API_KEY"),
api_secret=os.getenv("CLOB_SECRET"),
api_passphrase=os.getenv("CLOB_PASS_PHRASE"),
)
chain_id = MUMBAI
client = ClobClient(host, key=key, chain_id=chain_id, creds=creds)

print(client.get_markets())
print(client.get_simplified_markets())
print(client.get_sampling_markets())
print(client.get_sampling_simplified_markets())
print(client.get_market("condition_id"))

print("Done!")


main()
43 changes: 43 additions & 0 deletions py_clob_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
IS_ORDER_SCORING,
GET_TICK_SIZE,
ARE_ORDERS_SCORING,
GET_SIMPLIFIED_MARKETS,
GET_MARKETS,
GET_MARKET,
GET_SAMPLING_SIMPLIFIED_MARKETS,
GET_SAMPLING_MARKETS,
)
from .clob_types import (
ApiCreds,
Expand Down Expand Up @@ -480,3 +485,41 @@ def are_orders_scoring(self, params: OrdersScoringParams):
"{}{}".format(self.host, ARE_ORDERS_SCORING), params
)
return get(url, headers=headers)

def get_sampling_markets(self, next_cursor="MA=="):
"""
Get the current sampling markets
"""
return get(
"{}{}?next_cursor={}".format(self.host, GET_SAMPLING_MARKETS, next_cursor)
)

def get_sampling_simplified_markets(self, next_cursor="MA=="):
"""
Get the current sampling simplified markets
"""
return get(
"{}{}?next_cursor={}".format(
self.host, GET_SAMPLING_SIMPLIFIED_MARKETS, next_cursor
)
)

def get_markets(self, next_cursor="MA=="):
"""
Get the current markets
"""
return get("{}{}?next_cursor={}".format(self.host, GET_MARKETS, next_cursor))

def get_simplified_markets(self, next_cursor="MA=="):
"""
Get the current simplified markets
"""
return get(
"{}{}?next_cursor={}".format(self.host, GET_SIMPLIFIED_MARKETS, next_cursor)
)

def get_market(self, condition_id):
"""
Get a market by condition_id
"""
return get("{}{}{}".format(self.host, GET_MARKET, condition_id))
5 changes: 5 additions & 0 deletions py_clob_client/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@
IS_ORDER_SCORING = "/order-scoring"
ARE_ORDERS_SCORING = "/orders-scoring"
GET_TICK_SIZE = "/tick-size"
GET_SAMPLING_SIMPLIFIED_MARKETS = "/sampling-simplified-markets"
GET_SAMPLING_MARKETS = "/sampling-markets"
GET_SIMPLIFIED_MARKETS = "/simplified-markets"
GET_MARKETS = "/markets"
GET_MARKET = "/markets/"

0 comments on commit 0c2927e

Please sign in to comment.