diff --git a/examples/get_markets.py b/examples/get_markets.py new file mode 100644 index 0000000..1ca0a24 --- /dev/null +++ b/examples/get_markets.py @@ -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() diff --git a/py_clob_client/client.py b/py_clob_client/client.py index 8b2c896..8352455 100644 --- a/py_clob_client/client.py +++ b/py_clob_client/client.py @@ -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, @@ -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)) diff --git a/py_clob_client/endpoints.py b/py_clob_client/endpoints.py index e69e41b..2d735ba 100644 --- a/py_clob_client/endpoints.py +++ b/py_clob_client/endpoints.py @@ -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/"